#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <cuda.h>
#include <math.h>


#define BLOCK_SIZE 1024


// Kernel for the first iteration of parallel scan
__global__ void parallelScan(float *d_out, float *d_in, int length) {
  volatile extern __shared__ double sharedData[];
  int tid = threadIdx.x + blockIdx.x * blockDim.x;
  int threadx = threadIdx.x;
  // load the data into the shared memory
  sharedData[threadx] = d_in[tid];
  __syncthreads();
  
  int pout = 0; int pin = 1;
  
  if (tid < length) {
	for (int offset = 1; offset < blockDim.x; offset <<= 1) {
		pout = 1 - pout;
		pin = 1 - pin;

		if (threadx >= offset) {
			sharedData[pout * blockDim.x + threadx] = sharedData[pin * blockDim.x + threadx] + sharedData[pin * blockDim.x + threadx - offset];
		} else {
			sharedData[pout * blockDim.x + threadx] = sharedData[pin * blockDim.x + threadx];
		}
	__syncthreads();
  }

  d_out[tid] = sharedData[pout * blockDim.x + threadx];
  //save the sum of the block back to d_in
  if (threadx == blockDim.x - 1) d_in[tid] = sharedData[pout * blockDim.x + threadx];
  }
}


__global__ void addPreSums(float *d_out, float *d_in)
{
	volatile extern __shared__ double sharedData[];
	int tid = threadIdx.x + blockIdx.x * blockDim.x;
	int bid = blockIdx.x + 1;
	int threadx = threadIdx.x;
	int bDim = blockDim.x;
	
	//load seperatedly scanned blocks (with one block offset)
	sharedData[threadx] = d_out[tid + bDim];
	
	//each thread adds the previous sums stored in the d_in
	for (int i=0; i<bid; i++) {
		sharedData[threadx] += d_in[i*bDim + bDim - 1];
	}
	__syncthreads();
	//store the sums back to the correct position
	d_out[tid + bDim] = sharedData[threadx];
}

// The function starts the prefix scan on values from d_in
void prefixScan(float * d_in, float *d_out, int num)
{	
	int blockx = (num + BLOCK_SIZE - 1)/BLOCK_SIZE; //blockx < 2^14, not exceeding the maximum
	dim3 dimGrid(blockx, 1, 1);
	dim3 dimBlock(BLOCK_SIZE, 1, 1);
	
	parallelScan<<<dimGrid, dimBlock, sizeof(double)*BLOCK_SIZE*2>>>(d_out, d_in, num);
	
	//when there is one more block
	if (blockx > 1) {
		//launch with one less block since we do not need to add previous sum for the very first block
		addPreSums<<<blockx - 1, BLOCK_SIZE, sizeof(double)*(BLOCK_SIZE)>>>(d_out,d_in);
	}
	
}


int checkResults(float*res, float* cudaRes,int length)
{
	int nDiffs=0;
	const float smallVal = 0.3f; // Keeping this extra high as we have repetitive addition and sequence matters
	for(int i=0; i<length; i++)
		if(fabs(cudaRes[i]-res[i])>smallVal){
			nDiffs++;
		}
	return nDiffs;
}

void initializeArray(FILE* fp,float* arr, int nElements)
{
	for( int i=0; i<nElements; i++){
		int r=fscanf(fp,"%f",&arr[i]);
		if(r == EOF){
			rewind(fp);
		}
		arr[i]-=5; // This is to make the data zero mean. Otherwise we reach large numbers and lose precision
	}
}

void inclusiveScan_SEQ(float *in, float *out,int length) {
	float sum=0.f;
	for (int i =0; i < length; i++) {
		sum+=in[i];
		out[i]=sum;
	}
}


