
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <iostream>
#include <time.h> 
#include <random>

using namespace std;

//       nvidia http://developer.download.nvidia.com/assets/cuda/files/reduction.pdf
//       ,     
__global__ void piCalcKernel(int *d_odata, double* a, double* b, int size)
{
    __shared__ int sdata[1024];
    int tid = threadIdx.x;
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    sdata[tid] = ((a[i] * a[i] + b[i] * b[i]) < 1 ? 1 : 0);

    __syncthreads();
    for (int j = blockDim.x/2; j > 0; j>>=1)
    {
        if (tid < j)
        {
            sdata[tid] += sdata[tid + j];
        }
        __syncthreads();
    }
    if (tid == 0) d_odata[blockIdx.x] = sdata[0];
}
// Helper function for using CUDA to add vectors in parallel.
cudaError_t piCalcWithCuda(int* odata, double* a, double* b, int size)
{
    double* dev_a = 0;
    double* dev_b = 0;
    cudaError_t cudaStatus;
    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaStatus = cudaSetDevice(0);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?");
    }

    // Allocate GPU buffers for three vectors (two input, one output)    .
    cudaStatus = cudaMalloc((void**)&dev_a, size * sizeof(double));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
    }

    cudaStatus = cudaMalloc((void**)&dev_b, size * sizeof(double));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
    }

    int* dev_odata = 0;
    cudaStatus = cudaMalloc((void**)&dev_odata, (size / 1024) * sizeof(int));
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMalloc failed!");
    }

    // Copy input vectors from host memory to GPU buffers.
    cudaStatus = cudaMemcpy(dev_a, a, size * sizeof(double), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
    }

    cudaStatus = cudaMemcpy(dev_b, b, size * sizeof(double), cudaMemcpyHostToDevice);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
    }


    dim3 blockSize = dim3(1024, 1, 1);
    dim3 gridSize = dim3(size/1024, 1, 1);

    // Launch a kernel on the GPU with one thread for each element.
    piCalcKernel <<<gridSize, blockSize >>> (dev_odata, dev_a, dev_b, size);
    // Check for any errors launching the kernel
    cudaStatus = cudaGetLastError();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "piCalcKernel launch failed: %s\n", cudaGetErrorString(cudaStatus));
    }

    // cudaDeviceSynchronize waits for the kernel to finish, and returns
    // any errors encountered during the launch.
    cudaStatus = cudaDeviceSynchronize();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceSynchronize returned error code %d after launching piCalcKernel!\n", cudaStatus);
    }
    // Copy output vector from GPU buffer to host memory.
    cudaStatus = cudaMemcpy(odata, dev_odata, (size / 1024) * sizeof(int), cudaMemcpyDeviceToHost);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaMemcpy failed!");
    }
    cudaFree(dev_a);
    cudaFree(dev_b);
    cudaFree(dev_odata);

    return cudaStatus;
}

double simplePiCalc(double* a, double* b, int size) {
    int sum = 0;
    for (int i = 0; i < size; i++)
    {
        if (a[i] * a[i] + b[i] * b[i] < 1) 
        {
            sum++;
        }
    }
    return (double) 4*sum / size;
}
int main()
{
    int N;

    cout << "Enter the number of numbers: " << endl;
    cin >> N;

    //     
    double* a = new double[N];
    double* b = new double[N];
    int* cudaOut = new int[(N / 1024)];

    std::default_random_engine generator;
    std::uniform_real_distribution<double> distribution(-1.0, 1.0);
    for (int i = 0; i < N; i++)
    {
        a[i] = distribution(generator);
        b[i] = distribution(generator);
    }

    
    // cuda 
    double result = 0;
    clock_t start = clock();
    cudaError_t cudaStatus = piCalcWithCuda(cudaOut, a, b, N);
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "piCalcWithCuda failed!");
    }
    for (int i = 0; i < (N / 1024); i++)
    {
       result += cudaOut[i];
    }
    result = 4 * (double) result / (N - N%1024);
    clock_t end = clock();
    cout << "Cuda time: " << (double)(end - start) / CLOCKS_PER_SEC << endl;
    cout << "Cuda result: " << result << endl;
    // cpu 
    result = 0;
    start = clock();
    result = simplePiCalc(a, b, N);
    end = clock();
    cout << "CPU time: " << (double)(end - start) / CLOCKS_PER_SEC << endl;
    cout << "CPU result: " << result << endl;
    delete[] cudaOut;
    delete[] a;
    delete[] b;

    // cudaDeviceReset must be called before exiting in order for profiling and
    // tracing tools such as Nsight and Visual Profiler to show complete traces.
    cudaStatus = cudaDeviceReset();
    if (cudaStatus != cudaSuccess) {
        fprintf(stderr, "cudaDeviceReset failed!");
        return 1;
    }

    return 0;
}


	.file	"tmpxft_002d3dcf_00000000-6_kernel.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4724:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4724:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB5446:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE5446:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z12simplePiCalcPdS_i
	.type	_Z12simplePiCalcPdS_i, @function
