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

__global__ void block_scan(
    unsigned long long *g_odata, 
    unsigned long long *g_idata, 
    unsigned long long n, 
    unsigned long long *block_sums){

    __shared__ unsigned int temp[1024];

    int tid = threadIdx.x;
    int offset = 1;
    int block_offset = blockIdx.x * 1024;

    //Parallel Load into shared memory, each thread load 2 elements
    if(block_offset + 2*tid<n){
        temp[2*tid] = g_idata[block_offset + 2*tid];
    }
    else{
        temp[2*tid] = 0;
    }
    if(block_offset + 2*tid+1<n){
        temp[2*tid+1] = g_idata[block_offset + 2*tid+1];
    }
    else{
        temp[2*tid+1]=0;
    }
    
    //Downward pass
    for (int d = 1024>>1;d>0;d>>=1)
    {
        __syncthreads();
        if(tid < d)
        {
            //Compute indices of 2 elements to be handled
            int ai = offset*(2*tid+1)-1;
            int bi = offset*(2*tid+2)-1;
            temp[bi] += temp[ai];
        }
        offset *= 2;
    }

    //Zero the last element
    if (tid == 0){
        temp[1023]=0;
    }

    //Upward pass
    for (int d=1;d<1024;d*=2)
    {
        offset >>= 1;
        __syncthreads();
        if(tid<d)
        {
            int ai = offset*(2*tid+1)-1;
            int bi = offset*(2*tid+2)-1;
            int swap = temp[ai];
            temp[ai] = temp[bi];
            temp[bi]+= swap;
        }
    }

    __syncthreads();
    
    if(block_offset + 2*tid<n){
        g_odata[block_offset + 2*tid] = temp[2*tid];
    }
    if(block_offset + 2*tid+1<n){
        g_odata[block_offset + 2*tid + 1] = temp[2*tid+1];
    }

    //Compute block sum
    if(tid==0){
        int bid = blockIdx.x;
        if(1024*bid+1023<n){
            block_sums[bid] = temp[1023]+g_idata[1024*bid+1023];
        }
        else{
            block_sums[bid] = temp[1023];
        }
    }
    __syncthreads();    
}

__global__ void add_block_sums(
    unsigned long long *A_gpu, 
    unsigned long long *a, 
    unsigned long long N,
    unsigned long long *block_sums){
    //Load block sums    
    int tid = threadIdx.x;
    int bid = blockIdx.x;
    int block_offset = blockIdx.x * 1024;
    __shared__ long long blocksum;
    blocksum = block_sums[bid];    
    if(block_offset + 2*tid<N){
        A_gpu[block_offset + 2*tid] += blocksum;
    }
    if(block_offset + 2*tid+1<N){
        A_gpu[block_offset + 2*tid+1] += blocksum;
    }
    __syncthreads();
}

bool scan(
    unsigned long long *array_out,
    unsigned long long *array_in,
    unsigned long long N){
    // printf("scan %llu\n",N);
    //Allocate block sum
    unsigned long long numOfBlocks;    
    if(N>N/1024*1024){numOfBlocks = N/1024+1;}
    else{numOfBlocks = N/1024;}
    unsigned long long *block_sums;
    cudaMallocManaged(&block_sums,numOfBlocks*sizeof(unsigned long long));

    //Pascal+ GPU prefetch
    int device = -1;
    cudaGetDevice(&device);
    cudaMemPrefetchAsync(array_in,N*sizeof(unsigned long long),device, NULL);
    cudaMemPrefetchAsync(array_out,N*sizeof(unsigned long long),device, NULL);
    cudaMemPrefetchAsync(block_sums,numOfBlocks*sizeof(unsigned long long),device, NULL);

    //Scan 1024 element blocks
    block_scan<<<numOfBlocks,512>>>(array_out,array_in,N,block_sums);
    cudaDeviceSynchronize();
    // printf("%llu block scan completed!\n",numOfBlocks);

    //Scan block sums
    unsigned long long *block_sums_out;
    cudaMallocManaged(&block_sums_out,numOfBlocks*sizeof(unsigned long long));
    cudaMemPrefetchAsync(block_sums_out,numOfBlocks*sizeof(unsigned long long),device, NULL);
    
    if(numOfBlocks>1){
        scan(block_sums_out,block_sums,numOfBlocks);        
    }
    //Add block sums
    add_block_sums<<<numOfBlocks,512>>>(array_out,array_in,N,block_sums_out);
    cudaDeviceSynchronize();
    
    // printf("%llu block sum completed!\n",N);

    cudaFree(block_sums);
    cudaFree(block_sums_out);
    return true;
}

int main(int argc, char **argv)
{
    // 1) Take a positive integer N as an argument
    unsigned long long N;
    if(argc>1){
        N = std::stoll(argv[1]);
    }
    else{
        std::cerr << "Usage: ./homework4 N" << std::endl
            << "Testing with N=1000000" << std::endl;        
        N=1000000;
    }

    // 2) Create an input integer array a[N] of size N
    unsigned long long *a;    
    cudaMallocManaged(&a,N*sizeof(unsigned long long));

    // 3) Populate the array with random integers from he range [1,1000]
    for(unsigned long long i=0;i<N;i++){
        a[i]=rand()%1000+1;
    }

    // 4) Compute the scan output array A_cpu in sequential on the CPU
    unsigned long long *A_cpu;
    A_cpu = new unsigned long long[N];
    A_cpu[0]=0;
    for(unsigned long long i =1;i<N;i++){
        A_cpu[i]=A_cpu[i-1]+a[i-1];
    }

    // 5) Compute the scan output array A_gpu on the GPU   
    unsigned long long *A_gpu;
    cudaMallocManaged(&A_gpu,N*sizeof(unsigned long long));
    scan(A_gpu,a,N);    

    // 6) Compare A_cpu and A_gpu
    int error(0);
    for(int i=0;i<N;i++){
        if(A_cpu[i]!=A_gpu[i]){
            std::cout << "Not equal at " << i << ": "<< A_cpu[i] << " " << A_gpu[i] << std::endl;
            exit(0);
            error++;            
        }
    }
    if(error){
        printf("Scan Failed!\n");
    }
    else{
        printf("Scan Successful!\n");
    }

    cudaFree(A_gpu);
    cudaFree(a);
}

	.file	"tmpxft_0023ff3a_00000000-6_homework4_ziling_zhang.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3639:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3639:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z35__device_stub__Z10block_scanPyS_yS_PyS_yS_
	.type	_Z35__device_stub__Z10block_scanPyS_yS_PyS_yS_, @function
