//Nathanael Grix
//Hw5 Cuda Core Benchmark:
//Purpose: Compare cpu and gpu execution time to sum large arrays of numbers on
//	Penn State's computing cluster. I will compare the exectution time from 
//	sets of 1 to 200,000,000.
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define B 1024

//unused implementation
__global__ void scan(float *g_odata, float *g_idata, unsigned long long int n);
//first part of sacning a large array
__global__ void prescan(float *g_odata, float *g_idata, unsigned long long int n, float* blkSum, unsigned long int N);
//last part of scaning a large array
__global__ void postscan(float *g_odata, unsigned long long int n, float* blkSum);

//cpu impementation of a simple scan
void scanCPU(float *f_out, float *f_in, unsigned long long int i_n);

//function for getting the time difference
double myDiffTime(struct timeval &start, struct timeval &end)
{
	double d_start, d_end;
	d_start = (double)(start.tv_sec + start.tv_usec/1000000.0);
	d_end = (double)(end.tv_sec + end.tv_usec/1000000.0);
	return (d_end - d_start);
}

int main(int argc,char** argv) {

	//number of values and threads
	unsigned long int N;

	//default val or not?
	if(argc==2){
		N=atol(argv[1]);
	}
	else{
		N=100000000;
	}

	printf("N=%d, B=%d\n\n",N,B);
	//calculate the number of blocks
	unsigned long long int blkNum =(unsigned long long int)ceil((double)N/((double)(B*2)));
	
	//the values used to calculate the scans
	float *a, *c, *g, *blkSumin, *blkOut;
	//values used to time 
	timeval start, end;
	
	//variables used to talk to memory from cuda
	float *dev_a, *dev_g, *dev_blkSum;
	//sizes of an array of N and the sum of the blocks
	unsigned long long int size = N * sizeof(float);
	unsigned long long int blkSumSize = blkNum * sizeof(float);
	
	//time vars
	double d_gpuTime, d_cpuTime, d_gpuLoadT, d_gpuPreT, d_gpuScaT, d_gpuPostT;
	double load[4];

	//the serial final result
	c=(float*)malloc(size);

	//cuda optomized malloc for vars that cuda will need
	cudaMallocHost((void **) &a, size);
	cudaMallocHost((void **) &g, size);
	cudaMallocHost((void **) &blkSumin, blkSumSize);
	cudaMallocHost((void **) &blkOut, blkSumSize);
	
	// initialize matrices a 
	for (unsigned long long int i = 0; i < N; i++)
	{	
		// fill a with rand floats
		a[i] = (float)(rand() % 1000000) / 1000.0;
	}
	// initialize a and b matrices here
	cudaMalloc((void **) &dev_a, size);
	cudaMalloc((void **) &dev_g, size);
	cudaMalloc((void **) &dev_blkSum, blkSumSize);
	
	//		START TIME
	gettimeofday(&start, NULL);
	
	//		COPY 1 TIME
	// fill the graphics card's memory with a
	cudaMemcpy(dev_a, a, size, cudaMemcpyHostToDevice);
	gettimeofday(&end, NULL);
	load[0] = myDiffTime(start, end);

	//		PRE TIME
	// have small scans done on the memory in blocks
	gettimeofday(&start, NULL);
	prescan<<<blkNum,B,2*B*sizeof(float)>>>(dev_g, dev_a, B*2, dev_blkSum, N);
	cudaDeviceSynchronize();
	gettimeofday(&end, NULL);
	d_gpuPreT = myDiffTime(start, end);

	//		COPY 2 TIME
	// get the blocks' sums out of the graphics cards so we can do a small serial
	// 	scan on them.
	gettimeofday(&start, NULL);
	cudaMemcpy(blkSumin, dev_blkSum, blkSumSize, cudaMemcpyDeviceToHost);
	gettimeofday(&end, NULL);
	load[1] += myDiffTime(start, end);
	
	//		SCAN TIME
	// do a small serial scan on the blocks' sums.
	gettimeofday(&start, NULL);
	scanCPU(blkOut, blkSumin, blkNum);
	gettimeofday(&end, NULL);
	d_gpuScaT = myDiffTime(start, end);

	//		COPY 3 TIME
	// give the blocks back to the graphics cards for post.
	gettimeofday(&start, NULL);
	cudaMemcpy(dev_blkSum, blkOut, blkSumSize, cudaMemcpyHostToDevice);
	cudaDeviceSynchronize();
	gettimeofday(&end, NULL);
	load[2] += myDiffTime(start, end);

	//		POST TIME
	// add the new scanned sum to each block to get the scan of the whole array
	gettimeofday(&start, NULL);
	postscan<<<(unsigned long long int)ceil((double)N/(double)(B)),B>>>(dev_g, N, dev_blkSum);
	gettimeofday(&end, NULL);
	d_gpuPostT = myDiffTime(start, end);

	//		COPY 4 TIME
	// finally get the result into normal memory
	gettimeofday(&start, NULL);
	cudaMemcpy(g, dev_g, size, cudaMemcpyDeviceToHost);
	cudaDeviceSynchronize();
	
	//		END TIME
	gettimeofday(&end, NULL);
	load[3] += myDiffTime(start, end);

	// get the total time for the loads
	d_gpuLoadT = load[0] + load[1] + load[2] +load[3];
	// get the total time for my implementation
	d_gpuTime = d_gpuLoadT + d_gpuPreT + d_gpuScaT + d_gpuPostT;

	//do a serial scan on the whole array
	gettimeofday(&start, NULL);
	scanCPU(c, a, N);
	
	gettimeofday(&end, NULL);
	d_cpuTime = myDiffTime(start, end);
	
	// free the memory for the graphics card
	cudaFree(dev_a); cudaFree(dev_g); cudaFree(dev_blkSum);

	// display at least 50 sums and compare the error percent of the serial
	// 	vs cuda implentation.
	for (unsigned long long int i = 0; i < N; i++)
	{	if(N>50){
			if(i%(N/50)==0 || i == N-1){
				printf("c[%i] = %0.3f, g[%i] = %0.3f\n", i, c[i], i, g[i]);
				printf("error percent = %f%\n",fabs((g[i]-c[i])/c[i])*100.0);
			}
		}
		else{
			printf("c[%i] = %0.3f, g[%i] = %0.3f\n", i, c[i], i, g[i]);
			printf("error percent = %f%\n",fabs((g[i]-c[i])/c[i])*100.0);
		}
	}
	
	// print out the time for the cpu and the gpu
	printf("CPU Time for scan size %i: %f\n", N, d_cpuTime);
	printf("GPU Time for scan size %i: %f\n", N, d_gpuTime);
	// print out the times of the components of the gpu implementation
	printf("\tgpu Load=%f, Pre=%f, Sca=%f, Post=%f\n",d_gpuLoadT, d_gpuPreT, d_gpuScaT, d_gpuPostT);
	// print out the various loading times for the implementation
	printf("\t\tgpu load times={%f,%f,%f,%f}\n", load[0],load[1],load[2],load[3]);

	// free c from memory
	free(c);
	
	
	// free the rest of the variables
	cudaFreeHost(a);
	cudaFreeHost(g);
	cudaFreeHost(blkSumin);
	cudaFreeHost(blkOut);
}

// old unused verson of scan that was included in the naivescan
__global__ void scan(float *g_odata, float *g_idata, unsigned long long int n)
{
	extern __shared__ float temp[]; // allocated on invocation
	unsigned long long int thid = threadIdx.x;
	unsigned long long int pout = 0, pin = 1;
	// Load input into shared memory.
	// This is exclusive scan, so shift right by one
	// and set first element to 0
	temp[pout*n + thid] = (thid > 0) ? g_idata[thid-1] : 0;
	__syncthreads();
	for (unsigned long long int offset = 1; offset < n; offset *= 2)
	{
		pout = 1 - pout; // swap double buffer indices
		pin = 1 - pout;
		if (thid >= offset)
			temp[pout*n+thid] += temp[pin*n+thid - offset];
		else
			temp[pout*n+thid] = temp[pin*n+thid];

		__syncthreads();
	}
	g_odata[thid] = temp[pout*n+thid]; // write output
}

// function that adds the new blocks' sums back into the scanned blocks
__global__ void postscan(float *g_odata, unsigned long long int n, float* blkSum){
	unsigned long long int i = blockIdx.x * blockDim.x + threadIdx.x;
	if (i < n) 
	{	// prescan does two vals per block but this one does 1 so 
		// 	adjust the block ID to reflect that.
		g_odata[i] += blkSum[blockIdx.x/2];
	}
}