_Z12simplePiCalcPdS_i:
.LFB4720:
	.cfi_startproc
	endbr64
	movsd	.LC0(%rip), %xmm2
	xorl	%eax, %eax
	xorl	%ecx, %ecx
.L4:
	cmpl	%eax, %edx
	jle	.L10
	movsd	(%rdi,%rax,8), %xmm0
	movsd	(%rsi,%rax,8), %xmm1
	mulsd	%xmm0, %xmm0
	mulsd	%xmm1, %xmm1
	addsd	%xmm1, %xmm0
	comisd	%xmm0, %xmm2
	jbe	.L5
	incl	%ecx
.L5:
	incq	%rax
	jmp	.L4
.L10:
	cvtsi2sdl	%ecx, %xmm0
	mulsd	.LC1(%rip), %xmm0
	cvtsi2sdl	%edx, %xmm1
	divsd	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE4720:
	.size	_Z12simplePiCalcPdS_i, .-_Z12simplePiCalcPdS_i
	.globl	_Z38__device_stub__Z12piCalcKernelPiPdS0_iPiPdS0_i
	.type	_Z38__device_stub__Z12piCalcKernelPiPdS0_iPiPdS0_i, @function
_Z38__device_stub__Z12piCalcKernelPiPdS0_iPiPdS0_i:
.LFB4746:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z12piCalcKernelPiPdS0_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L11:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4746:
	.size	_Z38__device_stub__Z12piCalcKernelPiPdS0_iPiPdS0_i, .-_Z38__device_stub__Z12piCalcKernelPiPdS0_iPiPdS0_i
	.globl	_Z12piCalcKernelPiPdS0_i
	.type	_Z12piCalcKernelPiPdS0_i, @function
_Z12piCalcKernelPiPdS0_i:
.LFB4747:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z12piCalcKernelPiPdS0_iPiPdS0_i
	.cfi_endproc
.LFE4747:
	.size	_Z12piCalcKernelPiPdS0_i, .-_Z12piCalcKernelPiPdS0_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?"
.LC3:
	.string	"cudaMalloc failed!"
.LC4:
	.string	"cudaMemcpy failed!"
.LC5:
	.string	"piCalcKernel launch failed: %s\n"
.LC6:
	.string	"cudaDeviceSynchronize returned error code %d after launching piCalcKernel!\n"
	.text
	.globl	_Z14piCalcWithCudaPiPdS0_i
	.type	_Z14piCalcWithCudaPiPdS0_i, @function