_Z35__device_stub__Z10block_scanPyS_yS_PyS_yS_:
.LFB3661:
	.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
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%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	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%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	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z10block_scanPyS_yS_(%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
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3661:
	.size	_Z35__device_stub__Z10block_scanPyS_yS_PyS_yS_, .-_Z35__device_stub__Z10block_scanPyS_yS_PyS_yS_
	.globl	_Z10block_scanPyS_yS_
	.type	_Z10block_scanPyS_yS_, @function
_Z10block_scanPyS_yS_:
.LFB3662:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z10block_scanPyS_yS_PyS_yS_
	.cfi_endproc
.LFE3662:
	.size	_Z10block_scanPyS_yS_, .-_Z10block_scanPyS_yS_
	.globl	_Z39__device_stub__Z14add_block_sumsPyS_yS_PyS_yS_
	.type	_Z39__device_stub__Z14add_block_sumsPyS_yS_PyS_yS_, @function
_Z39__device_stub__Z14add_block_sumsPyS_yS_PyS_yS_:
.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
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%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	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%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	.L8
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z14add_block_sumsPyS_yS_(%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
.L8:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3663:
	.size	_Z39__device_stub__Z14add_block_sumsPyS_yS_PyS_yS_, .-_Z39__device_stub__Z14add_block_sumsPyS_yS_PyS_yS_
	.globl	_Z14add_block_sumsPyS_yS_
	.type	_Z14add_block_sumsPyS_yS_, @function
_Z14add_block_sumsPyS_yS_:
.LFB3664:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z14add_block_sumsPyS_yS_PyS_yS_
	.cfi_endproc
.LFE3664:
	.size	_Z14add_block_sumsPyS_yS_, .-_Z14add_block_sumsPyS_yS_
	.globl	_Z4scanPyS_y
	.type	_Z4scanPyS_y, @function
_Z4scanPyS_y:
.LFB3635:
	.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
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	shrq	$10, %rbp
	movq	%rdx, %rbx
	leaq	0(,%rbx,8), %r15
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	movq	%rdx, %rax
	leaq	16(%rsp), %rdi
	andq	$-1024, %rax
	cmpq	%rdx, %rax
	movl	$1, %edx
	adcq	$0, %rbp
	leaq	0(,%rbp,8), %r14
	movq	%r14, %rsi
	call	cudaMallocManaged@PLT
	leaq	12(%rsp), %rdi
	movl	$-1, 12(%rsp)
	call	cudaGetDevice@PLT
	movl	12(%rsp), %edx
	xorl	%ecx, %ecx
	movq	%r15, %rsi
	movq	%r13, %rdi
	call	cudaMemPrefetchAsync@PLT
	movl	12(%rsp), %edx
	xorl	%ecx, %ecx
	movq	%r15, %rsi
	movq	%r12, %rdi
	movl	%ebp, %r15d
	call	cudaMemPrefetchAsync@PLT
	movl	12(%rsp), %edx
	movq	16(%rsp), %rdi
	xorl	%ecx, %ecx
	movq	%r14, %rsi
	call	cudaMemPrefetchAsync@PLT
	movl	%ebp, 32(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	$8388609, %edx
	movl	$1, %ecx
	movl	$1, 52(%rsp)
	movq	%rax, 36(%rsp)
	movq	32(%rsp), %rdi
	salq	$9, %rdx
	movl	40(%rsp), %esi
	movq	%rdx, 44(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	movq	16(%rsp), %rcx
	movq	%rbx, %rdx
	movq	%r13, %rsi
	movq	%r12, %rdi
	call	_Z35__device_stub__Z10block_scanPyS_yS_PyS_yS_
.L15:
	call	cudaDeviceSynchronize@PLT
	leaq	24(%rsp), %rdi
	movl	$1, %edx
	movq	%r14, %rsi
	call	cudaMallocManaged@PLT
	movl	12(%rsp), %edx
	movq	24(%rsp), %rdi
	xorl	%ecx, %ecx
	movq	%r14, %rsi
	call	cudaMemPrefetchAsync@PLT
	cmpq	$1, %rbp
	jbe	.L16
	movq	16(%rsp), %rsi
	movq	24(%rsp), %rdi
	movq	%rbp, %rdx
	call	_Z4scanPyS_y
.L16:
	movl	%r15d, 32(%rsp)
	movl	$8388609, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	salq	$9, %rdx
	movl	$1, %ecx
	movl	$1, 52(%rsp)
	movq	%rax, 36(%rsp)
	movq	32(%rsp), %rdi
	movl	40(%rsp), %esi
	movq	%rdx, 44(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	movq	24(%rsp), %rcx
	movq	%rbx, %rdx
	movq	%r13, %rsi
	movq	%r12, %rdi
	call	_Z39__device_stub__Z14add_block_sumsPyS_yS_PyS_yS_
.L17:
	call	cudaDeviceSynchronize@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	movb	$1, %al
	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
.LFE3635:
	.size	_Z4scanPyS_y, .-_Z4scanPyS_y
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z14add_block_sumsPyS_yS_"
.LC1:
	.string	"_Z10block_scanPyS_yS_"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3666:
	.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	.LC0(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z14add_block_sumsPyS_yS_(%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	.LC1(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z10block_scanPyS_yS_(%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
.LFE3666:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev,"axG",@progbits,_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD5Ev,comdat
	.align 2
	.weak	_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.type	_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev, @function
_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev:
.LFB3772:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	__errno_location@PLT
	cmpl	$0, (%rax)
	jne	.L22
	movl	(%rbx), %edx
	movl	%edx, (%rax)
.L22:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3772:
	.size	_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev, .-_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.weak	_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	.set	_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev,_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.section	.rodata.str1.1
.LC2:
	.string	"basic_string: construction from null is not valid"
.LC3:
	.string	"stoll"
.LC4:
	.string	"Usage: ./homework4 N"
.LC5:
	.string	"Testing with N=1000000"
.LC6:
	.string	"Not equal at "
.LC7:
	.string	": "
.LC8:
	.string	" "
.LC9:
	.string	"Scan Successful!\n"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3636:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3636
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	decl	%edi
	leaq	8(%rsp), %r12
	jle	.L26
	movq	8(%rsi), %rbx
	leaq	40(%rsp), %rax
	leaq	24(%rsp), %r13
	movq	%rax, 24(%rsp)
	testq	%rbx, %rbx
	jne	.L27
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L50
	leaq	.LC2(%rip), %rdi
.LEHB0:
	call	_ZSt19__throw_logic_errorPKc@PLT
.L27:
	movq	%rbx, %rdi
	leaq	16(%rsp), %r14
	call	strlen@PLT
	cmpq	$15, %rax
	movq	%rax, 16(%rsp)
	leaq	(%rbx,%rax), %rbp
	jbe	.L29
	xorl	%edx, %edx
	movq	%r14, %rsi
	movq	%r13, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm@PLT
.LEHE0:
	movq	%rax, 24(%rsp)
	movq	16(%rsp), %rax
	movq	%rax, 40(%rsp)
.L29:
	movq	24(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rbp, %rdx
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE13_S_copy_charsEPcPKcS7_@PLT
	movq	16(%rsp), %rax
	movq	24(%rsp), %rdx
	movq	%rax, 32(%rsp)
	movb	$0, (%rdx,%rax)
	movq	24(%rsp), %r15
	call	__errno_location@PLT
	xorl	%edx, %edx
	movq	%r14, %rsi
	movq	%r15, %rdi
	movq	%rax, %rbp
	movl	(%rax), %eax
	movl	%edx, 0(%rbp)
	movl	$10, %edx
	movl	%eax, 8(%rsp)
	call	__isoc23_strtoll@PLT
	movq	%rax, %rbx
	cmpq	16(%rsp), %r15
	jne	.L30
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L50
	leaq	.LC3(%rip), %rdi
.LEHB1:
	call	_ZSt24__throw_invalid_argumentPKc@PLT
.L30:
	cmpl	$34, 0(%rbp)
	jne	.L32
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L50
	leaq	.LC3(%rip), %rdi
	call	_ZSt20__throw_out_of_rangePKc@PLT
.LEHE1:
.L32:
	movq	%r12, %rdi
	call	_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	movq	%r13, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L34
.L47:
	endbr64
	movq	%rax, %rbx
.L35:
	movq	%r12, %rdi
	call	_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	movq	%r13, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L50
	movq	%rbx, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.L26:
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	$1000000, %ebx
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	leaq	.LC5(%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@PLT
.L34:
	leaq	0(,%rbx,8), %rbp
	movq	%r12, %rdi
	movl	$1, %edx
	xorl	%r13d, %r13d
	movq	%rbp, %rsi
	movl	$1000, %r12d
	call	cudaMallocManaged@PLT
.L37:
	cmpq	%r13, %rbx
	je	.L51
	call	rand@PLT
	cltd
	idivl	%r12d
	movq	8(%rsp), %rax
	incl	%edx
	movslq	%edx, %rdx
	movq	%rdx, (%rax,%r13,8)
	incq	%r13
	jmp	.L37
.L51:
	movabsq	$1152921504606846975, %rax
	cmpq	%rbx, %rax
	jb	.L39
	movq	%rbp, %rdi
	call	_Znam@PLT
	movq	8(%rsp), %rcx
	movq	%rax, %r12
	xorl	%eax, %eax
	movq	%rax, (%r12)
	movl	$1, %eax
	jmp	.L40
.L39:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L50
	call	__cxa_throw_bad_array_new_length@PLT
.L40:
	cmpq	%rbx, %rax
	jnb	.L52
	movq	-8(%rcx,%rax,8), %rdx
	addq	-8(%r12,%rax,8), %rdx
	movq	%rdx, (%r12,%rax,8)
	incq	%rax
	jmp	.L40
.L52:
	movq	%rbp, %rsi
	leaq	16(%rsp), %rdi
	movl	$1, %edx
	xorl	%ebp, %ebp
	call	cudaMallocManaged@PLT
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	movq	%rbx, %rdx
	call	_Z4scanPyS_y
	movq	16(%rsp), %rax
.L43:
	cmpq	%rbp, %rbx
	je	.L53
	movq	(%r12,%rbp,8), %r13
	leaq	1(%rbp), %rdx
	cmpq	(%rax,%rbp,8), %r13
	je	.L46
	leaq	.LC6(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r13, %rsi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIyEERSoT_@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movq	16(%rsp), %rax
	movq	(%rax,%rbp,8), %rsi
	call	_ZNSo9_M_insertIyEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	xorl	%edi, %edi
	call	exit@PLT
.L46:
	movq	%rdx, %rbp
	jmp	.L43
.L53:
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
.LEHE2:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L45
.L50:
	call	__stack_chk_fail@PLT
.L45:
	addq	$72, %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
.LFE3636:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3636:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3636-.LLSDACSB3636
.LLSDACSB3636:
	.uleb128 .LEHB0-.LFB3636
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3636
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L47-.LFB3636
	.uleb128 0
	.uleb128 .LEHB2-.LFB3636
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE3636:
	.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 <stdio.h>
#include <stdlib.h>
#include <iostream>

__global__ void block_scan(
    unsigned long long *g_odata, 
    unsigned long long *g_idata, 
    unsigned long long n, 
    unsigned long long *block_sums){

    __shared__ unsigned int temp[1024];

    int tid = threadIdx.x;
    int offset = 1;
    int block_offset = blockIdx.x * 1024;

    //Parallel Load into shared memory, each thread load 2 elements
    if(block_offset + 2*tid<n){
        temp[2*tid] = g_idata[block_offset + 2*tid];
    }
    else{
        temp[2*tid] = 0;
    }
    if(block_offset + 2*tid+1<n){
        temp[2*tid+1] = g_idata[block_offset + 2*tid+1];
    }
    else{
        temp[2*tid+1]=0;
    }
    
    //Downward pass
    for (int d = 1024>>1;d>0;d>>=1)
    {
        __syncthreads();
        if(tid < d)
        {
            //Compute indices of 2 elements to be handled
            int ai = offset*(2*tid+1)-1;
            int bi = offset*(2*tid+2)-1;
            temp[bi] += temp[ai];
        }
        offset *= 2;
    }

    //Zero the last element
    if (tid == 0){
        temp[1023]=0;
    }

    //Upward pass
    for (int d=1;d<1024;d*=2)
    {
        offset >>= 1;
        __syncthreads();
        if(tid<d)
        {
            int ai = offset*(2*tid+1)-1;
            int bi = offset*(2*tid+2)-1;
            int swap = temp[ai];
            temp[ai] = temp[bi];
            temp[bi]+= swap;
        }
    }

    __syncthreads();
    
    if(block_offset + 2*tid<n){
        g_odata[block_offset + 2*tid] = temp[2*tid];
    }
    if(block_offset + 2*tid+1<n){
        g_odata[block_offset + 2*tid + 1] = temp[2*tid+1];
    }

    //Compute block sum
    if(tid==0){
        int bid = blockIdx.x;
        if(1024*bid+1023<n){
            block_sums[bid] = temp[1023]+g_idata[1024*bid+1023];
        }
        else{
            block_sums[bid] = temp[1023];
        }
    }
    __syncthreads();    
}

__global__ void add_block_sums(
    unsigned long long *A_gpu, 
    unsigned long long *a, 
    unsigned long long N,
    unsigned long long *block_sums){
    //Load block sums    
    int tid = threadIdx.x;
    int bid = blockIdx.x;
    int block_offset = blockIdx.x * 1024;
    __shared__ long long blocksum;
    blocksum = block_sums[bid];    
    if(block_offset + 2*tid<N){
        A_gpu[block_offset + 2*tid] += blocksum;
    }
    if(block_offset + 2*tid+1<N){
        A_gpu[block_offset + 2*tid+1] += blocksum;
    }
    __syncthreads();
}

bool scan(
    unsigned long long *array_out,
    unsigned long long *array_in,
    unsigned long long N){
    // printf("scan %llu\n",N);
    //Allocate block sum
    unsigned long long numOfBlocks;    
    if(N>N/1024*1024){numOfBlocks = N/1024+1;}
    else{numOfBlocks = N/1024;}
    unsigned long long *block_sums;
    hipMallocManaged(&block_sums,numOfBlocks*sizeof(unsigned long long));

    //Pascal+ GPU prefetch
    int device = -1;
    hipGetDevice(&device);
    hipMemPrefetchAsync(array_in,N*sizeof(unsigned long long),device, NULL);
    hipMemPrefetchAsync(array_out,N*sizeof(unsigned long long),device, NULL);
    hipMemPrefetchAsync(block_sums,numOfBlocks*sizeof(unsigned long long),device, NULL);

    //Scan 1024 element blocks
    block_scan<<<numOfBlocks,512>>>(array_out,array_in,N,block_sums);
    hipDeviceSynchronize();
    // printf("%llu block scan completed!\n",numOfBlocks);

    //Scan block sums
    unsigned long long *block_sums_out;
    hipMallocManaged(&block_sums_out,numOfBlocks*sizeof(unsigned long long));
    hipMemPrefetchAsync(block_sums_out,numOfBlocks*sizeof(unsigned long long),device, NULL);
    
    if(numOfBlocks>1){
        scan(block_sums_out,block_sums,numOfBlocks);        
    }
    //Add block sums
    add_block_sums<<<numOfBlocks,512>>>(array_out,array_in,N,block_sums_out);
    hipDeviceSynchronize();
    
    // printf("%llu block sum completed!\n",N);

    hipFree(block_sums);
    hipFree(block_sums_out);
    return true;
}

int main(int argc, char **argv)
{
    // 1) Take a positive integer N as an argument
    unsigned long long N;
    if(argc>1){
        N = std::stoll(argv[1]);
    }
    else{
        std::cerr << "Usage: ./homework4 N" << std::endl
            << "Testing with N=1000000" << std::endl;        
        N=1000000;
    }

    // 2) Create an input integer array a[N] of size N
    unsigned long long *a;    
    hipMallocManaged(&a,N*sizeof(unsigned long long));

    // 3) Populate the array with random integers from he range [1,1000]
    for(unsigned long long i=0;i<N;i++){
        a[i]=rand()%1000+1;
    }

    // 4) Compute the scan output array A_cpu in sequential on the CPU
    unsigned long long *A_cpu;
    A_cpu = new unsigned long long[N];
    A_cpu[0]=0;
    for(unsigned long long i =1;i<N;i++){
        A_cpu[i]=A_cpu[i-1]+a[i-1];
    }

    // 5) Compute the scan output array A_gpu on the GPU   
    unsigned long long *A_gpu;
    hipMallocManaged(&A_gpu,N*sizeof(unsigned long long));
    scan(A_gpu,a,N);    

    // 6) Compare A_cpu and A_gpu
    int error(0);
    for(int i=0;i<N;i++){
        if(A_cpu[i]!=A_gpu[i]){
            std::cout << "Not equal at " << i << ": "<< A_cpu[i] << " " << A_gpu[i] << std::endl;
            exit(0);
            error++;            
        }
    }
    if(error){
        printf("Scan Failed!\n");
    }
    else{
        printf("Scan Successful!\n");
    }

    hipFree(A_gpu);
    hipFree(a);
}

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

                                        # End of file scope inline assembly
	.globl	_Z25__device_stub__block_scanPyS_yS_ # -- Begin function _Z25__device_stub__block_scanPyS_yS_
	.type	_Z25__device_stub__block_scanPyS_yS_,@function
_Z25__device_stub__block_scanPyS_yS_:   # @_Z25__device_stub__block_scanPyS_yS_
	.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	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	16(%rsp), %rdx
	movq	%rcx, (%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	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z10block_scanPyS_yS_, %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	_Z25__device_stub__block_scanPyS_yS_, .Lfunc_end0-_Z25__device_stub__block_scanPyS_yS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__add_block_sumsPyS_yS_ # -- Begin function _Z29__device_stub__add_block_sumsPyS_yS_
	.type	_Z29__device_stub__add_block_sumsPyS_yS_,@function
_Z29__device_stub__add_block_sumsPyS_yS_: # @_Z29__device_stub__add_block_sumsPyS_yS_
	.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	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	16(%rsp), %rdx
	movq	%rcx, (%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	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z14add_block_sumsPyS_yS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z29__device_stub__add_block_sumsPyS_yS_, .Lfunc_end1-_Z29__device_stub__add_block_sumsPyS_yS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z4scanPyS_y                    # -- Begin function _Z4scanPyS_y
	.type	_Z4scanPyS_y,@function
_Z4scanPyS_y:                           # @_Z4scanPyS_y
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, %r15
	movq	%rsi, %r12
	movq	%rdi, %rbx
	movq	%rdx, %r13
	shrq	$10, %r13
	movl	%r15d, %eax
	andl	$1023, %eax                     # imm = 0x3FF
	cmpq	$1, %rax
	sbbq	$-1, %r13
	leaq	(,%r13,8), %rbp
	leaq	8(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	28(%rsp), %r14
	movl	$-1, (%r14)
	movq	%r14, %rdi
	callq	hipGetDevice
	movq	%r15, 32(%rsp)                  # 8-byte Spill
	leaq	(,%r15,8), %r15
	movl	(%r14), %edx
	movq	%r12, 48(%rsp)                  # 8-byte Spill
	movq	%r12, %rdi
	movq	%r15, %rsi
	xorl	%ecx, %ecx
	callq	hipMemPrefetchAsync
	movl	(%r14), %edx
	movq	%rbx, 40(%rsp)                  # 8-byte Spill
	movq	%rbx, %rdi
	movabsq	$4294967808, %rbx               # imm = 0x100000200
	movq	%r15, %rsi
	xorl	%ecx, %ecx
	callq	hipMemPrefetchAsync
	leaq	8(%rsp), %rax
	movq	(%rax), %rdi
	movl	(%r14), %edx
	movq	%rbp, %rsi
	xorl	%ecx, %ecx
	callq	hipMemPrefetchAsync
	movl	%r13d, %eax
	leaq	(%rax,%rbx), %r12
	addq	$-512, %r12                     # imm = 0xFE00
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	movq	8(%rsp), %rcx
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movq	48(%rsp), %rsi                  # 8-byte Reload
	movq	32(%rsp), %rdx                  # 8-byte Reload
	callq	_Z25__device_stub__block_scanPyS_yS_
.LBB2_2:
	callq	hipDeviceSynchronize
	leaq	16(%rsp), %r14
	movq	%r14, %rdi
	movq	%rbp, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	(%r14), %rdi
	movl	28(%rsp), %edx
	movq	%rbp, %rsi
	xorl	%ecx, %ecx
	callq	hipMemPrefetchAsync
	cmpq	$2, %r13
	jb	.LBB2_4
# %bb.3:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	%r13, %rdx
	callq	_Z4scanPyS_y
.LBB2_4:
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_6
# %bb.5:
	movq	16(%rsp), %rcx
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movq	48(%rsp), %rsi                  # 8-byte Reload
	movq	32(%rsp), %rdx                  # 8-byte Reload
	callq	_Z29__device_stub__add_block_sumsPyS_yS_
.LBB2_6:
	callq	hipDeviceSynchronize
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movb	$1, %al
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z4scanPyS_y, .Lfunc_end2-_Z4scanPyS_y
	.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
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$2, %edi
	jl	.LBB3_26
# %bb.1:
	movq	8(%rsi), %rsi
	leaq	16(%rsp), %rbx
	leaq	7(%rsp), %rdx
	movq	%rbx, %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	movq	(%rbx), %r15
	callq	__errno_location
	movq	%rax, %r14
	movl	(%rax), %ebp
	movl	$0, (%rax)
	leaq	8(%rsp), %r12
	movq	%r15, %rdi
	movq	%r12, %rsi
	movl	$10, %edx
	callq	__isoc23_strtoll
	cmpq	%r15, (%r12)
	je	.LBB3_2
# %bb.9:
	movq	%rax, %rbx
	movl	(%r14), %eax
	testl	%eax, %eax
	je	.LBB3_13
# %bb.10:
	cmpl	$34, %eax
	jne	.LBB3_14
# %bb.11:                               # %.critedge.i.i
.Ltmp0:
	movl	$.L.str.7, %edi
	callq	_ZSt20__throw_out_of_rangePKc
.Ltmp1:
# %bb.12:
.LBB3_26:                               # %.thread
	movl	$_ZSt4cerr, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cerr, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rax, %rbx
	movl	$.L.str.1, %esi
	movl	$22, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	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
	leaq	16(%rsp), %rdi
	movl	$8000000, %r14d                 # imm = 0x7A1200
	movl	$8000000, %esi                  # imm = 0x7A1200
	movl	$1, %edx
	callq	hipMallocManaged
	movl	$1000000, %ebx                  # imm = 0xF4240
	jmp	.LBB3_27
.LBB3_13:
	movl	%ebp, (%r14)
.LBB3_14:
	leaq	32(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB3_16
# %bb.15:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	callq	_ZdlPv
.LBB3_16:
	leaq	(,%rbx,8), %r14
	leaq	16(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	testq	%rbx, %rbx
	je	.LBB3_17
.LBB3_27:                               # %.lr.ph.preheader
	xorl	%r15d, %r15d
.LBB3_28:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$38, %rcx
	addl	%edx, %ecx
	imull	$1000, %ecx, %ecx               # imm = 0x3E8
	negl	%ecx
	addl	%ecx, %eax
	incl	%eax
	cltq
	movq	16(%rsp), %rcx
	movq	%rax, (%rcx,%r15,8)
	incq	%r15
	cmpq	%r15, %rbx
	jne	.LBB3_28
# %bb.29:
	xorl	%ebp, %ebp
.LBB3_18:                               # %._crit_edge
	movq	%rbx, %rax
	shrq	$61, %rax
	xorl	%edi, %edi
	negq	%rax
	sbbq	%rdi, %rdi
	orq	%r14, %rdi
	callq	_Znam
	movq	%rax, %r15
	movq	$0, (%rax)
	cmpq	$2, %rbx
	jb	.LBB3_21
# %bb.19:                               # %.lr.ph48
	movq	16(%rsp), %rax
	leaq	-1(%rbx), %rcx
	xorl	%edx, %edx
	xorl	%esi, %esi
.LBB3_20:                               # =>This Inner Loop Header: Depth=1
	addq	(%rax,%rdx,8), %rsi
	movq	%rsi, 8(%r15,%rdx,8)
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB3_20
.LBB3_21:                               # %._crit_edge49
	leaq	8(%rsp), %r12
	movq	%r12, %rdi
	movq	%r14, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	(%r12), %rdi
	movq	16(%rsp), %rsi
	movq	%rbx, %rdx
	callq	_Z4scanPyS_y
	testb	%bpl, %bpl
	jne	.LBB3_25
# %bb.22:                               # %.lr.ph52
	movq	8(%rsp), %rax
	xorl	%r14d, %r14d
.LBB3_23:                               # =>This Inner Loop Header: Depth=1
	movq	(%r15,%r14,8), %r12
	cmpq	(%rax,%r14,8), %r12
	jne	.LBB3_30
# %bb.24:                               #   in Loop: Header=BB3_23 Depth=1
	incq	%r14
	cmpq	%r14, %rbx
	jne	.LBB3_23
.LBB3_25:                               # %._crit_edge53
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_17:
	.cfi_def_cfa_offset 96
	movb	$1, %bpl
	xorl	%r14d, %r14d
	xorl	%ebx, %ebx
	jmp	.LBB3_18
.LBB3_30:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	%r14d, %esi
	callq	_ZNSolsEi
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movq	%r12, %rsi
	callq	_ZNSolsEy
	movl	$.L.str.4, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	8(%rsp), %rcx
	movq	(%rcx,%r14,8), %rsi
	movq	%rax, %rdi
	callq	_ZNSolsEy
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	xorl	%edi, %edi
	callq	exit
.LBB3_2:
.Ltmp2:
	movl	$.L.str.7, %edi
	callq	_ZSt24__throw_invalid_argumentPKc
.Ltmp3:
# %bb.3:
.LBB3_4:
.Ltmp4:
	movq	%rax, %rbx
	cmpl	$0, (%r14)
	jne	.LBB3_6
# %bb.5:
	movl	%ebp, (%r14)
.LBB3_6:                                # %_ZZN9__gnu_cxx6__stoaIxxcJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev.exit.i.i
	leaq	32(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB3_8
# %bb.7:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i39
	callq	_ZdlPv
.LBB3_8:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit41
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.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	255                             # @TType Encoding = omit
	.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 .Ltmp4-.Lfunc_begin0           #     jumps to .Ltmp4
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp1-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp2-.Ltmp1                  #   Call between .Ltmp1 and .Ltmp2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp2-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp3-.Ltmp2                  #   Call between .Ltmp2 and .Ltmp3
	.uleb128 .Ltmp4-.Lfunc_begin0           #     jumps to .Ltmp4
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 5 <<
	.uleb128 .Lfunc_end3-.Ltmp3             #   Call between .Ltmp3 and .Lfunc_end3
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_ # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	leaq	16(%rdi), %rax
	movq	%rax, (%rdi)
	testq	%rsi, %rsi
	je	.LBB4_1
# %bb.2:
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	%rsi, %rdi
	callq	strlen
	leaq	(%rax,%rbx), %rdx
	movq	%r14, %rdi
	movq	%rbx, %rsi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # TAILCALL
.LBB4_1:
	.cfi_def_cfa_offset 32
	movl	$.L.str.8, %edi
	callq	_ZSt19__throw_logic_errorPKc
.Lfunc_end4:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .Lfunc_end4-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_endproc
                                        # -- 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
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10block_scanPyS_yS_, %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	$_Z14add_block_sumsPyS_yS_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB7_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z10block_scanPyS_yS_,@object   # @_Z10block_scanPyS_yS_
	.section	.rodata,"a",@progbits
	.globl	_Z10block_scanPyS_yS_
	.p2align	3, 0x0
_Z10block_scanPyS_yS_:
	.quad	_Z25__device_stub__block_scanPyS_yS_
	.size	_Z10block_scanPyS_yS_, 8

	.type	_Z14add_block_sumsPyS_yS_,@object # @_Z14add_block_sumsPyS_yS_
	.globl	_Z14add_block_sumsPyS_yS_
	.p2align	3, 0x0
_Z14add_block_sumsPyS_yS_:
	.quad	_Z29__device_stub__add_block_sumsPyS_yS_
	.size	_Z14add_block_sumsPyS_yS_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Usage: ./homework4 N"
	.size	.L.str, 21

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Testing with N=1000000"
	.size	.L.str.1, 23

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Not equal at "
	.size	.L.str.2, 14

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

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"stoll"
	.size	.L.str.7, 6

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"basic_string: construction from null is not valid"
	.size	.L.str.8, 50

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

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z14add_block_sumsPyS_yS_"
	.size	.L__unnamed_2, 26

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

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Scan Successful!"
	.size	.Lstr, 17

	.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 _Z25__device_stub__block_scanPyS_yS_
	.addrsig_sym _Z29__device_stub__add_block_sumsPyS_yS_
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z10block_scanPyS_yS_
	.addrsig_sym _Z14add_block_sumsPyS_yS_
	.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	_Z10block_scanPyS_yS_   ; -- Begin function _Z10block_scanPyS_yS_
	.globl	_Z10block_scanPyS_yS_
	.p2align	8
	.type	_Z10block_scanPyS_yS_,@function
_Z10block_scanPyS_yS_:                  ; @_Z10block_scanPyS_yS_
; %bb.0:
	s_load_b256 s[4:11], s[0:1], 0x0
	v_dual_mov_b32 v6, 0 :: v_dual_lshlrev_b32 v5, 1, v0
	s_lshl_b32 s3, s15, 10
	s_mov_b32 s12, s15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v3, s3, v5
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 3, v[3:4]
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_u64_e32 vcc_lo, s[8:9], v[3:4]
	v_mov_b32_e32 v4, 0
	s_and_saveexec_b32 s1, vcc_lo
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_add_co_u32 v7, s0, s6, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v8, s0, s7, v2, s0
	global_load_b32 v4, v[7:8], off
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s1
	v_or_b32_e32 v7, 1, v3
	v_lshlrev_b32_e32 v3, 2, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v8, 31, v7
	s_waitcnt vmcnt(0)
	ds_store_b32 v3, v4
	v_cmp_gt_u64_e64 s0, s[8:9], v[7:8]
	s_and_saveexec_b32 s2, s0
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_add_co_u32 v6, s1, s6, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s1, s7, v2, s1
	global_load_b32 v6, v[6:7], off offset:8
.LBB0_4:
	s_or_b32 exec_lo, exec_lo, s2
	v_or_b32_e32 v4, 1, v5
	s_mov_b32 s2, 1
	s_movk_i32 s13, 0x200
	s_waitcnt vmcnt(0)
	ds_store_b32 v3, v6 offset:4
.LBB0_5:                                ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s14, exec_lo
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u32_e64 s13, v0
	s_cbranch_execz .LBB0_7
; %bb.6:                                ;   in Loop: Header=BB0_5 Depth=1
	v_mul_lo_u32 v5, s2, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshl_add_u32 v5, v5, 2, -4
	v_lshl_add_u32 v6, s2, 2, v5
	ds_load_b32 v5, v5
	ds_load_b32 v7, v6
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v5, v7, v5
	ds_store_b32 v6, v5
.LBB0_7:                                ;   in Loop: Header=BB0_5 Depth=1
	s_or_b32 exec_lo, exec_lo, s14
	s_lshr_b32 s1, s13, 1
	s_lshl_b32 s2, s2, 1
	s_cmp_lt_u32 s13, 2
	s_mov_b32 s13, s1
	s_cbranch_scc0 .LBB0_5
; %bb.8:
	v_cmp_eq_u32_e64 s1, 0, v0
	s_delay_alu instid0(VALU_DEP_1)
	s_and_saveexec_b32 s2, s1
	s_cbranch_execz .LBB0_10
; %bb.9:
	v_mov_b32_e32 v5, 0
	ds_store_b32 v5, v5 offset:4092
.LBB0_10:                               ; %.preheader
	s_or_b32 exec_lo, exec_lo, s2
	s_mov_b32 s14, 1
	s_movk_i32 s13, 0x400
.LBB0_11:                               ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshr_b32 s13, s13, 1
	s_mov_b32 s15, exec_lo
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u32_e64 s14, v0
	s_cbranch_execz .LBB0_13
; %bb.12:                               ;   in Loop: Header=BB0_11 Depth=1
	v_mul_u32_u24_e32 v5, s13, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshl_add_u32 v5, v5, 2, -4
	v_lshl_add_u32 v6, s13, 2, v5
	ds_load_b32 v7, v5
	ds_load_b32 v8, v6
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v7, v8, v7
	ds_store_b32 v5, v8
	ds_store_b32 v6, v7
.LBB0_13:                               ;   in Loop: Header=BB0_11 Depth=1
	s_or_b32 exec_lo, exec_lo, s15
	s_lshl_b32 s2, s14, 1
	s_cmpk_gt_u32 s14, 0x1ff
	s_mov_b32 s14, s2
	s_cbranch_scc0 .LBB0_11
; %bb.14:
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_16
; %bb.15:
	ds_load_b32 v4, v3
	v_add_co_u32 v6, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v2, vcc_lo
	v_mov_b32_e32 v5, 0
	s_waitcnt lgkmcnt(0)
	global_store_b64 v[6:7], v[4:5], off
.LBB0_16:
	s_or_b32 exec_lo, exec_lo, s2
	s_and_saveexec_b32 s2, s0
	s_cbranch_execz .LBB0_18
; %bb.17:
	ds_load_b32 v0, v3 offset:4
	v_add_co_u32 v3, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v2, vcc_lo
	v_mov_b32_e32 v1, 0
	s_waitcnt lgkmcnt(0)
	global_store_b64 v[3:4], v[0:1], off offset:8
.LBB0_18:
	s_or_b32 exec_lo, exec_lo, s2
	s_and_saveexec_b32 s2, s1
	s_cbranch_execz .LBB0_22
; %bb.19:
	v_mov_b32_e32 v1, 0
	s_or_b32 s0, s3, 0x3ff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_ashr_i32 s1, s0, 31
	v_cmp_ge_u64_e64 s3, s[0:1], s[8:9]
	ds_load_b32 v0, v1 offset:4092
	s_waitcnt lgkmcnt(0)
	v_mov_b32_e32 v3, v1
	s_and_b32 vcc_lo, exec_lo, s3
	v_mov_b32_e32 v2, v0
	s_cbranch_vccnz .LBB0_21
; %bb.20:
	s_lshl_b64 s[0:1], s[0:1], 3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s6, s0
	s_addc_u32 s1, s7, s1
	global_load_b64 v[2:3], v1, s[0:1]
	s_waitcnt vmcnt(0)
	v_add_co_u32 v2, vcc_lo, v2, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
.LBB0_21:                               ; %.sink.split
	s_ashr_i32 s13, s12, 31
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[0:1], s[12:13], 3
	s_add_u32 s0, s10, s0
	s_addc_u32 s1, s11, s1
	global_store_b64 v1, v[2:3], s[0:1]
.LBB0_22:                               ; %Flow
	s_or_b32 exec_lo, exec_lo, s2
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10block_scanPyS_yS_
		.amdhsa_group_segment_fixed_size 4096
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.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_end0:
	.size	_Z10block_scanPyS_yS_, .Lfunc_end0-_Z10block_scanPyS_yS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 752
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4096 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	_Z14add_block_sumsPyS_yS_ ; -- Begin function _Z14add_block_sumsPyS_yS_
	.globl	_Z14add_block_sumsPyS_yS_
	.p2align	8
	.type	_Z14add_block_sumsPyS_yS_,@function
_Z14add_block_sumsPyS_yS_:              ; @_Z14add_block_sumsPyS_yS_
; %bb.0:
	s_load_b128 s[4:7], s[0:1], 0x10
	s_mov_b32 s8, s15
	s_ashr_i32 s9, s15, 31
	v_lshlrev_b32_e32 v0, 1, v0
	s_lshl_b64 s[2:3], s[8:9], 3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshl_add_u32 v2, s8, 10, v0
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 3, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_add_u32 s6, s6, s2
	s_addc_u32 s7, s7, s3
	s_load_b64 s[2:3], s[0:1], 0x0
	s_load_b64 s[0:1], s[6:7], 0x0
	s_mov_b32 s6, exec_lo
	v_cmpx_gt_u64_e64 s[4:5], v[2:3]
	s_cbranch_execz .LBB1_2
; %bb.1:
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v4, vcc_lo, s3, v1, vcc_lo
	global_load_b64 v[5:6], v[3:4], off
	s_waitcnt vmcnt(0)
	v_add_co_u32 v5, vcc_lo, v5, s0
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v6, vcc_lo
	global_store_b64 v[3:4], v[5:6], off
.LBB1_2:
	s_or_b32 exec_lo, exec_lo, s6
	v_or_b32_e32 v2, 1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_cmp_gt_u64_e32 vcc_lo, s[4:5], v[2:3]
	s_and_saveexec_b32 s4, vcc_lo
	s_cbranch_execz .LBB1_4
; %bb.3:
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_load_b64 v[2:3], v[0:1], off offset:8
	s_waitcnt vmcnt(0)
	v_add_co_u32 v2, vcc_lo, v2, s0
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	global_store_b64 v[0:1], v[2:3], off offset:8
.LBB1_4:
	s_or_b32 exec_lo, exec_lo, s4
	s_waitcnt lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14add_block_sumsPyS_yS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 7
		.amdhsa_next_free_sgpr 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	_Z14add_block_sumsPyS_yS_, .Lfunc_end1-_Z14add_block_sumsPyS_yS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 248
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.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
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 4096
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10block_scanPyS_yS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10block_scanPyS_yS_.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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           8
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14add_block_sumsPyS_yS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14add_block_sumsPyS_yS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
