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

#define BLOCK_SIZE 512

#define _check(stmt)                                                      \
  do {                                                                    \
    cudaError_t err = stmt;                                               \
    if (err != cudaSuccess) {                                             \
      printf("Failed to run stmt ", #stmt);                               \
      printf("Got CUDA error ...  ", cudaGetErrorString(err));            \
      return -1;                                                          \
    }                                                                     \
  } while (0)

__global__ void add(float* arr, float* aux, int len) {
  int j = blockIdx.x-1;
  int i = threadIdx.x + blockIdx.x*BLOCK_SIZE;
  if(i < len && j >= 0) {
    arr[i] = arr[i] + aux[j];
  }
}

__global__ void reduce(float *input, float *output, int len) {
  int id = threadIdx.x;
  int pos = threadIdx.x + blockIdx.x*BLOCK_SIZE;
  if((blockIdx.x+1)*BLOCK_SIZE > len) {
    if(id == (len - blockIdx.x*BLOCK_SIZE - 1)) {
      output[blockIdx.x] = input[pos];
    }
  }
  else {
    output[blockIdx.x] = input[(blockIdx.x+1)*BLOCK_SIZE - 1];
  }
}

__global__ void scan(float *input, float *output, int len) {
  __shared__ float ls[BLOCK_SIZE];

  int stride = 0x1;
  int i = threadIdx.x;
  int ind = threadIdx.x + blockIdx.x*BLOCK_SIZE;
  float temp;
  // Load into the local_scan:
  if(ind < len){
    ls[i] = input[ind];
  }
  else {
    ls[i] = 0.0;
  }
  
  for(stride = 0x1; stride < BLOCK_SIZE; stride = stride << 1) {
    __syncthreads();
    if(i >= stride) {
      temp = ls[i] + ls[i-stride];
    }
    __syncthreads();
    if(i >= stride) {
      ls[i] = temp;
    }
  }
  
  // Copy to output array:
  if(ind < len) {
    output[ind] = ls[i];
  }
}

int main(int argc, char** argv) {
  if(argc != 2) {
    printf("Usage: ./scan <input_data_file>\n");
    return -1;
  }

  float *hostInput;  // The input 1D list
  float *hostOutput; // The output list
  float *deviceInput;
  float *deviceOutput;
  int numElements; // number of elements in the list

  FILE* infile = fopen(argv[1], "r");
  fscanf(infile, "%d\n", &numElements);

  hostInput = (float*)malloc(numElements * sizeof(float));
  hostOutput = (float *)malloc(numElements * sizeof(float));

  for(int i = 0; i < numElements; i++) {
    int temp;
    fscanf(infile, "%d\n", &temp);
    hostInput[i] = (float)temp;
    printf("%d, ", (int)hostInput[i]);
  }
  printf("\n");

  _check(cudaMalloc((void **)&deviceInput, numElements * sizeof(float)));
  _check(cudaMalloc((void **)&deviceOutput, numElements * sizeof(float)));

  _check(cudaMemset(deviceOutput, 0, numElements * sizeof(float)));

  _check(cudaMemcpy(deviceInput, hostInput, numElements * sizeof(float), cudaMemcpyHostToDevice));

  int grid_size = ceil((float)numElements/BLOCK_SIZE);
  dim3 scan_grid(grid_size,1,1);
  dim3 scan_block(BLOCK_SIZE,1,1);
  dim3 aux_grid(ceil((float)grid_size/BLOCK_SIZE),1,1);
  dim3 aux_block(BLOCK_SIZE,1,1);
  dim3 reduce_block(BLOCK_SIZE>>1,1,1);

  // Allocate the auxillary reduction array:
  float* deviceAuxIn;
  float* hostAuxIn;
  float* deviceAuxOut;
  float* hostAuxOut;
  _check(cudaMalloc((void **)&deviceAuxIn, grid_size*sizeof(float)));
  _check(cudaMalloc((void **)&deviceAuxOut, grid_size*sizeof(float)));
  hostAuxIn = (float*)malloc(grid_size*sizeof(float));
  hostAuxIn = (float*)malloc(grid_size*sizeof(float));

  // 1. Scan individual blocks:
  scan<<<scan_grid, scan_block>>>(deviceInput, deviceOutput, numElements);

  // 2. Compute a Reduction on Each Block:
  reduce<<<scan_grid, reduce_block>>>(deviceOutput, deviceAuxIn, numElements);

  _check(cudaMemcpy(hostAuxIn, deviceAuxIn, grid_size * sizeof(float), cudaMemcpyDeviceToHost));
  for(int i = 0; i < grid_size; i++) {
    printf("%d, ",(int)hostAuxIn[i]);
  }
  printf("\n");


  // 3. Scan the aux array:
  scan<<<aux_grid, aux_block>>>(deviceAuxIn, deviceAuxOut, grid_size);

  _check(cudaMemcpy(hostAuxOut, deviceAuxOut, grid_size * sizeof(float), cudaMemcpyDeviceToHost));
  for(int i = 0; i < grid_size; i++) {
    printf("%d, ",(int)hostAuxOut[i]);
  }
  printf("\n");

  // 4. Add the aux to the individual scanned blocks:
  add<<<scan_grid, scan_block>>>(deviceOutput, deviceAuxOut, numElements);

  cudaDeviceSynchronize();

  _check(cudaMemcpy(hostOutput, deviceOutput, numElements * sizeof(float), cudaMemcpyDeviceToHost));

  for(int i = 0; i < numElements; i++) {
    printf("%d, ", (int)hostOutput[i]);
  }
  printf("\n");

  cudaFree(deviceInput);
  cudaFree(deviceOutput);
  free(hostInput);
  free(hostOutput);

  return 0;
} 

	.file	"tmpxft_00312658_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z25__device_stub__Z3addPfS_iPfS_i
	.type	_Z25__device_stub__Z3addPfS_iPfS_i, @function
_Z25__device_stub__Z3addPfS_iPfS_i:
.LFB2052:
	.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	.L2
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z3addPfS_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
.L2:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z25__device_stub__Z3addPfS_iPfS_i, .-_Z25__device_stub__Z3addPfS_iPfS_i
	.globl	_Z3addPfS_i
	.type	_Z3addPfS_i, @function
_Z3addPfS_i:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z25__device_stub__Z3addPfS_iPfS_i
	.cfi_endproc
.LFE2053:
	.size	_Z3addPfS_i, .-_Z3addPfS_i
	.globl	_Z28__device_stub__Z6reducePfS_iPfS_i
	.type	_Z28__device_stub__Z6reducePfS_iPfS_i, @function
_Z28__device_stub__Z6reducePfS_iPfS_i:
.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
	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	.L8
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z6reducePfS_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
.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	_Z28__device_stub__Z6reducePfS_iPfS_i, .-_Z28__device_stub__Z6reducePfS_iPfS_i
	.globl	_Z6reducePfS_i
	.type	_Z6reducePfS_i, @function
_Z6reducePfS_i:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z6reducePfS_iPfS_i
	.cfi_endproc
.LFE2055:
	.size	_Z6reducePfS_i, .-_Z6reducePfS_i
	.globl	_Z26__device_stub__Z4scanPfS_iPfS_i
	.type	_Z26__device_stub__Z4scanPfS_iPfS_i, @function
_Z26__device_stub__Z4scanPfS_iPfS_i:
.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
	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	.L13
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z4scanPfS_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
.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	_Z26__device_stub__Z4scanPfS_iPfS_i, .-_Z26__device_stub__Z4scanPfS_iPfS_i
	.globl	_Z4scanPfS_i
	.type	_Z4scanPfS_i, @function
_Z4scanPfS_i:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z4scanPfS_iPfS_i
	.cfi_endproc
.LFE2057:
	.size	_Z4scanPfS_i, .-_Z4scanPfS_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Usage: ./scan <input_data_file>\n"
.LC1:
	.string	"r"
.LC2:
	.string	"%d\n"
.LC3:
	.string	"%d, "
.LC4:
	.string	"\n"
.LC5:
	.string	"cudaMalloc((void **)&deviceInput, numElements * sizeof(float))"
.LC6:
	.string	"Failed to run stmt "
.LC7:
	.string	"Got CUDA error ...  "
.LC8:
	.string	"cudaMalloc((void **)&deviceOutput, numElements * sizeof(float))"
.LC9:
	.string	"cudaMemset(deviceOutput, 0, numElements * sizeof(float))"
.LC10:
	.string	"cudaMemcpy(deviceInput, hostInput, numElements * sizeof(float), cudaMemcpyHostToDevice)"
.LC12:
	.string	"cudaMalloc((void **)&deviceAuxIn, grid_size*sizeof(float))"
.LC13:
	.string	"cudaMalloc((void **)&deviceAuxOut, grid_size*sizeof(float))"
.LC14:
	.string	"cudaMemcpy(hostAuxIn, deviceAuxIn, grid_size * sizeof(float), cudaMemcpyDeviceToHost)"
.LC15:
	.string	"cudaMemcpy(hostAuxOut, deviceAuxOut, grid_size * sizeof(float), cudaMemcpyDeviceToHost)"
.LC16:
	.string	"cudaMemcpy(hostOutput, deviceOutput, numElements * sizeof(float), cudaMemcpyDeviceToHost)"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.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	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	je	.L19
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L20
.L19:
	movq	8(%rsi), %rdi
	leaq	.LC1(%rip), %rsi
	leaq	.LC2(%rip), %r14
	leaq	.LC3(%rip), %r15
	call	fopen@PLT
	leaq	20(%rsp), %rdx
	movq	%r14, %rsi
	movq	%rax, %rdi
	movq	%rax, %r13
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movslq	20(%rsp), %rbx
	salq	$2, %rbx
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rdi
	xorl	%ebx, %ebx
	movq	%rax, %r12
	call	malloc@PLT
	movq	%rax, %rbp
.L21:
	cmpl	%ebx, 20(%rsp)
	jle	.L51
	leaq	108(%rsp), %rdx
	movq	%r14, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	cvtsi2ssl	108(%rsp), %xmm0
	movq	%r15, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	cvttss2sil	%xmm0, %edx
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L21
.L51:
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movslq	20(%rsp), %rsi
	leaq	24(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L23
	leaq	.LC5(%rip), %rdx
.L49:
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %edi
.L48:
	call	cudaGetErrorString@PLT
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L20:
	orl	$-1, %eax
	jmp	.L18
.L23:
	movslq	20(%rsp), %rsi
	leaq	32(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	leaq	.LC8(%rip), %rdx
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L49
	movslq	20(%rsp), %rdx
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	salq	$2, %rdx
	call	cudaMemset@PLT
	leaq	.LC9(%rip), %rdx
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L49
	movslq	20(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	leaq	.LC10(%rip), %rdx
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L49
	movabsq	$4294967808, %r14
	cvtsi2ssl	20(%rsp), %xmm0
	movabsq	$4294967297, %r15
	mulss	.LC11(%rip), %xmm0
	call	ceilf@PLT
	movq	%r14, 72(%rsp)
	cvttss2sil	%xmm0, %ebx
	movq	%r15, 64(%rsp)
	movl	$1, 80(%rsp)
	cvtsi2ssl	%ebx, %xmm0
	mulss	.LC11(%rip), %xmm0
	movl	%ebx, 60(%rsp)
	call	ceilf@PLT
	leaq	40(%rsp), %rdi
	movq	%r14, 96(%rsp)
	cvttss2siq	%xmm0, %rax
	movq	%r15, 88(%rsp)
	movl	$1, 104(%rsp)
	movl	$1, 116(%rsp)
	movl	%eax, 84(%rsp)
	movl	$16777217, %eax
	salq	$8, %rax
	movq	%rax, 108(%rsp)
	movslq	%ebx, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
	leaq	.LC12(%rip), %rdx
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L50
	movq	8(%rsp), %rsi
	leaq	48(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	.LC13(%rip), %rdx
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L50
	movq	8(%rsp), %rdi
	call	malloc@PLT
	movl	80(%rsp), %ecx
	movl	68(%rsp), %esi
	xorl	%r9d, %r9d
	movq	72(%rsp), %rdx
	movq	60(%rsp), %rdi
	xorl	%r8d, %r8d
	movq	%rax, %r14
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L30
	movl	20(%rsp), %edx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z26__device_stub__Z4scanPfS_iPfS_i
.L30:
	movl	116(%rsp), %ecx
	movq	108(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	60(%rsp), %rdi
	movl	68(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movl	20(%rsp), %edx
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z28__device_stub__Z6reducePfS_iPfS_i
.L31:
	movq	8(%rsp), %rdx
	movq	40(%rsp), %rsi
	movq	%r14, %rdi
	xorl	%r13d, %r13d
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	%eax, %r15d
	testl	%eax, %eax
	je	.L32
	movl	$2, %edi
	leaq	.LC14(%rip), %rdx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%r15d, %edi
	jmp	.L48
.L32:
	cmpl	%r13d, %ebx
	jle	.L52
	cvttss2sil	(%r14,%r13,4), %edx
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%r13
	call	__printf_chk@PLT
	jmp	.L32
.L52:
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	104(%rsp), %ecx
	movl	92(%rsp), %esi
	xorl	%r9d, %r9d
	movq	96(%rsp), %rdx
	movq	84(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdi
	movl	%ebx, %edx
	call	_Z26__device_stub__Z4scanPfS_iPfS_i
.L34:
	movq	8(%rsp), %rdx
	movq	48(%rsp), %rsi
	xorl	%edi, %edi
	xorl	%r14d, %r14d
	movl	$2, %ecx
	leaq	.LC3(%rip), %r15
	call	cudaMemcpy@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L35
	movl	$2, %edi
	leaq	.LC15(%rip), %rdx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%r13d, %edi
	jmp	.L48
.L35:
	cmpl	%r14d, %ebx
	jle	.L53
	cvttss2sil	0(,%r14,4), %edx
	movq	%r15, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%r14
	call	__printf_chk@PLT
	jmp	.L35
.L53:
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	80(%rsp), %ecx
	movl	68(%rsp), %esi
	xorl	%r9d, %r9d
	movq	72(%rsp), %rdx
	movq	60(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	movl	20(%rsp), %edx
	movq	48(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z25__device_stub__Z3addPfS_iPfS_i
.L37:
	call	cudaDeviceSynchronize@PLT
	movslq	20(%rsp), %rdx
	movq	%rbp, %rdi
	xorl	%ebx, %ebx
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	leaq	.LC3(%rip), %r15
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	je	.L38
	leaq	.LC16(%rip), %rdx
.L50:
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%r14d, %edi
	jmp	.L48
.L38:
	cmpl	%ebx, 20(%rsp)
	jle	.L54
	cvttss2sil	0(%rbp,%rbx,4), %edx
	movq	%r15, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L38
.L54:
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L18:
	movq	120(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$136, %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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC17:
	.string	"_Z4scanPfS_i"
.LC18:
	.string	"_Z6reducePfS_i"
.LC19:
	.string	"_Z3addPfS_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.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	.LC17(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z4scanPfS_i(%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	.LC18(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z6reducePfS_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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC19(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z3addPfS_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
.LFE2059:
	.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.cst4,"aM",@progbits,4
	.align 4
.LC11:
	.long	989855744
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define BLOCK_SIZE 512

#define _check(stmt)                                                      \
  do {                                                                    \
    hipError_t err = stmt;                                               \
    if (err != hipSuccess) {                                             \
      printf("Failed to run stmt ", #stmt);                               \
      printf("Got CUDA error ...  ", hipGetErrorString(err));            \
      return -1;                                                          \
    }                                                                     \
  } while (0)

__global__ void add(float* arr, float* aux, int len) {
  int j = blockIdx.x-1;
  int i = threadIdx.x + blockIdx.x*BLOCK_SIZE;
  if(i < len && j >= 0) {
    arr[i] = arr[i] + aux[j];
  }
}

__global__ void reduce(float *input, float *output, int len) {
  int id = threadIdx.x;
  int pos = threadIdx.x + blockIdx.x*BLOCK_SIZE;
  if((blockIdx.x+1)*BLOCK_SIZE > len) {
    if(id == (len - blockIdx.x*BLOCK_SIZE - 1)) {
      output[blockIdx.x] = input[pos];
    }
  }
  else {
    output[blockIdx.x] = input[(blockIdx.x+1)*BLOCK_SIZE - 1];
  }
}

__global__ void scan(float *input, float *output, int len) {
  __shared__ float ls[BLOCK_SIZE];

  int stride = 0x1;
  int i = threadIdx.x;
  int ind = threadIdx.x + blockIdx.x*BLOCK_SIZE;
  float temp;
  // Load into the local_scan:
  if(ind < len){
    ls[i] = input[ind];
  }
  else {
    ls[i] = 0.0;
  }
  
  for(stride = 0x1; stride < BLOCK_SIZE; stride = stride << 1) {
    __syncthreads();
    if(i >= stride) {
      temp = ls[i] + ls[i-stride];
    }
    __syncthreads();
    if(i >= stride) {
      ls[i] = temp;
    }
  }
  
  // Copy to output array:
  if(ind < len) {
    output[ind] = ls[i];
  }
}

int main(int argc, char** argv) {
  if(argc != 2) {
    printf("Usage: ./scan <input_data_file>\n");
    return -1;
  }

  float *hostInput;  // The input 1D list
  float *hostOutput; // The output list
  float *deviceInput;
  float *deviceOutput;
  int numElements; // number of elements in the list

  FILE* infile = fopen(argv[1], "r");
  fscanf(infile, "%d\n", &numElements);

  hostInput = (float*)malloc(numElements * sizeof(float));
  hostOutput = (float *)malloc(numElements * sizeof(float));

  for(int i = 0; i < numElements; i++) {
    int temp;
    fscanf(infile, "%d\n", &temp);
    hostInput[i] = (float)temp;
    printf("%d, ", (int)hostInput[i]);
  }
  printf("\n");

  _check(hipMalloc((void **)&deviceInput, numElements * sizeof(float)));
  _check(hipMalloc((void **)&deviceOutput, numElements * sizeof(float)));

  _check(hipMemset(deviceOutput, 0, numElements * sizeof(float)));

  _check(hipMemcpy(deviceInput, hostInput, numElements * sizeof(float), hipMemcpyHostToDevice));

  int grid_size = ceil((float)numElements/BLOCK_SIZE);
  dim3 scan_grid(grid_size,1,1);
  dim3 scan_block(BLOCK_SIZE,1,1);
  dim3 aux_grid(ceil((float)grid_size/BLOCK_SIZE),1,1);
  dim3 aux_block(BLOCK_SIZE,1,1);
  dim3 reduce_block(BLOCK_SIZE>>1,1,1);

  // Allocate the auxillary reduction array:
  float* deviceAuxIn;
  float* hostAuxIn;
  float* deviceAuxOut;
  float* hostAuxOut;
  _check(hipMalloc((void **)&deviceAuxIn, grid_size*sizeof(float)));
  _check(hipMalloc((void **)&deviceAuxOut, grid_size*sizeof(float)));
  hostAuxIn = (float*)malloc(grid_size*sizeof(float));
  hostAuxIn = (float*)malloc(grid_size*sizeof(float));

  // 1. Scan individual blocks:
  scan<<<scan_grid, scan_block>>>(deviceInput, deviceOutput, numElements);

  // 2. Compute a Reduction on Each Block:
  reduce<<<scan_grid, reduce_block>>>(deviceOutput, deviceAuxIn, numElements);

  _check(hipMemcpy(hostAuxIn, deviceAuxIn, grid_size * sizeof(float), hipMemcpyDeviceToHost));
  for(int i = 0; i < grid_size; i++) {
    printf("%d, ",(int)hostAuxIn[i]);
  }
  printf("\n");


  // 3. Scan the aux array:
  scan<<<aux_grid, aux_block>>>(deviceAuxIn, deviceAuxOut, grid_size);

  _check(hipMemcpy(hostAuxOut, deviceAuxOut, grid_size * sizeof(float), hipMemcpyDeviceToHost));
  for(int i = 0; i < grid_size; i++) {
    printf("%d, ",(int)hostAuxOut[i]);
  }
  printf("\n");

  // 4. Add the aux to the individual scanned blocks:
  add<<<scan_grid, scan_block>>>(deviceOutput, deviceAuxOut, numElements);

  hipDeviceSynchronize();

  _check(hipMemcpy(hostOutput, deviceOutput, numElements * sizeof(float), hipMemcpyDeviceToHost));

  for(int i = 0; i < numElements; i++) {
    printf("%d, ", (int)hostOutput[i]);
  }
  printf("\n");

  hipFree(deviceInput);
  hipFree(deviceOutput);
  free(hostInput);
  free(hostOutput);

  return 0;
} 

	.text
	.file	"main.hip"
	.globl	_Z18__device_stub__addPfS_i     # -- Begin function _Z18__device_stub__addPfS_i
	.type	_Z18__device_stub__addPfS_i,@function
_Z18__device_stub__addPfS_i:            # @_Z18__device_stub__addPfS_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	$_Z3addPfS_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	_Z18__device_stub__addPfS_i, .Lfunc_end0-_Z18__device_stub__addPfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z21__device_stub__reducePfS_i  # -- Begin function _Z21__device_stub__reducePfS_i
	.type	_Z21__device_stub__reducePfS_i,@function
_Z21__device_stub__reducePfS_i:         # @_Z21__device_stub__reducePfS_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	$_Z6reducePfS_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_end1:
	.size	_Z21__device_stub__reducePfS_i, .Lfunc_end1-_Z21__device_stub__reducePfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z19__device_stub__scanPfS_i    # -- Begin function _Z19__device_stub__scanPfS_i
	.type	_Z19__device_stub__scanPfS_i,@function
_Z19__device_stub__scanPfS_i:           # @_Z19__device_stub__scanPfS_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	$_Z4scanPfS_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_end2:
	.size	_Z19__device_stub__scanPfS_i, .Lfunc_end2-_Z19__device_stub__scanPfS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI3_0:
	.long	0x3b000000                      # float 0.001953125
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	.LBB3_1
# %bb.4:
	movq	8(%rsi), %rdi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %r15
	leaq	4(%rsp), %rbx
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	(%rbx), %r12
	leaq	(,%r12,4), %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r14
	testq	%r12, %r12
	jle	.LBB3_7
# %bb.5:                                # %.lr.ph.preheader
	leaq	16(%rsp), %r12
	xorl	%r13d, %r13d
.LBB3_6:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.2, %esi
	movq	%r15, %rdi
	movq	%r12, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	xorps	%xmm0, %xmm0
	cvtsi2ssl	16(%rsp), %xmm0
	movss	%xmm0, (%rbx,%r13,4)
	cvttss2si	%xmm0, %esi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r13
	movslq	4(%rsp), %rax
	cmpq	%rax, %r13
	jl	.LBB3_6
.LBB3_7:                                # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	movslq	4(%rsp), %rsi
	shlq	$2, %rsi
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB3_10
# %bb.8:
	movl	%eax, %ebp
	movl	$.L.str.5, %edi
	movl	$.L.str.6, %esi
	jmp	.LBB3_9
.LBB3_1:
	movl	$.Lstr, %edi
	callq	puts@PLT
	jmp	.LBB3_2
.LBB3_10:
	movslq	4(%rsp), %rsi
	shlq	$2, %rsi
	leaq	8(%rsp), %rdi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB3_12
# %bb.11:
	movl	%eax, %ebp
	movl	$.L.str.5, %edi
	movl	$.L.str.8, %esi
	jmp	.LBB3_9
.LBB3_12:
	movq	8(%rsp), %rdi
	movslq	4(%rsp), %rdx
	shlq	$2, %rdx
	xorl	%esi, %esi
	callq	hipMemset
	testl	%eax, %eax
	je	.LBB3_14
# %bb.13:
	movl	%eax, %ebp
	movl	$.L.str.5, %edi
	movl	$.L.str.9, %esi
	jmp	.LBB3_9
.LBB3_14:
	movq	16(%rsp), %rdi
	movslq	4(%rsp), %rdx
	shlq	$2, %rdx
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB3_16
# %bb.15:
	movl	%eax, %ebp
	movl	$.L.str.5, %edi
	movl	$.L.str.10, %esi
.LBB3_9:
	xorl	%eax, %eax
	callq	printf
	movl	%ebp, %edi
.LBB3_19:
	callq	hipGetErrorString
	movl	$.L.str.7, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB3_2:
	movl	$-1, %eax
.LBB3_3:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_16:
	.cfi_def_cfa_offset 112
	xorps	%xmm0, %xmm0
	cvtsi2ssl	4(%rsp), %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r15d
	cvttps2dq	%xmm0, %xmm0
	cvtdq2ps	%xmm0, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	callq	ceilf@PLT
	movss	%xmm0, 24(%rsp)                 # 4-byte Spill
	movslq	%r15d, %rbp
	shlq	$2, %rbp
	leaq	40(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB3_20
# %bb.17:
	movl	%eax, %r12d
	movl	$.L.str.5, %edi
	movl	$.L.str.11, %esi
	jmp	.LBB3_18
.LBB3_20:
	leaq	32(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB3_22
# %bb.21:
	movl	%eax, %r12d
	movl	$.L.str.5, %edi
	movl	$.L.str.12, %esi
.LBB3_18:
	xorl	%eax, %eax
	callq	printf
	movl	%r12d, %edi
	jmp	.LBB3_19
.LBB3_22:
	movabsq	$4294967808, %rax               # imm = 0x100000200
	leaq	(%r15,%rax), %r13
	addq	$-512, %r13                     # imm = 0xFE00
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%r13, %rdi
	movl	$1, %esi
	movabsq	$4294967808, %rdx               # imm = 0x100000200
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_24
# %bb.23:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	4(%rsp), %edx
	callq	_Z19__device_stub__scanPfS_i
.LBB3_24:
	movabsq	$4294967808, %rax               # imm = 0x100000200
	leaq	-256(%rax), %rdx
	movq	%r13, 48(%rsp)                  # 8-byte Spill
	movq	%r13, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_26
# %bb.25:
	movq	8(%rsp), %rdi
	movq	40(%rsp), %rsi
	movl	4(%rsp), %edx
	callq	_Z21__device_stub__reducePfS_i
.LBB3_26:
	movq	40(%rsp), %rsi
	movq	%r12, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB3_27
# %bb.44:                               # %.thread172
	movl	%eax, %r13d
	movl	$.L.str.5, %edi
	movl	$.L.str.13, %esi
	xorl	%eax, %eax
	callq	printf
	movl	%r13d, %edi
	jmp	.LBB3_19
.LBB3_27:                               # %.preheader179
	cvttss2si	24(%rsp), %rax          # 4-byte Folded Reload
	movl	%eax, %eax
	movabsq	$4294967808, %rcx               # imm = 0x100000200
	addq	%rcx, %rax
	addq	$-512, %rax                     # imm = 0xFE00
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	testl	%r15d, %r15d
	jle	.LBB3_30
# %bb.28:                               # %.lr.ph182.preheader
	xorl	%r13d, %r13d
.LBB3_29:                               # %.lr.ph182
                                        # =>This Inner Loop Header: Depth=1
	cvttss2si	(%r12,%r13,4), %esi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r13
	cmpq	%r13, %r15
	jne	.LBB3_29
.LBB3_30:                               # %._crit_edge183
	movl	$10, %edi
	callq	putchar@PLT
	movq	24(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movabsq	$4294967808, %r12               # imm = 0x100000200
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_32
# %bb.31:
	movq	40(%rsp), %rdi
	movq	32(%rsp), %rsi
	movl	%r15d, %edx
	callq	_Z19__device_stub__scanPfS_i
.LBB3_32:
	movq	32(%rsp), %rsi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	movq	48(%rsp), %r13                  # 8-byte Reload
	je	.LBB3_33
# %bb.41:                               # %.thread174
	movl	%eax, %ebp
	movl	$.L.str.5, %edi
	movl	$.L.str.14, %esi
	jmp	.LBB3_9
.LBB3_33:                               # %.preheader178
	testl	%r15d, %r15d
	jle	.LBB3_34
.LBB3_42:                               # %.lr.ph185
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	decl	%r15d
	jne	.LBB3_42
.LBB3_34:                               # %._crit_edge186
	movl	$10, %edi
	callq	putchar@PLT
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_36
# %bb.35:
	movq	8(%rsp), %rdi
	movq	32(%rsp), %rsi
	movl	4(%rsp), %edx
	callq	_Z18__device_stub__addPfS_i
.LBB3_36:
	callq	hipDeviceSynchronize
	movq	8(%rsp), %rsi
	movslq	4(%rsp), %rdx
	shlq	$2, %rdx
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB3_37
# %bb.43:                               # %.thread176
	movl	%eax, %ebp
	movl	$.L.str.5, %edi
	movl	$.L.str.15, %esi
	jmp	.LBB3_9
.LBB3_37:                               # %.preheader
	cmpl	$0, 4(%rsp)
	jle	.LBB3_40
# %bb.38:                               # %.lr.ph188.preheader
	xorl	%r15d, %r15d
.LBB3_39:                               # %.lr.ph188
                                        # =>This Inner Loop Header: Depth=1
	cvttss2si	(%r14,%r15,4), %esi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	movslq	4(%rsp), %rax
	cmpq	%rax, %r15
	jl	.LBB3_39
.LBB3_40:                               # %._crit_edge189
	movl	$10, %edi
	callq	putchar@PLT
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	xorl	%eax, %eax
	jmp	.LBB3_3
.Lfunc_end3:
	.size	main, .Lfunc_end3-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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z3addPfS_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	$_Z6reducePfS_i, %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	$_Z4scanPfS_i, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z3addPfS_i,@object             # @_Z3addPfS_i
	.section	.rodata,"a",@progbits
	.globl	_Z3addPfS_i
	.p2align	3, 0x0
_Z3addPfS_i:
	.quad	_Z18__device_stub__addPfS_i
	.size	_Z3addPfS_i, 8

	.type	_Z6reducePfS_i,@object          # @_Z6reducePfS_i
	.globl	_Z6reducePfS_i
	.p2align	3, 0x0
_Z6reducePfS_i:
	.quad	_Z21__device_stub__reducePfS_i
	.size	_Z6reducePfS_i, 8

	.type	_Z4scanPfS_i,@object            # @_Z4scanPfS_i
	.globl	_Z4scanPfS_i
	.p2align	3, 0x0
_Z4scanPfS_i:
	.quad	_Z19__device_stub__scanPfS_i
	.size	_Z4scanPfS_i, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"r"
	.size	.L.str.1, 2

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%d\n"
	.size	.L.str.2, 4

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%d, "
	.size	.L.str.3, 5

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Failed to run stmt "
	.size	.L.str.5, 20

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"hipMalloc((void **)&deviceInput, numElements * sizeof(float))"
	.size	.L.str.6, 62

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Got CUDA error ...  "
	.size	.L.str.7, 21

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"hipMalloc((void **)&deviceOutput, numElements * sizeof(float))"
	.size	.L.str.8, 63

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"hipMemset(deviceOutput, 0, numElements * sizeof(float))"
	.size	.L.str.9, 56

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"hipMemcpy(deviceInput, hostInput, numElements * sizeof(float), hipMemcpyHostToDevice)"
	.size	.L.str.10, 86

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"hipMalloc((void **)&deviceAuxIn, grid_size*sizeof(float))"
	.size	.L.str.11, 58

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"hipMalloc((void **)&deviceAuxOut, grid_size*sizeof(float))"
	.size	.L.str.12, 59

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"hipMemcpy(hostAuxIn, deviceAuxIn, grid_size * sizeof(float), hipMemcpyDeviceToHost)"
	.size	.L.str.13, 84

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"hipMemcpy(hostAuxOut, deviceAuxOut, grid_size * sizeof(float), hipMemcpyDeviceToHost)"
	.size	.L.str.14, 86

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"hipMemcpy(hostOutput, deviceOutput, numElements * sizeof(float), hipMemcpyDeviceToHost)"
	.size	.L.str.15, 88

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z3addPfS_i"
	.size	.L__unnamed_1, 12

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z6reducePfS_i"
	.size	.L__unnamed_2, 15

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z4scanPfS_i"
	.size	.L__unnamed_3, 13

	.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	"Usage: ./scan <input_data_file>"
	.size	.Lstr, 32

	.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 _Z18__device_stub__addPfS_i
	.addrsig_sym _Z21__device_stub__reducePfS_i
	.addrsig_sym _Z19__device_stub__scanPfS_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z3addPfS_i
	.addrsig_sym _Z6reducePfS_i
	.addrsig_sym _Z4scanPfS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z3addPfS_i             ; -- Begin function _Z3addPfS_i
	.globl	_Z3addPfS_i
	.p2align	8
	.type	_Z3addPfS_i,@function
_Z3addPfS_i:                            ; @_Z3addPfS_i
; %bb.0:
	s_load_b32 s3, s[0:1], 0x10
	v_lshl_add_u32 v0, s15, 9, v0
	s_add_i32 s2, s15, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_cmp_gt_i32 s2, -1
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, s3, v0
	s_cselect_b32 s3, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s3, s3, vcc_lo
	s_and_saveexec_b32 s4, s3
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_ashrrev_i32_e32 v1, 31, v0
	s_mov_b32 s3, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_lshl_b64 s[0:1], s[2:3], 2
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	s_add_u32 s0, s6, s0
	s_addc_u32 s1, s7, s1
	s_load_b32 s0, s[0:1], 0x0
	global_load_b32 v2, v[0:1], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_add_f32_e32 v2, s0, v2
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z3addPfS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 20
		.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_end0:
	.size	_Z3addPfS_i, .Lfunc_end0-_Z3addPfS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 160
; 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	_Z6reducePfS_i          ; -- Begin function _Z6reducePfS_i
	.globl	_Z6reducePfS_i
	.p2align	8
	.type	_Z6reducePfS_i,@function
_Z6reducePfS_i:                         ; @_Z6reducePfS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s8, s[0:1], 0x10
	s_load_b128 s[0:3], s[0:1], 0x0
	s_lshl_b32 s6, s15, 9
	s_mov_b32 s4, s15
	s_add_i32 s5, s6, 0x200
	s_mov_b32 s7, -1
	s_waitcnt lgkmcnt(0)
	s_cmp_le_u32 s5, s8
	s_cbranch_scc0 .LBB1_2
; %bb.1:
	s_mov_b32 s7, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[10:11], s[6:7], 2
	s_mov_b32 s5, s7
	s_add_u32 s10, s0, s10
	s_addc_u32 s11, s1, s11
	s_load_b32 s9, s[10:11], 0x7fc
	s_lshl_b64 s[10:11], s[4:5], 2
	v_mov_b32_e32 v1, 0
	s_add_u32 s10, s2, s10
	s_addc_u32 s11, s3, s11
	s_waitcnt lgkmcnt(0)
	v_mov_b32_e32 v2, s9
	global_store_b32 v1, v2, s[10:11]
.LBB1_2:                                ; %Flow16
	s_and_not1_b32 vcc_lo, exec_lo, s7
	s_cbranch_vccnz .LBB1_5
; %bb.3:
	s_not_b32 s5, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s5, s5, s8
	v_cmp_eq_u32_e32 vcc_lo, s5, v0
	s_and_saveexec_b32 s5, vcc_lo
	s_cbranch_execz .LBB1_5
; %bb.4:
	v_add_nc_u32_e32 v0, s6, v0
	s_mov_b32 s5, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_lshl_b64 s[0:1], s[4:5], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s2, s0
	global_load_b32 v0, v[0:1], off
	v_mov_b32_e32 v1, 0
	s_addc_u32 s1, s3, s1
	s_waitcnt vmcnt(0)
	global_store_b32 v1, v0, s[0:1]
.LBB1_5:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6reducePfS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 20
		.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	_Z6reducePfS_i, .Lfunc_end1-_Z6reducePfS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 240
; 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	_Z4scanPfS_i            ; -- Begin function _Z4scanPfS_i
	.globl	_Z4scanPfS_i
	.p2align	8
	.type	_Z4scanPfS_i,@function
_Z4scanPfS_i:                           ; @_Z4scanPfS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x10
	s_load_b128 s[0:3], s[0:1], 0x0
	v_lshl_add_u32 v1, s15, 9, v0
	v_mov_b32_e32 v4, 0
	s_delay_alu instid0(VALU_DEP_2)
	v_ashrrev_i32_e32 v2, 31, v1
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, s4, v1
	s_and_saveexec_b32 s4, vcc_lo
	s_cbranch_execz .LBB2_2
; %bb.1:
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v3, s0, s0, v3
	v_add_co_ci_u32_e64 v4, s0, s1, v4, s0
	global_load_b32 v4, v[3:4], off
.LBB2_2:
	s_or_b32 exec_lo, exec_lo, s4
	v_lshlrev_b32_e32 v3, 2, v0
	s_mov_b32 s1, 1
	s_waitcnt vmcnt(0)
	ds_store_b32 v3, v4
                                        ; implicit-def: $vgpr4
.LBB2_3:                                ; =>This Inner Loop Header: Depth=1
	v_cmp_le_u32_e64 s0, s1, v0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s4, s0
	s_cbranch_execz .LBB2_5
; %bb.4:                                ;   in Loop: Header=BB2_3 Depth=1
	v_subrev_nc_u32_e32 v4, s1, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b32_e32 v4, 2, v4
	ds_load_b32 v5, v3
	ds_load_b32 v4, v4
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v4, v5, v4
.LBB2_5:                                ;   in Loop: Header=BB2_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s4
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s4, s0
	s_cbranch_execz .LBB2_7
; %bb.6:                                ;   in Loop: Header=BB2_3 Depth=1
	ds_store_b32 v3, v4
.LBB2_7:                                ;   in Loop: Header=BB2_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s4
	s_lshl_b32 s1, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_lt_i32 s1, 0x200
	s_cbranch_scc1 .LBB2_3
; %bb.8:
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB2_10
; %bb.9:
	ds_load_b32 v3, v3
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v3, off
.LBB2_10:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4scanPfS_i
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 20
		.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 6
		.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	_Z4scanPfS_i, .Lfunc_end2-_Z4scanPfS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 300
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; 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:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 20
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z3addPfS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z3addPfS_i.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:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 20
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6reducePfS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6reducePfS_i.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:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 20
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4scanPfS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z4scanPfS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
