#include <iostream>
template<typename T>
static inline void check(T err, const char* const func, const char* const file, const int line) {
  if (err != cudaSuccess) {
    std::cerr << "CUDA error at: " << file << ":" << line << std::endl;
    std::cerr << cudaGetErrorString(err) << " " << func << std::endl;
    exit(1);
  }
}

#define CHECK(x) check(x, #x,  __FILE__, __LINE__)



// template <class T>
// void cuda_memcpy(T* target, const T* source, std::size_t num, cudaMemcpyKind direction) {
// CHECK(cudaMemcpy(target, source, num * sizeof(T), direction));
// }


__global__ void prefixsum(unsigned int* mask, unsigned int* output,const int len, const unsigned int n ){
  // printf("checing len: %p",len);
  // printf("checing n: %p",n);


  unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
  int step=len;
  int start=index*len+1;//exclusive
  if (start>n) return; //exclusive, could equal to n
  int end=start+step;
  output[start]=mask[start-1];
  for(unsigned int i=start+1;i<end&&i<n;i++){
    output[i]+=output[i-1]+mask[i-1];//exclusive, therefore mask[i-1]
  }
}


__global__ void serialsum_accrossthread(unsigned int* sum,const int len, const unsigned int n){
  unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
  int step=len;
  // int offset=2*step-1;
  int offset=2*step;
  unsigned int start=step*blockDim.x*index+offset;
  unsigned int end=step*blockDim.x*(index+1)+1;
  for(unsigned int i=start;i<end && i<n; i+=step){
    sum[i]+=sum[i-step];
  }
}

__global__ void mergethread(unsigned int* sum,const int len, const unsigned int n){
  if (threadIdx.x==0) return;

  unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
  int step=len;
  unsigned int start=index*step+1;//exclusive
  unsigned int end=start+step-1; // -1 is important, this position has been added in serial sum
  unsigned int base=sum[start-1];

  for(unsigned int i=start; i<end && i<n; i++){
    sum[i]+=base;
  }

}

// __global__ void serialsum_accrossblock(unsigned int* sum,const int len, const unsigned int n){
  

//   unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
//   int step=len*blockDim.x;
//   // int offset=2*step-1;
//   int offset=2*step;
//   unsigned int start= blockDim.x*step*index+offset;
//   unsigned int end= blockDim.x*step*(index+1);
//   for(unsigned int i=start; i<end && i<n; i+=step){
//     sum[i]+=sum[i-step];
//   }
// }


void serialsum_accrossblock(unsigned int* sum,const int len, const unsigned int n, const int block_size){
  int step=len*block_size;//each block has step number
  int start=2*step;

  for(unsigned int i=start; i<n; i+=step){
    sum[i]+=sum[i-step];
  }

}


__global__ void mergeblock(unsigned int* sum,const int len, const unsigned int n){
  

  unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
  if (index==0) return;  //the first block is not needed to merge

  int step=len*blockDim.x;
  
  int start=index*step+1; //exclusive
  // int end=start+step;
  int end=start+step-1;// -1 is important, this position has been added in serial sum
  // int base=sum[blockIdx.x*len*blockDim.x-1];//last element at last block
  int base=sum[start-1];//last element at last block
  for(int i=start; i<end && i<n; i++){
    sum[i]+=base;
  }
}

static inline int divup(int a, int b) {
  return (a + b - 1)/b;
}