int main(int argc, char* argv[]) {
	if(argc!=2){
		printf("Usage %s N\n",argv[0]);
		return 1;
	}
	int N=atoi(argv[1]);
	FILE *fp = fopen("problem1.inp","r");
	int size = N * sizeof(float); 
	//allocate resources
	float *in      = (float *)malloc(size);
	float *out     = (float *)malloc(size); 
	float *cuda_out= (float *)malloc(size);
	float time = 0.f;
	initializeArray(fp,in, N);

	//start inclusive timing
	cudaEvent_t startIn,stopIn;
	cudaEventCreate(&startIn);
	cudaEventCreate(&stopIn);
	cudaEventRecord(startIn, 0);

	float *d_in;
	float *d_out;
	cudaMalloc(&d_in, size);
	cudaMalloc(&d_out, size);
	cudaMemcpy(d_in, in, size, cudaMemcpyHostToDevice);
	
	prefixScan(d_in, d_out, N);

	cudaMemcpy(cuda_out, d_out, size, cudaMemcpyDeviceToHost);

	//stop inclusive timing
	cudaEventRecord(stopIn, 0);     
	cudaEventSynchronize(stopIn);
	cudaEventElapsedTime(&time, startIn, stopIn);     
	cudaEventDestroy(startIn); 
	cudaEventDestroy(stopIn);


	inclusiveScan_SEQ(in, out,N);
	int nDiffs = checkResults(out, cuda_out,N);
	if(nDiffs)printf("Test Failed\n"); // This should never print
	printf("%d\n%f\n%f\n",N,cuda_out[N-1],time);
	//printf("%f\n", time);


	//free resources 
	cudaFree(d_in);cudaFree(d_out);free(in); free(out); free(cuda_out);
	return 0;
}

	.file	"tmpxft_0037c3de_00000000-6_problem1.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3642:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3642:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12checkResultsPfS_i
	.type	_Z12checkResultsPfS_i, @function
_Z12checkResultsPfS_i:
.LFB3636:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	movss	.LC0(%rip), %xmm1
.L3:
	cmpl	%eax, %edx
	jle	.L9
	movss	(%rsi,%rax,4), %xmm0
	subss	(%rdi,%rax,4), %xmm0
	andps	%xmm1, %xmm0
	comiss	.LC1(%rip), %xmm0
	jbe	.L4
	incl	%ecx
.L4:
	incq	%rax
	jmp	.L3
.L9:
	movl	%ecx, %eax
	ret
	.cfi_endproc
.LFE3636:
	.size	_Z12checkResultsPfS_i, .-_Z12checkResultsPfS_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"%f"
	.text
	.globl	_Z15initializeArrayP8_IO_FILEPfi
	.type	_Z15initializeArrayP8_IO_FILEPfi, @function
