#include <iostream>
#include <numeric>
#include <random>
#include <vector>

// Here you can set the device ID that was assigned to you
#define MYDEVICE 1
#define BLOCK_SIZE 512
#define BLOCKS_NUMBER 512

// Part 1 of 6: implement the kernel
__global__ void block_sum(const int* input, int* per_block_results,
                          const size_t n)
{
  // fill me
  __shared__ int shared_mem[BLOCK_SIZE];
  uint block_id = blockIdx.x;
  uint thread_id = threadIdx.x;

  shared_mem[thread_id] = input[block_id * BLOCK_SIZE + thread_id];

  __syncthreads();
  
  /*if (thread_id == 0) {
    int sum = 0;
    for (uint i = 0; i < BLOCK_SIZE; ++i) {
      sum += shared_mem[i];
    }
    per_block_results[block_id] = sum;
  }*/

  uint max_allowed_id = BLOCK_SIZE / 2;

  while (thread_id < max_allowed_id) {
    shared_mem[thread_id] += shared_mem[thread_id + max_allowed_id];
    max_allowed_id = max_allowed_id / 2;
    __syncthreads();
  }

  
  
  if (thread_id == 0) {
    per_block_results[block_id] = shared_mem[0];
  }
}

void cpu_block_sum(int block_id, int thread_id, int* global_inoutput, int* per_block_results) {
  // BLOCK_SIZE is a const si no : const size_t n
  
  uint istart = block_id * BLOCK_SIZE;
  
  /*if (thread_id == 0) {
    int sum = 0;
    for (uint i = 0; i < BLOCK_SIZE; ++i) {
      sum += shared_mem[i];
    }
    per_block_results[block_id] = sum;
  }*/

  uint max_allowed_id = BLOCK_SIZE / 2;

  while (thread_id < max_allowed_id) {
    global_inoutput[istart + thread_id] += global_inoutput[istart + thread_id + max_allowed_id];
    max_allowed_id = max_allowed_id / 2;
  }
  
  if (thread_id == 0) {
    per_block_results[block_id] = global_inoutput[istart + thread_id];
  }
}

void cpu_reduction(const int* input, int* per_block_results, const size_t input_size, uint blocks_number) {
  int global_inoutput[input_size];
  // Copy the input to a teporary array
  for (uint i = 0; i < input_size; ++i) {
    global_inoutput[i] = input[i];
  }
  // For each block
  for (uint ib = 0; ib < blocks_number; ++ib) {
    // For each thread, descending order
    for (int ith = BLOCK_SIZE - 1; ith >= 0; --ith) {
    //for (int ith = 0; ith < BLOCK_SIZE; ++ith) {
      cpu_block_sum(ib, ith, global_inoutput, per_block_results);
    }
  }
}

////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int main(void)
{
  std::random_device
      rd; // Will be used to obtain a seed for the random number engine
  std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd()
  std::uniform_int_distribution<> distrib(-10, 10);

  // create array of 262144 elements
  const int num_elements = 1 << 18;
  uint num_blocks = num_elements / BLOCK_SIZE;

  // generate random input on the host
  std::vector<int> h_input(num_elements);
  for (auto& elt : h_input) {
    elt = distrib(gen);
  }

  // Compute the sum on the host
  const int host_result = std::accumulate(h_input.begin(), h_input.end(), 0);
  std::cerr << "Host sum: " << host_result << std::endl;

  // Input size
  uint in_size = num_elements * sizeof(int);


  // === CPU verification ===
  int host_partial_sums_and_total[num_blocks];
  if (num_blocks == BLOCK_SIZE) {
    std::cout << "OK, right num_blocks and BLOCK_SIZE\n";
  } else {
    std::cout << "ERROR - num_blocks(" << num_blocks << ") != BLOCK_SIZE(" << BLOCK_SIZE << ")\n";
    return 1;
  }
  cpu_reduction(h_input.data(), host_partial_sums_and_total, num_elements, num_blocks);
  int h_result;
  cpu_reduction(host_partial_sums_and_total, &h_result, BLOCK_SIZE, 1);
  std::cout << "Host reduce sum: " << h_result << std::endl;



  // === CUDA kernels ===

  // Move input to device memory
  int* d_input;
  cudaMalloc(&d_input, in_size);
  cudaMemcpy(d_input, h_input.data(), in_size, cudaMemcpyHostToDevice);

  // Allocate the partial sums: How much space does it need?
  int* d_partial_sums_and_total;
  cudaMalloc(&d_partial_sums_and_total, in_size);


  // Launch one kernel to compute, per-block, a partial sum. How
  // much shared memory does it need?
  block_sum<<<num_blocks, BLOCK_SIZE>>>(d_input, d_partial_sums_and_total,
                                        num_elements);

  // 1) Sommer les sommes partielles sur CPU
  // 2) Comparer les sommes partielles lues depuis le GPU et depuis le CPU

  int* d_result;
  cudaMalloc(&d_result, sizeof(int));

  // Compute the sum of the partial sums
  block_sum<<<1, BLOCKS_NUMBER>>>(d_partial_sums_and_total, d_result, BLOCKS_NUMBER);

  // Copy the result back to the host
  int device_result = 0;
  cudaMemcpy(&device_result, d_result, sizeof(int), cudaMemcpyDeviceToHost);

  int h_partial_sums_and_total[num_blocks];
  cudaMemcpy(h_partial_sums_and_total, d_partial_sums_and_total, BLOCK_SIZE * sizeof(int), cudaMemcpyDeviceToHost);
  int hsum = 0;
  for (uint ib = 0; ib < num_blocks; ++ib) {
    hsum += h_partial_sums_and_total[ib];
    //std::cout << "b(" << ib << ") = " << h_partial_sums_and_total[ib] << std::endl;
  }

  std::cout << "Device sum: " << device_result << std::endl;
  std::cout << "Host sum of partial sums: " << hsum << std::endl;


  std::cout << "\nPartial sums comparison: " << std::endl;
  for (uint ib = 0; ib < num_blocks; ++ib) {
    int gpu_v = h_partial_sums_and_total[ib];
    int cpu_v = host_partial_sums_and_total[ib];
    if (gpu_v == cpu_v) {
      std::cout << "-\n";
    } else {
      std::cout << "e[" << ib << ": " << gpu_v << "!=" << cpu_v << "]\n";
    }
    //std::cout << "b(" << ib << ") = " << h_partial_sums_and_total[ib] << std::endl;
  }
  


  // // Part 1 of 6: deallocate device memory

  return 0;
}

	.file	"tmpxft_0029fa94_00000000-6_reduction_perso.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4724:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4724:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB5524:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE5524:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.section	.rodata._ZNSt13random_deviceC2Ev.str1.1,"aMS",@progbits,1
.LC0:
	.string	"default"
	.section	.text._ZNSt13random_deviceC2Ev,"axG",@progbits,_ZNSt13random_deviceC5Ev,comdat
	.align 2
	.weak	_ZNSt13random_deviceC2Ev
	.type	_ZNSt13random_deviceC2Ev, @function
_ZNSt13random_deviceC2Ev:
.LFB4139:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4139
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	7+.LC0(%rip), %rdx
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	-7(%rdx), %rsi
	movq	%rdi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rdi
	leaq	8(%rsp), %rbp
	movq	%rdi, 8(%rsp)
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE13_S_copy_charsEPcPKcS7_@PLT
	movq	8(%rsp), %rax
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	movq	$7, 16(%rsp)
	movb	$0, 7(%rax)
.LEHB0:
	call	_ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE@PLT
.LEHE0:
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	jmp	.L8
.L7:
	endbr64
	movq	%rax, %rbx
.L4:
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L8
	movq	%rbx, %rdi
.LEHB1:
	call	_Unwind_Resume@PLT
.LEHE1:
.L8:
	call	__stack_chk_fail@PLT
.L6:
	addq	$56, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4139:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table._ZNSt13random_deviceC2Ev,"aG",@progbits,_ZNSt13random_deviceC5Ev,comdat
.LLSDA4139:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4139-.LLSDACSB4139
.LLSDACSB4139:
	.uleb128 .LEHB0-.LFB4139
	.uleb128 .LEHE0-.LEHB0
	.uleb128 .L7-.LFB4139
	.uleb128 0
	.uleb128 .LEHB1-.LFB4139
	.uleb128 .LEHE1-.LEHB1
	.uleb128 0
	.uleb128 0
.LLSDACSE4139:
	.section	.text._ZNSt13random_deviceC2Ev,"axG",@progbits,_ZNSt13random_deviceC5Ev,comdat
	.size	_ZNSt13random_deviceC2Ev, .-_ZNSt13random_deviceC2Ev
	.weak	_ZNSt13random_deviceC1Ev
	.set	_ZNSt13random_deviceC1Ev,_ZNSt13random_deviceC2Ev
	.text
	.globl	_Z13cpu_block_sumiiPiS_
	.type	_Z13cpu_block_sumiiPiS_, @function