int main(){

  const unsigned int n=100000; //100000 number
  unsigned int data[n];
  unsigned int result[n];
  unsigned int inter_sum[n];

  unsigned int inter_result[n];
  unsigned int *cal_result=new unsigned int [n];

  
  for (unsigned int i=0; i<n; i++){
    data[i]=i;
  }
  for (unsigned int i=0; i<n; i++){
    cal_result[i]=i;
  }
  


  
  for (long long i=0; i<n; i++){
    result[i]=(i-1)*i/2;
  }


  std::cout<< "data preparation done"<<std::endl;
  const int block_size=64;//64 threads per block;
  const int len=1000; // add 1000 prefix sum per thread; 

  unsigned int *d_in=NULL;
  
  CHECK(cudaMalloc((void**)&d_in,n*sizeof(unsigned int)));
  unsigned int *d_sum=NULL;
  CHECK(cudaMalloc((void**)&d_sum,n*sizeof(unsigned int)));
  CHECK(cudaMemset(d_sum,0,n*sizeof(unsigned int)));
  CHECK(cudaMemcpy(d_in,data,n * sizeof(unsigned int), cudaMemcpyHostToDevice));
  // cuda_memcpy(d_in,data,n,cudaMemcpyHostToDevice);

  // std::cout<< divup(n,block_size*len) <<std::endl;
  // for (long long i=64001; i<65001; i++){
  //   inter_result[i]=(64000+i-1)*(i-64000)/2;
  // }

  prefixsum<<<divup(n,block_size*len),block_size>>>(d_in,d_sum,len,n);
  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  // for (int i=64001; i<65001; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"i: "<< i <<"error!"<<std::endl;
  //     std::cout<< inter_result[i] << "vs" << cal_result[i] <<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }
  // std::cout<<"pass here"<<std::endl;


  CHECK(cudaGetLastError());
  long long start=64001;
  // int end=start+1000;
  unsigned int end=100000;
  // std::cout<< end*end<<std::endl;
  for (unsigned int i=start; i<end; i++){
    // int index=i-64000;
    inter_result[i]=((start-1+i-1)*(i-start+1))/2;
  }

  start=1;
  end=start+64000;
  for (long long i=start; i<end; i++){
    // int index=i-64000;
    
    inter_result[i]=(i-1)*(i-start+1)/2;
  }
  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  // for (int i=65000; i<66000; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"i: "<< i <<"error!"<<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }
  // std::cout<<"pass"<<std::endl;
  

  // for (unsigned int i=65000; i<66000; i++){
  //   inter_result[i]=(65000+i)*(i-65000+1)/2;
  // }
    // for (long long i=64001; i<65001; i++){
  //   inter_result[i]=(64000+i-1)*(i-64000)/2;
  // }
  // for (unsigned int i=1001; i<2001; i++){
  //   inter_result[i]=(1000+i-1)*(i-1000)/2;
  // }
  // inter_result[2000]+=result[1000];

  serialsum_accrossthread<<<divup(n,block_size*len*block_size),block_size>>>(d_sum,len,n);
  CHECK(cudaGetLastError());
  
  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));

  // for(int i=1001; i<2001; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"first: i: "<< i << " " << cal_result[i] <<"error!"<<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }
  // std::cout<<"pass"<<std::endl;
  // std::cout << "pass first one"<<std::endl;
  // for (int i=64000; i<65000; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"i: "<< i << " " << cal_result[i] <<"error!"<<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }
  // inter_result[65999]+=inter_result[64999];
  // for (int i=65000; i<66000; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"i: "<< i << " " << cal_result[i] <<"error!"<<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }

  mergethread<<<divup(n,block_size*len),block_size>>>(d_sum,len,n);
  CHECK(cudaGetLastError());


  // CHECK(cudaMemcpy(inter_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  //serial sum
  CHECK(cudaMemcpy(inter_sum, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  for (int i=64001; i<100000; i++){
    if(inter_result[i]!=inter_sum[i]){
      std::cout<<"i: "<< i <<"error!"<<std::endl;
      std::cout<< inter_result[i] << "vs" << inter_sum[i] <<std::endl;
      break;
      // return 0;
    }
  }
  std::cout<<"pass here 1"<<std::endl;

  serialsum_accrossblock(inter_sum, len, n, block_size);
  CHECK(cudaMemcpy(d_sum, inter_sum,n * sizeof(unsigned int), cudaMemcpyHostToDevice));

  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  for (int i=1; i<100000; i++){
      if(inter_result[i]!=inter_sum[i]){
        std::cout<<"i: "<< i <<"error!"<<std::endl;
        std::cout<< inter_result[i] << "vs" << inter_sum[i] <<std::endl;
        break;
        // return 0;
    }
  }
  std::cout<<"pass here"<<std::endl;
  
  
  // serialsum_accrossblock<<<divup(n,block_size*len*block_size*block_size) ,block_size>>>(d_sum,len,n);
  // CHECK(cudaGetLastError());
  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  // for (int i=0; i<100000; i++){
  //     if(inter_result[i]!=cal_result[i]){
  //       std::cout<<"i: "<< i <<"error!"<<std::endl;
  //       std::cout<< inter_result[i] << "vs" << cal_result[i] <<std::endl;
  //       break;
  //       // return 0;
  //   }
  // }
  // for (unsigned int i=64000; i<100000; i++){
  //   inter_result[i]+=inter_result[63999];
  // }

  // std::cout<< divup(n,block_size*len) << std::endl;
  mergeblock<<<divup(n,block_size*len*block_size) ,block_size>>>(d_sum,len,n);
  CHECK(cudaGetLastError());
  


  // cuda_memcpy(cal_result, d_sum, n, cudaMemcpyDeviceToHost);
  CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  CHECK(cudaFree(d_in));
  CHECK(cudaFree(d_sum));

  //compare

  unsigned int i;
  for (i=0; i<n; i++){
    if(result[i]!=cal_result[i]){
      std::cout<<"i: "<< i <<"error!"<<std::endl;
      std::cout<<result[i]<<"vs"<<cal_result[i]<<std::endl;
      break;
    }
  }
  if(i==n){
    std::cout<<"correct"<<std::endl;
  }
  return 0;
}
	.file	"tmpxft_00203f99_00000000-6_prefixsum.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3641:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3641:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4304:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4304:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CUDA error at: "
.LC1:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/Haoping-Xiao/Parallel-Programming/main/prefixsum/prefixsum.cu"
.LC2:
	.string	":"
.LC3:
	.string	" "
	.text
	.type	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0, @function
_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0:
.LFB4305:
	.cfi_startproc
	testl	%edi, %edi
	je	.L3
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%edx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	_ZSt4cerr(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rsi, %rbp
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%edi, %ebx
	movq	%r12, %rdi
	pushq	%rax
	.cfi_def_cfa_offset 48
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r13d, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	%ebx, %edi
	call	cudaGetErrorString@PLT
	movq	%r12, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbp, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$1, %edi
	call	exit@PLT
.L3:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	.cfi_restore 12
	.cfi_restore 13
	ret
	.cfi_endproc
.LFE4305:
	.size	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0, .-_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	.globl	_Z22serialsum_accrossblockPjiji
	.type	_Z22serialsum_accrossblockPjiji, @function
_Z22serialsum_accrossblockPjiji:
.LFB3636:
	.cfi_startproc
	endbr64
	imull	%ecx, %esi
	leal	(%rsi,%rsi), %eax
.L10:
	cmpl	%edx, %eax
	jnb	.L12
	movl	%eax, %r8d
	movl	%eax, %ecx
	addl	%esi, %eax
	subl	%esi, %r8d
	movl	(%rdi,%r8,4), %r8d
	addl	%r8d, (%rdi,%rcx,4)
	jmp	.L10
.L12:
	ret
	.cfi_endproc
.LFE3636:
	.size	_Z22serialsum_accrossblockPjiji, .-_Z22serialsum_accrossblockPjiji
	.globl	_Z32__device_stub__Z9prefixsumPjS_ijPjS_ij
	.type	_Z32__device_stub__Z9prefixsumPjS_ijPjS_ij, @function
_Z32__device_stub__Z9prefixsumPjS_ijPjS_ij:
.LFB3663:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z9prefixsumPjS_ij(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L13:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3663:
	.size	_Z32__device_stub__Z9prefixsumPjS_ijPjS_ij, .-_Z32__device_stub__Z9prefixsumPjS_ijPjS_ij
	.globl	_Z9prefixsumPjS_ij
	.type	_Z9prefixsumPjS_ij, @function
_Z9prefixsumPjS_ij:
.LFB3664:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z9prefixsumPjS_ijPjS_ij
	.cfi_endproc
.LFE3664:
	.size	_Z9prefixsumPjS_ij, .-_Z9prefixsumPjS_ij
	.globl	_Z45__device_stub__Z23serialsum_accrossthreadPjijPjij
	.type	_Z45__device_stub__Z23serialsum_accrossthreadPjijPjij, @function
_Z45__device_stub__Z23serialsum_accrossthreadPjijPjij:
.LFB3665:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	32(%rsp), %rdi
	movl	%esi, 4(%rsp)
	leaq	44(%rsp), %rsi
	movl	%edx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z23serialsum_accrossthreadPjij(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L18:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3665:
	.size	_Z45__device_stub__Z23serialsum_accrossthreadPjijPjij, .-_Z45__device_stub__Z23serialsum_accrossthreadPjijPjij
	.globl	_Z23serialsum_accrossthreadPjij
	.type	_Z23serialsum_accrossthreadPjij, @function
_Z23serialsum_accrossthreadPjij:
.LFB3666:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z23serialsum_accrossthreadPjijPjij
	.cfi_endproc
.LFE3666:
	.size	_Z23serialsum_accrossthreadPjij, .-_Z23serialsum_accrossthreadPjij
	.globl	_Z33__device_stub__Z11mergethreadPjijPjij
	.type	_Z33__device_stub__Z11mergethreadPjijPjij, @function
_Z33__device_stub__Z11mergethreadPjijPjij:
.LFB3667:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	32(%rsp), %rdi
	movl	%esi, 4(%rsp)
	leaq	44(%rsp), %rsi
	movl	%edx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z11mergethreadPjij(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L23:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3667:
	.size	_Z33__device_stub__Z11mergethreadPjijPjij, .-_Z33__device_stub__Z11mergethreadPjijPjij
	.globl	_Z11mergethreadPjij
	.type	_Z11mergethreadPjij, @function
_Z11mergethreadPjij:
.LFB3668:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z11mergethreadPjijPjij
	.cfi_endproc
.LFE3668:
	.size	_Z11mergethreadPjij, .-_Z11mergethreadPjij
	.globl	_Z32__device_stub__Z10mergeblockPjijPjij
	.type	_Z32__device_stub__Z10mergeblockPjijPjij, @function
_Z32__device_stub__Z10mergeblockPjijPjij:
.LFB3669:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	32(%rsp), %rdi
	movl	%esi, 4(%rsp)
	leaq	44(%rsp), %rsi
	movl	%edx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L28
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z10mergeblockPjij(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L28:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3669:
	.size	_Z32__device_stub__Z10mergeblockPjijPjij, .-_Z32__device_stub__Z10mergeblockPjijPjij
	.globl	_Z10mergeblockPjij
	.type	_Z10mergeblockPjij, @function
_Z10mergeblockPjij:
.LFB3670:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z10mergeblockPjijPjij
	.cfi_endproc
.LFE3670:
	.size	_Z10mergeblockPjij, .-_Z10mergeblockPjij
	.section	.rodata.str1.1
.LC4:
	.string	"data preparation done"
.LC5:
	.string	"cudaMalloc((void**)&d_in,n*sizeof(unsigned int))"
.LC6:
	.string	"cudaMalloc((void**)&d_sum,n*sizeof(unsigned int))"
.LC7:
	.string	"cudaMemset(d_sum,0,n*sizeof(unsigned int))"
.LC8:
	.string	"cudaMemcpy(d_in,data,n * sizeof(unsigned int), cudaMemcpyHostToDevice)"
.LC9:
	.string	"cudaGetLastError()"
.LC10:
	.string	"cudaMemcpy(inter_sum, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost)"
.LC11:
	.string	"i: "
.LC12:
	.string	"error!"
.LC13:
	.string	"vs"
.LC14:
	.string	"pass here 1"
.LC15:
	.string	"cudaMemcpy(d_sum, inter_sum,n * sizeof(unsigned int), cudaMemcpyHostToDevice)"
.LC16:
	.string	"pass here"
.LC17:
	.string	"cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost)"
.LC18:
	.string	"cudaFree(d_in)"
.LC19:
	.string	"cudaFree(d_sum)"
.LC20:
	.string	"correct"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3638:
	.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
	leaq	-1597440(%rsp), %r11
	.cfi_def_cfa 11, 1597496
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2632, %rsp
	.cfi_def_cfa_offset 1600128
	movl	$400000, %edi
	movq	%fs:40, %rax
	movq	%rax, 1600056(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rbp
	call	_Znam@PLT
	movq	%rax, %rbx
	xorl	%eax, %eax
.L34:
	movl	%eax, 0(%rbp,%rax,4)
	incq	%rax
	cmpq	$100000, %rax
	jne	.L34
	xorl	%eax, %eax
.L35:
	movl	%eax, (%rbx,%rax,4)
	incq	%rax
	cmpq	$100000, %rax
	jne	.L35
	xorl	%ecx, %ecx
	leaq	400056(%rsp), %r14
	movl	$2, %esi
.L36:
	leaq	-1(%rcx), %rax
	imulq	%rcx, %rax
	cqto
	idivq	%rsi
	movl	%eax, (%r14,%rcx,4)
	incq	%rcx
	cmpq	$100000, %rcx
	jne	.L36
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	movl	$400000, %esi
	movq	%rax, 16(%rsp)
	call	cudaMalloc@PLT
	movl	$145, %edx
	leaq	.LC5(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	xorl	%edx, %edx
	leaq	24(%rsp), %rdi
	movl	$400000, %esi
	movq	%rdx, 24(%rsp)
	call	cudaMalloc@PLT
	movl	$147, %edx
	leaq	.LC6(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	movl	$400000, %edx
	call	cudaMemset@PLT
	movl	$148, %edx
	leaq	.LC7(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$400000, %edx
	call	cudaMemcpy@PLT
	movl	$149, %edx
	leaq	.LC8(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	movl	$67108865, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$2147483649, %edi
	salq	$6, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	addq	%rdi, %rdi
	movq	%rdx, 44(%rsp)
	movl	$1, 52(%rsp)
	movq	%rdi, 32(%rsp)
	movl	$1, 40(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	$100000, %ecx
	movl	$1000, %edx
	call	_Z32__device_stub__Z9prefixsumPjS_ijPjS_ij
.L37:
	call	cudaGetLastError@PLT
	movl	$170, %edx
	leaq	.LC9(%rip), %rsi
	leaq	1200056(%rsp), %r13
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	movl	$128000, %eax
.L38:
	leaq	-127999(%rax), %rdx
	imulq	%rax, %rdx
	sarq	%rdx
	movl	%edx, -255996(%r13,%rax,4)
	incq	%rax
	cmpq	$163999, %rax
	jne	.L38
	movl	$1, %eax
.L39:
	leaq	-1(%rax), %rdx
	imulq	%rax, %rdx
	sarq	%rdx
	movl	%edx, 0(%r13,%rax,4)
	incq	%rax
	cmpq	$64001, %rax
	jne	.L39
	movl	$67108865, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	salq	$6, %rdx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movl	$1, 52(%rsp)
	movq	%rdx, 44(%rsp)
	movq	%rdi, 32(%rsp)
	movl	$1, 40(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movq	24(%rsp), %rdi
	movl	$100000, %edx
	movl	$1000, %esi
	call	_Z45__device_stub__Z23serialsum_accrossthreadPjijPjij
.L40:
	call	cudaGetLastError@PLT
	movl	$210, %edx
	leaq	.LC9(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	movl	$67108865, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$2147483649, %edi
	salq	$6, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	addq	%rdi, %rdi
	movq	%rdx, 44(%rsp)
	movl	$1, 52(%rsp)
	movq	%rdi, 32(%rsp)
	movl	$1, 40(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L41
	movq	24(%rsp), %rdi
	movl	$100000, %edx
	movl	$1000, %esi
	call	_Z33__device_stub__Z11mergethreadPjijPjij
.L41:
	call	cudaGetLastError@PLT
	movl	$240, %edx
	leaq	.LC9(%rip), %rsi
	leaq	800056(%rsp), %rbp
	movl	%eax, %edi
	movl	$64001, %r12d
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	movl	$400000, %edx
	call	cudaMemcpy@PLT
	movl	$245, %edx
	leaq	.LC10(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
.L44:
	movl	0(%r13,%r12,4), %r15d
	cmpl	0(%rbp,%r12,4), %r15d
	je	.L42
	leaq	.LC11(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	%r12d, 12(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	12(%rsp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	%r15d, %esi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movslq	%r12d, %rdx
	movl	800056(%rsp,%rdx,4), %esi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	jmp	.L43
.L42:
	incq	%r12
	cmpq	$100000, %r12
	jne	.L44
.L43:
	leaq	.LC14(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	$1, %r15d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$64, %ecx
	movl	$100000, %edx
	movq	%rbp, %rdi
	movl	$1000, %esi
	call	_Z22serialsum_accrossblockPjiji
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$400000, %edx
	call	cudaMemcpy@PLT
	movl	$257, %edx
	leaq	.LC15(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
.L47:
	movl	0(%r13,%r15,4), %r12d
	cmpl	0(%rbp,%r15,4), %r12d
	je	.L45
	leaq	.LC11(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r15d, %esi
	movslq	%r15d, %r15
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	%r12d, %esi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	800056(%rsp,%r15,4), %esi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	jmp	.L46
.L45:
	incq	%r15
	cmpq	$100000, %r15
	jne	.L47
.L46:
	leaq	.LC16(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$67108865, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$6, %rdx
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movq	%rdx, 44(%rsp)
	movl	$1, 52(%rsp)
	movq	%rdi, 32(%rsp)
	movl	$1, 40(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L48
	movq	24(%rsp), %rdi
	movl	$100000, %edx
	movl	$1000, %esi
	call	_Z32__device_stub__Z10mergeblockPjijPjij
.L48:
	call	cudaGetLastError@PLT
	movl	$288, %edx
	leaq	.LC9(%rip), %rsi
	xorl	%ebp, %ebp
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$400000, %edx
	call	cudaMemcpy@PLT
	movl	$293, %edx
	leaq	.LC17(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	$294, %edx
	leaq	.LC18(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movl	$295, %edx
	leaq	.LC19(%rip), %rsi
	movl	%eax, %edi
	call	_Z5checkI9cudaErrorEvT_PKcS3_i.constprop.0
.L51:
	movl	(%r14,%rbp,4), %r12d
	cmpl	(%rbx), %r12d
	je	.L49
	leaq	.LC11(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbp, %rsi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	%r12d, %esi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	(%rbx), %esi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	jmp	.L62
.L49:
	incq	%rbp
	addq	$4, %rbx
	cmpq	$100000, %rbp
	jne	.L51
	leaq	.LC20(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L62:
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	1600056(%rsp), %rax
	subq	%fs:40, %rax
	je	.L52
	call	__stack_chk_fail@PLT
.L52:
	addq	$1600072, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3638:
	.size	main, .-main
	.section	.rodata.str1.1
.LC21:
	.string	"_Z10mergeblockPjij"
.LC22:
	.string	"_Z11mergethreadPjij"
.LC23:
	.string	"_Z23serialsum_accrossthreadPjij"
.LC24:
	.string	"_Z9prefixsumPjS_ij"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3672:
	.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	.LC21(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z10mergeblockPjij(%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	.LC22(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z11mergethreadPjij(%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	.LC23(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z23serialsum_accrossthreadPjij(%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	.LC24(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z9prefixsumPjS_ij(%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
.LFE3672:
	.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
	.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 <iostream>
template<typename T>
static inline void check(T err, const char* const func, const char* const file, const int line) {
  if (err != hipSuccess) {
    std::cerr << "CUDA error at: " << file << ":" << line << std::endl;
    std::cerr << hipGetErrorString(err) << " " << func << std::endl;
    exit(1);
  }
}

#define CHECK(x) check(x, #x,  __FILE__, __LINE__)



// template <class T>
// void cuda_memcpy(T* target, const T* source, std::size_t num, cudaMemcpyKind direction) {
// CHECK(cudaMemcpy(target, source, num * sizeof(T), direction));
// }


__global__ void prefixsum(unsigned int* mask, unsigned int* output,const int len, const unsigned int n ){
  // printf("checing len: %p",len);
  // printf("checing n: %p",n);


  unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
  int step=len;
  int start=index*len+1;//exclusive
  if (start>n) return; //exclusive, could equal to n
  int end=start+step;
  output[start]=mask[start-1];
  for(unsigned int i=start+1;i<end&&i<n;i++){
    output[i]+=output[i-1]+mask[i-1];//exclusive, therefore mask[i-1]
  }
}


__global__ void serialsum_accrossthread(unsigned int* sum,const int len, const unsigned int n){
  unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
  int step=len;
  // int offset=2*step-1;
  int offset=2*step;
  unsigned int start=step*blockDim.x*index+offset;
  unsigned int end=step*blockDim.x*(index+1)+1;
  for(unsigned int i=start;i<end && i<n; i+=step){
    sum[i]+=sum[i-step];
  }
}

__global__ void mergethread(unsigned int* sum,const int len, const unsigned int n){
  if (threadIdx.x==0) return;

  unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
  int step=len;
  unsigned int start=index*step+1;//exclusive
  unsigned int end=start+step-1; // -1 is important, this position has been added in serial sum
  unsigned int base=sum[start-1];

  for(unsigned int i=start; i<end && i<n; i++){
    sum[i]+=base;
  }

}

// __global__ void serialsum_accrossblock(unsigned int* sum,const int len, const unsigned int n){
  

//   unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
//   int step=len*blockDim.x;
//   // int offset=2*step-1;
//   int offset=2*step;
//   unsigned int start= blockDim.x*step*index+offset;
//   unsigned int end= blockDim.x*step*(index+1);
//   for(unsigned int i=start; i<end && i<n; i+=step){
//     sum[i]+=sum[i-step];
//   }
// }


void serialsum_accrossblock(unsigned int* sum,const int len, const unsigned int n, const int block_size){
  int step=len*block_size;//each block has step number
  int start=2*step;

  for(unsigned int i=start; i<n; i+=step){
    sum[i]+=sum[i-step];
  }

}


__global__ void mergeblock(unsigned int* sum,const int len, const unsigned int n){
  

  unsigned int index = threadIdx.x + blockDim.x * blockIdx.x;
  if (index==0) return;  //the first block is not needed to merge

  int step=len*blockDim.x;
  
  int start=index*step+1; //exclusive
  // int end=start+step;
  int end=start+step-1;// -1 is important, this position has been added in serial sum
  // int base=sum[blockIdx.x*len*blockDim.x-1];//last element at last block
  int base=sum[start-1];//last element at last block
  for(int i=start; i<end && i<n; i++){
    sum[i]+=base;
  }
}

static inline int divup(int a, int b) {
  return (a + b - 1)/b;
}

int main(){

  const unsigned int n=100000; //100000 number
  unsigned int data[n];
  unsigned int result[n];
  unsigned int inter_sum[n];

  unsigned int inter_result[n];
  unsigned int *cal_result=new unsigned int [n];

  
  for (unsigned int i=0; i<n; i++){
    data[i]=i;
  }
  for (unsigned int i=0; i<n; i++){
    cal_result[i]=i;
  }
  


  
  for (long long i=0; i<n; i++){
    result[i]=(i-1)*i/2;
  }


  std::cout<< "data preparation done"<<std::endl;
  const int block_size=64;//64 threads per block;
  const int len=1000; // add 1000 prefix sum per thread; 

  unsigned int *d_in=NULL;
  
  CHECK(hipMalloc((void**)&d_in,n*sizeof(unsigned int)));
  unsigned int *d_sum=NULL;
  CHECK(hipMalloc((void**)&d_sum,n*sizeof(unsigned int)));
  CHECK(hipMemset(d_sum,0,n*sizeof(unsigned int)));
  CHECK(hipMemcpy(d_in,data,n * sizeof(unsigned int), hipMemcpyHostToDevice));
  // cuda_memcpy(d_in,data,n,cudaMemcpyHostToDevice);

  // std::cout<< divup(n,block_size*len) <<std::endl;
  // for (long long i=64001; i<65001; i++){
  //   inter_result[i]=(64000+i-1)*(i-64000)/2;
  // }

  prefixsum<<<divup(n,block_size*len),block_size>>>(d_in,d_sum,len,n);
  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  // for (int i=64001; i<65001; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"i: "<< i <<"error!"<<std::endl;
  //     std::cout<< inter_result[i] << "vs" << cal_result[i] <<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }
  // std::cout<<"pass here"<<std::endl;


  CHECK(hipGetLastError());
  long long start=64001;
  // int end=start+1000;
  unsigned int end=100000;
  // std::cout<< end*end<<std::endl;
  for (unsigned int i=start; i<end; i++){
    // int index=i-64000;
    inter_result[i]=((start-1+i-1)*(i-start+1))/2;
  }

  start=1;
  end=start+64000;
  for (long long i=start; i<end; i++){
    // int index=i-64000;
    
    inter_result[i]=(i-1)*(i-start+1)/2;
  }
  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  // for (int i=65000; i<66000; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"i: "<< i <<"error!"<<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }
  // std::cout<<"pass"<<std::endl;
  

  // for (unsigned int i=65000; i<66000; i++){
  //   inter_result[i]=(65000+i)*(i-65000+1)/2;
  // }
    // for (long long i=64001; i<65001; i++){
  //   inter_result[i]=(64000+i-1)*(i-64000)/2;
  // }
  // for (unsigned int i=1001; i<2001; i++){
  //   inter_result[i]=(1000+i-1)*(i-1000)/2;
  // }
  // inter_result[2000]+=result[1000];

  serialsum_accrossthread<<<divup(n,block_size*len*block_size),block_size>>>(d_sum,len,n);
  CHECK(hipGetLastError());
  
  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));

  // for(int i=1001; i<2001; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"first: i: "<< i << " " << cal_result[i] <<"error!"<<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }
  // std::cout<<"pass"<<std::endl;
  // std::cout << "pass first one"<<std::endl;
  // for (int i=64000; i<65000; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"i: "<< i << " " << cal_result[i] <<"error!"<<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }
  // inter_result[65999]+=inter_result[64999];
  // for (int i=65000; i<66000; i++){
  //   if(inter_result[i]!=cal_result[i]){
  //     std::cout<<"i: "<< i << " " << cal_result[i] <<"error!"<<std::endl;
  //     break;
  //     // return 0;
  //   }
  // }

  mergethread<<<divup(n,block_size*len),block_size>>>(d_sum,len,n);
  CHECK(hipGetLastError());


  // CHECK(cudaMemcpy(inter_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  //serial sum
  CHECK(hipMemcpy(inter_sum, d_sum, n * sizeof(unsigned int), hipMemcpyDeviceToHost));
  for (int i=64001; i<100000; i++){
    if(inter_result[i]!=inter_sum[i]){
      std::cout<<"i: "<< i <<"error!"<<std::endl;
      std::cout<< inter_result[i] << "vs" << inter_sum[i] <<std::endl;
      break;
      // return 0;
    }
  }
  std::cout<<"pass here 1"<<std::endl;

  serialsum_accrossblock(inter_sum, len, n, block_size);
  CHECK(hipMemcpy(d_sum, inter_sum,n * sizeof(unsigned int), hipMemcpyHostToDevice));

  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  for (int i=1; i<100000; i++){
      if(inter_result[i]!=inter_sum[i]){
        std::cout<<"i: "<< i <<"error!"<<std::endl;
        std::cout<< inter_result[i] << "vs" << inter_sum[i] <<std::endl;
        break;
        // return 0;
    }
  }
  std::cout<<"pass here"<<std::endl;
  
  
  // serialsum_accrossblock<<<divup(n,block_size*len*block_size*block_size) ,block_size>>>(d_sum,len,n);
  // CHECK(cudaGetLastError());
  // CHECK(cudaMemcpy(cal_result, d_sum, n * sizeof(unsigned int), cudaMemcpyDeviceToHost));
  // for (int i=0; i<100000; i++){
  //     if(inter_result[i]!=cal_result[i]){
  //       std::cout<<"i: "<< i <<"error!"<<std::endl;
  //       std::cout<< inter_result[i] << "vs" << cal_result[i] <<std::endl;
  //       break;
  //       // return 0;
  //   }
  // }
  // for (unsigned int i=64000; i<100000; i++){
  //   inter_result[i]+=inter_result[63999];
  // }

  // std::cout<< divup(n,block_size*len) << std::endl;
  mergeblock<<<divup(n,block_size*len*block_size) ,block_size>>>(d_sum,len,n);
  CHECK(hipGetLastError());
  


  // cuda_memcpy(cal_result, d_sum, n, cudaMemcpyDeviceToHost);
  CHECK(hipMemcpy(cal_result, d_sum, n * sizeof(unsigned int), hipMemcpyDeviceToHost));
  CHECK(hipFree(d_in));
  CHECK(hipFree(d_sum));

  //compare

  unsigned int i;
  for (i=0; i<n; i++){
    if(result[i]!=cal_result[i]){
      std::cout<<"i: "<< i <<"error!"<<std::endl;
      std::cout<<result[i]<<"vs"<<cal_result[i]<<std::endl;
      break;
    }
  }
  if(i==n){
    std::cout<<"correct"<<std::endl;
  }
  return 0;
}
	.text
	.file	"prefixsum.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z24__device_stub__prefixsumPjS_ij # -- Begin function _Z24__device_stub__prefixsumPjS_ij
	.type	_Z24__device_stub__prefixsumPjS_ij,@function
_Z24__device_stub__prefixsumPjS_ij:     # @_Z24__device_stub__prefixsumPjS_ij
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	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	$_Z9prefixsumPjS_ij, %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	_Z24__device_stub__prefixsumPjS_ij, .Lfunc_end0-_Z24__device_stub__prefixsumPjS_ij
	.cfi_endproc
                                        # -- End function
	.globl	_Z38__device_stub__serialsum_accrossthreadPjij # -- Begin function _Z38__device_stub__serialsum_accrossthreadPjij
	.type	_Z38__device_stub__serialsum_accrossthreadPjij,@function
_Z38__device_stub__serialsum_accrossthreadPjij: # @_Z38__device_stub__serialsum_accrossthreadPjij
	.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	$96, %rsp
	.cfi_def_cfa_offset 144
	.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	4(%rsp), %rcx
	movl	%esi, (%rcx)
	movq	%rsp, %rsi
	movl	%edx, (%rsi)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z23serialsum_accrossthreadPjij, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$112, %rsp
	.cfi_adjust_cfa_offset -112
	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	_Z38__device_stub__serialsum_accrossthreadPjij, .Lfunc_end1-_Z38__device_stub__serialsum_accrossthreadPjij
	.cfi_endproc
                                        # -- End function
	.globl	_Z26__device_stub__mergethreadPjij # -- Begin function _Z26__device_stub__mergethreadPjij
	.type	_Z26__device_stub__mergethreadPjij,@function
_Z26__device_stub__mergethreadPjij:     # @_Z26__device_stub__mergethreadPjij
	.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	$96, %rsp
	.cfi_def_cfa_offset 144
	.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	4(%rsp), %rcx
	movl	%esi, (%rcx)
	movq	%rsp, %rsi
	movl	%edx, (%rsi)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z11mergethreadPjij, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$112, %rsp
	.cfi_adjust_cfa_offset -112
	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	_Z26__device_stub__mergethreadPjij, .Lfunc_end2-_Z26__device_stub__mergethreadPjij
	.cfi_endproc
                                        # -- End function
	.globl	_Z22serialsum_accrossblockPjiji # -- Begin function _Z22serialsum_accrossblockPjiji
	.type	_Z22serialsum_accrossblockPjiji,@function
_Z22serialsum_accrossblockPjiji:        # @_Z22serialsum_accrossblockPjiji
	.cfi_startproc
# %bb.0:
                                        # kill: def $esi killed $esi def $rsi
	imull	%ecx, %esi
	leal	(%rsi,%rsi), %eax
	cmpl	%edx, %eax
	jae	.LBB3_3
# %bb.1:
	movl	%esi, %ecx
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%ecx, %r8d
	movl	(%rdi,%r8,4), %r8d
	movl	%eax, %r9d
	addl	%r8d, (%rdi,%r9,4)
	addl	%esi, %eax
	addl	%esi, %ecx
	cmpl	%edx, %eax
	jb	.LBB3_2
.LBB3_3:                                # %._crit_edge
	retq
.Lfunc_end3:
	.size	_Z22serialsum_accrossblockPjiji, .Lfunc_end3-_Z22serialsum_accrossblockPjiji
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__mergeblockPjij # -- Begin function _Z25__device_stub__mergeblockPjij
	.type	_Z25__device_stub__mergeblockPjij,@function
_Z25__device_stub__mergeblockPjij:      # @_Z25__device_stub__mergeblockPjij
	.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	$96, %rsp
	.cfi_def_cfa_offset 144
	.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	4(%rsp), %rcx
	movl	%esi, (%rcx)
	movq	%rsp, %rsi
	movl	%edx, (%rsi)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z10mergeblockPjij, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$112, %rsp
	.cfi_adjust_cfa_offset -112
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z25__device_stub__mergeblockPjij, .Lfunc_end4-_Z25__device_stub__mergeblockPjij
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function 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	$1600024, %rsp                  # imm = 0x186A18
	.cfi_def_cfa_offset 1600080
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$400000, %edi                   # imm = 0x61A80
	callq	_Znam
	movq	%rax, %rbx
	xorl	%eax, %eax
.LBB5_1:                                # =>This Inner Loop Header: Depth=1
	movl	%eax, 1200016(%rsp,%rax,4)
	incq	%rax
	cmpq	$100000, %rax                   # imm = 0x186A0
	jne	.LBB5_1
# %bb.2:                                # %.preheader107.preheader
	xorl	%eax, %eax
.LBB5_3:                                # %.preheader107
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, (%rbx,%rax,4)
	incq	%rax
	cmpq	$100000, %rax                   # imm = 0x186A0
	jne	.LBB5_3
# %bb.4:                                # %.preheader106.preheader
	xorl	%eax, %eax
.LBB5_5:                                # %.preheader106
                                        # =>This Inner Loop Header: Depth=1
	leaq	-1(%rax), %rcx
	imulq	%rax, %rcx
	movq	%rcx, %rdx
	shrq	$63, %rdx
	addq	%rcx, %rdx
	shrq	%rdx
	movl	%edx, 800016(%rsp,%rax,4)
	incq	%rax
	cmpq	$100000, %rax                   # imm = 0x186A0
	jne	.LBB5_5
# %bb.6:
	movabsq	$4294967360, %r14               # imm = 0x100000040
	movl	$_ZSt4cout, %r15d
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$21, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorl	%r13d, %r13d
	leaq	8(%rsp), %r15
	movq	%r13, (%r15)
	movl	$400000, %esi                   # imm = 0x61A80
	movq	%r15, %rdi
	callq	hipMalloc
	movl	$.L.str.1, %esi
	movl	%eax, %edi
	movl	$147, %edx
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movq	%rsp, %r12
	movq	%r13, (%r12)
	movl	$400000, %esi                   # imm = 0x61A80
	movq	%r12, %rdi
	callq	hipMalloc
	movl	$.L.str.3, %esi
	movl	%eax, %edi
	movl	$149, %edx
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movq	(%r12), %rdi
	movl	$400000, %edx                   # imm = 0x61A80
	xorl	%esi, %esi
	callq	hipMemset
	movl	$.L.str.4, %esi
	movl	%eax, %edi
	movl	$150, %edx
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movq	(%r15), %rdi
	leaq	1200016(%rsp), %rsi
	movl	$400000, %edx                   # imm = 0x61A80
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.5, %esi
	movl	%eax, %edi
	movl	$151, %edx
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	leaq	-62(%r14), %r12
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_8
# %bb.7:
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movl	$1000, %edx                     # imm = 0x3E8
	movl	$100000, %ecx                   # imm = 0x186A0
	callq	_Z24__device_stub__prefixsumPjS_ij
.LBB5_8:
	callq	hipGetLastError
	movl	$.L.str.6, %esi
	movl	%eax, %edi
	movl	$172, %edx
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movl	$128000, %eax                   # imm = 0x1F400
.LBB5_9:                                # =>This Inner Loop Header: Depth=1
	leaq	-127999(%rax), %rcx
	imulq	%rax, %rcx
	movq	%rcx, %rdx
	shrq	$63, %rdx
	addq	%rcx, %rdx
	shrq	%rdx
	movl	%edx, 144020(%rsp,%rax,4)
	incq	%rax
	cmpq	$163999, %rax                   # imm = 0x2809F
	jne	.LBB5_9
# %bb.10:                               # %.preheader.preheader
	movl	$1, %eax
.LBB5_11:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	leaq	-1(%rax), %rcx
	imulq	%rax, %rcx
	movq	%rcx, %rdx
	shrq	$63, %rdx
	addq	%rcx, %rdx
	shrq	%rdx
	movl	%edx, 400016(%rsp,%rax,4)
	incq	%rax
	cmpq	$64001, %rax                    # imm = 0xFA01
	jne	.LBB5_11
# %bb.12:
	leaq	-63(%r14), %r15
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_14
# %bb.13:
	movq	(%rsp), %rdi
	movl	$1000, %esi                     # imm = 0x3E8
	movl	$100000, %edx                   # imm = 0x186A0
	callq	_Z38__device_stub__serialsum_accrossthreadPjij
.LBB5_14:
	callq	hipGetLastError
	movl	$.L.str.6, %esi
	movl	%eax, %edi
	movl	$212, %edx
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_16
# %bb.15:
	movq	(%rsp), %rdi
	movl	$1000, %esi                     # imm = 0x3E8
	movl	$100000, %edx                   # imm = 0x186A0
	callq	_Z26__device_stub__mergethreadPjij
.LBB5_16:
	callq	hipGetLastError
	movl	$.L.str.6, %esi
	movl	%eax, %edi
	movl	$242, %edx
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movq	(%rsp), %rsi
	leaq	16(%rsp), %rdi
	movl	$400000, %edx                   # imm = 0x61A80
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.7, %esi
	movl	%eax, %edi
	movl	$247, %edx
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movl	$64001, %r12d                   # imm = 0xFA01
.LBB5_17:                               # =>This Inner Loop Header: Depth=1
	movl	400016(%rsp,%r12,4), %r13d
	cmpl	16(%rsp,%r12,4), %r13d
	jne	.LBB5_18
# %bb.19:                               #   in Loop: Header=BB5_17 Depth=1
	incq	%r12
	cmpq	$100000, %r12                   # imm = 0x186A0
	jne	.LBB5_17
	jmp	.LBB5_20
.LBB5_18:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$3, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%r12d, %esi
	callq	_ZNSolsEi
	movq	%rax, %rbp
	movl	$.L.str.9, %esi
	movl	$6, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbp), %rax
	movq	-24(%rax), %rdi
	addq	%rbp, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbp, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movq	%r13, %rsi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %r13
	movl	$.L.str.10, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	16(%rsp,%r12,4), %esi
	movq	%r13, %rdi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB5_20:                               # %.loopexit105
	movl	$_ZSt4cout, %r12d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.11, %esi
	movl	$11, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	(%rsp), %rdi
	leaq	16(%rsp), %rsi
	movl	$400000, %edx                   # imm = 0x61A80
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.12, %esi
	movl	%eax, %edi
	movl	$259, %edx                      # imm = 0x103
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movl	$1, %r12d
.LBB5_21:                               # =>This Inner Loop Header: Depth=1
	movl	400016(%rsp,%r12,4), %r13d
	cmpl	16(%rsp,%r12,4), %r13d
	jne	.LBB5_22
# %bb.23:                               #   in Loop: Header=BB5_21 Depth=1
	incq	%r12
	cmpq	$100000, %r12                   # imm = 0x186A0
	jne	.LBB5_21
	jmp	.LBB5_24
.LBB5_22:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$3, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%r12d, %esi
	callq	_ZNSolsEi
	movq	%rax, %rbp
	movl	$.L.str.9, %esi
	movl	$6, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbp), %rax
	movq	-24(%rax), %rdi
	addq	%rbp, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbp, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movq	%r13, %rsi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %r13
	movl	$.L.str.10, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	16(%rsp,%r12,4), %esi
	movq	%r13, %rdi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB5_24:                               # %.loopexit
	movl	$_ZSt4cout, %r12d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.13, %esi
	movl	$9, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_26
# %bb.25:
	movq	(%rsp), %rdi
	movl	$1000, %esi                     # imm = 0x3E8
	movl	$100000, %edx                   # imm = 0x186A0
	callq	_Z25__device_stub__mergeblockPjij
.LBB5_26:
	callq	hipGetLastError
	movl	$.L.str.6, %esi
	movl	%eax, %edi
	movl	$290, %edx                      # imm = 0x122
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movq	(%rsp), %rsi
	movl	$400000, %edx                   # imm = 0x61A80
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.14, %esi
	movl	%eax, %edi
	movl	$295, %edx                      # imm = 0x127
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movq	8(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.15, %esi
	movl	%eax, %edi
	movl	$296, %edx                      # imm = 0x128
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	movq	(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.16, %esi
	movl	%eax, %edi
	movl	$297, %edx                      # imm = 0x129
	callq	_ZL5checkI10hipError_tEvT_PKcS3_i
	xorl	%r14d, %r14d
.LBB5_27:                               # =>This Inner Loop Header: Depth=1
	movl	800016(%rsp,%r14,4), %r15d
	cmpl	(%rbx,%r14,4), %r15d
	jne	.LBB5_28
# %bb.29:                               #   in Loop: Header=BB5_27 Depth=1
	incq	%r14
	cmpq	$100000, %r14                   # imm = 0x186A0
	jne	.LBB5_27
# %bb.30:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.17, %esi
	movl	$7, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB5_31
.LBB5_28:                               # %.thread
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$3, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movq	%r14, %rsi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %r12
	movl	$.L.str.9, %esi
	movl	$6, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r12), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movq	%r15, %rsi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %r15
	movl	$.L.str.10, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	(%rbx,%r14,4), %esi
	movq	%r15, %rdi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %rbx
.LBB5_31:
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorl	%eax, %eax
	addq	$1600024, %rsp                  # imm = 0x186A18
	.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_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.type	_ZL5checkI10hipError_tEvT_PKcS3_i,@function # -- Begin function _ZL5checkI10hipError_tEvT_PKcS3_i
_ZL5checkI10hipError_tEvT_PKcS3_i:      # @_ZL5checkI10hipError_tEvT_PKcS3_i
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB6_2
# %bb.1:
	retq
.LBB6_2:
	pushq	%rbp
	.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 %rbp, -16
	movl	%edx, %r14d
	movq	%rsi, %rbx
	movl	%edi, %ebp
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.18, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.19, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	%r14d, %esi
	callq	_ZNSolsEi
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	%ebp, %edi
	callq	hipGetErrorString
	movl	$_ZSt4cerr, %edi
	movq	%rax, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.20, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movq	%rbx, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.Lfunc_end6:
	.size	_ZL5checkI10hipError_tEvT_PKcS3_i, .Lfunc_end6-_ZL5checkI10hipError_tEvT_PKcS3_i
	.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	$_Z9prefixsumPjS_ij, %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	$_Z23serialsum_accrossthreadPjij, %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	$_Z11mergethreadPjij, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10mergeblockPjij, %esi
	movl	$.L__unnamed_4, %edx
	movl	$.L__unnamed_4, %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	_Z9prefixsumPjS_ij,@object      # @_Z9prefixsumPjS_ij
	.section	.rodata,"a",@progbits
	.globl	_Z9prefixsumPjS_ij
	.p2align	3, 0x0
_Z9prefixsumPjS_ij:
	.quad	_Z24__device_stub__prefixsumPjS_ij
	.size	_Z9prefixsumPjS_ij, 8

	.type	_Z23serialsum_accrossthreadPjij,@object # @_Z23serialsum_accrossthreadPjij
	.globl	_Z23serialsum_accrossthreadPjij
	.p2align	3, 0x0
_Z23serialsum_accrossthreadPjij:
	.quad	_Z38__device_stub__serialsum_accrossthreadPjij
	.size	_Z23serialsum_accrossthreadPjij, 8

	.type	_Z11mergethreadPjij,@object     # @_Z11mergethreadPjij
	.globl	_Z11mergethreadPjij
	.p2align	3, 0x0
_Z11mergethreadPjij:
	.quad	_Z26__device_stub__mergethreadPjij
	.size	_Z11mergethreadPjij, 8

	.type	_Z10mergeblockPjij,@object      # @_Z10mergeblockPjij
	.globl	_Z10mergeblockPjij
	.p2align	3, 0x0
_Z10mergeblockPjij:
	.quad	_Z25__device_stub__mergeblockPjij
	.size	_Z10mergeblockPjij, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"data preparation done"
	.size	.L.str, 22

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"hipMalloc((void**)&d_in,n*sizeof(unsigned int))"
	.size	.L.str.1, 48

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/Haoping-Xiao/Parallel-Programming/main/prefixsum/prefixsum.hip"
	.size	.L.str.2, 125

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"hipMalloc((void**)&d_sum,n*sizeof(unsigned int))"
	.size	.L.str.3, 49

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"hipMemset(d_sum,0,n*sizeof(unsigned int))"
	.size	.L.str.4, 42

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"hipMemcpy(d_in,data,n * sizeof(unsigned int), hipMemcpyHostToDevice)"
	.size	.L.str.5, 69

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"hipGetLastError()"
	.size	.L.str.6, 18

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"hipMemcpy(inter_sum, d_sum, n * sizeof(unsigned int), hipMemcpyDeviceToHost)"
	.size	.L.str.7, 77

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"i: "
	.size	.L.str.8, 4

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"error!"
	.size	.L.str.9, 7

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"vs"
	.size	.L.str.10, 3

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"pass here 1"
	.size	.L.str.11, 12

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"hipMemcpy(d_sum, inter_sum,n * sizeof(unsigned int), hipMemcpyHostToDevice)"
	.size	.L.str.12, 76

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"pass here"
	.size	.L.str.13, 10

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"hipMemcpy(cal_result, d_sum, n * sizeof(unsigned int), hipMemcpyDeviceToHost)"
	.size	.L.str.14, 78

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"hipFree(d_in)"
	.size	.L.str.15, 14

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"hipFree(d_sum)"
	.size	.L.str.16, 15

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"correct"
	.size	.L.str.17, 8

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"CUDA error at: "
	.size	.L.str.18, 16

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

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9prefixsumPjS_ij"
	.size	.L__unnamed_1, 19

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z23serialsum_accrossthreadPjij"
	.size	.L__unnamed_2, 32

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z11mergethreadPjij"
	.size	.L__unnamed_3, 20

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"_Z10mergeblockPjij"
	.size	.L__unnamed_4, 19

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

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z24__device_stub__prefixsumPjS_ij
	.addrsig_sym _Z38__device_stub__serialsum_accrossthreadPjij
	.addrsig_sym _Z26__device_stub__mergethreadPjij
	.addrsig_sym _Z25__device_stub__mergeblockPjij
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9prefixsumPjS_ij
	.addrsig_sym _Z23serialsum_accrossthreadPjij
	.addrsig_sym _Z11mergethreadPjij
	.addrsig_sym _Z10mergeblockPjij
	.addrsig_sym _ZSt4cout
	.addrsig_sym _ZSt4cerr
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9prefixsumPjS_ij      ; -- Begin function _Z9prefixsumPjS_ij
	.globl	_Z9prefixsumPjS_ij
	.p2align	8
	.type	_Z9prefixsumPjS_ij,@function
_Z9prefixsumPjS_ij:                     ; @_Z9prefixsumPjS_ij
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b64 s[2:3], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_mov_b32 s4, exec_lo
	v_mul_lo_u32 v1, v1, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, 1, v1
	v_cmpx_ge_u32_e64 s3, v0
	s_cbranch_execz .LBB0_4
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_add_nc_u32_e32 v2, 2, v1
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v5, vcc_lo, s4, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v4, vcc_lo
	v_add_co_u32 v3, vcc_lo, s6, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s7, v4, vcc_lo
	global_load_b32 v6, v[5:6], off
	v_add_nc_u32_e32 v5, s2, v0
	v_min_u32_e32 v5, s3, v5
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_u32_e32 vcc_lo, v2, v5
	s_waitcnt vmcnt(0)
	global_store_b32 v[3:4], v6, off offset:4
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_4
; %bb.2:                                ; %.lr.ph.preheader
	v_mov_b32_e32 v1, 0
	s_mov_b32 s1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[0:1]
	v_add_co_u32 v3, vcc_lo, s6, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v4, vcc_lo, s7, v4, vcc_lo
	global_load_b32 v6, v[3:4], off
	v_mov_b32_e32 v3, v1
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s6, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s7, v4, vcc_lo
.LBB0_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_add_nc_u32_e32 v0, -1, v2
	global_load_b32 v9, v[3:4], off
	v_add_nc_u32_e32 v2, 1, v2
	v_lshlrev_b64 v[7:8], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v7, vcc_lo, s4, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s5, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_cmp_ge_u32_e32 vcc_lo, v2, v5
	global_load_b32 v0, v[7:8], off
	s_or_b32 s1, vcc_lo, s1
	s_waitcnt vmcnt(0)
	v_add3_u32 v6, v0, v6, v9
	global_store_b32 v[3:4], v6, off
	v_add_co_u32 v3, s0, v3, 4
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v4, s0, 0, v4, s0
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB0_3
.LBB0_4:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9prefixsumPjS_ij
		.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 10
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z9prefixsumPjS_ij, .Lfunc_end0-_Z9prefixsumPjS_ij
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 372
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 10
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z23serialsum_accrossthreadPjij ; -- Begin function _Z23serialsum_accrossthreadPjij
	.globl	_Z23serialsum_accrossthreadPjij
	.p2align	8
	.type	_Z23serialsum_accrossthreadPjij,@function
_Z23serialsum_accrossthreadPjij:        ; @_Z23serialsum_accrossthreadPjij
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b64 s[2:3], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_mul_i32 s5, s4, s2
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mul_lo_u32 v0, v1, s5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add3_u32 v2, v0, s5, 1
	v_lshl_add_u32 v3, s2, 1, v0
	v_min_u32_e32 v4, s3, v2
	s_mov_b32 s3, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_lt_u32_e64 v3, v4
	s_cbranch_execz .LBB1_3
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b64 s[0:1], s[0:1], 0x0
	v_mul_lo_u32 v2, v1, s4
	s_mov_b32 s4, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_mad_u64_u32 v[0:1], null, s2, v2, s[2:3]
	v_mov_b32_e32 v2, 0
	s_mov_b32 s3, 0
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_dual_mov_b32 v6, v2 :: v_dual_add_nc_u32 v1, s4, v0
	v_add_nc_u32_e32 v5, s4, v3
	s_add_i32 s4, s4, s2
	v_lshlrev_b64 v[7:8], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v7, vcc_lo, s0, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v8, vcc_lo
	v_add_co_u32 v5, vcc_lo, s0, v5
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v6, vcc_lo
	s_clause 0x1
	global_load_b32 v1, v[7:8], off
	global_load_b32 v7, v[5:6], off
	v_add_nc_u32_e32 v8, s4, v3
	v_cmp_ge_u32_e32 vcc_lo, v8, v4
	s_or_b32 s3, vcc_lo, s3
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v1, v7, v1
	global_store_b32 v[5:6], v1, off
	s_and_not1_b32 exec_lo, exec_lo, s3
	s_cbranch_execnz .LBB1_2
.LBB1_3:                                ; %Flow27
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z23serialsum_accrossthreadPjij
		.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	_Z23serialsum_accrossthreadPjij, .Lfunc_end1-_Z23serialsum_accrossthreadPjij
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 288
; 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
	.protected	_Z11mergethreadPjij     ; -- Begin function _Z11mergethreadPjij
	.globl	_Z11mergethreadPjij
	.p2align	8
	.type	_Z11mergethreadPjij,@function
_Z11mergethreadPjij:                    ; @_Z11mergethreadPjij
; %bb.0:
	s_mov_b32 s2, exec_lo
	v_cmpx_ne_u32_e32 0, v0
	s_cbranch_execz .LBB2_4
; %bb.1:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b64 s[2:3], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_mul_lo_u32 v1, v1, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, s2, v1
	v_min_u32_e32 v3, s3, v0
	v_add_nc_u32_e32 v0, 1, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_u32_e32 vcc_lo, v0, v3
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB2_4
; %bb.2:                                ; %.lr.ph.preheader
	s_load_b64 s[0:1], s[0:1], 0x0
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[4:5], 2, v[1:2]
	v_mov_b32_e32 v1, v2
	v_lshlrev_b64 v[1:2], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v4, vcc_lo, s0, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v1, vcc_lo, s0, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_load_b32 v4, v[4:5], off
	s_mov_b32 s1, 0
.LBB2_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b32 v5, v[1:2], off
	v_add_nc_u32_e32 v0, 1, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ge_u32_e32 vcc_lo, v0, v3
	s_or_b32 s1, vcc_lo, s1
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v5, v5, v4
	global_store_b32 v[1:2], v5, off
	v_add_co_u32 v1, s0, v1, 4
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v2, s0, 0, v2, s0
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB2_3
.LBB2_4:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11mergethreadPjij
		.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 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	_Z11mergethreadPjij, .Lfunc_end2-_Z11mergethreadPjij
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 260
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 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
	.protected	_Z10mergeblockPjij      ; -- Begin function _Z10mergeblockPjij
	.globl	_Z10mergeblockPjij
	.p2align	8
	.type	_Z10mergeblockPjij,@function
_Z10mergeblockPjij:                     ; @_Z10mergeblockPjij
; %bb.0:
	s_load_b32 s2, s[0:1], 0x1c
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s2, 0xffff
	s_mov_b32 s2, exec_lo
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ne_u32_e32 0, v1
	s_cbranch_execz .LBB3_4
; %bb.1:
	s_load_b64 s[2:3], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s4, s4, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v0, v1, s4
	v_add_nc_u32_e32 v4, s4, v0
	v_add_nc_u32_e32 v2, 1, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_lt_i32_e32 vcc_lo, v2, v4
	v_cmp_gt_u32_e64 s2, s3, v2
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s2
	s_cbranch_execz .LBB3_4
; %bb.2:                                ; %.lr.ph.preheader
	s_load_b64 s[0:1], s[0:1], 0x0
	v_ashrrev_i32_e32 v1, 31, v0
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v5, vcc_lo, s0, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v6, vcc_lo
	global_load_b32 v5, v[5:6], off
	v_lshlrev_b64 v[6:7], 2, v[2:3]
	v_add_nc_u32_e32 v2, 2, v0
	v_add_co_u32 v0, vcc_lo, s0, v6
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v7, vcc_lo
	s_mov_b32 s1, 0
.LBB3_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b32 v3, v[0:1], off
	v_cmp_ge_i32_e32 vcc_lo, v2, v4
	v_cmp_le_u32_e64 s0, s3, v2
	v_add_nc_u32_e32 v2, 1, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s0, vcc_lo, s0
	s_and_b32 s0, exec_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s1, s0, s1
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v3, v3, v5
	global_store_b32 v[0:1], v3, off
	v_add_co_u32 v0, vcc_lo, v0, 4
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB3_3
.LBB3_4:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10mergeblockPjij
		.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 8
		.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_end3:
	.size	_Z10mergeblockPjij, .Lfunc_end3-_Z10mergeblockPjij
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 292
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; 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
      - .offset:         20
        .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
    .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:           _Z9prefixsumPjS_ij
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9prefixsumPjS_ij.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .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
    .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:           _Z23serialsum_accrossthreadPjij
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z23serialsum_accrossthreadPjij.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .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
    .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:           _Z11mergethreadPjij
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z11mergethreadPjij.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .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
    .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:           _Z10mergeblockPjij
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10mergeblockPjij.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