_Z15initializeArrayP8_IO_FILEPfi:
.LFB3637:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC2(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rsi, %rbx
.L11:
	cmpl	%r12d, %r13d
	jge	.L15
	xorl	%eax, %eax
	movq	%rbx, %rdx
	movq	%r14, %rsi
	movq	%rbp, %rdi
	call	__isoc23_fscanf@PLT
	incl	%eax
	jne	.L12
	movq	%rbp, %rdi
	call	rewind@PLT
.L12:
	movss	(%rbx), %xmm0
	subss	.LC3(%rip), %xmm0
	incl	%r13d
	addq	$4, %rbx
	movss	%xmm0, -4(%rbx)
	jmp	.L11
.L15:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3637:
	.size	_Z15initializeArrayP8_IO_FILEPfi, .-_Z15initializeArrayP8_IO_FILEPfi
	.globl	_Z17inclusiveScan_SEQPfS_i
	.type	_Z17inclusiveScan_SEQPfS_i, @function
_Z17inclusiveScan_SEQPfS_i:
.LFB3638:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L17:
	cmpl	%eax, %edx
	jle	.L19
	addss	(%rdi,%rax,4), %xmm0
	movss	%xmm0, (%rsi,%rax,4)
	incq	%rax
	jmp	.L17
.L19:
	ret
	.cfi_endproc
.LFE3638:
	.size	_Z17inclusiveScan_SEQPfS_i, .-_Z17inclusiveScan_SEQPfS_i
	.globl	_Z35__device_stub__Z12parallelScanPfS_iPfS_i
	.type	_Z35__device_stub__Z12parallelScanPfS_iPfS_i, @function
_Z35__device_stub__Z12parallelScanPfS_iPfS_i:
.LFB3664:
	.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
	movl	%edx, 12(%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	12(%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	.L20
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z12parallelScanPfS_i(%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
.L20:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3664:
	.size	_Z35__device_stub__Z12parallelScanPfS_iPfS_i, .-_Z35__device_stub__Z12parallelScanPfS_iPfS_i
	.globl	_Z12parallelScanPfS_i
	.type	_Z12parallelScanPfS_i, @function
_Z12parallelScanPfS_i:
.LFB3665:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z12parallelScanPfS_iPfS_i
	.cfi_endproc
.LFE3665:
	.size	_Z12parallelScanPfS_i, .-_Z12parallelScanPfS_i
	.globl	_Z32__device_stub__Z10addPreSumsPfS_PfS_
	.type	_Z32__device_stub__Z10addPreSumsPfS_PfS_, @function
_Z32__device_stub__Z10addPreSumsPfS_PfS_:
.LFB3666:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z10addPreSumsPfS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L25:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3666:
	.size	_Z32__device_stub__Z10addPreSumsPfS_PfS_, .-_Z32__device_stub__Z10addPreSumsPfS_PfS_
	.globl	_Z10addPreSumsPfS_
	.type	_Z10addPreSumsPfS_, @function
_Z10addPreSumsPfS_:
.LFB3667:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z10addPreSumsPfS_PfS_
	.cfi_endproc
.LFE3667:
	.size	_Z10addPreSumsPfS_, .-_Z10addPreSumsPfS_
	.globl	_Z10prefixScanPfS_i
	.type	_Z10prefixScanPfS_i, @function
_Z10prefixScanPfS_i:
.LFB3635:
	.cfi_startproc
	endbr64
	leal	1023(%rdx), %eax
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$1024, %ecx
	movl	%edx, %r13d
	cltd
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	xorl	%r9d, %r9d
	idivl	%ecx
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%rsi, %rbp
	movl	$4194305, %edx
	movl	$16384, %r8d
	salq	$10, %rdx
	movl	$1, %ecx
	movl	%eax, (%rsp)
	movl	%eax, %ebx
	movabsq	$4294967297, %rax
	movq	%rax, 4(%rsp)
	movq	(%rsp), %rdi
	movl	8(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movl	%r13d, %edx
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	_Z35__device_stub__Z12parallelScanPfS_iPfS_i
.L31:
	cmpl	$1024, %r13d
	jle	.L30
	decl	%ebx
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	movl	$8192, %r8d
	movl	%ebx, 24(%rsp)
	salq	$10, %rdx
	movl	$1, %ecx
	movabsq	$4294967297, %rax
	movq	%rax, 28(%rsp)
	movq	24(%rsp), %rdi
	movl	32(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L30
	addq	$56, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movq	%r12, %rsi
	movq	%rbp, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	_Z32__device_stub__Z10addPreSumsPfS_PfS_
.L30:
	.cfi_restore_state
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z10prefixScanPfS_i, .-_Z10prefixScanPfS_i
	.section	.rodata.str1.1
.LC5:
	.string	"Usage %s N\n"
.LC6:
	.string	"r"
.LC7:
	.string	"problem1.inp"
.LC8:
	.string	"Test Failed\n"
.LC9:
	.string	"%d\n%f\n%f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3639:
	.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
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	je	.L36
	movq	(%rsi), %rdx
	movl	$2, %edi
	leaq	.LC5(%rip), %rsi
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L35
.L36:
	movq	8(%rsi), %rdi
	call	atoi@PLT
	leaq	.LC6(%rip), %rsi
	leaq	.LC7(%rip), %rdi
	movslq	%eax, %r15
	call	fopen@PLT
	leal	0(,%r15,4), %ebp
	movq	%r15, %rbx
	movslq	%ebp, %rbp
	movq	%rax, %r14
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movl	%r15d, %edx
	movq	%r13, %rsi
	movq	%r14, %rdi
	movq	%rax, %r12
	movl	$0x00000000, 20(%rsp)
	call	_Z15initializeArrayP8_IO_FILEPfi
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	leaq	40(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	leaq	48(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movq	40(%rsp), %rdi
	movq	%rbp, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdi
	movl	%r15d, %edx
	call	_Z10prefixScanPfS_i
	movq	48(%rsp), %rsi
	movq	%rbp, %rdx
	movq	%r12, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	leaq	20(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	24(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	32(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	8(%rsp), %rsi
	movq	%r13, %rdi
	movl	%r15d, %edx
	call	_Z17inclusiveScan_SEQPfS_i
	movq	8(%rsp), %rdi
	movq	%r12, %rsi
	call	_Z12checkResultsPfS_i
	testl	%eax, %eax
	je	.L38
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L38:
	movl	%ebx, %edx
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movb	$2, %al
	cvtss2sd	-4(%r12,%r15,4), %xmm0
	cvtss2sd	20(%rsp), %xmm1
	call	__printf_chk@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L35:
	movq	56(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$72, %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
.LFE3639:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z10addPreSumsPfS_"
.LC11:
	.string	"_Z12parallelScanPfS_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3669:
	.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	.LC10(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z10addPreSumsPfS_(%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	.LC11(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z12parallelScanPfS_i(%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
.LFE3669:
	.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.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1050253722
	.align 4
.LC3:
	.long	1084227584
	.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<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <hip/hip_runtime.h>
#include <math.h>


#define BLOCK_SIZE 1024


// Kernel for the first iteration of parallel scan
__global__ void parallelScan(float *d_out, float *d_in, int length) {
  volatile extern __shared__ double sharedData[];
  int tid = threadIdx.x + blockIdx.x * blockDim.x;
  int threadx = threadIdx.x;
  // load the data into the shared memory
  sharedData[threadx] = d_in[tid];
  __syncthreads();
  
  int pout = 0; int pin = 1;
  
  if (tid < length) {
	for (int offset = 1; offset < blockDim.x; offset <<= 1) {
		pout = 1 - pout;
		pin = 1 - pin;

		if (threadx >= offset) {
			sharedData[pout * blockDim.x + threadx] = sharedData[pin * blockDim.x + threadx] + sharedData[pin * blockDim.x + threadx - offset];
		} else {
			sharedData[pout * blockDim.x + threadx] = sharedData[pin * blockDim.x + threadx];
		}
	__syncthreads();
  }

  d_out[tid] = sharedData[pout * blockDim.x + threadx];
  //save the sum of the block back to d_in
  if (threadx == blockDim.x - 1) d_in[tid] = sharedData[pout * blockDim.x + threadx];
  }
}


__global__ void addPreSums(float *d_out, float *d_in)
{
	volatile extern __shared__ double sharedData[];
	int tid = threadIdx.x + blockIdx.x * blockDim.x;
	int bid = blockIdx.x + 1;
	int threadx = threadIdx.x;
	int bDim = blockDim.x;
	
	//load seperatedly scanned blocks (with one block offset)
	sharedData[threadx] = d_out[tid + bDim];
	
	//each thread adds the previous sums stored in the d_in
	for (int i=0; i<bid; i++) {
		sharedData[threadx] += d_in[i*bDim + bDim - 1];
	}
	__syncthreads();
	//store the sums back to the correct position
	d_out[tid + bDim] = sharedData[threadx];
}

// The function starts the prefix scan on values from d_in
void prefixScan(float * d_in, float *d_out, int num)
{	
	int blockx = (num + BLOCK_SIZE - 1)/BLOCK_SIZE; //blockx < 2^14, not exceeding the maximum
	dim3 dimGrid(blockx, 1, 1);
	dim3 dimBlock(BLOCK_SIZE, 1, 1);
	
	parallelScan<<<dimGrid, dimBlock, sizeof(double)*BLOCK_SIZE*2>>>(d_out, d_in, num);
	
	//when there is one more block
	if (blockx > 1) {
		//launch with one less block since we do not need to add previous sum for the very first block
		addPreSums<<<blockx - 1, BLOCK_SIZE, sizeof(double)*(BLOCK_SIZE)>>>(d_out,d_in);
	}
	
}


int checkResults(float*res, float* cudaRes,int length)
{
	int nDiffs=0;
	const float smallVal = 0.3f; // Keeping this extra high as we have repetitive addition and sequence matters
	for(int i=0; i<length; i++)
		if(fabs(cudaRes[i]-res[i])>smallVal){
			nDiffs++;
		}
	return nDiffs;
}

void initializeArray(FILE* fp,float* arr, int nElements)
{
	for( int i=0; i<nElements; i++){
		int r=fscanf(fp,"%f",&arr[i]);
		if(r == EOF){
			rewind(fp);
		}
		arr[i]-=5; // This is to make the data zero mean. Otherwise we reach large numbers and lose precision
	}
}

void inclusiveScan_SEQ(float *in, float *out,int length) {
	float sum=0.f;
	for (int i =0; i < length; i++) {
		sum+=in[i];
		out[i]=sum;
	}
}


int main(int argc, char* argv[]) {
	if(argc!=2){
		printf("Usage %s N\n",argv[0]);
		return 1;
	}
	int N=atoi(argv[1]);
	FILE *fp = fopen("problem1.inp","r");
	int size = N * sizeof(float); 
	//allocate resources
	float *in      = (float *)malloc(size);
	float *out     = (float *)malloc(size); 
	float *cuda_out= (float *)malloc(size);
	float time = 0.f;
	initializeArray(fp,in, N);

	//start inclusive timing
	hipEvent_t startIn,stopIn;
	hipEventCreate(&startIn);
	hipEventCreate(&stopIn);
	hipEventRecord(startIn, 0);

	float *d_in;
	float *d_out;
	hipMalloc(&d_in, size);
	hipMalloc(&d_out, size);
	hipMemcpy(d_in, in, size, hipMemcpyHostToDevice);
	
	prefixScan(d_in, d_out, N);

	hipMemcpy(cuda_out, d_out, size, hipMemcpyDeviceToHost);

	//stop inclusive timing
	hipEventRecord(stopIn, 0);     
	hipEventSynchronize(stopIn);
	hipEventElapsedTime(&time, startIn, stopIn);     
	hipEventDestroy(startIn); 
	hipEventDestroy(stopIn);


	inclusiveScan_SEQ(in, out,N);
	int nDiffs = checkResults(out, cuda_out,N);
	if(nDiffs)printf("Test Failed\n"); // This should never print
	printf("%d\n%f\n%f\n",N,cuda_out[N-1],time);
	//printf("%f\n", time);


	//free resources 
	hipFree(d_in);hipFree(d_out);free(in); free(out); free(cuda_out);
	return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z27__device_stub__parallelScanPfS_i # -- Begin function _Z27__device_stub__parallelScanPfS_i
	.type	_Z27__device_stub__parallelScanPfS_i,@function
_Z27__device_stub__parallelScanPfS_i:   # @_Z27__device_stub__parallelScanPfS_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), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%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	24(%rsp), %r12
	leaq	16(%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	$_Z12parallelScanPfS_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__parallelScanPfS_i, .Lfunc_end0-_Z27__device_stub__parallelScanPfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__addPreSumsPfS_ # -- Begin function _Z25__device_stub__addPreSumsPfS_
	.type	_Z25__device_stub__addPreSumsPfS_,@function
_Z25__device_stub__addPreSumsPfS_:      # @_Z25__device_stub__addPreSumsPfS_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z10addPreSumsPfS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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_end1:
	.size	_Z25__device_stub__addPreSumsPfS_, .Lfunc_end1-_Z25__device_stub__addPreSumsPfS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z10prefixScanPfS_i             # -- Begin function _Z10prefixScanPfS_i
	.type	_Z10prefixScanPfS_i,@function
_Z10prefixScanPfS_i:                    # @_Z10prefixScanPfS_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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edx, %r13d
	movq	%rsi, %r14
	movq	%rdi, %rbx
	movabsq	$4294967296, %r15               # imm = 0x100000000
	leal	1023(%r13), %eax
	leal	2046(%r13), %r12d
	testl	%eax, %eax
	cmovnsl	%eax, %r12d
	sarl	$10, %r12d
	movq	%r12, %rdi
	btsq	$32, %rdi
	leaq	1024(%r15), %rdx
	movl	$16384, %r8d                    # imm = 0x4000
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	movq	%r14, %rdi
	movq	%rbx, %rsi
	movl	%r13d, %edx
	callq	_Z27__device_stub__parallelScanPfS_i
.LBB2_2:
	cmpl	$1025, %r13d                    # imm = 0x401
	jl	.LBB2_4
# %bb.3:
	decl	%r12d
	orq	%r15, %r12
	addq	$1024, %r15                     # imm = 0x400
	movl	$8192, %r8d                     # imm = 0x2000
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	je	.LBB2_5
.LBB2_4:
	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
.LBB2_5:
	.cfi_def_cfa_offset 48
	movq	%r14, %rdi
	movq	%rbx, %rsi
	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
	jmp	_Z25__device_stub__addPreSumsPfS_ # TAILCALL
.Lfunc_end2:
	.size	_Z10prefixScanPfS_i, .Lfunc_end2-_Z10prefixScanPfS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z12checkResultsPfS_i
.LCPI3_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI3_1:
	.long	0x3e99999a                      # float 0.300000012
	.text
	.globl	_Z12checkResultsPfS_i
	.type	_Z12checkResultsPfS_i,@function
_Z12checkResultsPfS_i:                  # @_Z12checkResultsPfS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB3_1
# %bb.3:                                # %.lr.ph.preheader
	movl	%edx, %ecx
	xorl	%edx, %edx
	movaps	.LCPI3_0(%rip), %xmm0           # xmm0 = [NaN,NaN,NaN,NaN]
	movss	.LCPI3_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorl	%eax, %eax
.LBB3_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rsi,%rdx,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	(%rdi,%rdx,4), %xmm2
	andps	%xmm0, %xmm2
	xorl	%r8d, %r8d
	ucomiss	%xmm1, %xmm2
	seta	%r8b
	addl	%r8d, %eax
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB3_4
# %bb.2:                                # %._crit_edge
	retq
.LBB3_1:
	xorl	%eax, %eax
	retq
.Lfunc_end3:
	.size	_Z12checkResultsPfS_i, .Lfunc_end3-_Z12checkResultsPfS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z15initializeArrayP8_IO_FILEPfi
.LCPI4_0:
	.long	0xc0a00000                      # float -5
	.text
	.globl	_Z15initializeArrayP8_IO_FILEPfi
	.type	_Z15initializeArrayP8_IO_FILEPfi,@function
_Z15initializeArrayP8_IO_FILEPfi:       # @_Z15initializeArrayP8_IO_FILEPfi
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB4_6
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movl	%edx, %r15d
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str, %esi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$-1, %eax
	jne	.LBB4_4
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=1
	movq	%r14, %rdi
	callq	rewind
.LBB4_4:                                #   in Loop: Header=BB4_2 Depth=1
	movss	(%rbx), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	addss	.LCPI4_0(%rip), %xmm0
	movss	%xmm0, (%rbx)
	addq	$4, %rbx
	decq	%r15
	jne	.LBB4_2
# %bb.5:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB4_6:                                # %._crit_edge
	retq
.Lfunc_end4:
	.size	_Z15initializeArrayP8_IO_FILEPfi, .Lfunc_end4-_Z15initializeArrayP8_IO_FILEPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z17inclusiveScan_SEQPfS_i      # -- Begin function _Z17inclusiveScan_SEQPfS_i
	.type	_Z17inclusiveScan_SEQPfS_i,@function
_Z17inclusiveScan_SEQPfS_i:             # @_Z17inclusiveScan_SEQPfS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB5_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%edx, %eax
	xorps	%xmm0, %xmm0
	xorl	%ecx, %ecx
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	addss	(%rdi,%rcx,4), %xmm0
	movss	%xmm0, (%rsi,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB5_2
.LBB5_3:                                # %._crit_edge
	retq
.Lfunc_end5:
	.size	_Z17inclusiveScan_SEQPfS_i, .Lfunc_end5-_Z17inclusiveScan_SEQPfS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI6_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI6_1:
	.long	0x3e99999a                      # float 0.300000012
	.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
	cmpl	$2, %edi
	jne	.LBB6_1
# %bb.2:
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r14d
	movl	$.L.str.2, %edi
	movl	$.L.str.3, %esi
	callq	fopen
	movq	%rax, %r13
	leal	(,%r14,4), %eax
	movslq	%eax, %rbp
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r12
	leaq	4(%rsp), %rax
	movl	$0, (%rax)
	movq	%r13, %rdi
	movq	%rbx, %rsi
	movl	%r14d, %edx
	callq	_Z15initializeArrayP8_IO_FILEPfi
	leaq	32(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	16(%rsp), %r13
	movq	%r13, %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	movq	(%r13), %rdi
	movq	%rbx, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	leaq	8(%rsp), %rax
	movq	(%rax), %rsi
	movl	%r14d, %edx
	callq	_Z10prefixScanPfS_i
	leaq	8(%rsp), %rax
	movq	(%rax), %rsi
	movq	%r12, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %r13
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r13), %rdi
	callq	hipEventSynchronize
	leaq	32(%rsp), %rbp
	movq	(%rbp), %rsi
	movq	(%r13), %rdx
	leaq	4(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	(%rbp), %rdi
	callq	hipEventDestroy
	movq	(%r13), %rdi
	callq	hipEventDestroy
	testl	%r14d, %r14d
	jle	.LBB6_9
# %bb.3:                                # %.lr.ph.preheader.i
	movl	%r14d, %eax
	xorps	%xmm0, %xmm0
	xorl	%ecx, %ecx
.LBB6_4:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	addss	(%rbx,%rcx,4), %xmm0
	movss	%xmm0, (%r15,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB6_4
# %bb.5:                                # %.lr.ph.i33.preheader
	xorl	%ecx, %ecx
	movaps	.LCPI6_0(%rip), %xmm0           # xmm0 = [NaN,NaN,NaN,NaN]
	movss	.LCPI6_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorl	%edx, %edx
.LBB6_6:                                # %.lr.ph.i33
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r12,%rcx,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	(%r15,%rcx,4), %xmm2
	andps	%xmm0, %xmm2
	xorl	%esi, %esi
	ucomiss	%xmm1, %xmm2
	seta	%sil
	addl	%esi, %edx
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB6_6
# %bb.7:                                # %_Z12checkResultsPfS_i.exit
	testl	%edx, %edx
	je	.LBB6_9
# %bb.8:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB6_9:                                # %_Z12checkResultsPfS_i.exit.thread
	movslq	%r14d, %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	-4(%r12,%rax,4), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	4(%rsp), %xmm1
	movl	$.L.str.5, %edi
	movl	%r14d, %esi
	movb	$2, %al
	callq	printf
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	xorl	%eax, %eax
	jmp	.LBB6_10
.LBB6_1:
	movq	(%rsi), %rsi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %eax
.LBB6_10:
                                        # kill: def $eax killed $eax killed $rax
	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
.Lfunc_end6:
	.size	main, .Lfunc_end6-main
	.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	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12parallelScanPfS_i, %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	$_Z10addPreSumsPfS_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %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_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z12parallelScanPfS_i,@object   # @_Z12parallelScanPfS_i
	.section	.rodata,"a",@progbits
	.globl	_Z12parallelScanPfS_i
	.p2align	3, 0x0
_Z12parallelScanPfS_i:
	.quad	_Z27__device_stub__parallelScanPfS_i
	.size	_Z12parallelScanPfS_i, 8

	.type	_Z10addPreSumsPfS_,@object      # @_Z10addPreSumsPfS_
	.globl	_Z10addPreSumsPfS_
	.p2align	3, 0x0
_Z10addPreSumsPfS_:
	.quad	_Z25__device_stub__addPreSumsPfS_
	.size	_Z10addPreSumsPfS_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%f"
	.size	.L.str, 3

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Usage %s N\n"
	.size	.L.str.1, 12

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"problem1.inp"
	.size	.L.str.2, 13

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"r"
	.size	.L.str.3, 2

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%d\n%f\n%f\n"
	.size	.L.str.5, 10

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12parallelScanPfS_i"
	.size	.L__unnamed_1, 22

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z10addPreSumsPfS_"
	.size	.L__unnamed_2, 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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Test Failed"
	.size	.Lstr, 12

	.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__parallelScanPfS_i
	.addrsig_sym _Z25__device_stub__addPreSumsPfS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z12parallelScanPfS_i
	.addrsig_sym _Z10addPreSumsPfS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12parallelScanPfS_i   ; -- Begin function _Z12parallelScanPfS_i
	.globl	_Z12parallelScanPfS_i
	.p2align	8
	.type	_Z12parallelScanPfS_i,@function
_Z12parallelScanPfS_i:                  ; @_Z12parallelScanPfS_i
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s8, s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	v_lshl_add_u32 v7, v0, 3, 0
	s_mov_b64 s[0:1], src_shared_base
	s_mov_b32 s3, 0
	s_mov_b32 s0, exec_lo
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[5:6], null, s15, s2, v[0:1]
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[5:6]
	v_add_co_u32 v1, vcc_lo, s6, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v4, vcc_lo
	v_cmp_ne_u32_e32 vcc_lo, -1, v7
	global_load_b32 v6, v[1:2], off
	v_cndmask_b32_e32 v10, 0, v7, vcc_lo
	v_cndmask_b32_e64 v11, 0, s1, vcc_lo
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[8:9], v6
	flat_store_b64 v[10:11], v[8:9] dlc
	s_waitcnt_vscnt null, 0x0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_i32_e64 s8, v5
	s_cbranch_execz .LBB0_8
; %bb.1:                                ; %.preheader
	s_cmp_lt_u32 s2, 2
	s_cbranch_scc1 .LBB0_6
; %bb.2:                                ; %.lr.ph.preheader
	s_mov_b64 s[0:1], src_shared_base
	s_mov_b32 s6, 1
	s_mov_b32 s0, 1
.LBB0_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_sub_i32 s0, 1, s0
	s_mov_b32 s7, exec_lo
	s_mul_i32 s8, s0, s2
	v_lshl_add_u32 v5, s8, 3, v7
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v5
	v_cndmask_b32_e32 v5, 0, v5, vcc_lo
	v_cndmask_b32_e64 v6, 0, s1, vcc_lo
	flat_load_b64 v[5:6], v[5:6] glc dlc
	s_waitcnt vmcnt(0)
	v_cmpx_le_u32_e64 s6, v0
	s_cbranch_execz .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=1
	v_add_nc_u32_e32 v8, s8, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_subrev_nc_u32_e32 v8, s6, v8
	v_lshl_add_u32 v8, v8, 3, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v8
	v_cndmask_b32_e32 v8, 0, v8, vcc_lo
	v_cndmask_b32_e64 v9, 0, s1, vcc_lo
	flat_load_b64 v[8:9], v[8:9] glc dlc
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_add_f64 v[5:6], v[5:6], v[8:9]
.LBB0_5:                                ;   in Loop: Header=BB0_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s7
	s_sub_i32 s3, 1, s3
	s_lshl_b32 s6, s6, 1
	s_mul_i32 s7, s3, s2
	s_cmp_ge_u32 s6, s2
	v_lshl_add_u32 v8, s7, 3, v7
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v8
	v_cndmask_b32_e32 v8, 0, v8, vcc_lo
	v_cndmask_b32_e64 v9, 0, s1, vcc_lo
	s_waitcnt lgkmcnt(0)
	flat_store_b64 v[8:9], v[5:6] dlc
	s_waitcnt_vscnt null, 0x0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_3
.LBB0_6:                                ; %Flow50
	s_mul_i32 s0, s3, s2
	s_add_i32 s2, s2, -1
	v_lshl_add_u32 v5, s0, 3, v7
	s_mov_b64 s[0:1], src_shared_base
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v5
	v_cndmask_b32_e32 v5, 0, v5, vcc_lo
	v_cndmask_b32_e64 v6, 0, s1, vcc_lo
	v_add_co_u32 v3, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	flat_load_b64 v[7:8], v[5:6] glc dlc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, s2, v0
	s_waitcnt lgkmcnt(0)
	v_cvt_f32_f64_e32 v7, v[7:8]
	global_store_b32 v[3:4], v7, off
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_8
; %bb.7:
	flat_load_b64 v[3:4], v[5:6] glc dlc
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_cvt_f32_f64_e32 v0, v[3:4]
	global_store_b32 v[1:2], v0, off
.LBB0_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12parallelScanPfS_i
		.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 12
		.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	_Z12parallelScanPfS_i, .Lfunc_end0-_Z12parallelScanPfS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 536
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; 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	_Z10addPreSumsPfS_      ; -- Begin function _Z10addPreSumsPfS_
	.globl	_Z10addPreSumsPfS_
	.p2align	8
	.type	_Z10addPreSumsPfS_,@function
_Z10addPreSumsPfS_:                     ; @_Z10addPreSumsPfS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_cmp_gt_u32 s15, 0x7ffffffe
	s_mul_i32 s5, s15, s4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add3_u32 v1, s5, s4, v0
	v_lshl_add_u32 v0, v0, 3, 0
	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], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	v_cmp_ne_u32_e32 vcc_lo, -1, v0
	s_mov_b64 s[0:1], src_shared_base
	global_load_b32 v3, v[1:2], off
	v_cndmask_b32_e64 v4, 0, s1, vcc_lo
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[5:6], v3
	v_cndmask_b32_e32 v3, 0, v0, vcc_lo
	flat_store_b64 v[3:4], v[5:6] dlc
	s_waitcnt_vscnt null, 0x0
	s_cbranch_scc1 .LBB1_3
; %bb.1:                                ; %.lr.ph.preheader
	s_add_u32 s2, s2, -4
	s_addc_u32 s3, s3, -1
	s_add_i32 s5, s15, 1
	s_mov_b32 s0, s4
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_ashr_i32 s1, s0, 31
	s_lshl_b64 s[6:7], s[0:1], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s6, s2, s6
	s_addc_u32 s7, s3, s7
	s_add_i32 s5, s5, -1
	s_load_b32 s1, s[6:7], 0x0
	flat_load_b64 v[5:6], v[3:4] glc dlc
	s_waitcnt vmcnt(0)
	s_add_i32 s0, s0, s4
	s_cmp_eq_u32 s5, 0
	s_waitcnt lgkmcnt(0)
	v_cvt_f64_f32_e32 v[7:8], s1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[5:6], v[5:6], v[7:8]
	flat_store_b64 v[3:4], v[5:6] dlc
	s_waitcnt_vscnt null, 0x0
	s_cbranch_scc0 .LBB1_2
.LBB1_3:                                ; %._crit_edge
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	flat_load_b64 v[3:4], v[3:4] glc dlc
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_cvt_f32_f64_e32 v0, v[3:4]
	global_store_b32 v[1:2], v0, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10addPreSumsPfS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 9
		.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	_Z10addPreSumsPfS_, .Lfunc_end1-_Z10addPreSumsPfS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 308
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; 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 sharedData
	.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:           4
        .value_kind:     by_value
      - .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
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .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:           _Z12parallelScanPfS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12parallelScanPfS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .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:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         136
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10addPreSumsPfS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10addPreSumsPfS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