_Z13cpu_block_sumiiPiS_:
.LFB4719:
	.cfi_startproc
	endbr64
	movslq	%edi, %rax
	movl	%eax, %edi
	sall	$9, %edi
	leal	(%rsi,%rdi), %r8d
	movq	%r8, %r9
	leaq	(%rdx,%r8,4), %r10
	movl	$256, %r8d
.L12:
	cmpl	%r8d, %esi
	jnb	.L15
	leal	(%r9,%r8), %r11d
	shrl	%r8d
	movl	(%rdx,%r11,4), %r11d
	addl	%r11d, (%r10)
	jmp	.L12
.L15:
	testl	%esi, %esi
	jne	.L11
	movl	(%rdx,%rdi,4), %edx
	movl	%edx, (%rcx,%rax,4)
.L11:
	ret
	.cfi_endproc
.LFE4719:
	.size	_Z13cpu_block_sumiiPiS_, .-_Z13cpu_block_sumiiPiS_
	.globl	_Z13cpu_reductionPKiPimj
	.type	_Z13cpu_reductionPKiPimj, @function
_Z13cpu_reductionPKiPimj:
.LFB4720:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	movq	%rsi, %r12
	leaq	15(,%rdx,4), %rsi
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %r8
	movq	%rsi, %rax
	andq	$-4096, %rsi
	andq	$-16, %rax
	subq	%rsi, %r8
.L17:
	cmpq	%r8, %rsp
	je	.L18
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L17
.L18:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L19
	orq	$0, -8(%rsp,%rax)
.L19:
	movq	%rsp, %r14
	xorl	%esi, %esi
.L20:
	movl	%esi, %eax
	cmpq	%rdx, %rax
	jnb	.L31
	movl	(%rdi,%rax,4), %r8d
	incl	%esi
	movl	%r8d, (%r14,%rax,4)
	jmp	.L20
.L31:
	movl	%ecx, %ebx
	xorl	%r13d, %r13d
.L22:
	cmpq	%rbx, %r13
	je	.L32
	movl	$511, %esi
	movl	%r13d, %r15d
.L23:
	movq	%r12, %rcx
	movq	%r14, %rdx
	movl	%r15d, %edi
	call	_Z13cpu_block_sumiiPiS_
	subl	$1, %esi
	jnb	.L23
	incq	%r13
	jmp	.L22
.L32:
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE4720:
	.size	_Z13cpu_reductionPKiPimj, .-_Z13cpu_reductionPKiPimj
	.globl	_Z32__device_stub__Z9block_sumPKiPimPKiPim
	.type	_Z32__device_stub__Z9block_sumPKiPimPKiPim, @function