// scans a block of the data
__global__ void prescan(float *g_odata, float *g_idata, unsigned long long int n, float* blkSum, unsigned long int N) 
{ 
	// name the newly allocated memory as temp.
	extern  __shared__  float temp[];
	
	//get the begining of the array for this block
	unsigned long long int bldata = blockIdx.x*(blockDim.x);

	// get the thread's id for the block
	unsigned long long int thid = threadIdx.x; 
	
	// initialize the offset to 1
	unsigned long long int offset = 1;

	// fill the temp array with the input data because the math can be executed
	// 	much faster than other forms of meory
	temp[2*thid]   = 0.0; 
    	temp[2*thid+1] = 0.0;
	if(2*(thid+bldata)<N){
		temp[2*thid]   = g_idata[2*(thid+bldata)]; 
	}
	if(2*(thid+bldata)+1<N){
    		temp[2*thid+1] = g_idata[2*(thid+bldata)+1];
	}
	
	//log for loop
	for (unsigned long long int d = n>>1; d > 0; d >>= 1) 
	// build sum in place up the tree 
    	{ 
        	__syncthreads(); 
		if (thid < d){    
        		unsigned long long int ai = offset*(2*thid+1)-1; 
			unsigned long long int bi = ai+offset; 
		    	temp[bi] += temp[ai];
  		} 
		// exponential offset
        	offset <<= 1; 
    	}
 
	// set the lst value and get the total sum
	if (thid == 0){
		blkSum[blockIdx.x] = temp[n-1];
		temp[n-1] = 0;
	}
 
	for (unsigned long long int d = 1; d < n; d <<= 1) 
	// traverse down tree & build scan 
    	{ 
        	offset >>= 1; 
        	__syncthreads(); 
		if (thid < d){
			unsigned long long int ai = offset*(2*thid+1)-1; 
			unsigned long long int bi = ai+offset; 
			float t   = temp[ai]; 
            		temp[ai]  = temp[bi]; 
            		temp[bi] += t; 
        	} 
    	}
	__syncthreads();

	// write results to device memory 
	if(2*(thid+bldata)<N){
		g_odata[2*(thid+bldata)]   = temp[2*thid];
	}
	if(2*(thid+bldata)+1<N){
		g_odata[2*(thid+bldata)+1] = temp[2*thid+1];
	}
}
 
void scanCPU(float *f_out, float *f_in, unsigned long long int i_n)
{
	f_out[0] = 0;
	for (unsigned long long int i = 1; i < i_n; i++)
		f_out[i] = f_out[i-1] + f_in[i-1];

}

	.file	"tmpxft_00251f44_00000000-6_hw5_part1_njg5244.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z10myDiffTimeR7timevalS0_
	.type	_Z10myDiffTimeR7timevalS0_, @function
_Z10myDiffTimeR7timevalS0_:
.LFB2027:
	.cfi_startproc
	endbr64
	cvtsi2sdq	8(%rsi), %xmm0
	movsd	.LC0(%rip), %xmm2
	cvtsi2sdq	(%rsi), %xmm1
	divsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvtsi2sdq	8(%rdi), %xmm1
	divsd	%xmm2, %xmm1
	cvtsi2sdq	(%rdi), %xmm2
	addsd	%xmm2, %xmm1
	subsd	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z10myDiffTimeR7timevalS0_, .-_Z10myDiffTimeR7timevalS0_
	.globl	_Z7scanCPUPfS_y
	.type	_Z7scanCPUPfS_y, @function
_Z7scanCPUPfS_y:
.LFB2029:
	.cfi_startproc
	endbr64
	movl	$0x00000000, (%rdi)
	movl	$1, %eax
.L4:
	cmpq	%rdx, %rax
	jnb	.L7
	movss	-4(%rdi,%rax,4), %xmm0
	addss	-4(%rsi,%rax,4), %xmm0
	movss	%xmm0, (%rdi,%rax,4)
	incq	%rax
	jmp	.L4
.L7:
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z7scanCPUPfS_y, .-_Z7scanCPUPfS_y
	.globl	_Z26__device_stub__Z4scanPfS_yPfS_y
	.type	_Z26__device_stub__Z4scanPfS_yPfS_y, @function