_Z14piCalcWithCudaPiPdS0_i:
.LFB4719:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	xorl	%edx, %edx
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	xorl	%edi, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	movq	%rdx, 24(%rsp)
	movq	%rdx, 32(%rsp)
	call	cudaSetDevice@PLT
	testl	%eax, %eax
	je	.L17
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L17:
	movslq	%ebx, %rbp
	leaq	24(%rsp), %rdi
	salq	$3, %rbp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L18
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L18:
	leaq	32(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L19
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L19:
	xorl	%eax, %eax
	movl	$1024, %ecx
	leaq	40(%rsp), %rdi
	movq	%rax, 40(%rsp)
	movl	%ebx, %eax
	cltd
	idivl	%ecx
	cltq
	movq	%rax, %r15
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L20
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L20:
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L21
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L21:
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L22
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L22:
	movl	%r15d, 60(%rsp)
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	salq	$10, %rdx
	movl	$1, %ecx
	movq	%rax, 64(%rsp)
	movq	60(%rsp), %rdi
	movl	68(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	%ebx, %ecx
	movq	40(%rsp), %rdi
	call	_Z38__device_stub__Z12piCalcKernelPiPdS0_iPiPdS0_i
.L23:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L24
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC5(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L24:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %ecx
	testl	%eax, %eax
	je	.L25
	movq	stderr(%rip), %rdi
	leaq	.LC6(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L25:
	movq	8(%rsp), %rdx
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L26
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L26:
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4719:
	.size	_Z14piCalcWithCudaPiPdS0_i, .-_Z14piCalcWithCudaPiPdS0_i
	.section	.rodata.str1.1
.LC7:
	.string	"_Z12piCalcKernelPiPdS0_i"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4749:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC7(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12piCalcKernelPiPdS0_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4749:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_,"axG",@progbits,_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_,comdat
	.weak	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	.type	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_, @function
_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_:
.LFB5402:
	.cfi_startproc
	endbr64
	imulq	$16807, (%rdi), %rax
	movl	$2147483647, %ecx
	xorl	%edx, %edx
	divq	%rcx
	movq	%rdx, %rax
	decq	%rax
	js	.L59
	cvtsi2sdq	%rax, %xmm0
	jmp	.L60
.L59:
	movq	%rax, %rcx
	andl	$1, %eax
	shrq	%rcx
	orq	%rax, %rcx
	cvtsi2sdq	%rcx, %xmm0
	addsd	%xmm0, %xmm0
.L60:
	imulq	$16807, %rdx, %rax
	movl	$2147483647, %ecx
	xorps	%xmm1, %xmm1
	xorl	%edx, %edx
	addsd	%xmm1, %xmm0
	divq	%rcx
	movq	%rdx, (%rdi)
	decq	%rdx
	js	.L61
	cvtsi2sdq	%rdx, %xmm1
	jmp	.L62
.L61:
	movq	%rdx, %rax
	andl	$1, %edx
	shrq	%rax
	orq	%rdx, %rax
	cvtsi2sdq	%rax, %xmm1
	addsd	%xmm1, %xmm1
.L62:
	mulsd	.LC10(%rip), %xmm1
	addsd	%xmm1, %xmm0
	divsd	.LC11(%rip), %xmm0
	comisd	.LC0(%rip), %xmm0
	jb	.L58
	movsd	.LC8(%rip), %xmm0
.L58:
	ret
	.cfi_endproc
.LFE5402:
	.size	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_, .-_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	.section	.rodata.str1.1
.LC12:
	.string	"Enter the number of numbers: "
.LC13:
	.string	"piCalcWithCuda failed!"
.LC14:
	.string	"Cuda time: "
.LC16:
	.string	"Cuda result: "
.LC17:
	.string	"CPU time: "
.LC18:
	.string	"CPU result: "
.LC19:
	.string	"cudaDeviceReset failed!"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB4721:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC12(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	_ZSt4cout(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r13, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movabsq	$1152921504606846975, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	_ZSt3cin(%rip), %rdi
	leaq	28(%rsp), %rsi
	call	_ZNSirsERi@PLT
	movslq	28(%rsp), %rdi
	cmpq	%rdi, %rbx
	jb	.L66
	salq	$3, %rdi
	call	_Znam@PLT
	movslq	28(%rsp), %rdi
	movq	%rax, %rbp
	cmpq	%rdi, %rbx
	jnb	.L67
.L66:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L82
	call	__cxa_throw_bad_array_new_length@PLT
.L67:
	salq	$3, %rdi
	call	_Znam@PLT
	movl	$1024, %ecx
	movq	%rax, %rbx
	movl	28(%rsp), %eax
	cltd
	idivl	%ecx
	movabsq	$2305843009213693950, %rdx
	cltq
	cmpq	%rax, %rdx
	jb	.L66
	leaq	0(,%rax,4), %rdi
	xorl	%r15d, %r15d
	call	_Znam@PLT
	movq	$1, 32(%rsp)
	movq	%rax, %r12
.L69:
	cmpl	%r15d, 28(%rsp)
	jle	.L83
	leaq	32(%rsp), %r14
	movq	%r14, %rdi
	call	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	movq	%r14, %rdi
	addsd	%xmm0, %xmm0
	subsd	.LC0(%rip), %xmm0
	movsd	%xmm0, 0(%rbp,%r15,8)
	call	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	addsd	%xmm0, %xmm0
	subsd	.LC0(%rip), %xmm0
	movsd	%xmm0, (%rbx,%r15,8)
	incq	%r15
	jmp	.L69
.L83:
	call	clock@PLT
	movl	28(%rsp), %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	movq	%r12, %rdi
	movq	%rax, %r15
	call	_Z14piCalcWithCudaPiPdS0_i
	testl	%eax, %eax
	je	.L71
	movq	stderr(%rip), %rdi
	leaq	.LC13(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L71:
	movl	28(%rsp), %ecx
	movl	$1024, %esi
	xorps	%xmm0, %xmm0
	movl	%ecx, %eax
	cltd
	idivl	%esi
	xorl	%edx, %edx
.L72:
	cmpl	%edx, %eax
	jle	.L84
	cvtsi2sdl	(%r12,%rdx,4), %xmm1
	incq	%rdx
	addsd	%xmm1, %xmm0
	jmp	.L72
.L84:
	mulsd	.LC1(%rip), %xmm0
	movl	%ecx, %eax
	movl	$1024, %esi
	cltd
	idivl	%esi
	subl	%edx, %ecx
	cvtsi2sdl	%ecx, %xmm1
	divsd	%xmm1, %xmm0
	movsd	%xmm0, 8(%rsp)
	call	clock@PLT
	leaq	.LC14(%rip), %rsi
	movq	%r13, %rdi
	movq	%rax, %r14
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	subq	%r15, %r14
	movq	%rax, %rdi
	cvtsi2sdq	%r14, %xmm0
	divsd	.LC15(%rip), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC16(%rip), %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	call	clock@PLT
	movl	28(%rsp), %edx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	movq	%rax, %r15
	call	_Z12simplePiCalcPdS_i
	movsd	%xmm0, 8(%rsp)
	call	clock@PLT
	leaq	.LC17(%rip), %rsi
	movq	%r13, %rdi
	movq	%rax, %r14
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	subq	%r15, %r14
	movq	%rax, %rdi
	cvtsi2sdq	%r14, %xmm0
	divsd	.LC15(%rip), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC18(%rip), %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%r12, %rdi
	call	_ZdaPv@PLT
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	call	cudaDeviceReset@PLT
	movl	%eax, %edx
	xorl	%eax, %eax
	testl	%edx, %edx
	je	.L65
	movq	stderr(%rip), %rdi
	leaq	.LC19(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %eax
.L65:
	movq	40(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L75
.L82:
	call	__stack_chk_fail@PLT
.L75:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4721:
	.size	main, .-main
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1072693248
	.align 8
.LC1:
	.long	0
	.long	1074790400
	.align 8
.LC8:
	.long	-1
	.long	1072693247
	.align 8
.LC10:
	.long	-8388608
	.long	1105199103
	.align 8
.LC11:
	.long	-16777216
	.long	1137704959
	.align 8
.LC15:
	.long	0
	.long	1093567616
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include "hip/hip_runtime.h"


#include <stdio.h>
#include <iostream>
#include <time.h> 
#include <random>

using namespace std;

//       nvidia http://developer.download.nvidia.com/assets/cuda/files/reduction.pdf
//       ,     
__global__ void piCalcKernel(int *d_odata, double* a, double* b, int size)
{
    __shared__ int sdata[1024];
    int tid = threadIdx.x;
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    sdata[tid] = ((a[i] * a[i] + b[i] * b[i]) < 1 ? 1 : 0);

    __syncthreads();
    for (int j = blockDim.x/2; j > 0; j>>=1)
    {
        if (tid < j)
        {
            sdata[tid] += sdata[tid + j];
        }
        __syncthreads();
    }
    if (tid == 0) d_odata[blockIdx.x] = sdata[0];
}
// Helper function for using CUDA to add vectors in parallel.
hipError_t piCalcWithCuda(int* odata, double* a, double* b, int size)
{
    double* dev_a = 0;
    double* dev_b = 0;
    hipError_t cudaStatus;
    // Choose which GPU to run on, change this on a multi-GPU system.
    cudaStatus = hipSetDevice(0);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipSetDevice failed!  Do you have a CUDA-capable GPU installed?");
    }

    // Allocate GPU buffers for three vectors (two input, one output)    .
    cudaStatus = hipMalloc((void**)&dev_a, size * sizeof(double));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
    }

    cudaStatus = hipMalloc((void**)&dev_b, size * sizeof(double));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
    }

    int* dev_odata = 0;
    cudaStatus = hipMalloc((void**)&dev_odata, (size / 1024) * sizeof(int));
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMalloc failed!");
    }

    // Copy input vectors from host memory to GPU buffers.
    cudaStatus = hipMemcpy(dev_a, a, size * sizeof(double), hipMemcpyHostToDevice);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
    }

    cudaStatus = hipMemcpy(dev_b, b, size * sizeof(double), hipMemcpyHostToDevice);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
    }


    dim3 blockSize = dim3(1024, 1, 1);
    dim3 gridSize = dim3(size/1024, 1, 1);

    // Launch a kernel on the GPU with one thread for each element.
    piCalcKernel <<<gridSize, blockSize >>> (dev_odata, dev_a, dev_b, size);
    // Check for any errors launching the kernel
    cudaStatus = hipGetLastError();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "piCalcKernel launch failed: %s\n", hipGetErrorString(cudaStatus));
    }

    // cudaDeviceSynchronize waits for the kernel to finish, and returns
    // any errors encountered during the launch.
    cudaStatus = hipDeviceSynchronize();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipDeviceSynchronize returned error code %d after launching piCalcKernel!\n", cudaStatus);
    }
    // Copy output vector from GPU buffer to host memory.
    cudaStatus = hipMemcpy(odata, dev_odata, (size / 1024) * sizeof(int), hipMemcpyDeviceToHost);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipMemcpy failed!");
    }
    hipFree(dev_a);
    hipFree(dev_b);
    hipFree(dev_odata);

    return cudaStatus;
}