_Z32__device_stub__Z9block_sumPKiPimPKiPim:
.LFB4746:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z9block_sumPKiPim(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L33:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4746:
	.size	_Z32__device_stub__Z9block_sumPKiPimPKiPim, .-_Z32__device_stub__Z9block_sumPKiPimPKiPim
	.globl	_Z9block_sumPKiPim
	.type	_Z9block_sumPKiPim, @function
_Z9block_sumPKiPim:
.LFB4747:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z9block_sumPKiPimPKiPim
	.cfi_endproc
.LFE4747:
	.size	_Z9block_sumPKiPim, .-_Z9block_sumPKiPim
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"_Z9block_sumPKiPim"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4749:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC1(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9block_sumPKiPim(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4749:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZNSt6vectorIiSaIiEED2Ev,"axG",@progbits,_ZNSt6vectorIiSaIiEED5Ev,comdat
	.align 2
	.weak	_ZNSt6vectorIiSaIiEED2Ev
	.type	_ZNSt6vectorIiSaIiEED2Ev, @function
_ZNSt6vectorIiSaIiEED2Ev:
.LFB5081:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	testq	%rax, %rax
	je	.L40
	movq	16(%rdi), %rsi
	movq	%rax, %rdi
	subq	%rax, %rsi
	jmp	_ZdlPvm@PLT
.L40:
	ret
	.cfi_endproc
.LFE5081:
	.size	_ZNSt6vectorIiSaIiEED2Ev, .-_ZNSt6vectorIiSaIiEED2Ev
	.weak	_ZNSt6vectorIiSaIiEED1Ev
	.set	_ZNSt6vectorIiSaIiEED1Ev,_ZNSt6vectorIiSaIiEED2Ev
	.section	.text._ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,"axG",@progbits,_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,comdat
	.align 2
	.weak	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.type	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv, @function
_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv:
.LFB5470:
	.cfi_startproc
	endbr64
	movq	%rdi, %rax
	xorl	%edx, %edx
	movl	$2567483615, %edi
.L44:
	movq	(%rax,%rdx,8), %rsi
	incq	%rdx
	movq	(%rax,%rdx,8), %rcx
	andq	$-2147483648, %rsi
	andl	$2147483647, %ecx
	orq	%rsi, %rcx
	movq	%rcx, %rsi
	shrq	%rsi
	xorq	3168(%rax,%rdx,8), %rsi
	andl	$1, %ecx
	je	.L43
	movq	%rdi, %rcx
.L43:
	xorq	%rsi, %rcx
	movq	%rcx, -8(%rax,%rdx,8)
	cmpq	$227, %rdx
	jne	.L44
	movl	$2567483615, %edi
.L46:
	movq	(%rax,%rdx,8), %rsi
	incq	%rdx
	movq	(%rax,%rdx,8), %rcx
	andq	$-2147483648, %rsi
	andl	$2147483647, %ecx
	orq	%rsi, %rcx
	movq	%rcx, %rsi
	shrq	%rsi
	xorq	-1824(%rax,%rdx,8), %rsi
	andl	$1, %ecx
	je	.L45
	movq	%rdi, %rcx
.L45:
	xorq	%rsi, %rcx
	movq	%rcx, -8(%rax,%rdx,8)
	cmpq	$623, %rdx
	jne	.L46
	movq	4984(%rax), %rdx
	movq	(%rax), %rcx
	andq	$-2147483648, %rdx
	andl	$2147483647, %ecx
	orq	%rcx, %rdx
	movq	%rdx, %rcx
	shrq	%rcx
	xorq	3168(%rax), %rcx
	andl	$1, %edx
	je	.L47
	movl	$2567483615, %edx
.L47:
	xorq	%rcx, %rdx
	movq	%rdx, 4984(%rax)
	xorl	%edx, %edx
	movq	%rdx, 4992(%rax)
	ret
	.cfi_endproc
.LFE5470:
	.size	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv, .-_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.section	.text._ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,"axG",@progbits,_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,comdat
	.align 2
	.weak	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.type	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv, @function
_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv:
.LFB5394:
	.cfi_startproc
	endbr64
	cmpq	$623, 4992(%rdi)
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	jbe	.L60
	call	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
.L60:
	movq	4992(%rbx), %rax
	leaq	1(%rax), %rdx
	movq	(%rbx,%rax,8), %rax
	movq	%rdx, 4992(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	movq	%rax, %rdx
	shrq	$11, %rdx
	movl	%edx, %edx
	xorq	%rax, %rdx
	movq	%rdx, %rax
	salq	$7, %rax
	andl	$2636928640, %eax
	xorq	%rdx, %rax
	movq	%rax, %rdx
	salq	$15, %rdx
	andl	$4022730752, %edx
	xorq	%rax, %rdx
	movq	%rdx, %rax
	shrq	$18, %rax
	xorq	%rdx, %rax
	ret
	.cfi_endproc
.LFE5394:
	.size	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv, .-_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.text
	.align 2
	.type	_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE.isra.0, @function
_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE.isra.0:
.LFB5531:
	.cfi_startproc
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movslq	%esi, %rax
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rax, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movslq	%edx, %rbx
	subq	%rax, %rbx
	movl	$4294967294, %eax
	movq	%rbx, %r13
	cmpq	%rbx, %rax
	jb	.L63
	call	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	leaq	1(%rbx), %rbx
	imulq	%rbx, %rax
	movq	%rax, %rcx
	movl	%eax, %esi
	cmpl	%ebx, %eax
	jnb	.L64
	movl	%ebx, %eax
	xorl	%edx, %edx
	negl	%eax
	divl	%ebx
	movl	%edx, %r14d
.L65:
	cmpl	%r14d, %esi
	jnb	.L64
	movq	%rbp, %rdi
	call	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	imulq	%rbx, %rax
	movq	%rax, %rcx
	movl	%eax, %esi
	jmp	.L65
.L64:
	shrq	$32, %rcx
	jmp	.L67
.L63:
	movl	$4294967295, %eax
	cmpq	%rax, %rbx
	je	.L68
.L72:
	orl	$-1, %edx
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE.isra.0
	movq	%rbp, %rdi
	movl	%eax, %ebx
	call	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	movq	%rbx, %rcx
	salq	$32, %rcx
	addq	%rax, %rcx
	setc	%al
	movzbl	%al, %eax
	cmpq	%rcx, %r13
	jb	.L72
	testq	%rax, %rax
	jne	.L72
	jmp	.L67
.L68:
	call	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	movq	%rax, %rcx
.L67:
	popq	%rbx
	.cfi_def_cfa_offset 40
	leal	(%r12,%rcx), %eax
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5531:
	.size	_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE.isra.0, .-_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE.isra.0
	.section	.rodata.str1.1
.LC2:
	.string	"Host sum: "
.LC3:
	.string	"OK, right num_blocks and BLOCK_SIZE\n"
.LC4:
	.string	"Host reduce sum: "
.LC5:
	.string	"Device sum: "
.LC6:
	.string	"Host sum of partial sums: "
.LC7:
	.string	"\nPartial sums comparison: "
.LC8:
	.string	"-\n"
.LC9:
	.string	"e["
.LC10:
	.string	": "
.LC11:
	.string	"!="
.LC12:
	.string	"]\n"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB4721:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4721
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$4096, %rsp
	orq	$0, (%rsp)
	subq	$4096, %rsp
	orq	$0, (%rsp)
	subq	$1928, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	leaq	-10056(%rbp), %rax
	movq	%rax, %rdi
	movq	%rax, -10152(%rbp)
.LEHB2:
	call	_ZNSt13random_deviceC1Ev
.LEHE2:
	movq	-10152(%rbp), %rdi
.LEHB3:
	call	_ZNSt13random_device9_M_getvalEv@PLT
	movl	%eax, %eax
	movl	$1, %edx
	leaq	-5056(%rbp), %r12
	movq	%rax, -5056(%rbp)
.L75:
	movq	-8(%r12,%rdx,8), %rax
	movq	%rax, %rcx
	shrq	$30, %rcx
	xorq	%rcx, %rax
	imulq	$1812433253, %rax, %rax
	addl	%edx, %eax
	movq	%rax, (%r12,%rdx,8)
	incq	%rdx
	cmpq	$624, %rdx
	jne	.L75
	xorl	%edi, %edi
	movq	$624, -64(%rbp)
	movq	%rdi, -10072(%rbp)
	movq	%rdi, -10064(%rbp)
	movl	$1048576, %edi
	call	_Znwm@PLT
.LEHE3:
	leaq	1048576(%rax), %rdx
	xorl	%esi, %esi
	movq	%rax, -10080(%rbp)
	movq	%rax, %rbx
	movq	%rdx, -10064(%rbp)
	movl	%esi, (%rax)
	xorl	%eax, %eax
.L76:
	addq	$4, %rax
	cmpq	$1048576, %rax
	je	.L107
	xorl	%ecx, %ecx
	movl	%ecx, (%rbx,%rax)
	jmp	.L76
.L107:
	movq	%rdx, -10072(%rbp)
	xorl	%r13d, %r13d
.L78:
	movl	$10, %edx
	movl	$-10, %esi
	movq	%r12, %rdi
	call	_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE.isra.0
	movl	%eax, (%rbx,%r13)
	addq	$4, %r13
	cmpq	$1048576, %r13
	jne	.L78
	xorl	%eax, %eax
	xorl	%edx, %edx
.L79:
	addl	(%rbx,%rax), %edx
	addq	$4, %rax
	movl	%edx, %r12d
	cmpq	$1048576, %rax
	jne	.L79
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
.LEHB4:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movl	%r12d, %esi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%rsp, %rax
.L80:
	cmpq	%rax, %rsp
	je	.L81
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L80
.L81:
	subq	$2048, %rsp
	orq	$0, 2040(%rsp)
	leaq	.LC3(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movq	%rsp, -10160(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	-10160(%rbp), %rsi
	movl	$512, %ecx
	movl	$262144, %edx
	movq	%rbx, %rdi
	call	_Z13cpu_reductionPKiPimj
	movl	$1, %ecx
	movl	$512, %edx
	movq	-10160(%rbp), %rdi
	leaq	-10132(%rbp), %rsi
	call	_Z13cpu_reductionPKiPimj
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	-10132(%rbp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	-10128(%rbp), %rdi
	movl	$1048576, %esi
	call	cudaMalloc@PLT
	movq	-10128(%rbp), %rdi
	movl	$1, %ecx
	movl	$1048576, %edx
	movq	%rbx, %rsi
	call	cudaMemcpy@PLT
	leaq	-10120(%rbp), %rdi
	movl	$1048576, %esi
	call	cudaMalloc@PLT
	movl	$8388609, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	salq	$9, %rdi
	movl	$1, %esi
	movl	$1, -10084(%rbp)
	movq	%rdi, %rdx
	movq	%rdi, -10092(%rbp)
	movq	%rdi, -10104(%rbp)
	movl	$1, -10096(%rbp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L83
	movq	-10120(%rbp), %rsi
	movq	-10128(%rbp), %rdi
	movl	$262144, %edx
	call	_Z32__device_stub__Z9block_sumPKiPimPKiPim
.L83:
	leaq	-10112(%rbp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movl	$8388609, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	salq	$9, %rdx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movl	$1, -10084(%rbp)
	movq	%rdx, -10092(%rbp)
	movq	%rdi, -10104(%rbp)
	movl	$1, -10096(%rbp)
	call	__cudaPushCallConfiguration@PLT
	movq	-10112(%rbp), %rsi
	testl	%eax, %eax
	jne	.L84
	movq	-10120(%rbp), %rdi
	movl	$512, %edx
	call	_Z32__device_stub__Z9block_sumPKiPimPKiPim
.L84:
	movq	-10112(%rbp), %rsi
	xorl	%eax, %eax
	movl	$2, %ecx
	leaq	-10092(%rbp), %rdi
	movl	$4, %edx
	movl	%eax, -10092(%rbp)
	call	cudaMemcpy@PLT
	movq	%rsp, %rax
.L85:
	cmpq	%rax, %rsp
	je	.L86
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L85
.L86:
	subq	$2048, %rsp
	orq	$0, 2040(%rsp)
	movl	$2, %ecx
	movl	$2048, %edx
	movq	-10120(%rbp), %rsi
	movq	%rsp, %r12
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	xorl	%eax, %eax
	xorl	%edx, %edx
.L88:
	movl	(%r12,%rax,4), %ebx
	incq	%rax
	addl	%edx, %ebx
	movl	%ebx, %edx
	cmpq	$512, %rax
	jne	.L88
	leaq	.LC5(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	-10092(%rbp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC6(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movl	%ebx, %esi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC7(%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	%ebx, %ebx
	leaq	.LC9(%rip), %r15
.L91:
	movq	-10160(%rbp), %rax
	movl	(%r12,%rbx,4), %r14d
	leaq	.LC8(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	(%rax,%rbx,4), %r13d
	cmpl	%r13d, %r14d
	je	.L106
	movq	%r15, %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movq	%rbx, %rsi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	%rax, %rdi
	leaq	.LC10(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movl	%r14d, %esi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	leaq	.LC11(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movl	%r13d, %esi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	leaq	.LC12(%rip), %rsi
.L106:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.LEHE4:
	incq	%rbx
	cmpq	$512, %rbx
	jne	.L91
	leaq	-10080(%rbp), %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	leaq	-10056(%rbp), %rdi
	call	_ZNSt13random_device7_M_finiEv@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L95
	jmp	.L103
.L97:
	endbr64
	movq	%rax, %rbx
.L92:
	leaq	-10080(%rbp), %rdi
	call	_ZNSt6vectorIiSaIiEED1Ev
	jmp	.L93
.L96:
	endbr64
	movq	%rax, %rbx
.L93:
	movq	-10152(%rbp), %rdi
	call	_ZNSt13random_device7_M_finiEv@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L103
	movq	%rbx, %rdi
.LEHB5:
	call	_Unwind_Resume@PLT
.LEHE5:
.L103:
	call	__stack_chk_fail@PLT
.L95:
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE4721:
	.section	.gcc_except_table,"a",@progbits
.LLSDA4721:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4721-.LLSDACSB4721
.LLSDACSB4721:
	.uleb128 .LEHB2-.LFB4721
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB3-.LFB4721
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L96-.LFB4721
	.uleb128 0
	.uleb128 .LEHB4-.LFB4721
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L97-.LFB4721
	.uleb128 0
	.uleb128 .LEHB5-.LFB4721
	.uleb128 .LEHE5-.LEHB5
	.uleb128 0
	.uleb128 0
.LLSDACSE4721:
	.section	.text.startup
	.size	main, .-main
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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>
#include <numeric>
#include <random>
#include <vector>

// Here you can set the device ID that was assigned to you
#define MYDEVICE 1
#define BLOCK_SIZE 512
#define BLOCKS_NUMBER 512

// Part 1 of 6: implement the kernel
__global__ void block_sum(const int* input, int* per_block_results,
                          const size_t n)
{
  // fill me
  __shared__ int shared_mem[BLOCK_SIZE];
  uint block_id = blockIdx.x;
  uint thread_id = threadIdx.x;

  shared_mem[thread_id] = input[block_id * BLOCK_SIZE + thread_id];

  __syncthreads();
  
  /*if (thread_id == 0) {
    int sum = 0;
    for (uint i = 0; i < BLOCK_SIZE; ++i) {
      sum += shared_mem[i];
    }
    per_block_results[block_id] = sum;
  }*/

  uint max_allowed_id = BLOCK_SIZE / 2;

  while (thread_id < max_allowed_id) {
    shared_mem[thread_id] += shared_mem[thread_id + max_allowed_id];
    max_allowed_id = max_allowed_id / 2;
    __syncthreads();
  }

  
  
  if (thread_id == 0) {
    per_block_results[block_id] = shared_mem[0];
  }
}

void cpu_block_sum(int block_id, int thread_id, int* global_inoutput, int* per_block_results) {
  // BLOCK_SIZE is a const si no : const size_t n
  
  uint istart = block_id * BLOCK_SIZE;
  
  /*if (thread_id == 0) {
    int sum = 0;
    for (uint i = 0; i < BLOCK_SIZE; ++i) {
      sum += shared_mem[i];
    }
    per_block_results[block_id] = sum;
  }*/

  uint max_allowed_id = BLOCK_SIZE / 2;

  while (thread_id < max_allowed_id) {
    global_inoutput[istart + thread_id] += global_inoutput[istart + thread_id + max_allowed_id];
    max_allowed_id = max_allowed_id / 2;
  }
  
  if (thread_id == 0) {
    per_block_results[block_id] = global_inoutput[istart + thread_id];
  }
}

void cpu_reduction(const int* input, int* per_block_results, const size_t input_size, uint blocks_number) {
  int global_inoutput[input_size];
  // Copy the input to a teporary array
  for (uint i = 0; i < input_size; ++i) {
    global_inoutput[i] = input[i];
  }
  // For each block
  for (uint ib = 0; ib < blocks_number; ++ib) {
    // For each thread, descending order
    for (int ith = BLOCK_SIZE - 1; ith >= 0; --ith) {
    //for (int ith = 0; ith < BLOCK_SIZE; ++ith) {
      cpu_block_sum(ib, ith, global_inoutput, per_block_results);
    }
  }
}

////////////////////////////////////////////////////////////////////////////////
// Program main
////////////////////////////////////////////////////////////////////////////////
int main(void)
{
  std::random_device
      rd; // Will be used to obtain a seed for the random number engine
  std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd()
  std::uniform_int_distribution<> distrib(-10, 10);

  // create array of 262144 elements
  const int num_elements = 1 << 18;
  uint num_blocks = num_elements / BLOCK_SIZE;

  // generate random input on the host
  std::vector<int> h_input(num_elements);
  for (auto& elt : h_input) {
    elt = distrib(gen);
  }

  // Compute the sum on the host
  const int host_result = std::accumulate(h_input.begin(), h_input.end(), 0);
  std::cerr << "Host sum: " << host_result << std::endl;

  // Input size
  uint in_size = num_elements * sizeof(int);


  // === CPU verification ===
  int host_partial_sums_and_total[num_blocks];
  if (num_blocks == BLOCK_SIZE) {
    std::cout << "OK, right num_blocks and BLOCK_SIZE\n";
  } else {
    std::cout << "ERROR - num_blocks(" << num_blocks << ") != BLOCK_SIZE(" << BLOCK_SIZE << ")\n";
    return 1;
  }
  cpu_reduction(h_input.data(), host_partial_sums_and_total, num_elements, num_blocks);
  int h_result;
  cpu_reduction(host_partial_sums_and_total, &h_result, BLOCK_SIZE, 1);
  std::cout << "Host reduce sum: " << h_result << std::endl;



  // === CUDA kernels ===

  // Move input to device memory
  int* d_input;
  hipMalloc(&d_input, in_size);
  hipMemcpy(d_input, h_input.data(), in_size, hipMemcpyHostToDevice);

  // Allocate the partial sums: How much space does it need?
  int* d_partial_sums_and_total;
  hipMalloc(&d_partial_sums_and_total, in_size);


  // Launch one kernel to compute, per-block, a partial sum. How
  // much shared memory does it need?
  block_sum<<<num_blocks, BLOCK_SIZE>>>(d_input, d_partial_sums_and_total,
                                        num_elements);

  // 1) Sommer les sommes partielles sur CPU
  // 2) Comparer les sommes partielles lues depuis le GPU et depuis le CPU

  int* d_result;
  hipMalloc(&d_result, sizeof(int));

  // Compute the sum of the partial sums
  block_sum<<<1, BLOCKS_NUMBER>>>(d_partial_sums_and_total, d_result, BLOCKS_NUMBER);

  // Copy the result back to the host
  int device_result = 0;
  hipMemcpy(&device_result, d_result, sizeof(int), hipMemcpyDeviceToHost);

  int h_partial_sums_and_total[num_blocks];
  hipMemcpy(h_partial_sums_and_total, d_partial_sums_and_total, BLOCK_SIZE * sizeof(int), hipMemcpyDeviceToHost);
  int hsum = 0;
  for (uint ib = 0; ib < num_blocks; ++ib) {
    hsum += h_partial_sums_and_total[ib];
    //std::cout << "b(" << ib << ") = " << h_partial_sums_and_total[ib] << std::endl;
  }

  std::cout << "Device sum: " << device_result << std::endl;
  std::cout << "Host sum of partial sums: " << hsum << std::endl;


  std::cout << "\nPartial sums comparison: " << std::endl;
  for (uint ib = 0; ib < num_blocks; ++ib) {
    int gpu_v = h_partial_sums_and_total[ib];
    int cpu_v = host_partial_sums_and_total[ib];
    if (gpu_v == cpu_v) {
      std::cout << "-\n";
    } else {
      std::cout << "e[" << ib << ": " << gpu_v << "!=" << cpu_v << "]\n";
    }
    //std::cout << "b(" << ib << ") = " << h_partial_sums_and_total[ib] << std::endl;
  }
  


  // // Part 1 of 6: deallocate device memory

  return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z24__device_stub__block_sumPKiPim # -- Begin function _Z24__device_stub__block_sumPKiPim
	.type	_Z24__device_stub__block_sumPKiPim,@function
_Z24__device_stub__block_sumPKiPim:     # @_Z24__device_stub__block_sumPKiPim
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z9block_sumPKiPim, %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__block_sumPKiPim, .Lfunc_end0-_Z24__device_stub__block_sumPKiPim
	.cfi_endproc
                                        # -- End function
	.globl	_Z13cpu_block_sumiiPiS_         # -- Begin function _Z13cpu_block_sumiiPiS_
	.type	_Z13cpu_block_sumiiPiS_,@function
_Z13cpu_block_sumiiPiS_:                # @_Z13cpu_block_sumiiPiS_
	.cfi_startproc
# %bb.0:
	cmpl	$255, %esi
	ja	.LBB1_5
# %bb.1:                                # %.lr.ph
	movl	%edi, %eax
	shll	$9, %eax
	movl	%eax, %r8d
	orl	%esi, %r8d
	movl	(%rdx,%r8,4), %r9d
	movl	$256, %r10d                     # imm = 0x100
.LBB1_2:                                # =>This Inner Loop Header: Depth=1
	leal	(%r10,%r8), %r11d
	addl	(%rdx,%r11,4), %r9d
	shrl	%r10d
	cmpl	%esi, %r10d
	ja	.LBB1_2
# %bb.3:
	movl	%r9d, (%rdx,%r8,4)
	testl	%esi, %esi
	je	.LBB1_4
.LBB1_5:                                # %.thread
	retq
.LBB1_4:
	movl	%eax, %eax
	movl	(%rdx,%rax,4), %eax
	movslq	%edi, %rdx
	movl	%eax, (%rcx,%rdx,4)
	retq
.Lfunc_end1:
	.size	_Z13cpu_block_sumiiPiS_, .Lfunc_end1-_Z13cpu_block_sumiiPiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z13cpu_reductionPKiPimj        # -- Begin function _Z13cpu_reductionPKiPimj
	.type	_Z13cpu_reductionPKiPimj,@function
_Z13cpu_reductionPKiPimj:               # @_Z13cpu_reductionPKiPimj
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%rbx
	pushq	%rax
	.cfi_offset %rbx, -24
	movq	%rsp, %rax
	leaq	15(,%rdx,4), %r8
	andq	$-16, %r8
	subq	%r8, %rax
	movq	%rax, %rsp
	testq	%rdx, %rdx
	je	.LBB2_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%r8d, %r8d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rdi,%r8,4), %r9d
	movl	%r9d, (%rax,%r8,4)
	incq	%r8
	movl	%r8d, %r9d
	cmpq	%rdx, %r9
	jb	.LBB2_2
.LBB2_3:                                # %.preheader18
	testl	%ecx, %ecx
	je	.LBB2_11
# %bb.4:                                # %.preheader.preheader
	xorl	%edx, %edx
.LBB2_5:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_6 Depth 2
                                        #       Child Loop BB2_8 Depth 3
	movslq	%edx, %rdi
	shll	$9, %edx
	movl	$511, %r8d                      # imm = 0x1FF
.LBB2_6:                                #   Parent Loop BB2_5 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB2_8 Depth 3
	cmpq	$255, %r8
	ja	.LBB2_12
# %bb.7:                                # %.lr.ph.i
                                        #   in Loop: Header=BB2_6 Depth=2
	movl	%edx, %r9d
	orl	%r8d, %r9d
	movl	(%rax,%r9,4), %r10d
	movl	$256, %r11d                     # imm = 0x100
.LBB2_8:                                #   Parent Loop BB2_5 Depth=1
                                        #     Parent Loop BB2_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	leal	(%r11,%r9), %ebx
	addl	(%rax,%rbx,4), %r10d
	shrl	%r11d
	cmpq	%r11, %r8
	jb	.LBB2_8
# %bb.9:                                #   in Loop: Header=BB2_6 Depth=2
	movl	%r10d, (%rax,%r9,4)
	testq	%r8, %r8
	je	.LBB2_10
.LBB2_12:                               # %_Z13cpu_block_sumiiPiS_.exit
                                        #   in Loop: Header=BB2_6 Depth=2
	decq	%r8
	jmp	.LBB2_6
.LBB2_10:                               #   in Loop: Header=BB2_5 Depth=1
	movl	(%rax,%rdx,4), %edx
	movl	%edx, (%rsi,%rdi,4)
	incl	%edi
	movl	%edi, %edx
	cmpl	%ecx, %edi
	jne	.LBB2_5
.LBB2_11:                               # %._crit_edge
	leaq	-8(%rbp), %rsp
	popq	%rbx
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end2:
	.size	_Z13cpu_reductionPKiPimj, .Lfunc_end2-_Z13cpu_reductionPKiPimj
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$10072, %rsp                    # imm = 0x2758
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	leaq	-10104(%rbp), %rbx
	movq	%rbx, %rdi
	callq	_ZNSt13random_deviceC2Ev
.Ltmp0:
	movq	%rbx, %rdi
	callq	_ZNSt13random_device9_M_getvalEv
.Ltmp1:
# %bb.1:                                # %_ZNSt13random_deviceclEv.exit
	movl	%eax, %eax
	movq	%rax, -5104(%rbp)
	movl	$1, %ecx
.LBB3_2:                                # =>This Inner Loop Header: Depth=1
	movq	%rax, %rdx
	shrq	$30, %rdx
	xorl	%eax, %edx
	imull	$1812433253, %edx, %eax         # imm = 0x6C078965
	addl	%ecx, %eax
	movq	%rax, -5104(%rbp,%rcx,8)
	incq	%rcx
	cmpq	$624, %rcx                      # imm = 0x270
	jne	.LBB3_2
# %bb.3:
	movq	$624, -112(%rbp)                # imm = 0x270
	movabsq	$47244640246, %rax              # imm = 0xAFFFFFFF6
	movq	%rax, -104(%rbp)
.Ltmp3:
	movl	$1048576, %edi                  # imm = 0x100000
	callq	_Znwm
.Ltmp4:
# %bb.4:
	movq	%rax, %r12
	xorl	%ebx, %ebx
	movl	$1048576, %edx                  # imm = 0x100000
	movq	%rax, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	leaq	-5104(%rbp), %r14
	leaq	-104(%rbp), %r15
.LBB3_5:                                # =>This Inner Loop Header: Depth=1
.Ltmp6:
	movq	%r15, %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	callq	_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE
.Ltmp7:
# %bb.6:                                # %_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_.exit
                                        #   in Loop: Header=BB3_5 Depth=1
	movl	%eax, (%r12,%rbx)
	addq	$4, %rbx
	cmpq	$1048576, %rbx                  # imm = 0x100000
	jne	.LBB3_5
# %bb.7:                                # %.lr.ph.i.preheader
	xorl	%r14d, %r14d
	xorl	%eax, %eax
.LBB3_8:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	addl	(%r12,%rax), %r14d
	addq	$4, %rax
	cmpq	$1048576, %rax                  # imm = 0x100000
	jne	.LBB3_8
# %bb.9:                                # %_ZSt10accumulateIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEEiET0_T_S8_S7_.exit
.Ltmp9:
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	movl	$10, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp10:
# %bb.10:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
.Ltmp11:
	movl	$_ZSt4cerr, %edi
	movl	%r14d, %esi
	callq	_ZNSolsEi
.Ltmp12:
# %bb.11:
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
.Ltmp13:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp14:
# %bb.12:                               # %.noexc
.Ltmp15:
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
.Ltmp16:
# %bb.13:                               # %.noexc91
.Ltmp17:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp18:
# %bb.14:                               # %_ZNSolsEPFRSoS_E.exit
	movq	%rsp, %rbx
	movq	%rsp, %r15
	addq	$-2048, %r15                    # imm = 0xF800
	movq	%r15, %rsp
.Ltmp20:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$36, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp21:
# %bb.15:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit72
	movl	$262144, %edx                   # imm = 0x40000
	movq	%r12, %rdi
	movq	%r15, %rsi
	movl	$512, %ecx                      # imm = 0x200
	callq	_Z13cpu_reductionPKiPimj
	leaq	-56(%rbp), %rsi
	movl	$512, %edx                      # imm = 0x200
	movq	%r15, %rdi
	movl	$1, %ecx
	callq	_Z13cpu_reductionPKiPimj
.Ltmp23:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$17, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp24:
# %bb.16:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit73
	movl	-56(%rbp), %esi
.Ltmp25:
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
.Ltmp26:
# %bb.17:
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
.Ltmp27:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp28:
# %bb.18:                               # %.noexc93
.Ltmp29:
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
.Ltmp30:
# %bb.19:                               # %.noexc94
.Ltmp31:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp32:
# %bb.20:                               # %_ZNSolsEPFRSoS_E.exit74
.Ltmp34:
	leaq	-80(%rbp), %rdi
	movl	$1048576, %esi                  # imm = 0x100000
	callq	hipMalloc
.Ltmp35:
# %bb.21:                               # %_ZL9hipMallocIiE10hipError_tPPT_m.exit
	movq	-80(%rbp), %rdi
.Ltmp36:
	movl	$1048576, %edx                  # imm = 0x100000
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp37:
# %bb.22:
.Ltmp39:
	leaq	-48(%rbp), %rdi
	movl	$1048576, %esi                  # imm = 0x100000
	callq	hipMalloc
.Ltmp40:
# %bb.23:                               # %_ZL9hipMallocIiE10hipError_tPPT_m.exit75
.Ltmp41:
	movabsq	$4294967808, %rdi               # imm = 0x100000200
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp42:
# %bb.24:
	testl	%eax, %eax
	jne	.LBB3_26
# %bb.25:
	movq	-80(%rbp), %rdi
	movq	-48(%rbp), %rsi
.Ltmp43:
	movl	$262144, %edx                   # imm = 0x40000
	callq	_Z24__device_stub__block_sumPKiPim
.Ltmp44:
.LBB3_26:
.Ltmp46:
	movq	%r15, -96(%rbp)                 # 8-byte Spill
	movq	%rbx, -88(%rbp)                 # 8-byte Spill
	leaq	-72(%rbp), %rdi
	movl	$4, %esi
	callq	hipMalloc
.Ltmp47:
# %bb.27:                               # %_ZL9hipMallocIiE10hipError_tPPT_m.exit76
.Ltmp48:
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movabsq	$4294967808, %rdx               # imm = 0x100000200
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp49:
# %bb.28:
	testl	%eax, %eax
	jne	.LBB3_30
# %bb.29:
	movq	-48(%rbp), %rdi
	movq	-72(%rbp), %rsi
.Ltmp50:
	movl	$512, %edx                      # imm = 0x200
	callq	_Z24__device_stub__block_sumPKiPim
.Ltmp51:
.LBB3_30:
	movq	%r12, -64(%rbp)                 # 8-byte Spill
	leaq	-52(%rbp), %rdi
	movl	$0, (%rdi)
	movq	-72(%rbp), %rsi
.Ltmp53:
	movl	$4, %edx
	movl	$2, %ecx
	callq	hipMemcpy
.Ltmp54:
# %bb.31:
	movq	%rsp, %r15
	addq	$-2048, %r15                    # imm = 0xF800
	movq	%r15, %rsp
	movq	-48(%rbp), %rsi
.Ltmp55:
	movl	$2048, %edx                     # imm = 0x800
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
.Ltmp56:
# %bb.32:                               # %.preheader.preheader
	xorl	%eax, %eax
	xorl	%r12d, %r12d
.LBB3_33:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	addl	(%r15,%rax,4), %r12d
	incq	%rax
	cmpq	$512, %rax                      # imm = 0x200
	jne	.LBB3_33
# %bb.34:
.Ltmp58:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp59:
# %bb.35:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit77
	movl	-52(%rbp), %esi
.Ltmp60:
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
.Ltmp61:
# %bb.36:
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
.Ltmp62:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp63:
# %bb.37:                               # %.noexc97
.Ltmp64:
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
.Ltmp65:
# %bb.38:                               # %.noexc98
.Ltmp66:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp67:
# %bb.39:                               # %_ZNSolsEPFRSoS_E.exit78
.Ltmp68:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$26, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp69:
# %bb.40:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit79
.Ltmp70:
	movl	$_ZSt4cout, %edi
	movl	%r12d, %esi
	callq	_ZNSolsEi
.Ltmp71:
# %bb.41:
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
.Ltmp72:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp73:
# %bb.42:                               # %.noexc101
.Ltmp74:
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
.Ltmp75:
# %bb.43:                               # %.noexc102
.Ltmp76:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp77:
# %bb.44:                               # %_ZNSolsEPFRSoS_E.exit80
.Ltmp78:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$26, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp79:
# %bb.45:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit81
	movq	_ZSt4cout(%rip), %rax
	addq	-24(%rax), %rbx
.Ltmp80:
	movq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp81:
# %bb.46:                               # %.noexc105
.Ltmp82:
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
.Ltmp83:
# %bb.47:                               # %.noexc106
.Ltmp84:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp85:
# %bb.48:                               # %_ZNSolsEPFRSoS_E.exit82.preheader.preheader
	xorl	%r12d, %r12d
.LBB3_49:                               # %_ZNSolsEPFRSoS_E.exit82.preheader
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r15,%r12,4), %r14d
	movq	-96(%rbp), %rax                 # 8-byte Reload
	movl	(%rax,%r12,4), %r13d
	movl	$.L.str.9, %esi
	movl	$_ZSt4cout, %eax
	cmpl	%r13d, %r14d
	je	.LBB3_57
# %bb.50:                               #   in Loop: Header=BB3_49 Depth=1
.Ltmp87:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	movl	$2, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp88:
# %bb.51:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit84
                                        #   in Loop: Header=BB3_49 Depth=1
.Ltmp89:
	movl	$_ZSt4cout, %edi
	movq	%r12, %rsi
	callq	_ZNSo9_M_insertImEERSoT_
.Ltmp90:
# %bb.52:                               # %_ZNSolsEj.exit
                                        #   in Loop: Header=BB3_49 Depth=1
.Ltmp91:
	movq	%rax, %rbx
	movl	$.L.str.11, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp92:
# %bb.53:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit85
                                        #   in Loop: Header=BB3_49 Depth=1
.Ltmp93:
	movq	%rbx, %rdi
	movl	%r14d, %esi
	callq	_ZNSolsEi
.Ltmp94:
# %bb.54:                               #   in Loop: Header=BB3_49 Depth=1
.Ltmp95:
	movq	%rax, %rbx
	movl	$.L.str.12, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp96:
# %bb.55:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit86
                                        #   in Loop: Header=BB3_49 Depth=1
.Ltmp97:
	movq	%rbx, %rdi
	movl	%r13d, %esi
	callq	_ZNSolsEi
.Ltmp98:
# %bb.56:                               #   in Loop: Header=BB3_49 Depth=1
	movl	$.L.str.13, %esi
.LBB3_57:                               # %.invoke
                                        #   in Loop: Header=BB3_49 Depth=1
.Ltmp99:
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp100:
# %bb.58:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit83
                                        #   in Loop: Header=BB3_49 Depth=1
	incq	%r12
	cmpq	$512, %r12                      # imm = 0x200
	jne	.LBB3_49
# %bb.59:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit
	movq	-88(%rbp), %rsp                 # 8-byte Reload
	movq	-64(%rbp), %rdi                 # 8-byte Reload
	callq	_ZdlPv
.Ltmp105:
	leaq	-10104(%rbp), %rdi
	callq	_ZNSt13random_device7_M_finiEv
.Ltmp106:
# %bb.60:                               # %_ZNSt13random_deviceD2Ev.exit
	xorl	%eax, %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.LBB3_61:
	.cfi_def_cfa %rbp, 16
.Ltmp107:
	jmp	.LBB3_62
.LBB3_63:
.Ltmp22:
	jmp	.LBB3_75
.LBB3_64:
.Ltmp5:
	jmp	.LBB3_66
.LBB3_65:
.Ltmp2:
.LBB3_66:
	movq	%rax, %r14
	jmp	.LBB3_79
.LBB3_67:
.Ltmp57:
	jmp	.LBB3_77
.LBB3_68:
.Ltmp38:
	jmp	.LBB3_75
.LBB3_69:
.Ltmp52:
	jmp	.LBB3_75
.LBB3_70:
.Ltmp45:
	jmp	.LBB3_75
.LBB3_71:
.Ltmp33:
	jmp	.LBB3_75
.LBB3_72:
.Ltmp19:
	jmp	.LBB3_75
.LBB3_73:
.Ltmp86:
	jmp	.LBB3_77
.LBB3_74:
.Ltmp8:
.LBB3_75:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit89
	movq	%rax, %r14
	jmp	.LBB3_78
.LBB3_76:
.Ltmp101:
.LBB3_77:
	movq	%rax, %r14
	movq	-64(%rbp), %r12                 # 8-byte Reload
.LBB3_78:                               # %_ZNSt6vectorIiSaIiEED2Ev.exit89
	movq	%r12, %rdi
	callq	_ZdlPv
.LBB3_79:
.Ltmp102:
	leaq	-10104(%rbp), %rdi
	callq	_ZNSt13random_device7_M_finiEv
.Ltmp103:
# %bb.80:                               # %_ZNSt13random_deviceD2Ev.exit90
	movq	%r14, %rdi
	callq	_Unwind_Resume@PLT
.LBB3_81:
.Ltmp104:
.LBB3_62:
	movq	%rax, %rdi
	callq	__clang_call_terminate
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table3:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	3                               # @TType Encoding = udata4
	.uleb128 .Lttbase0-.Lttbaseref0
.Lttbaseref0:
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp4-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp4
	.uleb128 .Ltmp5-.Lfunc_begin0           #     jumps to .Ltmp5
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp4-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp6-.Ltmp4                  #   Call between .Ltmp4 and .Ltmp6
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin0           # >> Call Site 5 <<
	.uleb128 .Ltmp7-.Ltmp6                  #   Call between .Ltmp6 and .Ltmp7
	.uleb128 .Ltmp8-.Lfunc_begin0           #     jumps to .Ltmp8
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp9-.Lfunc_begin0           # >> Call Site 6 <<
	.uleb128 .Ltmp18-.Ltmp9                 #   Call between .Ltmp9 and .Ltmp18
	.uleb128 .Ltmp19-.Lfunc_begin0          #     jumps to .Ltmp19
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp20-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp21-.Ltmp20                #   Call between .Ltmp20 and .Ltmp21
	.uleb128 .Ltmp22-.Lfunc_begin0          #     jumps to .Ltmp22
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp23-.Lfunc_begin0          # >> Call Site 8 <<
	.uleb128 .Ltmp32-.Ltmp23                #   Call between .Ltmp23 and .Ltmp32
	.uleb128 .Ltmp33-.Lfunc_begin0          #     jumps to .Ltmp33
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp34-.Lfunc_begin0          # >> Call Site 9 <<
	.uleb128 .Ltmp37-.Ltmp34                #   Call between .Ltmp34 and .Ltmp37
	.uleb128 .Ltmp38-.Lfunc_begin0          #     jumps to .Ltmp38
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp39-.Lfunc_begin0          # >> Call Site 10 <<
	.uleb128 .Ltmp44-.Ltmp39                #   Call between .Ltmp39 and .Ltmp44
	.uleb128 .Ltmp45-.Lfunc_begin0          #     jumps to .Ltmp45
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp46-.Lfunc_begin0          # >> Call Site 11 <<
	.uleb128 .Ltmp51-.Ltmp46                #   Call between .Ltmp46 and .Ltmp51
	.uleb128 .Ltmp52-.Lfunc_begin0          #     jumps to .Ltmp52
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp53-.Lfunc_begin0          # >> Call Site 12 <<
	.uleb128 .Ltmp56-.Ltmp53                #   Call between .Ltmp53 and .Ltmp56
	.uleb128 .Ltmp57-.Lfunc_begin0          #     jumps to .Ltmp57
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp58-.Lfunc_begin0          # >> Call Site 13 <<
	.uleb128 .Ltmp85-.Ltmp58                #   Call between .Ltmp58 and .Ltmp85
	.uleb128 .Ltmp86-.Lfunc_begin0          #     jumps to .Ltmp86
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp87-.Lfunc_begin0          # >> Call Site 14 <<
	.uleb128 .Ltmp100-.Ltmp87               #   Call between .Ltmp87 and .Ltmp100
	.uleb128 .Ltmp101-.Lfunc_begin0         #     jumps to .Ltmp101
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp105-.Lfunc_begin0         # >> Call Site 15 <<
	.uleb128 .Ltmp106-.Ltmp105              #   Call between .Ltmp105 and .Ltmp106
	.uleb128 .Ltmp107-.Lfunc_begin0         #     jumps to .Ltmp107
	.byte	1                               #   On action: 1
	.uleb128 .Ltmp102-.Lfunc_begin0         # >> Call Site 16 <<
	.uleb128 .Ltmp103-.Ltmp102              #   Call between .Ltmp102 and .Ltmp103
	.uleb128 .Ltmp104-.Lfunc_begin0         #     jumps to .Ltmp104
	.byte	1                               #   On action: 1
	.uleb128 .Ltmp103-.Lfunc_begin0         # >> Call Site 17 <<
	.uleb128 .Lfunc_end3-.Ltmp103           #   Call between .Ltmp103 and .Lfunc_end3
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.byte	1                               # >> Action Record 1 <<
                                        #   Catch TypeInfo 1
	.byte	0                               #   No further actions
	.p2align	2, 0x0
                                        # >> Catch TypeInfos <<
	.long	0                               # TypeInfo 1
.Lttbase0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt13random_deviceC2Ev,"axG",@progbits,_ZNSt13random_deviceC2Ev,comdat
	.weak	_ZNSt13random_deviceC2Ev        # -- Begin function _ZNSt13random_deviceC2Ev
	.p2align	1, 0x90
	.type	_ZNSt13random_deviceC2Ev,@function
_ZNSt13random_deviceC2Ev:               # @_ZNSt13random_deviceC2Ev
.Lfunc_begin1:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception1
# %bb.0:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_.exit
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	leaq	16(%rsp), %r15
	movq	%r15, -16(%r15)
	movq	%rsp, %r14
	movl	$.L.str.14, %esi
	movl	$.L.str.14+7, %edx
	movq	%r14, %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
.Ltmp108:
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
.Ltmp109:
# %bb.1:
	movq	(%rsp), %rdi
	cmpq	%r15, %rdi
	je	.LBB4_3
# %bb.2:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	callq	_ZdlPv
.LBB4_3:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB4_4:
	.cfi_def_cfa_offset 64
.Ltmp110:
	movq	%rax, %rbx
	movq	(%rsp), %rdi
	cmpq	%r15, %rdi
	je	.LBB4_6
# %bb.5:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i4
	callq	_ZdlPv
.LBB4_6:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit6
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end4:
	.size	_ZNSt13random_deviceC2Ev, .Lfunc_end4-_ZNSt13random_deviceC2Ev
	.cfi_endproc
	.section	.gcc_except_table._ZNSt13random_deviceC2Ev,"aG",@progbits,_ZNSt13random_deviceC2Ev,comdat
	.p2align	2, 0x0
GCC_except_table4:
.Lexception1:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end1-.Lcst_begin1
.Lcst_begin1:
	.uleb128 .Lfunc_begin1-.Lfunc_begin1    # >> Call Site 1 <<
	.uleb128 .Ltmp108-.Lfunc_begin1         #   Call between .Lfunc_begin1 and .Ltmp108
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp108-.Lfunc_begin1         # >> Call Site 2 <<
	.uleb128 .Ltmp109-.Ltmp108              #   Call between .Ltmp108 and .Ltmp109
	.uleb128 .Ltmp110-.Lfunc_begin1         #     jumps to .Ltmp110
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp109-.Lfunc_begin1         # >> Call Site 3 <<
	.uleb128 .Lfunc_end4-.Ltmp109           #   Call between .Ltmp109 and .Lfunc_end4
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end1:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %rbx
	subq	%rsi, %r14
	movq	%r14, (%rsp)
	cmpq	$15, %r14
	jbe	.LBB5_1
# %bb.2:
	movq	%rsp, %r12
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm
	movq	%rax, (%rbx)
	movq	(%r12), %rcx
	movq	%rcx, 16(%rbx)
	jmp	.LBB5_3
.LBB5_1:                                # %._crit_edge
	movq	(%rbx), %rax
.LBB5_3:
	testq	%r14, %r14
	je	.LBB5_7
# %bb.4:
	cmpq	$1, %r14
	jne	.LBB5_6
# %bb.5:
	movb	(%r15), %cl
	movb	%cl, (%rax)
	jmp	.LBB5_7
.LBB5_6:
	movq	%rax, %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	callq	memcpy@PLT
.LBB5_7:                                # %_ZZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tagEN6_GuardD2Ev.exit
	movq	(%rsp), %rax
	movq	%rax, 8(%rbx)
	movq	(%rbx), %rcx
	movb	$0, (%rcx,%rax)
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag, .Lfunc_end5-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.cfi_endproc
                                        # -- End function
	.section	.text.__clang_call_terminate,"axG",@progbits,__clang_call_terminate,comdat
	.hidden	__clang_call_terminate          # -- Begin function __clang_call_terminate
	.weak	__clang_call_terminate
	.type	__clang_call_terminate,@function
__clang_call_terminate:                 # @__clang_call_terminate
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__cxa_begin_catch
	callq	_ZSt9terminatev
.Lfunc_end6:
	.size	__clang_call_terminate, .Lfunc_end6-__clang_call_terminate
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE,"axG",@progbits,_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE,comdat
	.weak	_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE # -- Begin function _ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE
	.p2align	1, 0x90
	.type	_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE,@function
_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE: # @_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r14
	movslq	4(%rdx), %r15
	movq	%rdx, 8(%rsp)                   # 8-byte Spill
	movslq	(%rdx), %rax
	subq	%rax, %r15
	movl	$4294967294, %eax               # imm = 0xFFFFFFFE
	cmpq	%rax, %r15
	ja	.LBB7_2
# %bb.1:
	incl	%r15d
	movq	%r14, %rdi
	movl	%r15d, %esi
	callq	_ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_
	movl	%eax, %eax
	jmp	.LBB7_7
.LBB7_2:
	movl	$4294967295, %eax               # imm = 0xFFFFFFFF
	cmpq	%rax, %r15
	jne	.LBB7_3
# %bb.6:
	movq	%r14, %rdi
	callq	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	jmp	.LBB7_7
.LBB7_3:                                # %.preheader
	movq	%rdi, %r12
	movabsq	$-4294967296, %rbx              # imm = 0xFFFFFFFF00000000
	leaq	16(%rsp), %r13
.LBB7_4:                                # =>This Inner Loop Header: Depth=1
	movq	%rbx, 16(%rsp)
	movq	%r12, %rdi
	movq	%r14, %rsi
	movq	%r13, %rdx
	callq	_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE
	movl	%eax, %ebp
	shlq	$32, %rbp
	movq	%r14, %rdi
	callq	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	addq	%rbp, %rax
	setb	%cl
	cmpq	%r15, %rax
	ja	.LBB7_4
# %bb.5:                                #   in Loop: Header=BB7_4 Depth=1
	testb	%cl, %cl
	jne	.LBB7_4
.LBB7_7:                                # %.loopexit
	movq	8(%rsp), %rcx                   # 8-byte Reload
	addl	(%rcx), %eax
                                        # kill: def $eax killed $eax killed $rax
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE, .Lfunc_end7-_ZNSt24uniform_int_distributionIiEclISt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEEEiRT_RKNS0_10param_typeE
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_,"axG",@progbits,_ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_,comdat
	.weak	_ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_ # -- Begin function _ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_
	.p2align	1, 0x90
	.type	_ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_,@function
_ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_: # @_ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_
	.cfi_startproc
# %bb.0:
	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	%esi, %ebp
	movq	%rdi, %rbx
	callq	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	movq	%rax, %rcx
	movl	%ebp, %r14d
	imulq	%r14, %rcx
	cmpl	%ebp, %ecx
	jae	.LBB8_4
# %bb.1:
	movl	%ebp, %eax
	negl	%eax
	xorl	%edx, %edx
	divl	%ebp
	cmpl	%ecx, %edx
	jbe	.LBB8_4
# %bb.2:                                # %.lr.ph.preheader
	movl	%edx, %ebp
.LBB8_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	callq	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	movq	%rax, %rcx
	imulq	%r14, %rcx
	cmpl	%ecx, %ebp
	ja	.LBB8_3
.LBB8_4:                                # %.loopexit
	shrq	$32, %rcx
	movl	%ecx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	_ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_, .Lfunc_end8-_ZNSt24uniform_int_distributionIiE5_S_ndImSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEjEET1_RT0_S4_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,"axG",@progbits,_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,comdat
	.weak	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv # -- Begin function _ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.p2align	1, 0x90
	.type	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv,@function
_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv: # @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movq	4992(%rdi), %rax
	cmpq	$624, %rax                      # imm = 0x270
	jb	.LBB9_2
# %bb.1:
	movq	%rbx, %rdi
	callq	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	movq	4992(%rbx), %rax
.LBB9_2:
	leaq	1(%rax), %rcx
	movq	%rcx, 4992(%rbx)
	movq	(%rbx,%rax,8), %rax
	movq	%rax, %rcx
	shrq	$11, %rcx
	movl	%ecx, %ecx
	xorq	%rax, %rcx
	movl	%ecx, %eax
	shll	$7, %eax
	andl	$-1658038656, %eax              # imm = 0x9D2C5680
	xorq	%rcx, %rax
	movl	%eax, %ecx
	shll	$15, %ecx
	andl	$-272236544, %ecx               # imm = 0xEFC60000
	xorq	%rax, %rcx
	movq	%rcx, %rax
	shrq	$18, %rax
	xorq	%rcx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end9:
	.size	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv, .Lfunc_end9-_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,"axG",@progbits,_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,comdat
	.weak	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv # -- Begin function _ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.p2align	1, 0x90
	.type	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv,@function
_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv: # @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.cfi_startproc
# %bb.0:
	movl	$2567483615, %eax               # imm = 0x9908B0DF
	movq	(%rdi), %rdx
	xorl	%ecx, %ecx
.LBB10_1:                               # =>This Inner Loop Header: Depth=1
	andq	$-2147483648, %rdx              # imm = 0x80000000
	movq	8(%rdi,%rcx,8), %rsi
	movl	%esi, %r8d
	andl	$2147483646, %r8d               # imm = 0x7FFFFFFE
	orq	%rdx, %r8
	shrq	%r8
	xorq	3176(%rdi,%rcx,8), %r8
	movq	%rsi, %rdx
                                        # kill: def $esi killed $esi killed $rsi def $rsi
	andl	$1, %esi
	negl	%esi
	andl	%eax, %esi
	xorq	%r8, %rsi
	movq	%rsi, (%rdi,%rcx,8)
	leaq	1(%rcx), %rsi
	movq	%rsi, %rcx
	cmpq	$227, %rsi
	jne	.LBB10_1
# %bb.2:                                # %.preheader.preheader
	movq	1816(%rdi), %rdx
	movl	$228, %ecx
.LBB10_3:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	andq	$-2147483648, %rdx              # imm = 0x80000000
	movq	(%rdi,%rcx,8), %rsi
	movl	%esi, %r8d
	andl	$2147483646, %r8d               # imm = 0x7FFFFFFE
	orq	%rdx, %r8
	shrq	%r8
	xorq	-1824(%rdi,%rcx,8), %r8
	movq	%rsi, %rdx
                                        # kill: def $esi killed $esi killed $rsi def $rsi
	andl	$1, %esi
	negl	%esi
	andl	%eax, %esi
	xorq	%r8, %rsi
	movq	%rsi, -8(%rdi,%rcx,8)
	incq	%rcx
	cmpq	$624, %rcx                      # imm = 0x270
	jne	.LBB10_3
# %bb.4:
	movq	$-2147483648, %rcx              # imm = 0x80000000
	andq	4984(%rdi), %rcx
	movq	(%rdi), %rdx
	movl	%edx, %esi
	andl	$2147483646, %esi               # imm = 0x7FFFFFFE
	orq	%rcx, %rsi
	shrq	%rsi
	xorq	3168(%rdi), %rsi
	andl	$1, %edx
	negl	%edx
	andl	%eax, %edx
	xorq	%rsi, %rdx
	movq	%rdx, 4984(%rdi)
	movq	$0, 4992(%rdi)
	retq
.Lfunc_end10:
	.size	_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv, .Lfunc_end10-_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE11_M_gen_randEv
	.cfi_endproc
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB11_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB11_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9block_sumPKiPim, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end11:
	.size	__hip_module_ctor, .Lfunc_end11-__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	.LBB12_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
.LBB12_2:
	retq
.Lfunc_end12:
	.size	__hip_module_dtor, .Lfunc_end12-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9block_sumPKiPim,@object      # @_Z9block_sumPKiPim
	.section	.rodata,"a",@progbits
	.globl	_Z9block_sumPKiPim
	.p2align	3, 0x0
_Z9block_sumPKiPim:
	.quad	_Z24__device_stub__block_sumPKiPim
	.size	_Z9block_sumPKiPim, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Host sum: "
	.size	.L.str, 11

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"OK, right num_blocks and BLOCK_SIZE\n"
	.size	.L.str.1, 37

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Host reduce sum: "
	.size	.L.str.5, 18

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Device sum: "
	.size	.L.str.6, 13

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Host sum of partial sums: "
	.size	.L.str.7, 27

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"\nPartial sums comparison: "
	.size	.L.str.8, 27

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"-\n"
	.size	.L.str.9, 3

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

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

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"!="
	.size	.L.str.12, 3

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"]\n"
	.size	.L.str.13, 3

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9block_sumPKiPim"
	.size	.L__unnamed_1, 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__block_sumPKiPim
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z9block_sumPKiPim
	.addrsig_sym _ZSt4cerr
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9block_sumPKiPim      ; -- Begin function _Z9block_sumPKiPim
	.globl	_Z9block_sumPKiPim
	.p2align	8
	.type	_Z9block_sumPKiPim,@function
_Z9block_sumPKiPim:                     ; @_Z9block_sumPKiPim
; %bb.0:
	s_load_b128 s[0:3], s[0:1], 0x0
	s_mov_b32 s4, s15
	v_mov_b32_e32 v2, 0
	v_lshl_add_u32 v1, s4, 9, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	s_movk_i32 s0, 0x100
	s_mov_b32 s1, exec_lo
	global_load_b32 v2, v[1:2], off
	v_lshlrev_b32_e32 v1, 2, v0
	s_waitcnt vmcnt(0)
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u32_e32 0x100, v0
	s_cbranch_execz .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	s_mov_b32 s5, 0
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_lshl_add_u32 v2, s0, 2, v1
	s_lshr_b32 s0, s0, 1
	ds_load_b32 v2, v2
	ds_load_b32 v3, v1
	v_cmp_le_u32_e32 vcc_lo, s0, v0
	s_or_b32 s5, vcc_lo, s5
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v2, v3, v2
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_not1_b32 exec_lo, exec_lo, s5
	s_cbranch_execnz .LBB0_2
.LBB0_3:                                ; %Flow21
	s_or_b32 exec_lo, exec_lo, s1
	s_mov_b32 s5, 0
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_5
; %bb.4:
	v_mov_b32_e32 v0, 0
	s_lshl_b64 s[0:1], s[4:5], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s2, s0
	s_addc_u32 s1, s3, s1
	ds_load_b32 v1, v0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB0_5:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9block_sumPKiPim
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 24
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 4
		.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	_Z9block_sumPKiPim, .Lfunc_end0-_Z9block_sumPKiPim
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 268
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           8
        .value_kind:     by_value
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9block_sumPKiPim
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9block_sumPKiPim.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