_Z26__device_stub__Z4scanPfS_yPfS_y:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z4scanPfS_y(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L8:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z26__device_stub__Z4scanPfS_yPfS_y, .-_Z26__device_stub__Z4scanPfS_yPfS_y
	.globl	_Z4scanPfS_y
	.type	_Z4scanPfS_y, @function
_Z4scanPfS_y:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z4scanPfS_yPfS_y
	.cfi_endproc
.LFE2055:
	.size	_Z4scanPfS_y, .-_Z4scanPfS_y
	.globl	_Z30__device_stub__Z8postscanPfyS_PfyS_
	.type	_Z30__device_stub__Z8postscanPfyS_PfyS_, @function
_Z30__device_stub__Z8postscanPfyS_PfyS_:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z8postscanPfyS_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L13:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z30__device_stub__Z8postscanPfyS_PfyS_, .-_Z30__device_stub__Z8postscanPfyS_PfyS_
	.globl	_Z8postscanPfyS_
	.type	_Z8postscanPfyS_, @function
_Z8postscanPfyS_:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z30__device_stub__Z8postscanPfyS_PfyS_
	.cfi_endproc
.LFE2057:
	.size	_Z8postscanPfyS_, .-_Z8postscanPfyS_
	.globl	_Z32__device_stub__Z7prescanPfS_yS_mPfS_yS_m
	.type	_Z32__device_stub__Z7prescanPfS_yS_mPfS_yS_m, @function
_Z32__device_stub__Z7prescanPfS_yS_mPfS_yS_m:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movq	%r8, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z7prescanPfS_yS_m(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L18:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z32__device_stub__Z7prescanPfS_yS_mPfS_yS_m, .-_Z32__device_stub__Z7prescanPfS_yS_mPfS_yS_m
	.globl	_Z7prescanPfS_yS_m
	.type	_Z7prescanPfS_yS_m, @function
_Z7prescanPfS_yS_m:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z7prescanPfS_yS_mPfS_yS_m
	.cfi_endproc
.LFE2059:
	.size	_Z7prescanPfS_yS_m, .-_Z7prescanPfS_yS_m
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"N=%d, B=%d\n\n"
.LC7:
	.string	"c[%i] = %0.3f, g[%i] = %0.3f\n"
.LC10:
	.string	"error percent = %f%\n"
.LC11:
	.string	"CPU Time for scan size %i: %f\n"
.LC12:
	.string	"GPU Time for scan size %i: %f\n"
.LC13:
	.string	"\tgpu Load=%f, Pre=%f, Sca=%f, Post=%f\n"
.LC14:
	.string	"\t\tgpu load times={%f,%f,%f,%f}\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	$100000000, %ebx
	subq	$216, %rsp
	.cfi_def_cfa_offset 272
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	jne	.L24
	movq	8(%rsi), %rdi
	call	atol@PLT
	movq	%rax, %rbx
.L24:
	xorl	%eax, %eax
	movl	$1024, %ecx
	movq	%rbx, %rdx
	movl	$2, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	testq	%rbx, %rbx
	js	.L25
	cvtsi2sdq	%rbx, %xmm4
	movsd	%xmm4, 8(%rsp)
	jmp	.L26
.L25:
	movq	%rbx, %rax
	movq	%rbx, %rdx
	shrq	%rax
	andl	$1, %edx
	orq	%rdx, %rax
	cvtsi2sdq	%rax, %xmm0
	addsd	%xmm0, %xmm0
	movsd	%xmm0, 8(%rsp)
.L26:
	movsd	8(%rsp), %xmm0
	mulsd	.LC3(%rip), %xmm0
	call	ceil@PLT
	comisd	.LC4(%rip), %xmm0
	jnb	.L27
	cvttsd2siq	%xmm0, %r14
	jmp	.L28
.L27:
	subsd	.LC4(%rip), %xmm0
	cvttsd2siq	%xmm0, %r14
	btcq	$63, %r14
.L28:
	leaq	0(,%rbx,4), %r12
	leaq	0(,%r14,4), %r15
	xorl	%ebp, %ebp
	movq	%r12, %rdi
	call	malloc@PLT
	leaq	88(%rsp), %rdi
	movq	%r12, %rsi
	movq	%rax, %r13
	call	cudaMallocHost@PLT
	leaq	96(%rsp), %rdi
	movq	%r12, %rsi
	call	cudaMallocHost@PLT
	leaq	104(%rsp), %rdi
	movq	%r15, %rsi
	call	cudaMallocHost@PLT
	leaq	112(%rsp), %rdi
	movq	%r15, %rsi
	call	cudaMallocHost@PLT
.L29:
	cmpq	%rbp, %rbx
	je	.L47
	call	rand@PLT
	movl	$1000000, %ecx
	cltd
	idivl	%ecx
	movq	88(%rsp), %rax
	cvtsi2ssl	%edx, %xmm0
	divss	.LC5(%rip), %xmm0
	movss	%xmm0, (%rax,%rbp,4)
	incq	%rbp
	jmp	.L29
.L47:
	leaq	120(%rsp), %rdi
	movq	%r12, %rsi
	leaq	184(%rsp), %rbp
	call	cudaMalloc@PLT
	leaq	128(%rsp), %rdi
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	leaq	136(%rsp), %rdi
	movq	%r15, %rsi
	call	cudaMalloc@PLT
	leaq	168(%rsp), %rax
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	gettimeofday@PLT
	movq	88(%rsp), %rsi
	movq	120(%rsp), %rdi
	movq	%r12, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	gettimeofday@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z10myDiffTimeR7timevalS0_
	xorl	%esi, %esi
	movsd	%xmm0, 16(%rsp)
	call	gettimeofday@PLT
	movl	%r14d, 144(%rsp)
	movl	$4194305, %edx
	movabsq	$4294967297, %rax
	movq	%rax, 148(%rsp)
	movl	152(%rsp), %esi
	salq	$10, %rdx
	xorl	%r9d, %r9d
	movq	144(%rsp), %rdi
	movl	$8192, %r8d
	movl	$1, %ecx
	movq	%rdx, 156(%rsp)
	movl	$1, 164(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movq	136(%rsp), %rcx
	movq	120(%rsp), %rsi
	movq	%rbx, %r8
	movl	$2048, %edx
	movq	128(%rsp), %rdi
	call	_Z32__device_stub__Z7prescanPfS_yS_mPfS_yS_m
.L31:
	call	cudaDeviceSynchronize@PLT
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	gettimeofday@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z10myDiffTimeR7timevalS0_
	xorl	%esi, %esi
	movsd	%xmm0, 40(%rsp)
	call	gettimeofday@PLT
	movq	136(%rsp), %rsi
	movq	104(%rsp), %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	gettimeofday@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z10myDiffTimeR7timevalS0_
	addsd	.LC15(%rip), %xmm0
	xorl	%esi, %esi
	movsd	%xmm0, 24(%rsp)
	call	gettimeofday@PLT
	movq	104(%rsp), %rsi
	movq	112(%rsp), %rdi
	movq	%r14, %rdx
	call	_Z7scanCPUPfS_y
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	gettimeofday@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z10myDiffTimeR7timevalS0_
	xorl	%esi, %esi
	movsd	%xmm0, 48(%rsp)
	call	gettimeofday@PLT
	movq	112(%rsp), %rsi
	movl	$1, %ecx
	movq	%r15, %rdx
	movq	136(%rsp), %rdi
	call	cudaMemcpy@PLT
	call	cudaDeviceSynchronize@PLT
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	gettimeofday@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z10myDiffTimeR7timevalS0_
	addsd	.LC15(%rip), %xmm0
	xorl	%esi, %esi
	movsd	%xmm0, 32(%rsp)
	call	gettimeofday@PLT
	movsd	8(%rsp), %xmm0
	movl	$4194305, %eax
	movl	$1, 164(%rsp)
	mulsd	.LC6(%rip), %xmm0
	salq	$10, %rax
	movq	%rax, 156(%rsp)
	call	ceil@PLT
	comisd	.LC4(%rip), %xmm0
	jnb	.L32
	cvttsd2siq	%xmm0, %rax
	jmp	.L33
.L32:
	subsd	.LC4(%rip), %xmm0
	cvttsd2siq	%xmm0, %rax
	btcq	$63, %rax
.L33:
	movl	%eax, 144(%rsp)
	movl	164(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movq	156(%rsp), %rdx
	movq	%rax, 148(%rsp)
	movq	144(%rsp), %rdi
	movl	152(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	movq	136(%rsp), %rdx
	movq	128(%rsp), %rdi
	movq	%rbx, %rsi
	call	_Z30__device_stub__Z8postscanPfyS_PfyS_
.L34:
	movq	%rbp, %rdi
	xorl	%esi, %esi
	leaq	.LC7(%rip), %r15
	call	gettimeofday@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z10myDiffTimeR7timevalS0_
	xorl	%esi, %esi
	movsd	%xmm0, 56(%rsp)
	call	gettimeofday@PLT
	movq	128(%rsp), %rsi
	movq	96(%rsp), %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	call	cudaDeviceSynchronize@PLT
	movq	%rbp, %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	call	_Z10myDiffTimeR7timevalS0_
	addsd	.LC15(%rip), %xmm0
	xorl	%esi, %esi
	movsd	%xmm0, 8(%rsp)
	movsd	16(%rsp), %xmm0
	addsd	24(%rsp), %xmm0
	addsd	32(%rsp), %xmm0
	addsd	8(%rsp), %xmm0
	movsd	%xmm0, 64(%rsp)
	movsd	40(%rsp), %xmm0
	addsd	64(%rsp), %xmm0
	addsd	48(%rsp), %xmm0
	addsd	56(%rsp), %xmm0
	movq	%xmm0, %r12
	call	gettimeofday@PLT
	movq	88(%rsp), %rsi
	movq	%rbx, %rdx
	movq	%r13, %rdi
	call	_Z7scanCPUPfS_y
	movq	%rbp, %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	xorl	%ebp, %ebp
	call	_Z10myDiffTimeR7timevalS0_
	movq	120(%rsp), %rdi
	movsd	%xmm0, (%rsp)
	call	cudaFree@PLT
	movq	128(%rsp), %rdi
	call	cudaFree@PLT
	movq	136(%rsp), %rdi
	call	cudaFree@PLT
	movl	$50, %ecx
	movq	%rbx, %rax
	xorl	%edx, %edx
	divq	%rcx
	movq	%rax, %r14
.L35:
	cmpq	%rbp, %rbx
	je	.L48
	cmpq	$50, %rbx
	jbe	.L36
	movq	%rbp, %rax
	xorl	%edx, %edx
	divq	%r14
	testq	%rdx, %rdx
	je	.L36
	leaq	-1(%rbx), %rax
	cmpq	%rbp, %rax
	jne	.L38
.L36:
	movq	96(%rsp), %rax
	movq	%r15, %rsi
	movl	$2, %edi
	movq	%rbp, %rcx
	movss	0(%r13,%rbp,4), %xmm2
	movq	%rbp, %rdx
	cvtss2sd	(%rax,%rbp,4), %xmm1
	movb	$2, %al
	cvtss2sd	%xmm2, %xmm0
	movss	%xmm2, 76(%rsp)
	call	__printf_chk@PLT
	movq	96(%rsp), %rax
	movss	76(%rsp), %xmm2
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	movss	(%rax,%rbp,4), %xmm0
	movb	$1, %al
	subss	%xmm2, %xmm0
	divss	%xmm2, %xmm0
	andps	.LC8(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC9(%rip), %xmm0
	call	__printf_chk@PLT
.L38:
	incq	%rbp
	jmp	.L35
.L48:
	movsd	(%rsp), %xmm0
	movq	%rbx, %rdx
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC11(%rip), %rsi
	call	__printf_chk@PLT
	movq	%rbx, %rdx
	movq	%r12, %xmm0
	movb	$1, %al
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movsd	56(%rsp), %xmm3
	movl	$2, %edi
	movb	$4, %al
	movsd	48(%rsp), %xmm2
	movsd	40(%rsp), %xmm1
	leaq	.LC13(%rip), %rsi
	movsd	64(%rsp), %xmm0
	call	__printf_chk@PLT
	movsd	8(%rsp), %xmm3
	movl	$2, %edi
	movb	$4, %al
	movsd	32(%rsp), %xmm2
	movsd	24(%rsp), %xmm1
	leaq	.LC14(%rip), %rsi
	movsd	16(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	88(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	96(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	104(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	112(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$216, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %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
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC16:
	.string	"_Z7prescanPfS_yS_m"
.LC17:
	.string	"_Z8postscanPfyS_"
.LC18:
	.string	"_Z4scanPfS_y"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC16(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7prescanPfS_yS_m(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC17(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z8postscanPfyS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC18(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z4scanPfS_y(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2061:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.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	1093567616
	.align 8
.LC3:
	.long	0
	.long	1061158912
	.align 8
.LC4:
	.long	0
	.long	1138753536
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC5:
	.long	1148846080
	.section	.rodata.cst8
	.align 8
.LC6:
	.long	0
	.long	1062207488
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC8:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC9:
	.long	0
	.long	1079574528
	.set	.LC15,.LC8+8
	.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:

//Nathanael Grix
//Hw5 Cuda Core Benchmark:
//Purpose: Compare cpu and gpu execution time to sum large arrays of numbers on
//	Penn State's computing cluster. I will compare the exectution time from 
//	sets of 1 to 200,000,000.

#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define B 1024

//unused implementation
__global__ void scan(float *g_odata, float *g_idata, unsigned long long int n);
//first part of sacning a large array
__global__ void prescan(float *g_odata, float *g_idata, unsigned long long int n, float* blkSum, unsigned long int N);
//last part of scaning a large array
__global__ void postscan(float *g_odata, unsigned long long int n, float* blkSum);

//cpu impementation of a simple scan
void scanCPU(float *f_out, float *f_in, unsigned long long int i_n);

//function for getting the time difference
double myDiffTime(struct timeval &start, struct timeval &end)
{
	double d_start, d_end;
	d_start = (double)(start.tv_sec + start.tv_usec/1000000.0);
	d_end = (double)(end.tv_sec + end.tv_usec/1000000.0);
	return (d_end - d_start);
}

int main(int argc,char** argv) {

	//number of values and threads
	unsigned long int N;

	//default val or not?
	if(argc==2){
		N=atol(argv[1]);
	}
	else{
		N=100000000;
	}

	printf("N=%d, B=%d\n\n",N,B);
	//calculate the number of blocks
	unsigned long long int blkNum =(unsigned long long int)ceil((double)N/((double)(B*2)));
	
	//the values used to calculate the scans
	float *a, *c, *g, *blkSumin, *blkOut;
	//values used to time 
	timeval start, end;
	
	//variables used to talk to memory from cuda
	float *dev_a, *dev_g, *dev_blkSum;
	//sizes of an array of N and the sum of the blocks
	unsigned long long int size = N * sizeof(float);
	unsigned long long int blkSumSize = blkNum * sizeof(float);
	
	//time vars
	double d_gpuTime, d_cpuTime, d_gpuLoadT, d_gpuPreT, d_gpuScaT, d_gpuPostT;
	double load[4];

	//the serial final result
	c=(float*)malloc(size);

	//cuda optomized malloc for vars that cuda will need
	hipHostMalloc((void **) &a, size, hipHostMallocDefault);
	hipHostMalloc((void **) &g, size, hipHostMallocDefault);
	hipHostMalloc((void **) &blkSumin, blkSumSize, hipHostMallocDefault);
	hipHostMalloc((void **) &blkOut, blkSumSize, hipHostMallocDefault);
	
	// initialize matrices a 
	for (unsigned long long int i = 0; i < N; i++)
	{	
		// fill a with rand floats
		a[i] = (float)(rand() % 1000000) / 1000.0;
	}
	// initialize a and b matrices here
	hipMalloc((void **) &dev_a, size);
	hipMalloc((void **) &dev_g, size);
	hipMalloc((void **) &dev_blkSum, blkSumSize);
	
	//		START TIME
	gettimeofday(&start, NULL);
	
	//		COPY 1 TIME
	// fill the graphics card's memory with a
	hipMemcpy(dev_a, a, size, hipMemcpyHostToDevice);
	gettimeofday(&end, NULL);
	load[0] = myDiffTime(start, end);

	//		PRE TIME
	// have small scans done on the memory in blocks
	gettimeofday(&start, NULL);
	prescan<<<blkNum,B,2*B*sizeof(float)>>>(dev_g, dev_a, B*2, dev_blkSum, N);
	hipDeviceSynchronize();
	gettimeofday(&end, NULL);
	d_gpuPreT = myDiffTime(start, end);

	//		COPY 2 TIME
	// get the blocks' sums out of the graphics cards so we can do a small serial
	// 	scan on them.
	gettimeofday(&start, NULL);
	hipMemcpy(blkSumin, dev_blkSum, blkSumSize, hipMemcpyDeviceToHost);
	gettimeofday(&end, NULL);
	load[1] += myDiffTime(start, end);
	
	//		SCAN TIME
	// do a small serial scan on the blocks' sums.
	gettimeofday(&start, NULL);
	scanCPU(blkOut, blkSumin, blkNum);
	gettimeofday(&end, NULL);
	d_gpuScaT = myDiffTime(start, end);

	//		COPY 3 TIME
	// give the blocks back to the graphics cards for post.
	gettimeofday(&start, NULL);
	hipMemcpy(dev_blkSum, blkOut, blkSumSize, hipMemcpyHostToDevice);
	hipDeviceSynchronize();
	gettimeofday(&end, NULL);
	load[2] += myDiffTime(start, end);

	//		POST TIME
	// add the new scanned sum to each block to get the scan of the whole array
	gettimeofday(&start, NULL);
	postscan<<<(unsigned long long int)ceil((double)N/(double)(B)),B>>>(dev_g, N, dev_blkSum);
	gettimeofday(&end, NULL);
	d_gpuPostT = myDiffTime(start, end);

	//		COPY 4 TIME
	// finally get the result into normal memory
	gettimeofday(&start, NULL);
	hipMemcpy(g, dev_g, size, hipMemcpyDeviceToHost);
	hipDeviceSynchronize();
	
	//		END TIME
	gettimeofday(&end, NULL);
	load[3] += myDiffTime(start, end);

	// get the total time for the loads
	d_gpuLoadT = load[0] + load[1] + load[2] +load[3];
	// get the total time for my implementation
	d_gpuTime = d_gpuLoadT + d_gpuPreT + d_gpuScaT + d_gpuPostT;

	//do a serial scan on the whole array
	gettimeofday(&start, NULL);
	scanCPU(c, a, N);
	
	gettimeofday(&end, NULL);
	d_cpuTime = myDiffTime(start, end);
	
	// free the memory for the graphics card
	hipFree(dev_a); hipFree(dev_g); hipFree(dev_blkSum);

	// display at least 50 sums and compare the error percent of the serial
	// 	vs cuda implentation.
	for (unsigned long long int i = 0; i < N; i++)
	{	if(N>50){
			if(i%(N/50)==0 || i == N-1){
				printf("c[%i] = %0.3f, g[%i] = %0.3f\n", i, c[i], i, g[i]);
				printf("error percent = %f%\n",fabs((g[i]-c[i])/c[i])*100.0);
			}
		}
		else{
			printf("c[%i] = %0.3f, g[%i] = %0.3f\n", i, c[i], i, g[i]);
			printf("error percent = %f%\n",fabs((g[i]-c[i])/c[i])*100.0);
		}
	}
	
	// print out the time for the cpu and the gpu
	printf("CPU Time for scan size %i: %f\n", N, d_cpuTime);
	printf("GPU Time for scan size %i: %f\n", N, d_gpuTime);
	// print out the times of the components of the gpu implementation
	printf("\tgpu Load=%f, Pre=%f, Sca=%f, Post=%f\n",d_gpuLoadT, d_gpuPreT, d_gpuScaT, d_gpuPostT);
	// print out the various loading times for the implementation
	printf("\t\tgpu load times={%f,%f,%f,%f}\n", load[0],load[1],load[2],load[3]);

	// free c from memory
	free(c);
	
	
	// free the rest of the variables
	hipHostFree(a);
	hipHostFree(g);
	hipHostFree(blkSumin);
	hipHostFree(blkOut);
}

// old unused verson of scan that was included in the naivescan
__global__ void scan(float *g_odata, float *g_idata, unsigned long long int n)
{
	extern __shared__ float temp[]; // allocated on invocation
	unsigned long long int thid = threadIdx.x;
	unsigned long long int pout = 0, pin = 1;
	// Load input into shared memory.
	// This is exclusive scan, so shift right by one
	// and set first element to 0
	temp[pout*n + thid] = (thid > 0) ? g_idata[thid-1] : 0;
	__syncthreads();
	for (unsigned long long int offset = 1; offset < n; offset *= 2)
	{
		pout = 1 - pout; // swap double buffer indices
		pin = 1 - pout;
		if (thid >= offset)
			temp[pout*n+thid] += temp[pin*n+thid - offset];
		else
			temp[pout*n+thid] = temp[pin*n+thid];

		__syncthreads();
	}
	g_odata[thid] = temp[pout*n+thid]; // write output
}

// function that adds the new blocks' sums back into the scanned blocks
__global__ void postscan(float *g_odata, unsigned long long int n, float* blkSum){
	unsigned long long int i = blockIdx.x * blockDim.x + threadIdx.x;
	if (i < n) 
	{	// prescan does two vals per block but this one does 1 so 
		// 	adjust the block ID to reflect that.
		g_odata[i] += blkSum[blockIdx.x/2];
	}
}

// scans a block of the data
__global__ void prescan(float *g_odata, float *g_idata, unsigned long long int n, float* blkSum, unsigned long int N) 
{ 
	// name the newly allocated memory as temp.
	extern  __shared__  float temp[];
	
	//get the begining of the array for this block
	unsigned long long int bldata = blockIdx.x*(blockDim.x);

	// get the thread's id for the block
	unsigned long long int thid = threadIdx.x; 
	
	// initialize the offset to 1
	unsigned long long int offset = 1;

	// fill the temp array with the input data because the math can be executed
	// 	much faster than other forms of meory
	temp[2*thid]   = 0.0; 
    	temp[2*thid+1] = 0.0;
	if(2*(thid+bldata)<N){
		temp[2*thid]   = g_idata[2*(thid+bldata)]; 
	}
	if(2*(thid+bldata)+1<N){
    		temp[2*thid+1] = g_idata[2*(thid+bldata)+1];
	}
	
	//log for loop
	for (unsigned long long int d = n>>1; d > 0; d >>= 1) 
	// build sum in place up the tree 
    	{ 
        	__syncthreads(); 
		if (thid < d){    
        		unsigned long long int ai = offset*(2*thid+1)-1; 
			unsigned long long int bi = ai+offset; 
		    	temp[bi] += temp[ai];
  		} 
		// exponential offset
        	offset <<= 1; 
    	}
 
	// set the lst value and get the total sum
	if (thid == 0){
		blkSum[blockIdx.x] = temp[n-1];
		temp[n-1] = 0;
	}
 
	for (unsigned long long int d = 1; d < n; d <<= 1) 
	// traverse down tree & build scan 
    	{ 
        	offset >>= 1; 
        	__syncthreads(); 
		if (thid < d){
			unsigned long long int ai = offset*(2*thid+1)-1; 
			unsigned long long int bi = ai+offset; 
			float t   = temp[ai]; 
            		temp[ai]  = temp[bi]; 
            		temp[bi] += t; 
        	} 
    	}
	__syncthreads();

	// write results to device memory 
	if(2*(thid+bldata)<N){
		g_odata[2*(thid+bldata)]   = temp[2*thid];
	}
	if(2*(thid+bldata)+1<N){
		g_odata[2*(thid+bldata)+1] = temp[2*thid+1];
	}
}
 
void scanCPU(float *f_out, float *f_in, unsigned long long int i_n)
{
	f_out[0] = 0;
	for (unsigned long long int i = 1; i < i_n; i++)
		f_out[i] = f_out[i-1] + f_in[i-1];

}

	.text
	.file	"hw5_part1_njg5244.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z10myDiffTimeR7timevalS0_
.LCPI0_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z10myDiffTimeR7timevalS0_
	.type	_Z10myDiffTimeR7timevalS0_,@function
_Z10myDiffTimeR7timevalS0_:             # @_Z10myDiffTimeR7timevalS0_
	.cfi_startproc
# %bb.0:
	cvtsi2sdq	(%rdi), %xmm0
	cvtsi2sdq	8(%rdi), %xmm1
	movsd	.LCPI0_0(%rip), %xmm2           # xmm2 = mem[0],zero
	divsd	%xmm2, %xmm1
	addsd	%xmm0, %xmm1
	cvtsi2sdq	(%rsi), %xmm3
	xorps	%xmm0, %xmm0
	cvtsi2sdq	8(%rsi), %xmm0
	divsd	%xmm2, %xmm0
	addsd	%xmm3, %xmm0
	subsd	%xmm1, %xmm0
	retq
.Lfunc_end0:
	.size	_Z10myDiffTimeR7timevalS0_, .Lfunc_end0-_Z10myDiffTimeR7timevalS0_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	1127219200                      # 0x43300000
	.long	1160773632                      # 0x45300000
	.long	0                               # 0x0
	.long	0                               # 0x0
.LCPI1_1:
	.quad	0x4330000000000000              # double 4503599627370496
	.quad	0x4530000000000000              # double 1.9342813113834067E+25
.LCPI1_6:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_2:
	.quad	0x3f40000000000000              # double 4.8828125E-4
.LCPI1_3:
	.quad	0x43e0000000000000              # double 9.2233720368547758E+18
.LCPI1_5:
	.quad	0x3f50000000000000              # double 9.765625E-4
.LCPI1_7:
	.quad	0x4059000000000000              # double 100
.LCPI1_8:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI1_9:
	.quad	0x7ff8000000000000              # double NaN
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI1_4:
	.long	0x447a0000                      # float 1000
	.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	$264, %rsp                      # imm = 0x108
	.cfi_def_cfa_offset 320
	.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	$100000000, %ebx                # imm = 0x5F5E100
	cmpl	$2, %edi
	jne	.LBB1_2
# %bb.1:
	movq	8(%rsi), %rdi
	callq	atol
	movq	%rax, %rbx
.LBB1_2:
	movl	$.L.str, %edi
	movq	%rbx, %rsi
	movl	$1024, %edx                     # imm = 0x400
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %xmm0
	punpckldq	.LCPI1_0(%rip), %xmm0   # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
	subpd	.LCPI1_1(%rip), %xmm0
	movapd	%xmm0, %xmm1
	unpckhpd	%xmm0, %xmm1                    # xmm1 = xmm1[1],xmm0[1]
	addsd	%xmm0, %xmm1
	movsd	.LCPI1_2(%rip), %xmm0           # xmm0 = mem[0],zero
	movapd	%xmm1, 128(%rsp)                # 16-byte Spill
	mulsd	%xmm1, %xmm0
	callq	ceil@PLT
	cvttsd2si	%xmm0, %rax
	movq	%rax, %rcx
	sarq	$63, %rcx
	subsd	.LCPI1_3(%rip), %xmm0
	cvttsd2si	%xmm0, %r15
	andq	%rcx, %r15
	orq	%rax, %r15
	leaq	(,%rbx,4), %r12
	leaq	(,%r15,4), %r13
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r14
	leaq	48(%rsp), %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	leaq	40(%rsp), %rdi
	movq	%r12, 16(%rsp)                  # 8-byte Spill
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	leaq	80(%rsp), %rdi
	movq	%r13, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	leaq	72(%rsp), %rdi
	movq	%r13, 8(%rsp)                   # 8-byte Spill
	movq	%r13, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	testq	%rbx, %rbx
	je	.LBB1_5
# %bb.3:                                # %.lr.ph.preheader
	xorl	%r12d, %r12d
.LBB1_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1125899907, %rax, %rcx         # imm = 0x431BDE83
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$50, %rcx
	addl	%edx, %ecx
	imull	$1000000, %ecx, %ecx            # imm = 0xF4240
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	.LCPI1_4(%rip), %xmm0
	movq	48(%rsp), %rax
	movss	%xmm0, (%rax,%r12,4)
	incq	%r12
	cmpq	%r12, %rbx
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
	leaq	88(%rsp), %rbp
	movq	%rbp, %rdi
	movq	16(%rsp), %r13                  # 8-byte Reload
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	8(%rsp), %rsi                   # 8-byte Reload
	callq	hipMalloc
	leaq	96(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbp), %rdi
	movq	48(%rsp), %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	112(%rsp), %rbp
	movq	%rbp, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r12), %rax
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movq	8(%r12), %rax
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	movq	(%rbp), %rax
	movq	%rax, 256(%rsp)                 # 8-byte Spill
	movq	8(%rbp), %rax
	movq	%rax, 248(%rsp)                 # 8-byte Spill
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	%r15d, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rax               # imm = 0x100000000
	leaq	1024(%rax), %rdx
	movl	$8192, %r8d                     # imm = 0x2000
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_7
# %bb.6:
	movq	32(%rsp), %rdi
	movq	88(%rsp), %rsi
	movq	24(%rsp), %rcx
	movl	$2048, %edx                     # imm = 0x800
	movq	%rbx, %r8
	callq	_Z22__device_stub__prescanPfS_yS_m
.LBB1_7:
	callq	hipDeviceSynchronize
	leaq	112(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	leaq	96(%rsp), %rbp
	movq	(%rbp), %rax
	movq	%rax, 240(%rsp)                 # 8-byte Spill
	movq	8(%rbp), %rax
	movq	%rax, 232(%rsp)                 # 8-byte Spill
	movq	(%r12), %rax
	movq	%rax, 224(%rsp)                 # 8-byte Spill
	movq	8(%r12), %rax
	movq	%rax, 216(%rsp)                 # 8-byte Spill
	movq	%rbp, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	80(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	8(%rsp), %r13                   # 8-byte Reload
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	%rbp, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	72(%rsp), %rax
	movq	80(%rsp), %rcx
	movl	$0, (%rax)
	cmpq	$2, %r15
	jb	.LBB1_10
# %bb.8:                                # %.lr.ph.preheader.i
	decq	%r15
	xorpd	%xmm0, %xmm0
	xorl	%edx, %edx
.LBB1_9:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	addss	(%rcx,%rdx,4), %xmm0
	movss	%xmm0, 4(%rax,%rdx,4)
	incq	%rdx
	cmpq	%rdx, %r15
	jne	.LBB1_9
.LBB1_10:                               # %_Z7scanCPUPfS_y.exit
	leaq	112(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	leaq	96(%rsp), %rbp
	movq	(%rbp), %rax
	movq	%rax, 208(%rsp)                 # 8-byte Spill
	movq	8(%rbp), %rax
	movq	%rax, 200(%rsp)                 # 8-byte Spill
	movq	(%r12), %rax
	movq	%rax, 192(%rsp)                 # 8-byte Spill
	movq	8(%r12), %rax
	movq	%rax, 184(%rsp)                 # 8-byte Spill
	movq	%rbp, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	24(%rsp), %rdi
	movq	72(%rsp), %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	%rbp, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movapd	128(%rsp), %xmm0                # 16-byte Reload
	mulsd	.LCPI1_5(%rip), %xmm0
	callq	ceil@PLT
	cvttsd2si	%xmm0, %rdi
	movq	%rdi, %rax
	sarq	$63, %rax
	subsd	.LCPI1_3(%rip), %xmm0
	cvttsd2si	%xmm0, %rcx
	andl	%eax, %ecx
	orl	%ecx, %edi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	%rdx, %rdi
	addq	$1024, %rdx                     # imm = 0x400
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_12
# %bb.11:
	movq	32(%rsp), %rdi
	movq	24(%rsp), %rdx
	movq	%rbx, %rsi
	callq	_Z23__device_stub__postscanPfyS_
.LBB1_12:
	leaq	112(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	leaq	96(%rsp), %r13
	movq	(%r13), %rax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movq	8(%r13), %rax
	movq	%rax, 128(%rsp)                 # 8-byte Spill
	movq	(%r12), %rax
	movq	%rax, 176(%rsp)                 # 8-byte Spill
	movq	8(%r12), %rax
	movq	%rax, 168(%rsp)                 # 8-byte Spill
	movq	%r13, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	40(%rsp), %rdi
	movq	32(%rsp), %rsi
	movq	16(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	%r13, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	48(%rsp), %rax
	movl	$0, (%r14)
	cmpq	$2, %rbx
	jb	.LBB1_15
# %bb.13:                               # %.lr.ph.preheader.i88
	leaq	-1(%rbx), %rcx
	xorpd	%xmm0, %xmm0
	xorl	%edx, %edx
.LBB1_14:                               # %.lr.ph.i90
                                        # =>This Inner Loop Header: Depth=1
	addss	(%rax,%rdx,4), %xmm0
	movss	%xmm0, 4(%r14,%rdx,4)
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB1_14
.LBB1_15:                               # %_Z7scanCPUPfS_y.exit94
	leaq	112(%rsp), %r15
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	96(%rsp), %rax
	movq	%rax, 160(%rsp)                 # 8-byte Spill
	movq	104(%rsp), %rax
	movq	%rax, 152(%rsp)                 # 8-byte Spill
	movq	(%r15), %rax
	movq	%rax, 144(%rsp)                 # 8-byte Spill
	movq	8(%r15), %rbp
	movq	88(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	testq	%rbx, %rbx
	je	.LBB1_22
# %bb.16:                               # %.lr.ph106
	movq	%rbx, %rax
	shrq	%rax
	movabsq	$-6640827866535438581, %rcx     # imm = 0xA3D70A3D70A3D70B
	mulq	%rcx
	movq	%rdx, %r15
	shrq	$4, %r15
	leaq	-1(%rbx), %r13
	xorl	%r12d, %r12d
.LBB1_17:                               # =>This Inner Loop Header: Depth=1
	cmpq	$51, %rbx
	jb	.LBB1_20
# %bb.18:                               #   in Loop: Header=BB1_17 Depth=1
	movq	%r12, %rax
	xorl	%edx, %edx
	divq	%r15
	cmpq	%r12, %r13
	je	.LBB1_20
# %bb.19:                               #   in Loop: Header=BB1_17 Depth=1
	testq	%rdx, %rdx
	jne	.LBB1_21
.LBB1_20:                               # %.sink.split
                                        #   in Loop: Header=BB1_17 Depth=1
	movss	(%r14,%r12,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 16(%rsp)                 # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movq	40(%rsp), %rax
	xorps	%xmm1, %xmm1
	cvtss2sd	(%rax,%r12,4), %xmm1
	movl	$.L.str.1, %edi
	movq	%r12, %rsi
	movq	%r12, %rdx
	movb	$2, %al
	callq	printf
	movq	40(%rsp), %rax
	movss	(%rax,%r12,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	16(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	subss	%xmm1, %xmm0
	divss	%xmm1, %xmm0
	andps	.LCPI1_6(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI1_7(%rip), %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
.LBB1_21:                               #   in Loop: Header=BB1_17 Depth=1
	incq	%r12
	cmpq	%r12, %rbx
	jne	.LBB1_17
.LBB1_22:                               # %._crit_edge107
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rbp, %xmm1
	xorps	%xmm0, %xmm0
	cvtsi2sdq	144(%rsp), %xmm0        # 8-byte Folded Reload
	cvtsi2sdq	152(%rsp), %xmm2        # 8-byte Folded Reload
	cvtsi2sdq	160(%rsp), %xmm3        # 8-byte Folded Reload
	cvtsi2sdq	168(%rsp), %xmm4        # 8-byte Folded Reload
	cvtsi2sdq	176(%rsp), %xmm14       # 8-byte Folded Reload
	cvtsi2sdq	128(%rsp), %xmm6        # 8-byte Folded Reload
	cvtsi2sdq	8(%rsp), %xmm5          # 8-byte Folded Reload
	cvtsi2sdq	184(%rsp), %xmm7        # 8-byte Folded Reload
	cvtsi2sdq	192(%rsp), %xmm15       # 8-byte Folded Reload
	cvtsi2sdq	200(%rsp), %xmm8        # 8-byte Folded Reload
	cvtsi2sdq	208(%rsp), %xmm9        # 8-byte Folded Reload
	cvtsi2sdq	216(%rsp), %xmm10       # 8-byte Folded Reload
	cvtsi2sdq	224(%rsp), %xmm11       # 8-byte Folded Reload
	movsd	%xmm11, 16(%rsp)                # 8-byte Spill
	cvtsi2sdq	232(%rsp), %xmm12       # 8-byte Folded Reload
	movsd	.LCPI1_8(%rip), %xmm11          # xmm11 = mem[0],zero
	divsd	%xmm11, %xmm1
	cvtsi2sdq	240(%rsp), %xmm13       # 8-byte Folded Reload
	addsd	%xmm1, %xmm0
	divsd	%xmm11, %xmm2
	xorps	%xmm1, %xmm1
	cvtsi2sdq	248(%rsp), %xmm1        # 8-byte Folded Reload
	addsd	%xmm2, %xmm3
	subsd	%xmm3, %xmm0
	xorps	%xmm2, %xmm2
	cvtsi2sdq	256(%rsp), %xmm2        # 8-byte Folded Reload
	movsd	%xmm2, 8(%rsp)                  # 8-byte Spill
	divsd	%xmm11, %xmm4
	addsd	%xmm4, %xmm14
	xorps	%xmm2, %xmm2
	cvtsi2sdq	56(%rsp), %xmm2         # 8-byte Folded Reload
	divsd	%xmm11, %xmm6
	addsd	%xmm6, %xmm5
	xorps	%xmm3, %xmm3
	cvtsi2sdq	64(%rsp), %xmm3         # 8-byte Folded Reload
	subsd	%xmm5, %xmm14
	movsd	%xmm14, 64(%rsp)                # 8-byte Spill
	divsd	%xmm11, %xmm7
	addsd	%xmm7, %xmm15
	divsd	%xmm11, %xmm8
	addsd	%xmm8, %xmm9
	subsd	%xmm9, %xmm15
	movsd	%xmm15, 56(%rsp)                # 8-byte Spill
	divsd	%xmm11, %xmm10
	movsd	16(%rsp), %xmm4                 # 8-byte Reload
                                        # xmm4 = mem[0],zero
	addsd	%xmm10, %xmm4
	divsd	%xmm11, %xmm12
	addsd	%xmm12, %xmm13
	subsd	%xmm13, %xmm4
	movsd	%xmm4, 16(%rsp)                 # 8-byte Spill
	divsd	%xmm11, %xmm1
	movsd	8(%rsp), %xmm4                  # 8-byte Reload
                                        # xmm4 = mem[0],zero
	addsd	%xmm1, %xmm4
	divsd	%xmm11, %xmm2
	addsd	%xmm2, %xmm3
	subsd	%xmm3, %xmm4
	movsd	%xmm4, 8(%rsp)                  # 8-byte Spill
	movl	$.L.str.3, %edi
	movq	%rbx, %rsi
	movb	$1, %al
	callq	printf
	movsd	.LCPI1_9(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$.L.str.4, %edi
	movq	%rbx, %rsi
	movb	$1, %al
	callq	printf
	movl	$.L.str.5, %edi
	movsd	.LCPI1_9(%rip), %xmm0           # xmm0 = mem[0],zero
	movsd	16(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movsd	56(%rsp), %xmm2                 # 8-byte Reload
                                        # xmm2 = mem[0],zero
	movsd	64(%rsp), %xmm3                 # 8-byte Reload
                                        # xmm3 = mem[0],zero
	movb	$4, %al
	callq	printf
	movl	$.L.str.6, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movsd	.LCPI1_9(%rip), %xmm1           # xmm1 = mem[0],zero
	movaps	%xmm1, %xmm2
	movaps	%xmm1, %xmm3
	movb	$4, %al
	callq	printf
	movq	%r14, %rdi
	callq	free
	movq	48(%rsp), %rdi
	callq	hipHostFree
	movq	40(%rsp), %rdi
	callq	hipHostFree
	movq	80(%rsp), %rdi
	callq	hipHostFree
	movq	72(%rsp), %rdi
	callq	hipHostFree
	xorl	%eax, %eax
	addq	$264, %rsp                      # imm = 0x108
	.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
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__prescanPfS_yS_m # -- Begin function _Z22__device_stub__prescanPfS_yS_m
	.type	_Z22__device_stub__prescanPfS_yS_m,@function
_Z22__device_stub__prescanPfS_yS_m:     # @_Z22__device_stub__prescanPfS_yS_m
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%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	$_Z7prescanPfS_yS_m, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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_end2:
	.size	_Z22__device_stub__prescanPfS_yS_m, .Lfunc_end2-_Z22__device_stub__prescanPfS_yS_m
	.cfi_endproc
                                        # -- End function
	.globl	_Z7scanCPUPfS_y                 # -- Begin function _Z7scanCPUPfS_y
	.type	_Z7scanCPUPfS_y,@function
_Z7scanCPUPfS_y:                        # @_Z7scanCPUPfS_y
	.cfi_startproc
# %bb.0:
	movl	$0, (%rdi)
	cmpq	$2, %rdx
	jb	.LBB3_3
# %bb.1:                                # %.lr.ph.preheader
	decq	%rdx
	xorps	%xmm0, %xmm0
	xorl	%eax, %eax
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	addss	(%rsi,%rax,4), %xmm0
	movss	%xmm0, 4(%rdi,%rax,4)
	incq	%rax
	cmpq	%rax, %rdx
	jne	.LBB3_2
.LBB3_3:                                # %._crit_edge
	retq
.Lfunc_end3:
	.size	_Z7scanCPUPfS_y, .Lfunc_end3-_Z7scanCPUPfS_y
	.cfi_endproc
                                        # -- End function
	.globl	_Z23__device_stub__postscanPfyS_ # -- Begin function _Z23__device_stub__postscanPfyS_
	.type	_Z23__device_stub__postscanPfyS_,@function
_Z23__device_stub__postscanPfyS_:       # @_Z23__device_stub__postscanPfyS_
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z8postscanPfyS_, %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_end4:
	.size	_Z23__device_stub__postscanPfyS_, .Lfunc_end4-_Z23__device_stub__postscanPfyS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z19__device_stub__scanPfS_y    # -- Begin function _Z19__device_stub__scanPfS_y
	.type	_Z19__device_stub__scanPfS_y,@function
_Z19__device_stub__scanPfS_y:           # @_Z19__device_stub__scanPfS_y
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z4scanPfS_y, %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_end5:
	.size	_Z19__device_stub__scanPfS_y, .Lfunc_end5-_Z19__device_stub__scanPfS_y
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4scanPfS_y, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8postscanPfyS_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7prescanPfS_yS_m, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"N=%d, B=%d\n\n"
	.size	.L.str, 13

	.type	_Z7prescanPfS_yS_m,@object      # @_Z7prescanPfS_yS_m
	.section	.rodata,"a",@progbits
	.globl	_Z7prescanPfS_yS_m
	.p2align	3, 0x0
_Z7prescanPfS_yS_m:
	.quad	_Z22__device_stub__prescanPfS_yS_m
	.size	_Z7prescanPfS_yS_m, 8

	.type	_Z8postscanPfyS_,@object        # @_Z8postscanPfyS_
	.globl	_Z8postscanPfyS_
	.p2align	3, 0x0
_Z8postscanPfyS_:
	.quad	_Z23__device_stub__postscanPfyS_
	.size	_Z8postscanPfyS_, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"c[%i] = %0.3f, g[%i] = %0.3f\n"
	.size	.L.str.1, 30

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"error percent = %f%\n"
	.size	.L.str.2, 21

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"CPU Time for scan size %i: %f\n"
	.size	.L.str.3, 31

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"GPU Time for scan size %i: %f\n"
	.size	.L.str.4, 31

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\tgpu Load=%f, Pre=%f, Sca=%f, Post=%f\n"
	.size	.L.str.5, 39

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"\t\tgpu load times={%f,%f,%f,%f}\n"
	.size	.L.str.6, 32

	.type	_Z4scanPfS_y,@object            # @_Z4scanPfS_y
	.section	.rodata,"a",@progbits
	.globl	_Z4scanPfS_y
	.p2align	3, 0x0
_Z4scanPfS_y:
	.quad	_Z19__device_stub__scanPfS_y
	.size	_Z4scanPfS_y, 8

	.type	.L__unnamed_1,@object           # @0
	.section	.rodata.str1.1,"aMS",@progbits,1
.L__unnamed_1:
	.asciz	"_Z4scanPfS_y"
	.size	.L__unnamed_1, 13

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z8postscanPfyS_"
	.size	.L__unnamed_2, 17

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z7prescanPfS_yS_m"
	.size	.L__unnamed_3, 19

	.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 _Z22__device_stub__prescanPfS_yS_m
	.addrsig_sym _Z23__device_stub__postscanPfyS_
	.addrsig_sym _Z19__device_stub__scanPfS_y
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z7prescanPfS_yS_m
	.addrsig_sym _Z8postscanPfyS_
	.addrsig_sym _Z4scanPfS_y
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4scanPfS_y            ; -- Begin function _Z4scanPfS_y
	.globl	_Z4scanPfS_y
	.p2align	8
	.type	_Z4scanPfS_y,@function
_Z4scanPfS_y:                           ; @_Z4scanPfS_y
; %bb.0:
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_dual_mov_b32 v1, 0 :: v_dual_lshlrev_b32 v2, 2, v0
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v4, v1
	v_cmpx_ne_u32_e32 0, v0
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_waitcnt lgkmcnt(0)
	global_load_b32 v4, v2, s[6:7] offset:-4
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s2
	s_waitcnt lgkmcnt(0)
	v_cmp_lt_u64_e64 s2, s[0:1], 2
	v_lshl_add_u32 v3, v0, 2, 0
	s_waitcnt vmcnt(0)
	ds_store_b32 v3, v4
	s_and_b32 vcc_lo, exec_lo, s2
	s_mov_b64 s[2:3], 0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_vccnz .LBB0_9
; %bb.3:                                ; %.lr.ph.preheader
	s_mov_b64 s[6:7], 1
.LBB0_4:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_mov_b64 s[8:9], s[2:3]
	s_mov_b32 s10, exec_lo
	s_sub_u32 s2, 1, s8
	s_subb_u32 s3, 0, s9
	s_mul_i32 s9, s8, s0
	s_mul_i32 s8, s2, s0
	v_cmpx_le_u64_e64 s[6:7], v[0:1]
	s_xor_b32 s10, exec_lo, s10
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=1
	v_add_nc_u32_e32 v4, s9, v0
	v_lshl_add_u32 v5, s8, 2, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_subrev_nc_u32_e32 v4, s6, v4
	v_lshl_add_u32 v4, v4, 2, 0
	ds_load_b32 v4, v4
	ds_load_b32 v6, v5
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v4, v4, v6
	ds_store_b32 v5, v4
.LBB0_6:                                ; %Flow
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_and_not1_saveexec_b32 s10, s10
	s_cbranch_execz .LBB0_8
; %bb.7:                                ;   in Loop: Header=BB0_4 Depth=1
	v_lshl_add_u32 v4, s9, 2, v3
	v_lshl_add_u32 v5, s8, 2, v3
	ds_load_b32 v4, v4
	s_waitcnt lgkmcnt(0)
	ds_store_b32 v5, v4
.LBB0_8:                                ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	s_lshl_b64 s[6:7], s[6:7], 1
	s_waitcnt lgkmcnt(0)
	v_cmp_ge_u64_e64 s8, s[6:7], s[0:1]
	s_barrier
	buffer_gl0_inv
	s_and_b32 vcc_lo, exec_lo, s8
	s_cbranch_vccz .LBB0_4
.LBB0_9:                                ; %Flow48
	s_mul_i32 s0, s2, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	v_lshl_add_u32 v0, s0, 2, v3
	ds_load_b32 v0, v0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v2, v0, s[4:5]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4scanPfS_y
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 24
		.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 7
		.amdhsa_next_free_sgpr 11
		.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	_Z4scanPfS_y, .Lfunc_end0-_Z4scanPfS_y
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 360
; NumSgprs: 13
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 13
; NumVGPRsForWavesPerEU: 7
; 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
	.protected	_Z8postscanPfyS_        ; -- Begin function _Z8postscanPfyS_
	.globl	_Z8postscanPfyS_
	.p2align	8
	.type	_Z8postscanPfyS_,@function
_Z8postscanPfyS_:                       ; @_Z8postscanPfyS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_mov_b32_e32 v2, 0
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_u64_e64 s[6:7], v[1:2]
	s_cbranch_execz .LBB1_2
; %bb.1:
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_load_b64 s[0:1], s[0:1], 0x10
	s_lshr_b32 s2, s15, 1
	s_mov_b32 s3, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_lshl_b64 s[2:3], s[2:3], 2
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_load_b32 v2, v[0:1], off
	s_waitcnt lgkmcnt(0)
	s_add_u32 s0, s0, s2
	s_addc_u32 s1, s1, s3
	s_load_b32 s0, s[0:1], 0x0
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_add_f32_e32 v2, s0, v2
	global_store_b32 v[0:1], v2, off
.LBB1_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8postscanPfyS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 3
		.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_end1:
	.size	_Z8postscanPfyS_, .Lfunc_end1-_Z8postscanPfyS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 164
; NumSgprs: 18
; NumVgprs: 3
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 3
; 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
	.protected	_Z7prescanPfS_yS_m      ; -- Begin function _Z7prescanPfS_yS_m
	.globl	_Z7prescanPfS_yS_m
	.p2align	8
	.type	_Z7prescanPfS_yS_m,@function
_Z7prescanPfS_yS_m:                     ; @_Z7prescanPfS_yS_m
; %bb.0:
	s_clause 0x2
	s_load_b32 s3, s[0:1], 0x34
	s_load_b64 s[12:13], s[0:1], 0x20
	s_load_b256 s[4:11], s[0:1], 0x0
	v_lshl_add_u32 v6, v0, 3, 0
	v_lshlrev_b32_e32 v7, 1, v0
	s_mov_b32 s2, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s0, s15, s3
	v_add_co_u32 v1, s0, s0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v2, null, 0, 0, s0
	v_lshlrev_b64 v[4:5], 1, v[1:2]
	v_mov_b32_e32 v1, 0
	ds_store_2addr_b32 v6, v1, v1 offset1:1
	v_cmp_gt_u64_e64 s0, s[12:13], v[4:5]
	v_lshlrev_b64 v[2:3], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_2)
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB2_2
; %bb.1:
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v8, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v9, vcc_lo, s7, v3, vcc_lo
	global_load_b32 v8, v[8:9], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v6, v8
.LBB2_2:
	s_or_b32 exec_lo, exec_lo, s1
	v_or_b32_e32 v4, 1, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_u64_e64 s1, s[12:13], v[4:5]
	s_and_saveexec_b32 s3, s1
	s_cbranch_execz .LBB2_4
; %bb.3:
	v_add_co_u32 v4, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v3, vcc_lo
	global_load_b32 v4, v[4:5], off offset:4
	s_waitcnt vmcnt(0)
	ds_store_b32 v6, v4 offset:4
.LBB2_4:
	s_or_b32 exec_lo, exec_lo, s3
	v_cmp_lt_u64_e64 s3, s[8:9], 2
	v_or_b32_e32 v4, 1, v7
	s_mov_b64 s[6:7], 1
	s_delay_alu instid0(VALU_DEP_2)
	s_and_b32 vcc_lo, exec_lo, s3
	s_cbranch_vccnz .LBB2_10
; %bb.5:                                ; %.lr.ph.preheader
	s_mov_b64 s[12:13], s[8:9]
.LBB2_6:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshr_b64 s[14:15], s[12:13], 1
	s_mov_b32 s3, exec_lo
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u64_e64 s[14:15], v[0:1]
	s_cbranch_execz .LBB2_8
; %bb.7:                                ;   in Loop: Header=BB2_6 Depth=1
	v_mad_u64_u32 v[7:8], null, s6, v4, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, s6, v7
	v_lshl_add_u32 v7, v7, 2, 0
	v_lshl_add_u32 v5, v5, 2, 0
	ds_load_b32 v7, v7
	ds_load_b32 v8, v5
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v7, v7, v8
	ds_store_b32 v5, v7
.LBB2_8:                                ;   in Loop: Header=BB2_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	v_cmp_lt_u64_e64 s3, s[12:13], 4
	s_lshl_b64 s[6:7], s[6:7], 1
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s3
	s_cbranch_vccnz .LBB2_10
; %bb.9:                                ;   in Loop: Header=BB2_6 Depth=1
	s_mov_b64 s[12:13], s[14:15]
	s_branch .LBB2_6
.LBB2_10:                               ; %Flow95
	s_mov_b32 s3, 0
	s_mov_b32 s12, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB2_12
; %bb.11:
	s_lshl_b64 s[2:3], s[2:3], 2
	v_mov_b32_e32 v8, 0
	s_add_u32 s2, s10, s2
	s_addc_u32 s3, s11, s3
	s_lshl_b32 s10, s8, 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s10, s10, 0
	s_add_i32 s10, s10, -4
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mov_b32_e32 v5, s10
	ds_load_b32 v7, v5
	ds_store_b32 v5, v8
	s_waitcnt lgkmcnt(1)
	global_store_b32 v8, v7, s[2:3]
.LBB2_12:
	s_or_b32 exec_lo, exec_lo, s12
	v_cmp_lt_u64_e64 s2, s[8:9], 2
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB2_17
; %bb.13:                               ; %.lr.ph76.preheader
	s_mov_b64 s[2:3], 1
.LBB2_14:                               ; %.lr.ph76
                                        ; =>This Inner Loop Header: Depth=1
	s_lshr_b64 s[6:7], s[6:7], 1
	s_mov_b32 s10, exec_lo
	s_waitcnt lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u64_e64 s[2:3], v[0:1]
	s_cbranch_execz .LBB2_16
; %bb.15:                               ;   in Loop: Header=BB2_14 Depth=1
	v_mad_u64_u32 v[7:8], null, s6, v4, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, s6, v7
	v_lshl_add_u32 v7, v7, 2, 0
	v_lshl_add_u32 v5, v5, 2, 0
	ds_load_b32 v8, v7
	ds_load_b32 v9, v5
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v8, v8, v9
	ds_store_b32 v7, v9
	ds_store_b32 v5, v8
.LBB2_16:                               ;   in Loop: Header=BB2_14 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	s_lshl_b64 s[2:3], s[2:3], 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_u64_e64 s10, s[2:3], s[8:9]
	s_and_b32 vcc_lo, exec_lo, s10
	s_cbranch_vccz .LBB2_14
.LBB2_17:                               ; %._crit_edge77
	s_waitcnt lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s2, s0
	s_cbranch_execz .LBB2_19
; %bb.18:
	ds_load_b32 v4, v6
	v_add_co_u32 v0, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v3, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v4, off
.LBB2_19:
	s_or_b32 exec_lo, exec_lo, s2
	s_and_saveexec_b32 s0, s1
	s_cbranch_execz .LBB2_21
; %bb.20:
	ds_load_b32 v4, v6 offset:4
	v_add_co_u32 v0, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v3, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v4, off offset:4
.LBB2_21:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7prescanPfS_yS_m
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 10
		.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_end2:
	.size	_Z7prescanPfS_yS_m, .Lfunc_end2-_Z7prescanPfS_yS_m
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 772
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 10
; 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
      - .offset:         16
        .size:           8
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4scanPfS_y
    .private_segment_fixed_size: 0
    .sgpr_count:     13
    .sgpr_spill_count: 0
    .symbol:         _Z4scanPfS_y.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           8
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8postscanPfyS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z8postscanPfyS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     3
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           8
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           8
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         160
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7prescanPfS_yS_m
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7prescanPfS_yS_m.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