double simplePiCalc(double* a, double* b, int size) {
    int sum = 0;
    for (int i = 0; i < size; i++)
    {
        if (a[i] * a[i] + b[i] * b[i] < 1) 
        {
            sum++;
        }
    }
    return (double) 4*sum / size;
}
int main()
{
    int N;

    cout << "Enter the number of numbers: " << endl;
    cin >> N;

    //     
    double* a = new double[N];
    double* b = new double[N];
    int* cudaOut = new int[(N / 1024)];

    std::default_random_engine generator;
    std::uniform_real_distribution<double> distribution(-1.0, 1.0);
    for (int i = 0; i < N; i++)
    {
        a[i] = distribution(generator);
        b[i] = distribution(generator);
    }

    
    // cuda 
    double result = 0;
    clock_t start = clock();
    hipError_t cudaStatus = piCalcWithCuda(cudaOut, a, b, N);
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "piCalcWithCuda failed!");
    }
    for (int i = 0; i < (N / 1024); i++)
    {
       result += cudaOut[i];
    }
    result = 4 * (double) result / (N - N%1024);
    clock_t end = clock();
    cout << "Cuda time: " << (double)(end - start) / CLOCKS_PER_SEC << endl;
    cout << "Cuda result: " << result << endl;
    // cpu 
    result = 0;
    start = clock();
    result = simplePiCalc(a, b, N);
    end = clock();
    cout << "CPU time: " << (double)(end - start) / CLOCKS_PER_SEC << endl;
    cout << "CPU result: " << result << endl;
    delete[] cudaOut;
    delete[] a;
    delete[] b;

    // cudaDeviceReset must be called before exiting in order for profiling and
    // tracing tools such as Nsight and Visual Profiler to show complete traces.
    cudaStatus = hipDeviceReset();
    if (cudaStatus != hipSuccess) {
        fprintf(stderr, "hipDeviceReset failed!");
        return 1;
    }

    return 0;
}


	.text
	.file	"kernel.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z27__device_stub__piCalcKernelPiPdS0_i # -- Begin function _Z27__device_stub__piCalcKernelPiPdS0_i
	.type	_Z27__device_stub__piCalcKernelPiPdS0_i,@function
_Z27__device_stub__piCalcKernelPiPdS0_i: # @_Z27__device_stub__piCalcKernelPiPdS0_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z12piCalcKernelPiPdS0_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z27__device_stub__piCalcKernelPiPdS0_i, .Lfunc_end0-_Z27__device_stub__piCalcKernelPiPdS0_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z14piCalcWithCudaPiPdS0_i      # -- Begin function _Z14piCalcWithCudaPiPdS0_i
	.type	_Z14piCalcWithCudaPiPdS0_i,@function
_Z14piCalcWithCudaPiPdS0_i:             # @_Z14piCalcWithCudaPiPdS0_i
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %r14d
	movq	%rdx, %r12
	movq	%rsi, %r13
	movq	%rdi, 32(%rsp)                  # 8-byte Spill
	xorl	%eax, %eax
	movq	%rax, 16(%rsp)
	movq	%rax, 8(%rsp)
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB1_1
.LBB1_2:
	movslq	%r14d, %rbp
	shlq	$3, %rbp
	leaq	16(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_3
.LBB1_4:
	leaq	8(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_5
.LBB1_6:
	leaq	24(%rsp), %rdi
	leal	1023(%r14), %ebx
	testl	%r14d, %r14d
	cmovnsl	%r14d, %ebx
	movq	$0, (%rdi)
	sarl	$10, %ebx
	movslq	%ebx, %r15
	shlq	$2, %r15
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_7
.LBB1_8:
	movq	16(%rsp), %rdi
	movq	%r13, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_9
.LBB1_10:
	movq	8(%rsp), %rdi
	movq	%r12, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_11
.LBB1_12:
	movl	%ebx, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$1024, %rdx                     # imm = 0x400
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.13:
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	%r14d, %ecx
	callq	_Z27__device_stub__piCalcKernelPiPdS0_i
.LBB1_14:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_15
.LBB1_16:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB1_17
.LBB1_18:
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rdi                  # 8-byte Reload
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.LBB1_19
.LBB1_20:
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movl	%ebx, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_1:
	.cfi_def_cfa_offset 96
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$63, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB1_2
.LBB1_3:
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB1_4
.LBB1_5:
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB1_6
.LBB1_7:
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB1_8
.LBB1_9:
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB1_10
.LBB1_11:
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB1_12
.LBB1_15:
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_16
.LBB1_17:
	movq	stderr(%rip), %rdi
	movl	$.L.str.4, %esi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_18
.LBB1_19:
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$17, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB1_20
.Lfunc_end1:
	.size	_Z14piCalcWithCudaPiPdS0_i, .Lfunc_end1-_Z14piCalcWithCudaPiPdS0_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z12simplePiCalcPdS_i
.LCPI2_0:
	.quad	0x3ff0000000000000              # double 1
.LCPI2_1:
	.quad	0x4010000000000000              # double 4
	.text
	.globl	_Z12simplePiCalcPdS_i
	.type	_Z12simplePiCalcPdS_i,@function
_Z12simplePiCalcPdS_i:                  # @_Z12simplePiCalcPdS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB2_1
# %bb.4:                                # %.lr.ph.preheader
	movl	%edx, %eax
	xorl	%ecx, %ecx
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	xorl	%r8d, %r8d
.LBB2_5:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%rdi,%rcx,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm1
	movsd	(%rsi,%rcx,8), %xmm2            # xmm2 = mem[0],zero
	mulsd	%xmm2, %xmm2
	addsd	%xmm1, %xmm2
	xorl	%r9d, %r9d
	ucomisd	%xmm2, %xmm0
	seta	%r9b
	addl	%r9d, %r8d
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB2_5
# %bb.2:                                # %._crit_edge.loopexit
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r8d, %xmm0
	mulsd	.LCPI2_1(%rip), %xmm0
	jmp	.LBB2_3
.LBB2_1:
	xorpd	%xmm0, %xmm0
.LBB2_3:                                # %._crit_edge
	xorps	%xmm1, %xmm1
	cvtsi2sd	%edx, %xmm1
	divsd	%xmm1, %xmm0
	retq
.Lfunc_end2:
	.size	_Z12simplePiCalcPdS_i, .Lfunc_end2-_Z12simplePiCalcPdS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI3_0:
	.quad	0xbff0000000000000              # double -1
.LCPI3_1:
	.quad	0x4010000000000000              # double 4
.LCPI3_2:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI3_3:
	.quad	0x3ff0000000000000              # double 1
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$29, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	leaq	12(%rsp), %rbx
	movl	$_ZSt3cin, %edi
	movq	%rbx, %rsi
	callq	_ZNSirsERi
	movslq	(%rbx), %r12
	leaq	(,%r12,8), %r14
	testq	%r12, %r12
	movq	$-1, %r15
	cmovsq	%r15, %r14
	leal	1023(%r12), %ebp
	cmovnsl	%r12d, %ebp
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %rbx
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %r14
	sarl	$10, %ebp
	movslq	%ebp, %rdi
	shlq	$2, %rdi
	cmpq	$-1023, %r12                    # imm = 0xFC01
	cmovlq	%r15, %rdi
	callq	_Znam
	movq	%rax, %r15
	movq	$1, 32(%rsp)
	testq	%r12, %r12
	jle	.LBB3_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%r13d, %r13d
	leaq	32(%rsp), %r12
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%r12, %rdi
	callq	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	addsd	%xmm0, %xmm0
	movsd	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	movsd	%xmm0, (%rbx,%r13,8)
	movq	%r12, %rdi
	callq	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	addsd	%xmm0, %xmm0
	addsd	.LCPI3_0(%rip), %xmm0
	movsd	%xmm0, (%r14,%r13,8)
	incq	%r13
	movslq	12(%rsp), %rax
	cmpq	%rax, %r13
	jl	.LBB3_2
.LBB3_3:                                # %._crit_edge
	callq	clock
	movq	%rax, %r12
	movl	12(%rsp), %ecx
	movq	%r15, %rdi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	callq	_Z14piCalcWithCudaPiPdS0_i
	testl	%eax, %eax
	jne	.LBB3_4
.LBB3_5:
	movl	12(%rsp), %eax
	xorpd	%xmm0, %xmm0
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	xorpd	%xmm1, %xmm1
	cmpl	$1024, %eax                     # imm = 0x400
	jl	.LBB3_9
# %bb.6:                                # %.lr.ph38.preheader
	movl	%eax, %ecx
	shrl	$10, %ecx
	xorl	%edx, %edx
.LBB3_7:                                # %.lr.ph38
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2sdl	(%r15,%rdx,4), %xmm0
	addsd	%xmm0, %xmm1
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB3_7
# %bb.8:                                # %._crit_edge39.loopexit
	mulsd	.LCPI3_1(%rip), %xmm1
.LBB3_9:                                # %._crit_edge39
	leal	1023(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	andl	$-1024, %ecx                    # imm = 0xFC00
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ecx, %xmm0
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 24(%rsp)                 # 8-byte Spill
	callq	clock
	movq	%rax, %r13
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$11, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	subq	%r12, %r13
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r13, %xmm0
	divsd	.LCPI3_2(%rip), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$13, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	callq	clock
	movq	%rax, %r12
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.LBB3_13
# %bb.10:                               # %.lr.ph.preheader.i
	xorl	%ecx, %ecx
	movsd	.LCPI3_3(%rip), %xmm0           # xmm0 = mem[0],zero
	xorl	%edx, %edx
.LBB3_11:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%rbx,%rcx,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm1
	movsd	(%r14,%rcx,8), %xmm2            # xmm2 = mem[0],zero
	mulsd	%xmm2, %xmm2
	addsd	%xmm1, %xmm2
	xorl	%esi, %esi
	ucomisd	%xmm2, %xmm0
	seta	%sil
	addl	%esi, %edx
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB3_11
# %bb.12:                               # %._crit_edge.loopexit.i
	xorps	%xmm0, %xmm0
	cvtsi2sd	%edx, %xmm0
	mulsd	.LCPI3_1(%rip), %xmm0
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
.LBB3_13:                               # %_Z12simplePiCalcPdS_i.exit
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	16(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 16(%rsp)                 # 8-byte Spill
	callq	clock
	movq	%rax, %r13
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$10, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	subq	%r12, %r13
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r13, %xmm0
	divsd	.LCPI3_2(%rip), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%r15, %rdi
	callq	_ZdaPv
	movq	%rbx, %rdi
	callq	_ZdaPv
	movq	%r14, %rdi
	callq	_ZdaPv
	callq	hipDeviceReset
	movl	%eax, %ecx
	xorl	%eax, %eax
	testl	%ecx, %ecx
	jne	.LBB3_14
.LBB3_15:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_4:
	.cfi_def_cfa_offset 96
	movq	stderr(%rip), %rcx
	movl	$.L.str.6, %edi
	movl	$22, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB3_5
.LBB3_14:
	movq	stderr(%rip), %rcx
	movl	$.L.str.11, %edi
	movl	$22, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %eax
	jmp	.LBB3_15
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
.LCPI4_0:
	.quad	0x41dfffffff800000              # double 2147483646
.LCPI4_3:
	.quad	0x3ff0000000000000              # double 1
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI4_1:
	.long	0x40000000                      # float 2
.LCPI4_2:
	.long	0x5f000000                      # float 9.22337203E+18
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI4_4:
	.long	1127219200                      # 0x43300000
	.long	1160773632                      # 0x45300000
	.long	0                               # 0x0
	.long	0                               # 0x0
.LCPI4_5:
	.quad	0x4330000000000000              # double 4503599627370496
	.quad	0x4530000000000000              # double 1.9342813113834067E+25
	.section	.text._ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_,"axG",@progbits,_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_,comdat
	.weak	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	.type	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_,@function
_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_: # @_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$64, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	fldl	.LCPI4_0(%rip)
	fstpt	(%rsp)
	callq	logl
	fstpt	52(%rsp)                        # 10-byte Folded Spill
	flds	.LCPI4_1(%rip)
	fstpt	(%rsp)
	callq	logl
	fldt	52(%rsp)                        # 10-byte Folded Reload
	fdivp	%st, %st(1)
	flds	.LCPI4_2(%rip)
	xorl	%ecx, %ecx
	fxch	%st(1)
	fucomi	%st(1), %st
	fldz
	fcmovnb	%st(2), %st
	fstp	%st(2)
	fsubp	%st, %st(1)
	setae	%cl
	fnstcw	20(%rsp)
	movzwl	20(%rsp), %eax
	orl	$3072, %eax                     # imm = 0xC00
	movw	%ax, 22(%rsp)
	fldcw	22(%rsp)
	fistpll	40(%rsp)
	fldcw	20(%rsp)
	shlq	$63, %rcx
	xorq	40(%rsp), %rcx
	leaq	52(%rcx), %rax
	xorl	%edx, %edx
	divq	%rcx
	movq	%rax, %rcx
	cmpq	$1, %rax
	adcq	$0, %rcx
	movq	(%rbx), %rax
	xorpd	%xmm0, %xmm0
	movsd	.LCPI4_3(%rip), %xmm1           # xmm1 = mem[0],zero
	movabsq	$8589934597, %rdi               # imm = 0x200000005
	movdqa	.LCPI4_4(%rip), %xmm2           # xmm2 = [1127219200,1160773632,0,0]
	movapd	.LCPI4_5(%rip), %xmm3           # xmm3 = [4.503599627370496E+15,1.9342813113834067E+25]
.LBB4_1:                                # %select.unfold
                                        # =>This Inner Loop Header: Depth=1
	imulq	$16807, %rax, %rsi              # imm = 0x41A7
	movq	%rsi, %rax
	mulq	%rdi
	movq	%rsi, %r8
	subq	%rdx, %r8
	shrq	%r8
	addq	%rdx, %r8
	shrq	$30, %r8
	movq	%r8, %rax
	shlq	$31, %rax
	subq	%rax, %r8
	leaq	(%rsi,%r8), %rax
	leaq	(%rsi,%r8), %rdx
	decq	%rdx
	movq	%rdx, %xmm4
	punpckldq	%xmm2, %xmm4            # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1]
	subpd	%xmm3, %xmm4
	movapd	%xmm4, %xmm5
	unpckhpd	%xmm4, %xmm5                    # xmm5 = xmm5[1],xmm4[1]
	addsd	%xmm4, %xmm5
	mulsd	%xmm1, %xmm5
	movsd	%xmm1, 32(%rsp)
	fldl	32(%rsp)
	fmull	.LCPI4_0(%rip)
	addsd	%xmm5, %xmm0
	fstpl	24(%rsp)
	movsd	24(%rsp), %xmm1                 # xmm1 = mem[0],zero
	decq	%rcx
	jne	.LBB4_1
# %bb.2:
	movq	%rax, (%rbx)
	divsd	%xmm1, %xmm0
	ucomisd	.LCPI4_3(%rip), %xmm0
	jae	.LBB4_4
# %bb.3:
	addq	$64, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB4_4:
	.cfi_def_cfa_offset 80
	movsd	.LCPI4_3(%rip), %xmm0           # xmm0 = mem[0],zero
	xorpd	%xmm1, %xmm1
	addq	$64, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	nextafter                       # TAILCALL
.Lfunc_end4:
	.size	_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_, .Lfunc_end4-_ZSt18generate_canonicalIdLm53ESt26linear_congruential_engineImLm16807ELm0ELm2147483647EEET_RT1_
	.cfi_endproc
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12piCalcKernelPiPdS0_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z12piCalcKernelPiPdS0_i,@object # @_Z12piCalcKernelPiPdS0_i
	.section	.rodata,"a",@progbits
	.globl	_Z12piCalcKernelPiPdS0_i
	.p2align	3, 0x0
_Z12piCalcKernelPiPdS0_i:
	.quad	_Z27__device_stub__piCalcKernelPiPdS0_i
	.size	_Z12piCalcKernelPiPdS0_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"hipSetDevice failed!  Do you have a CUDA-capable GPU installed?"
	.size	.L.str, 64

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"hipMalloc failed!"
	.size	.L.str.1, 18

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"hipMemcpy failed!"
	.size	.L.str.2, 18

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"piCalcKernel launch failed: %s\n"
	.size	.L.str.3, 32

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"hipDeviceSynchronize returned error code %d after launching piCalcKernel!\n"
	.size	.L.str.4, 75

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Enter the number of numbers: "
	.size	.L.str.5, 30

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"piCalcWithCuda failed!"
	.size	.L.str.6, 23

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Cuda time: "
	.size	.L.str.7, 12

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Cuda result: "
	.size	.L.str.8, 14

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"CPU time: "
	.size	.L.str.9, 11

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"CPU result: "
	.size	.L.str.10, 13

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"hipDeviceReset failed!"
	.size	.L.str.11, 23

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12piCalcKernelPiPdS0_i"
	.size	.L__unnamed_1, 25

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z27__device_stub__piCalcKernelPiPdS0_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z12piCalcKernelPiPdS0_i
	.addrsig_sym _ZSt4cout
	.addrsig_sym _ZSt3cin
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12piCalcKernelPiPdS0_i ; -- Begin function _Z12piCalcKernelPiPdS0_i
	.globl	_Z12piCalcKernelPiPdS0_i
	.p2align	8
	.type	_Z12piCalcKernelPiPdS0_i,@function
_Z12piCalcKernelPiPdS0_i:               ; @_Z12piCalcKernelPiPdS0_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s5, s[0:1], 0x2c
	s_load_b64 s[2:3], s[0:1], 0x10
	s_mov_b32 s4, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s5, s5, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s4, s5, v[0:1]
	s_cmp_lt_u32 s5, 2
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 3, v[1:2]
	v_add_co_u32 v3, vcc_lo, s2, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s3, v2, vcc_lo
	s_load_b128 s[0:3], s[0:1], 0x0
	global_load_b64 v[3:4], v[3:4], off
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s2, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s3, v2, vcc_lo
	global_load_b64 v[1:2], v[1:2], off
	s_waitcnt vmcnt(1)
	v_mul_f64 v[3:4], v[3:4], v[3:4]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fma_f64 v[2:3], v[1:2], v[1:2], v[3:4]
	v_lshlrev_b32_e32 v1, 2, v0
	v_cmp_gt_f64_e32 vcc_lo, 1.0, v[2:3]
	v_cndmask_b32_e64 v2, 0, 1, vcc_lo
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_5
; %bb.2:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_lshr_b32 s2, s5, 1
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_u32_e64 s2, v0
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_1 Depth=1
	v_lshl_add_u32 v2, s2, 2, v1
	ds_load_b32 v2, v2
	ds_load_b32 v3, v1
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v2, v3, v2
	ds_store_b32 v1, v2
.LBB0_4:                                ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt lgkmcnt(0)
	s_barrier
	s_cmp_lt_u32 s5, 4
	s_mov_b32 s5, s2
	s_branch .LBB0_1
.LBB0_5:                                ; %._crit_edge
	s_mov_b32 s5, 0
	s_mov_b32 s2, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_7
; %bb.6:
	v_mov_b32_e32 v0, 0
	s_lshl_b64 s[2:3], s[4:5], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s0, s2
	s_addc_u32 s1, s1, s3
	ds_load_b32 v1, v0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB0_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12piCalcKernelPiPdS0_i
		.amdhsa_group_segment_fixed_size 4096
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z12piCalcKernelPiPdS0_i, .Lfunc_end0-_Z12piCalcKernelPiPdS0_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 348
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4096 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 4096
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z12piCalcKernelPiPdS0_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12piCalcKernelPiPdS0_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
