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

#define MAX_ARRAY_SIZE 1000000

/* 
* Check GPU device 
*/ 
void check_dev(void) {
    int deviceCount;
    cudaGetDeviceCount(&deviceCount);
    if (deviceCount == 0) {
        printf("!! Error: no devices supporting CUDA.\n");
        exit(EXIT_FAILURE);
    }
    int dev = 0;
    cudaSetDevice(dev);
}

/* 
* Round up to the nearest power of 2
*/ 
int round_up_pow2(int val) {
    if (val == 0) return 1; 
    int pow2 = 1; 
    while (pow2 < val) {
        pow2 <<= 1; 
    }
    return pow2; 
}

/*
* Calculate the number of threads per block based on array size 
* The function is so designed that a reduction on the array can 
* be completed in two steps. 
* The assumption is that the size of the array is no more than 
* 1,000,000, such that the number of threads is no more than 
* 1024, which is the computational limit of the GPU device. 
*/ 
int calc_num_thread(int size) {
    int approx = (int)sqrt((double)size); 
    // find the nearest power of 2 
    return round_up_pow2(approx); 
}

/* 
* Read data from ./inp.txt 
* Return the pointer to the data array 
* Ouput the number of data items thru passed-in pointer (int * size)
*/ 
int * read_data(int * size) 
{
    FILE * fptr = fopen("./inp.txt", "r"); 
    if (!fptr) {
        printf("!! Error in opening data file \n"); 
        exit(1); 
    }
    int cur_array_size = MAX_ARRAY_SIZE; 
    int * buffer = (int *)malloc(cur_array_size * sizeof(int)); 
    
    int i = 0; 
    while (!feof(fptr)) {
        if (fscanf(fptr, "%d,", &buffer[i]) != 1) {
            break; 
        }
        ++i;         
    }
    
    fclose(fptr); 
    *size = i; 
    return buffer; 
}

/* 
* Outputs the result array into file 
*/ 
void print_file(int * array, int array_size, const char fname[]) {
    FILE * fptr_b = fopen(fname, "w"); 
    if (!fptr_b) {
        printf("!! Error in opening output file \n"); 
        exit(1);
    }
    for (int i = 0; i < array_size; ++i) {
        fprintf(fptr_b, "%d", array[i]); 
        if (i < array_size - 1) 
            fprintf(fptr_b, ", "); 
    }
    fclose(fptr_b); 
}

/* 
* GPU kernel: inclusive prefix scan, one step 
* The result can not be stored in the original array since different blocks
* cannot be synchronized within the kernel 
*/ 
__global__ void prefix_scan_step(int * array_i, int * array_o, int array_size, int dist) {
    // shared memory to store intermediate results 
    extern __shared__ int sdata[]; 
    
    int myId = threadIdx.x + blockDim.x * blockIdx.x;
    int thId = threadIdx.x; 
    
    // load initial values to shared memory 
    sdata[thId] = array_i[myId]; 
    __syncthreads(); 
    
    // store block results in shared memory 
    if (!(myId < dist) && myId < array_size) {
        sdata[thId] += array_i[myId - dist]; 
    }
    __syncthreads();  
    // copy results to global memory 
    if (myId < array_size) {
        array_o[myId] = sdata[thId]; 
    }
}

/* 
* Inclusive prefix scan
*/ 
void prefix_scan(int * array_i, int * array_o, int array_size) {
    // dynamically calculate the number of threads and blocks 
    const int maxThreadsPerBlock = calc_num_thread(array_size);
    int threads = maxThreadsPerBlock;
    int blocks = (array_size + maxThreadsPerBlock - 1) / maxThreadsPerBlock;
    
    int dist = 1, i = 0; 
    while (dist < array_size) {
        // each array is alternatively used as the kernel input or output to avoid the overhead of 
        // copying the output to the input in evey iteration 
        if (i % 2 == 0) 
            prefix_scan_step<<<blocks, threads, threads * sizeof(int)>>>(array_i, array_o, array_size, dist);            
        else 
            prefix_scan_step<<<blocks, threads, threads * sizeof(int)>>>(array_o, array_i, array_size, dist);
        
        cudaDeviceSynchronize(); 
        ++i; 
        dist *= 2; 
    }
    
    if (i % 2 == 0)
        cudaMemcpy(array_o, array_i, array_size * sizeof(int), cudaMemcpyDeviceToDevice); 
}

/* 
* GPU kernel: reduction, getting the sum of an array 
*/ 
__global__ void shmem_reduce_kernel(int * d_out, const int * d_in, const int size)
{
    // sdata is allocated in the kernel call: 3rd arg to <<<b, t, shmem>>>
    extern __shared__ int sdata[];

    int myId = threadIdx.x + blockDim.x * blockIdx.x;
    int tid  = threadIdx.x;

    // load shared mem from global mem
    sdata[tid] = d_in[myId];
    __syncthreads();            // make sure entire block is loaded!

    // do reduction in shared mem
    for (unsigned int s = blockDim.x / 2; s > 0; s = s / 2)
    {
        if (tid < s && (myId + s) < size)
        {
            sdata[tid] += sdata[tid + s]; 
        }
        __syncthreads();        // make sure all adds at one stage are done!
    }

    // only thread 0 writes result for this block back to global mem
    if (tid == 0)
    {
        d_out[blockIdx.x] = sdata[0];
    }
}

/* 
* Reduction-based algorithm to find the sum of an array  
*/ 
void reduce(int * d_out, int * d_intermediate, int * d_in, int size)
{
    // assumes that size is not greater than maxThreadsPerBlock^2
    const int maxThreadsPerBlock = calc_num_thread(size);
    int threads = maxThreadsPerBlock;
    int blocks = (size + maxThreadsPerBlock - 1) / maxThreadsPerBlock;
    shmem_reduce_kernel<<<blocks, threads, threads * sizeof(int)>>>(d_intermediate, d_in, size); 

    // now we're down to one block left, so reduce it
    threads = blocks; 
    blocks = 1;
    shmem_reduce_kernel<<<blocks, round_up_pow2(threads), threads * sizeof(int)>>>(d_out, d_intermediate, threads);
}

/* 
* GPU kernel for part a
*/ 
__global__ void global_counter_kernel(int * array_i, int * cnt_o, int array_size) {
    int myId = threadIdx.x + blockDim.x * blockIdx.x; 
    if (myId < array_size) {
        atomicAdd(&cnt_o[array_i[myId] / 100], 1); 
    }
}

/* 
* part a: global memory counter 
* returns the pointer to the result array B 
*/ 
int * global_counter(int * array_i, int array_size) {
    // dynamically calculate the number of threads and blocks 
    const int maxThreadsPerBlock = calc_num_thread(array_size);
    int threads = maxThreadsPerBlock;
    int blocks = (array_size + maxThreadsPerBlock - 1) / maxThreadsPerBlock;
    
    // allocate GPU global memories for input & output arrays 
    int * array_device, * array_device_out; 
    cudaMalloc((void **) &array_device, array_size * sizeof(int)); 
    cudaMalloc((void **) &array_device_out, 11 * sizeof(int)); 
    
    // copy the input array into GPU shared memory 
    cudaMemcpy(array_device, array_i, array_size * sizeof(int), cudaMemcpyHostToDevice); 
    
    // launch the kernel 
    global_counter_kernel<<<blocks, threads>>>(array_device, array_device_out, array_size); 
    
    // allocate CPU memory for output array 
    int * array_o = (int *)malloc(10 * sizeof(int)); 
    
    // copy result back to CPU 
    cudaMemcpy(array_o, array_device_out, 10 * sizeof(int), cudaMemcpyDeviceToHost); 
    
    // finish 
    cudaFree(array_device); 
    cudaFree(array_device_out); 
    return array_o; 
}

/* 
* GPU kernel for part b 
* cnt_matrix dimensions: 10 x (# of blocks) 
*/ 
__global__ void shmem_counter_kernel(int * array_i, int * cnt_matrix, int array_size, int num_block) {
    // shared counter within block
    // size: 11 * sizeof(int) 
    // one extra int for numbers greater than 1000 
    extern __shared__ int scnt[]; 
    
    // initialize to 0 
    if (threadIdx.x < 10) {
        scnt[threadIdx.x] = 0; 
    }
    __syncthreads();
    
    // block-local counter 
    int myId = threadIdx.x + blockDim.x * blockIdx.x; 
    if (myId < array_size) {
        atomicAdd(&scnt[array_i[myId] / 100], 1); 
    }
    __syncthreads(); 
    
    // copy the counter values to shared memory 
    // only have 10 values 
    if (threadIdx.x < 10) {
        cnt_matrix[threadIdx.x * num_block + blockIdx.x] = scnt[threadIdx.x]; 
    }
}

/* 
* part b: shared memory counter 
* returns the pointer to the result array B 
*/ 
int * shmem_counter(int * array_i, int array_size) {
    // dynamically calculate the number of threads and blocks 
    const int maxThreadsPerBlock = calc_num_thread(array_size);
    int threads = maxThreadsPerBlock;
    int blocks = (array_size + maxThreadsPerBlock - 1) / maxThreadsPerBlock;
    
    // allocate GPU global memories for input & output arrays and intermediate counter matrix  
    int * array_device, * array_device_inter, * array_device_out; 
    cudaMalloc((void **) &array_device, array_size * sizeof(int)); 
    cudaMalloc((void **) &array_device_inter, 10 * blocks * sizeof(int)); 
    cudaMalloc((void **) &array_device_out, 10 * sizeof(int)); 
    
    /* --------------------------------------------------------------------------------
     * The intermediate counter matrix 
     *
     *             block 0 | block 1 | block 2 | ... ... | block N* 
     * [  0,  99]
     * [100, 199]
     * [200, 299]
     * ... ... 
     * [900, 999]
     *
     * *Note: the number of blocks, N, is stored in variable "blocks"
    -------------------------------------------------------------------------------- */
    
    // allocate GPU global memory for reduction's intermediate results 
    int * array_device_reduction_inter; 
    cudaMalloc((void **) &array_device_reduction_inter, blocks * sizeof(int)); 
    
    // allocate CPU memory for the output array  
    int * array_o = (int *)malloc(10 * sizeof(int));  
    
    // copy the input array into GPU shared memory 
    cudaMemcpy(array_device, array_i, array_size * sizeof(int), cudaMemcpyHostToDevice); 
    
    // launch the counter kernel 
    // shared memory size: 11 * sizeof(int) 
    // one extra int for numbers greater than 1000 
    shmem_counter_kernel<<<blocks, threads, 11 * sizeof(int)>>>(array_device, array_device_inter, array_size, blocks); 
    
    // do reduction for each range 
    for (int i = 0; i < 10; ++i) {
        reduce(&array_device_out[i], array_device_reduction_inter, &array_device_inter[blocks * i], blocks);  
    }
       
    // copy result back to CPU 
    cudaMemcpy(array_o, array_device_out, 10 * sizeof(int), cudaMemcpyDeviceToHost); 
    
    // finish 
    cudaFree(array_device); 
    cudaFree(array_device_out); 
    cudaFree(array_device_inter); 
    cudaFree(array_device_reduction_inter); 
    return array_o; 
}

/* 
* part c: prefix scan
* returns the pointer to the result array C  
*/ 
int * integrate_counter(int * array_i, int array_size) {
    // allocate GPU global memories for input/output array 
    int * array_device, * array_buffer; 
    cudaMalloc((void **) &array_device, array_size * sizeof(int)); 
    cudaMalloc((void **) &array_buffer, array_size * sizeof(int)); 
    
    // copy the input array into GPU shared memory 
    cudaMemcpy(array_device, array_i, array_size * sizeof(int), cudaMemcpyHostToDevice); 
    cudaMemcpy(array_buffer, array_device, array_size * sizeof(int), cudaMemcpyDeviceToDevice); 
    
    // run prefix scan
    prefix_scan(array_buffer, array_device, array_size); 
    
    // allocate CPU memory for the output array  
    int * array_o = (int *)malloc(array_size * sizeof(int));  
    
    // copy result back to CPU 
    cudaMemcpy(array_o, array_device, array_size * sizeof(int), cudaMemcpyDeviceToHost);
    
    // finish 
    cudaFree(array_device); 
    cudaFree(array_buffer); 
    return array_o; 
}

/* 
* CPU main routine 
*/ 
int main(void) {
    // check device 
    check_dev(); 
    
    // data array on host 
    int array_size = 0; 
    int * array_i = read_data(&array_size); 
    
    // part a ------------------------------------------------------------ 
    // compute counter values 
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    cudaEventRecord(start, 0);
    int * array_o_a = global_counter(array_i, array_size); 
    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    float elapsedTime;
    cudaEventElapsedTime(&elapsedTime, start, stop);
    
    // print to file 
    print_file(array_o_a, 10, "./q2a.txt"); 
    
    // print debug information to stdout 
    // printf(">> Average time elapsed in part a: %f\n", elapsedTime);

    
    // part b ------------------------------------------------------------ 
    cudaEvent_t start_b, stop_b;
    cudaEventCreate(&start_b);
    cudaEventCreate(&stop_b);
    cudaEventRecord(start_b, 0);
    int * array_o_b = shmem_counter(array_i, array_size); 
    cudaEventRecord(stop_b, 0);
    cudaEventSynchronize(stop_b);
    cudaEventElapsedTime(&elapsedTime, start_b, stop_b);
        
    // print to file 
    print_file(array_o_b, 10, "./q2b.txt"); 
    
    // print debug information to stdout 
    // printf(">> Average time elapsed in part b: %f\n", elapsedTime);
    
    // part c ------------------------------------------------------------ 
    cudaEvent_t start_c, stop_c;
    cudaEventCreate(&start_c);
    cudaEventCreate(&stop_c);
    cudaEventRecord(start_c, 0);   
    int * array_o_c = integrate_counter(array_o_b, 10);    
    cudaEventRecord(stop_c, 0);
    cudaEventSynchronize(stop_c);
    cudaEventElapsedTime(&elapsedTime, start_c, stop_c);
    
    // print to file 
    print_file(array_o_c, 10, "./q2c.txt");
    
    // print debug information to stdout 
    // printf(">> Average time elapsed in part c: %f\n", elapsedTime);
    
    // finish 
    free(array_i); 
    free(array_o_a); 
    free(array_o_b); 
    free(array_o_c); 
    return 0; 
}
	.file	"tmpxft_0023f8ea_00000000-6_q2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2040:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2040:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"!! Error: no devices supporting CUDA.\n"
	.text
	.globl	_Z9check_devv
	.type	_Z9check_devv, @function
_Z9check_devv:
.LFB2027:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	cmpl	$0, 4(%rsp)
	jne	.L3
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L3:
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z9check_devv, .-_Z9check_devv
	.globl	_Z13round_up_pow2i
	.type	_Z13round_up_pow2i, @function
_Z13round_up_pow2i:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	$1, %eax
	testl	%edi, %edi
	je	.L7
.L9:
	cmpl	%edi, %eax
	jge	.L7
	addl	%eax, %eax
	jmp	.L9
.L7:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z13round_up_pow2i, .-_Z13round_up_pow2i
	.globl	_Z15calc_num_threadi
	.type	_Z15calc_num_threadi, @function
_Z15calc_num_threadi:
.LFB2029:
	.cfi_startproc
	endbr64
	cvtsi2sdl	%edi, %xmm0
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	sqrt@PLT
	popq	%rdx
	.cfi_def_cfa_offset 8
	cvttsd2sil	%xmm0, %edi
	jmp	_Z13round_up_pow2i
	.cfi_endproc
.LFE2029:
	.size	_Z15calc_num_threadi, .-_Z15calc_num_threadi
	.section	.rodata.str1.1
.LC1:
	.string	"r"
.LC2:
	.string	"./inp.txt"
.LC3:
	.string	"!! Error in opening data file \n"
.LC4:
	.string	"%d,"
	.text
	.globl	_Z9read_dataPi
	.type	_Z9read_dataPi, @function
_Z9read_dataPi:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC1(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	leaq	.LC2(%rip), %rdi
	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
	pushq	%rcx
	.cfi_def_cfa_offset 64
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L15
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L15:
	movl	$4000000, %edi
	movq	%rax, %rbx
	xorl	%r12d, %r12d
	call	malloc@PLT
	leaq	.LC4(%rip), %r15
	movq	%rax, %rbp
	movq	%rax, %r14
.L16:
	movq	%rbx, %rdi
	call	feof@PLT
	testl	%eax, %eax
	jne	.L19
	movq	%r14, %rdx
	xorl	%eax, %eax
	movq	%r15, %rsi
	movq	%rbx, %rdi
	call	__isoc23_fscanf@PLT
	addq	$4, %r14
	decl	%eax
	jne	.L19
	incl	%r12d
	jmp	.L16
.L19:
	movq	%rbx, %rdi
	call	fclose@PLT
	movl	%r12d, 0(%r13)
	movq	%rbp, %rax
	popq	%rdx
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z9read_dataPi, .-_Z9read_dataPi
	.section	.rodata.str1.1
.LC5:
	.string	"w"
.LC6:
	.string	"!! Error in opening output file \n"
.LC7:
	.string	"%d"
.LC8:
	.string	", "
	.text
	.globl	_Z10print_filePiiPKc
	.type	_Z10print_filePiiPKc, @function
_Z10print_filePiiPKc:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rdi, %r13
	movq	%rdx, %rdi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%esi, %r12d
	leaq	.LC5(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L28
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L28:
	movq	%rax, %rbx
	xorl	%ebp, %ebp
	leaq	.LC7(%rip), %r14
.L23:
	cmpl	%ebp, %r12d
	jle	.L30
	movl	0(%r13,%rbp,4), %ecx
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	leal	-1(%r12), %eax
	cmpl	%ebp, %eax
	jle	.L24
	leaq	.LC8(%rip), %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L24:
	incq	%rbp
	jmp	.L23
.L30:
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE2031:
	.size	_Z10print_filePiiPKc, .-_Z10print_filePiiPKc
	.globl	_Z40__device_stub__Z16prefix_scan_stepPiS_iiPiS_ii
	.type	_Z40__device_stub__Z16prefix_scan_stepPiS_iiPiS_ii, @function
_Z40__device_stub__Z16prefix_scan_stepPiS_iiPiS_ii:
.LFB2062:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z16prefix_scan_stepPiS_ii(%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
.L31:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2062:
	.size	_Z40__device_stub__Z16prefix_scan_stepPiS_iiPiS_ii, .-_Z40__device_stub__Z16prefix_scan_stepPiS_iiPiS_ii
	.globl	_Z16prefix_scan_stepPiS_ii
	.type	_Z16prefix_scan_stepPiS_ii, @function
_Z16prefix_scan_stepPiS_ii:
.LFB2063:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z16prefix_scan_stepPiS_iiPiS_ii
	.cfi_endproc
.LFE2063:
	.size	_Z16prefix_scan_stepPiS_ii, .-_Z16prefix_scan_stepPiS_ii
	.globl	_Z11prefix_scanPiS_i
	.type	_Z11prefix_scanPiS_i, @function
_Z11prefix_scanPiS_i:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movabsq	$4294967297, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	$1, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	movl	%edx, %edi
	movq	%rsi, 16(%rsp)
	call	_Z15calc_num_threadi
	movl	%eax, %ebp
	leal	-1(%rax,%rbx), %eax
	cltd
	idivl	%ebp
	movl	%eax, %r13d
	movslq	%ebp, %rax
	salq	$2, %rax
	movq	%rax, 24(%rsp)
.L37:
	movl	%r15d, %eax
	andl	$1, %eax
	cmpl	%ebx, %r12d
	jge	.L46
	movq	%r14, 56(%rsp)
	movq	24(%rsp), %r8
	xorl	%r9d, %r9d
	movq	%r14, 44(%rsp)
	movl	60(%rsp), %ecx
	movl	%ebp, 52(%rsp)
	movl	48(%rsp), %esi
	movl	%r13d, 40(%rsp)
	movq	52(%rsp), %rdx
	movq	40(%rsp), %rdi
	testl	%eax, %eax
	jne	.L38
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	%r12d, %ecx
	movl	%ebx, %edx
	jmp	.L45
.L38:
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	%r12d, %ecx
	movl	%ebx, %edx
.L45:
	call	_Z40__device_stub__Z16prefix_scan_stepPiS_iiPiS_ii
.L40:
	call	cudaDeviceSynchronize@PLT
	incl	%r15d
	addl	%r12d, %r12d
	jmp	.L37
.L46:
	testl	%eax, %eax
	jne	.L36
	movslq	%ebx, %rdx
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	addq	$72, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	salq	$2, %rdx
	popq	%rbp
	.cfi_def_cfa_offset 40
	movl	$3, %ecx
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	cudaMemcpy@PLT
.L36:
	.cfi_restore_state
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z11prefix_scanPiS_i, .-_Z11prefix_scanPiS_i
	.globl	_Z17integrate_counterPii
	.type	_Z17integrate_counterPii, @function
_Z17integrate_counterPii:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movslq	%esi, %rbx
	movq	%rbx, %rbp
	salq	$2, %rbx
	movq	%rbx, %rsi
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	movq	%rbx, %rdx
	movl	$3, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	%ebp, %edx
	call	_Z11prefix_scanPiS_i
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%rax, %rdi
	movq	%rax, %rbp
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L48
	call	__stack_chk_fail@PLT
.L48:
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	movq	%rbp, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z17integrate_counterPii, .-_Z17integrate_counterPii
	.globl	_Z43__device_stub__Z19shmem_reduce_kernelPiPKiiPiPKii
	.type	_Z43__device_stub__Z19shmem_reduce_kernelPiPKiiPiPKii, @function
_Z43__device_stub__Z19shmem_reduce_kernelPiPKiiPiPKii:
.LFB2064:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L50
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z19shmem_reduce_kernelPiPKii(%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
.L50:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L52
	call	__stack_chk_fail@PLT
.L52:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2064:
	.size	_Z43__device_stub__Z19shmem_reduce_kernelPiPKiiPiPKii, .-_Z43__device_stub__Z19shmem_reduce_kernelPiPKiiPiPKii
	.globl	_Z19shmem_reduce_kernelPiPKii
	.type	_Z19shmem_reduce_kernelPiPKii, @function
_Z19shmem_reduce_kernelPiPKii:
.LFB2065:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z19shmem_reduce_kernelPiPKiiPiPKii
	.cfi_endproc
.LFE2065:
	.size	_Z19shmem_reduce_kernelPiPKii, .-_Z19shmem_reduce_kernelPiPKii
	.globl	_Z6reducePiS_S_i
	.type	_Z6reducePiS_S_i, @function
_Z6reducePiS_S_i:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rdx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rdi, %r13
	movl	%ecx, %edi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	call	_Z15calc_num_threadi
	xorl	%r9d, %r9d
	movslq	%eax, %rcx
	leal	-1(%rcx,%rbp), %eax
	movl	%ecx, 20(%rsp)
	leaq	0(,%rcx,4), %r8
	cltd
	idivl	%ecx
	movl	%eax, %ebx
	movabsq	$4294967297, %rax
	movq	%rax, 12(%rsp)
	movl	16(%rsp), %esi
	movq	%rax, 24(%rsp)
	movl	28(%rsp), %eax
	movl	%ebx, 8(%rsp)
	movq	20(%rsp), %rdx
	movq	8(%rsp), %rdi
	movq	%rax, %rcx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L56
	movl	%ebp, %edx
	movq	%r14, %rsi
	movq	%r12, %rdi
	call	_Z43__device_stub__Z19shmem_reduce_kernelPiPKiiPiPKii
.L56:
	movl	%ebx, %edi
	xorl	%r9d, %r9d
	movl	$1, %esi
	call	_Z13round_up_pow2i
	movl	$1, 16(%rsp)
	movabsq	$4294967297, %rdi
	movl	%eax, 20(%rsp)
	movslq	%ebx, %rax
	movq	%rdi, 24(%rsp)
	movl	28(%rsp), %ecx
	leaq	0(,%rax,4), %r8
	movq	20(%rsp), %rdx
	movq	%rdi, 8(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L55
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	movl	%ebx, %edx
	movq	%r12, %rsi
	movq	%r13, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	_Z43__device_stub__Z19shmem_reduce_kernelPiPKiiPiPKii
.L55:
	.cfi_restore_state
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z6reducePiS_S_i, .-_Z6reducePiS_S_i
	.globl	_Z44__device_stub__Z21global_counter_kernelPiS_iPiS_i
	.type	_Z44__device_stub__Z21global_counter_kernelPiS_iPiS_i, @function
_Z44__device_stub__Z21global_counter_kernelPiS_iPiS_i:
.LFB2066:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L59
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z21global_counter_kernelPiS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L59:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L61
	call	__stack_chk_fail@PLT
.L61:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2066:
	.size	_Z44__device_stub__Z21global_counter_kernelPiS_iPiS_i, .-_Z44__device_stub__Z21global_counter_kernelPiS_iPiS_i
	.globl	_Z21global_counter_kernelPiS_i
	.type	_Z21global_counter_kernelPiS_i, @function
_Z21global_counter_kernelPiS_i:
.LFB2067:
	.cfi_startproc
	endbr64
	jmp	_Z44__device_stub__Z21global_counter_kernelPiS_iPiS_i
	.cfi_endproc
.LFE2067:
	.size	_Z21global_counter_kernelPiS_i, .-_Z21global_counter_kernelPiS_i
	.globl	_Z14global_counterPii
	.type	_Z14global_counterPii, @function
_Z14global_counterPii:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movslq	%esi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%r13d, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%r13, %rbx
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	_Z15calc_num_threadi
	movq	%rsp, %rdi
	movl	%eax, %ebp
	leal	-1(%rax,%r13), %eax
	salq	$2, %r13
	cltd
	movq	%r13, %rsi
	idivl	%ebp
	movl	%eax, %r12d
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movl	$44, %esi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	movq	%r13, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebp, 28(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%r12d, 16(%rsp)
	movq	%rax, 32(%rsp)
	movl	36(%rsp), %ecx
	movq	%rax, 20(%rsp)
	movq	28(%rsp), %rdx
	movq	16(%rsp), %rdi
	movl	24(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L65
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	%ebx, %edx
	call	_Z44__device_stub__Z21global_counter_kernelPiS_iPiS_i
.L65:
	movl	$40, %edi
	call	malloc@PLT
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movl	$40, %edx
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L66
	call	__stack_chk_fail@PLT
.L66:
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z14global_counterPii, .-_Z14global_counterPii
	.globl	_Z44__device_stub__Z20shmem_counter_kernelPiS_iiPiS_ii
	.type	_Z44__device_stub__Z20shmem_counter_kernelPiS_iiPiS_ii, @function
_Z44__device_stub__Z20shmem_counter_kernelPiS_iiPiS_ii:
.LFB2068:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L68
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z20shmem_counter_kernelPiS_ii(%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
.L68:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L70
	call	__stack_chk_fail@PLT
.L70:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2068:
	.size	_Z44__device_stub__Z20shmem_counter_kernelPiS_iiPiS_ii, .-_Z44__device_stub__Z20shmem_counter_kernelPiS_iiPiS_ii
	.globl	_Z20shmem_counter_kernelPiS_ii
	.type	_Z20shmem_counter_kernelPiS_ii, @function
_Z20shmem_counter_kernelPiS_ii:
.LFB2069:
	.cfi_startproc
	endbr64
	jmp	_Z44__device_stub__Z20shmem_counter_kernelPiS_iiPiS_ii
	.cfi_endproc
.LFE2069:
	.size	_Z20shmem_counter_kernelPiS_ii, .-_Z20shmem_counter_kernelPiS_ii
	.globl	_Z13shmem_counterPii
	.type	_Z13shmem_counterPii, @function
_Z13shmem_counterPii:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	movl	%esi, %edi
	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
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	_Z15calc_num_threadi
	leaq	16(%rsp), %rdi
	movl	%eax, %r12d
	leal	-1(%rax,%rbp), %eax
	cltd
	idivl	%r12d
	movslq	%ebp, %rdx
	salq	$2, %rdx
	movq	%rdx, %rsi
	movq	%rdx, 8(%rsp)
	movslq	%eax, %r14
	call	cudaMalloc@PLT
	imull	$10, %r14d, %esi
	leaq	24(%rsp), %rdi
	movq	%r14, %rbx
	salq	$2, %r14
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$40, %esi
	call	cudaMalloc@PLT
	movq	%r14, %rsi
	leaq	40(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	$40, %edi
	call	malloc@PLT
	movq	8(%rsp), %rdx
	movq	16(%rsp), %rdi
	movq	%r15, %rsi
	movl	$1, %ecx
	movq	%rax, %r13
	call	cudaMemcpy@PLT
	movl	%r12d, 60(%rsp)
	xorl	%r9d, %r9d
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movl	68(%rsp), %ecx
	movl	$44, %r8d
	movq	%rax, 52(%rsp)
	movq	60(%rsp), %rdx
	movl	%ebx, 48(%rsp)
	movl	56(%rsp), %esi
	movq	48(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L74
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	%ebx, %ecx
	movl	%ebp, %edx
	call	_Z44__device_stub__Z20shmem_counter_kernelPiS_iiPiS_ii
.L74:
	xorl	%ebp, %ebp
	xorl	%r12d, %r12d
.L75:
	movq	24(%rsp), %rdx
	movq	32(%rsp), %rdi
	movl	%ebx, %ecx
	movq	40(%rsp), %rsi
	addq	%r12, %rdx
	addq	%rbp, %rdi
	addq	$4, %rbp
	addq	%r14, %r12
	call	_Z6reducePiS_S_i
	cmpq	$40, %rbp
	jne	.L75
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movl	$40, %edx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L76
	call	__stack_chk_fail@PLT
.L76:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	movq	%r13, %rax
	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
.LFE2035:
	.size	_Z13shmem_counterPii, .-_Z13shmem_counterPii
	.section	.rodata.str1.1
.LC9:
	.string	"./q2a.txt"
.LC10:
	.string	"./q2b.txt"
.LC11:
	.string	"./q2c.txt"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2037:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %r14
	call	_Z9check_devv
	xorl	%eax, %eax
	movq	%rsp, %rdi
	movl	%eax, (%rsp)
	call	_Z9read_dataPi
	leaq	8(%rsp), %rdi
	movq	%rax, %rbp
	call	cudaEventCreate@PLT
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	(%rsp), %ebx
	movq	%rbp, %rdi
	movl	%ebx, %esi
	call	_Z14global_counterPii
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rax, %r13
	call	cudaEventRecord@PLT
	movq	16(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movq	%r14, %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC9(%rip), %rdx
	movl	$10, %esi
	movq	%r13, %rdi
	call	_Z10print_filePiiPKc
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%ebx, %esi
	movq	%rbp, %rdi
	call	_Z13shmem_counterPii
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rax, %rbx
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	%r14, %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC10(%rip), %rdx
	movl	$10, %esi
	movq	%rbx, %rdi
	call	_Z10print_filePiiPKc
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$10, %esi
	movq	%rbx, %rdi
	call	_Z17integrate_counterPii
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rax, %r12
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	movq	%r14, %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC11(%rip), %rdx
	movl	$10, %esi
	movq	%r12, %rdi
	call	_Z10print_filePiiPKc
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L80
	call	__stack_chk_fail@PLT
.L80:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2037:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z20shmem_counter_kernelPiS_ii"
.LC13:
	.string	"_Z21global_counter_kernelPiS_i"
.LC14:
	.string	"_Z19shmem_reduce_kernelPiPKii"
.LC15:
	.string	"_Z16prefix_scan_stepPiS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2071:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z20shmem_counter_kernelPiS_ii(%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	.LC13(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z21global_counter_kernelPiS_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC14(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z19shmem_reduce_kernelPiPKii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC15(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z16prefix_scan_stepPiS_ii(%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
.LFE2071:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

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

#define MAX_ARRAY_SIZE 1000000

/* 
* Check GPU device 
*/ 
void check_dev(void) {
    int deviceCount;
    hipGetDeviceCount(&deviceCount);
    if (deviceCount == 0) {
        printf("!! Error: no devices supporting CUDA.\n");
        exit(EXIT_FAILURE);
    }
    int dev = 0;
    hipSetDevice(dev);
}

/* 
* Round up to the nearest power of 2
*/ 
int round_up_pow2(int val) {
    if (val == 0) return 1; 
    int pow2 = 1; 
    while (pow2 < val) {
        pow2 <<= 1; 
    }
    return pow2; 
}

/*
* Calculate the number of threads per block based on array size 
* The function is so designed that a reduction on the array can 
* be completed in two steps. 
* The assumption is that the size of the array is no more than 
* 1,000,000, such that the number of threads is no more than 
* 1024, which is the computational limit of the GPU device. 
*/ 
int calc_num_thread(int size) {
    int approx = (int)sqrt((double)size); 
    // find the nearest power of 2 
    return round_up_pow2(approx); 
}

/* 
* Read data from ./inp.txt 
* Return the pointer to the data array 
* Ouput the number of data items thru passed-in pointer (int * size)
*/ 
int * read_data(int * size) 
{
    FILE * fptr = fopen("./inp.txt", "r"); 
    if (!fptr) {
        printf("!! Error in opening data file \n"); 
        exit(1); 
    }
    int cur_array_size = MAX_ARRAY_SIZE; 
    int * buffer = (int *)malloc(cur_array_size * sizeof(int)); 
    
    int i = 0; 
    while (!feof(fptr)) {
        if (fscanf(fptr, "%d,", &buffer[i]) != 1) {
            break; 
        }
        ++i;         
    }
    
    fclose(fptr); 
    *size = i; 
    return buffer; 
}

/* 
* Outputs the result array into file 
*/ 
void print_file(int * array, int array_size, const char fname[]) {
    FILE * fptr_b = fopen(fname, "w"); 
    if (!fptr_b) {
        printf("!! Error in opening output file \n"); 
        exit(1);
    }
    for (int i = 0; i < array_size; ++i) {
        fprintf(fptr_b, "%d", array[i]); 
        if (i < array_size - 1) 
            fprintf(fptr_b, ", "); 
    }
    fclose(fptr_b); 
}

/* 
* GPU kernel: inclusive prefix scan, one step 
* The result can not be stored in the original array since different blocks
* cannot be synchronized within the kernel 
*/ 
__global__ void prefix_scan_step(int * array_i, int * array_o, int array_size, int dist) {
    // shared memory to store intermediate results 
    extern __shared__ int sdata[]; 
    
    int myId = threadIdx.x + blockDim.x * blockIdx.x;
    int thId = threadIdx.x; 
    
    // load initial values to shared memory 
    sdata[thId] = array_i[myId]; 
    __syncthreads(); 
    
    // store block results in shared memory 
    if (!(myId < dist) && myId < array_size) {
        sdata[thId] += array_i[myId - dist]; 
    }
    __syncthreads();  
    // copy results to global memory 
    if (myId < array_size) {
        array_o[myId] = sdata[thId]; 
    }
}

/* 
* Inclusive prefix scan
*/ 
void prefix_scan(int * array_i, int * array_o, int array_size) {
    // dynamically calculate the number of threads and blocks 
    const int maxThreadsPerBlock = calc_num_thread(array_size);
    int threads = maxThreadsPerBlock;
    int blocks = (array_size + maxThreadsPerBlock - 1) / maxThreadsPerBlock;
    
    int dist = 1, i = 0; 
    while (dist < array_size) {
        // each array is alternatively used as the kernel input or output to avoid the overhead of 
        // copying the output to the input in evey iteration 
        if (i % 2 == 0) 
            prefix_scan_step<<<blocks, threads, threads * sizeof(int)>>>(array_i, array_o, array_size, dist);            
        else 
            prefix_scan_step<<<blocks, threads, threads * sizeof(int)>>>(array_o, array_i, array_size, dist);
        
        hipDeviceSynchronize(); 
        ++i; 
        dist *= 2; 
    }
    
    if (i % 2 == 0)
        hipMemcpy(array_o, array_i, array_size * sizeof(int), hipMemcpyDeviceToDevice); 
}

/* 
* GPU kernel: reduction, getting the sum of an array 
*/ 
__global__ void shmem_reduce_kernel(int * d_out, const int * d_in, const int size)
{
    // sdata is allocated in the kernel call: 3rd arg to <<<b, t, shmem>>>
    extern __shared__ int sdata[];

    int myId = threadIdx.x + blockDim.x * blockIdx.x;
    int tid  = threadIdx.x;

    // load shared mem from global mem
    sdata[tid] = d_in[myId];
    __syncthreads();            // make sure entire block is loaded!

    // do reduction in shared mem
    for (unsigned int s = blockDim.x / 2; s > 0; s = s / 2)
    {
        if (tid < s && (myId + s) < size)
        {
            sdata[tid] += sdata[tid + s]; 
        }
        __syncthreads();        // make sure all adds at one stage are done!
    }

    // only thread 0 writes result for this block back to global mem
    if (tid == 0)
    {
        d_out[blockIdx.x] = sdata[0];
    }
}

/* 
* Reduction-based algorithm to find the sum of an array  
*/ 
void reduce(int * d_out, int * d_intermediate, int * d_in, int size)
{
    // assumes that size is not greater than maxThreadsPerBlock^2
    const int maxThreadsPerBlock = calc_num_thread(size);
    int threads = maxThreadsPerBlock;
    int blocks = (size + maxThreadsPerBlock - 1) / maxThreadsPerBlock;
    shmem_reduce_kernel<<<blocks, threads, threads * sizeof(int)>>>(d_intermediate, d_in, size); 

    // now we're down to one block left, so reduce it
    threads = blocks; 
    blocks = 1;
    shmem_reduce_kernel<<<blocks, round_up_pow2(threads), threads * sizeof(int)>>>(d_out, d_intermediate, threads);
}

/* 
* GPU kernel for part a
*/ 
__global__ void global_counter_kernel(int * array_i, int * cnt_o, int array_size) {
    int myId = threadIdx.x + blockDim.x * blockIdx.x; 
    if (myId < array_size) {
        atomicAdd(&cnt_o[array_i[myId] / 100], 1); 
    }
}

/* 
* part a: global memory counter 
* returns the pointer to the result array B 
*/ 
int * global_counter(int * array_i, int array_size) {
    // dynamically calculate the number of threads and blocks 
    const int maxThreadsPerBlock = calc_num_thread(array_size);
    int threads = maxThreadsPerBlock;
    int blocks = (array_size + maxThreadsPerBlock - 1) / maxThreadsPerBlock;
    
    // allocate GPU global memories for input & output arrays 
    int * array_device, * array_device_out; 
    hipMalloc((void **) &array_device, array_size * sizeof(int)); 
    hipMalloc((void **) &array_device_out, 11 * sizeof(int)); 
    
    // copy the input array into GPU shared memory 
    hipMemcpy(array_device, array_i, array_size * sizeof(int), hipMemcpyHostToDevice); 
    
    // launch the kernel 
    global_counter_kernel<<<blocks, threads>>>(array_device, array_device_out, array_size); 
    
    // allocate CPU memory for output array 
    int * array_o = (int *)malloc(10 * sizeof(int)); 
    
    // copy result back to CPU 
    hipMemcpy(array_o, array_device_out, 10 * sizeof(int), hipMemcpyDeviceToHost); 
    
    // finish 
    hipFree(array_device); 
    hipFree(array_device_out); 
    return array_o; 
}

/* 
* GPU kernel for part b 
* cnt_matrix dimensions: 10 x (# of blocks) 
*/ 
__global__ void shmem_counter_kernel(int * array_i, int * cnt_matrix, int array_size, int num_block) {
    // shared counter within block
    // size: 11 * sizeof(int) 
    // one extra int for numbers greater than 1000 
    extern __shared__ int scnt[]; 
    
    // initialize to 0 
    if (threadIdx.x < 10) {
        scnt[threadIdx.x] = 0; 
    }
    __syncthreads();
    
    // block-local counter 
    int myId = threadIdx.x + blockDim.x * blockIdx.x; 
    if (myId < array_size) {
        atomicAdd(&scnt[array_i[myId] / 100], 1); 
    }
    __syncthreads(); 
    
    // copy the counter values to shared memory 
    // only have 10 values 
    if (threadIdx.x < 10) {
        cnt_matrix[threadIdx.x * num_block + blockIdx.x] = scnt[threadIdx.x]; 
    }
}

/* 
* part b: shared memory counter 
* returns the pointer to the result array B 
*/ 
int * shmem_counter(int * array_i, int array_size) {
    // dynamically calculate the number of threads and blocks 
    const int maxThreadsPerBlock = calc_num_thread(array_size);
    int threads = maxThreadsPerBlock;
    int blocks = (array_size + maxThreadsPerBlock - 1) / maxThreadsPerBlock;
    
    // allocate GPU global memories for input & output arrays and intermediate counter matrix  
    int * array_device, * array_device_inter, * array_device_out; 
    hipMalloc((void **) &array_device, array_size * sizeof(int)); 
    hipMalloc((void **) &array_device_inter, 10 * blocks * sizeof(int)); 
    hipMalloc((void **) &array_device_out, 10 * sizeof(int)); 
    
    /* --------------------------------------------------------------------------------
     * The intermediate counter matrix 
     *
     *             block 0 | block 1 | block 2 | ... ... | block N* 
     * [  0,  99]
     * [100, 199]
     * [200, 299]
     * ... ... 
     * [900, 999]
     *
     * *Note: the number of blocks, N, is stored in variable "blocks"
    -------------------------------------------------------------------------------- */
    
    // allocate GPU global memory for reduction's intermediate results 
    int * array_device_reduction_inter; 
    hipMalloc((void **) &array_device_reduction_inter, blocks * sizeof(int)); 
    
    // allocate CPU memory for the output array  
    int * array_o = (int *)malloc(10 * sizeof(int));  
    
    // copy the input array into GPU shared memory 
    hipMemcpy(array_device, array_i, array_size * sizeof(int), hipMemcpyHostToDevice); 
    
    // launch the counter kernel 
    // shared memory size: 11 * sizeof(int) 
    // one extra int for numbers greater than 1000 
    shmem_counter_kernel<<<blocks, threads, 11 * sizeof(int)>>>(array_device, array_device_inter, array_size, blocks); 
    
    // do reduction for each range 
    for (int i = 0; i < 10; ++i) {
        reduce(&array_device_out[i], array_device_reduction_inter, &array_device_inter[blocks * i], blocks);  
    }
       
    // copy result back to CPU 
    hipMemcpy(array_o, array_device_out, 10 * sizeof(int), hipMemcpyDeviceToHost); 
    
    // finish 
    hipFree(array_device); 
    hipFree(array_device_out); 
    hipFree(array_device_inter); 
    hipFree(array_device_reduction_inter); 
    return array_o; 
}

/* 
* part c: prefix scan
* returns the pointer to the result array C  
*/ 
int * integrate_counter(int * array_i, int array_size) {
    // allocate GPU global memories for input/output array 
    int * array_device, * array_buffer; 
    hipMalloc((void **) &array_device, array_size * sizeof(int)); 
    hipMalloc((void **) &array_buffer, array_size * sizeof(int)); 
    
    // copy the input array into GPU shared memory 
    hipMemcpy(array_device, array_i, array_size * sizeof(int), hipMemcpyHostToDevice); 
    hipMemcpy(array_buffer, array_device, array_size * sizeof(int), hipMemcpyDeviceToDevice); 
    
    // run prefix scan
    prefix_scan(array_buffer, array_device, array_size); 
    
    // allocate CPU memory for the output array  
    int * array_o = (int *)malloc(array_size * sizeof(int));  
    
    // copy result back to CPU 
    hipMemcpy(array_o, array_device, array_size * sizeof(int), hipMemcpyDeviceToHost);
    
    // finish 
    hipFree(array_device); 
    hipFree(array_buffer); 
    return array_o; 
}

/* 
* CPU main routine 
*/ 
int main(void) {
    // check device 
    check_dev(); 
    
    // data array on host 
    int array_size = 0; 
    int * array_i = read_data(&array_size); 
    
    // part a ------------------------------------------------------------ 
    // compute counter values 
    hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);
    hipEventRecord(start, 0);
    int * array_o_a = global_counter(array_i, array_size); 
    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    float elapsedTime;
    hipEventElapsedTime(&elapsedTime, start, stop);
    
    // print to file 
    print_file(array_o_a, 10, "./q2a.txt"); 
    
    // print debug information to stdout 
    // printf(">> Average time elapsed in part a: %f\n", elapsedTime);

    
    // part b ------------------------------------------------------------ 
    hipEvent_t start_b, stop_b;
    hipEventCreate(&start_b);
    hipEventCreate(&stop_b);
    hipEventRecord(start_b, 0);
    int * array_o_b = shmem_counter(array_i, array_size); 
    hipEventRecord(stop_b, 0);
    hipEventSynchronize(stop_b);
    hipEventElapsedTime(&elapsedTime, start_b, stop_b);
        
    // print to file 
    print_file(array_o_b, 10, "./q2b.txt"); 
    
    // print debug information to stdout 
    // printf(">> Average time elapsed in part b: %f\n", elapsedTime);
    
    // part c ------------------------------------------------------------ 
    hipEvent_t start_c, stop_c;
    hipEventCreate(&start_c);
    hipEventCreate(&stop_c);
    hipEventRecord(start_c, 0);   
    int * array_o_c = integrate_counter(array_o_b, 10);    
    hipEventRecord(stop_c, 0);
    hipEventSynchronize(stop_c);
    hipEventElapsedTime(&elapsedTime, start_c, stop_c);
    
    // print to file 
    print_file(array_o_c, 10, "./q2c.txt");
    
    // print debug information to stdout 
    // printf(">> Average time elapsed in part c: %f\n", elapsedTime);
    
    // finish 
    free(array_i); 
    free(array_o_a); 
    free(array_o_b); 
    free(array_o_c); 
    return 0; 
}
	.text
	.file	"q2.hip"
	.globl	_Z9check_devv                   # -- Begin function _Z9check_devv
	.type	_Z9check_devv,@function
_Z9check_devv:                          # @_Z9check_devv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	leaq	12(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%rbx)
	je	.LBB0_2
# %bb.1:
	xorl	%edi, %edi
	callq	hipSetDevice
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB0_2:
	.cfi_def_cfa_offset 32
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z9check_devv, .Lfunc_end0-_Z9check_devv
	.cfi_endproc
                                        # -- End function
	.globl	_Z13round_up_pow2i              # -- Begin function _Z13round_up_pow2i
	.type	_Z13round_up_pow2i,@function
_Z13round_up_pow2i:                     # @_Z13round_up_pow2i
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	je	.LBB1_4
# %bb.1:                                # %.preheader.preheader
	movl	$1, %ecx
.LBB1_2:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movl	%ecx, %eax
	leal	(%rax,%rax), %ecx
	cmpl	%edi, %eax
	jl	.LBB1_2
# %bb.3:                                # %.loopexit
                                        # kill: def $eax killed $eax killed $rax
	retq
.LBB1_4:
	movl	$1, %eax
                                        # kill: def $eax killed $eax killed $rax
	retq
.Lfunc_end1:
	.size	_Z13round_up_pow2i, .Lfunc_end1-_Z13round_up_pow2i
	.cfi_endproc
                                        # -- End function
	.globl	_Z15calc_num_threadi            # -- Begin function _Z15calc_num_threadi
	.type	_Z15calc_num_threadi,@function
_Z15calc_num_threadi:                   # @_Z15calc_num_threadi
	.cfi_startproc
# %bb.0:
	cvtsi2sd	%edi, %xmm0
	xorpd	%xmm1, %xmm1
	ucomisd	%xmm1, %xmm0
	jb	.LBB2_2
# %bb.1:
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB2_3
.LBB2_2:                                # %call.sqrt
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	sqrt
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB2_3:                                # %.split
	cvttsd2si	%xmm0, %ecx
	testl	%ecx, %ecx
	je	.LBB2_7
# %bb.4:                                # %.preheader.i.preheader
	movl	$1, %edx
.LBB2_5:                                # %.preheader.i
                                        # =>This Inner Loop Header: Depth=1
	movl	%edx, %eax
	leal	(%rax,%rax), %edx
	cmpl	%ecx, %eax
	jl	.LBB2_5
# %bb.6:                                # %_Z13round_up_pow2i.exit
                                        # kill: def $eax killed $eax killed $rax
	retq
.LBB2_7:
	movl	$1, %eax
                                        # kill: def $eax killed $eax killed $rax
	retq
.Lfunc_end2:
	.size	_Z15calc_num_threadi, .Lfunc_end2-_Z15calc_num_threadi
	.cfi_endproc
                                        # -- End function
	.globl	_Z9read_dataPi                  # -- Begin function _Z9read_dataPi
	.type	_Z9read_dataPi,@function
_Z9read_dataPi:                         # @_Z9read_dataPi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	$.L.str.1, %edi
	movl	$.L.str.2, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB3_6
# %bb.1:
	movq	%rax, %r14
	movl	$4000000, %edi                  # imm = 0x3D0900
	callq	malloc
	movq	%rax, %r15
	movq	%r14, %rdi
	callq	feof
	xorl	%r13d, %r13d
	testl	%eax, %eax
	jne	.LBB3_5
# %bb.2:                                # %.lr.ph.preheader
	movq	%r15, %r12
	xorl	%r13d, %r13d
.LBB3_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	movq	%r12, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$1, %eax
	jne	.LBB3_5
# %bb.4:                                #   in Loop: Header=BB3_3 Depth=1
	incq	%r13
	movq	%r14, %rdi
	callq	feof
	addq	$4, %r12
	testl	%eax, %eax
	je	.LBB3_3
.LBB3_5:                                # %._crit_edge
	movq	%r14, %rdi
	callq	fclose
	movl	%r13d, (%rbx)
	movq	%r15, %rax
	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
.LBB3_6:
	.cfi_def_cfa_offset 48
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z9read_dataPi, .Lfunc_end3-_Z9read_dataPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10print_filePiiPKc            # -- Begin function _Z10print_filePiiPKc
	.type	_Z10print_filePiiPKc,@function
_Z10print_filePiiPKc:                   # @_Z10print_filePiiPKc
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%esi, %r15d
	movq	%rdi, %rbx
	movl	$.L.str.5, %esi
	movq	%rdx, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB4_7
# %bb.1:                                # %.preheader
	movq	%rax, %r14
	testl	%r15d, %r15d
	jle	.LBB4_6
# %bb.2:                                # %.lr.ph
	leal	-1(%r15), %r12d
	movl	%r15d, %r15d
	xorl	%r13d, %r13d
.LBB4_3:                                # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r13,4), %edx
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	cmpq	%r12, %r13
	jae	.LBB4_5
# %bb.4:                                #   in Loop: Header=BB4_3 Depth=1
	movl	$.L.str.8, %edi
	movl	$2, %esi
	movl	$1, %edx
	movq	%r14, %rcx
	callq	fwrite@PLT
.LBB4_5:                                #   in Loop: Header=BB4_3 Depth=1
	incq	%r13
	cmpq	%r13, %r15
	jne	.LBB4_3
.LBB4_6:                                # %._crit_edge
	movq	%r14, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.LBB4_7:
	.cfi_def_cfa_offset 48
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end4:
	.size	_Z10print_filePiiPKc, .Lfunc_end4-_Z10print_filePiiPKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__prefix_scan_stepPiS_ii # -- Begin function _Z31__device_stub__prefix_scan_stepPiS_ii
	.type	_Z31__device_stub__prefix_scan_stepPiS_ii,@function
_Z31__device_stub__prefix_scan_stepPiS_ii: # @_Z31__device_stub__prefix_scan_stepPiS_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z16prefix_scan_stepPiS_ii, %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_end5:
	.size	_Z31__device_stub__prefix_scan_stepPiS_ii, .Lfunc_end5-_Z31__device_stub__prefix_scan_stepPiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z11prefix_scanPiS_i            # -- Begin function _Z11prefix_scanPiS_i
	.type	_Z11prefix_scanPiS_i,@function
_Z11prefix_scanPiS_i:                   # @_Z11prefix_scanPiS_i
	.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
	movl	%edx, %r13d
	movq	%rsi, 8(%rsp)                   # 8-byte Spill
	cvtsi2sd	%edx, %xmm0
	movq	%rdi, (%rsp)                    # 8-byte Spill
	xorpd	%xmm1, %xmm1
	ucomisd	%xmm1, %xmm0
	jb	.LBB6_2
# %bb.1:
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB6_3
.LBB6_2:                                # %call.sqrt
	callq	sqrt
.LBB6_3:                                # %.split
	cvttsd2si	%xmm0, %eax
	testl	%eax, %eax
	je	.LBB6_4
# %bb.5:                                # %.preheader.i.i.preheader
	movl	$1, %edx
.LBB6_6:                                # %.preheader.i.i
                                        # =>This Inner Loop Header: Depth=1
	movl	%edx, %ecx
	leal	(%rcx,%rcx), %edx
	cmpl	%eax, %ecx
	jl	.LBB6_6
	jmp	.LBB6_7
.LBB6_4:
	movl	$1, %ecx
.LBB6_7:                                # %_Z15calc_num_threadi.exit
	cmpl	$2, %r13d
	jl	.LBB6_18
# %bb.8:                                # %.lr.ph
	leal	(%rcx,%r13), %eax
	decl	%eax
	cltd
	idivl	%ecx
	movl	%eax, %r12d
	movslq	%ecx, %rax
	leaq	(,%rax,4), %rcx
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	btsq	$32, %r12
	movl	%eax, %ebp
	btsq	$32, %rbp
	movl	$1, %ebx
	movl	$-1, %r14d
.LBB6_9:                                # =>This Inner Loop Header: Depth=1
	leal	1(%r14), %r15d
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	movq	16(%rsp), %r8                   # 8-byte Reload
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testb	$1, %r15b
	jne	.LBB6_12
# %bb.10:                               #   in Loop: Header=BB6_9 Depth=1
	testl	%eax, %eax
	jne	.LBB6_15
# %bb.11:                               #   in Loop: Header=BB6_9 Depth=1
	movq	(%rsp), %rdi                    # 8-byte Reload
	movq	8(%rsp), %rsi                   # 8-byte Reload
	jmp	.LBB6_14
.LBB6_12:                               #   in Loop: Header=BB6_9 Depth=1
	testl	%eax, %eax
	jne	.LBB6_15
# %bb.13:                               #   in Loop: Header=BB6_9 Depth=1
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	(%rsp), %rsi                    # 8-byte Reload
.LBB6_14:                               #   in Loop: Header=BB6_9 Depth=1
	movl	%r13d, %edx
	movl	%ebx, %ecx
	callq	_Z31__device_stub__prefix_scan_stepPiS_ii
.LBB6_15:                               #   in Loop: Header=BB6_9 Depth=1
	callq	hipDeviceSynchronize
	addl	%ebx, %ebx
	incl	%r14d
	cmpl	%r13d, %ebx
	jl	.LBB6_9
# %bb.16:                               # %._crit_edge
	testb	$1, %r14b
	jne	.LBB6_18
# %bb.17:
	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
.LBB6_18:                               # %._crit_edge.thread
	.cfi_def_cfa_offset 80
	movslq	%r13d, %rdx
	shlq	$2, %rdx
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	(%rsp), %rsi                    # 8-byte Reload
	movl	$3, %ecx
	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
	jmp	hipMemcpy                       # TAILCALL
.Lfunc_end6:
	.size	_Z11prefix_scanPiS_i, .Lfunc_end6-_Z11prefix_scanPiS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z34__device_stub__shmem_reduce_kernelPiPKii # -- Begin function _Z34__device_stub__shmem_reduce_kernelPiPKii
	.type	_Z34__device_stub__shmem_reduce_kernelPiPKii,@function
_Z34__device_stub__shmem_reduce_kernelPiPKii: # @_Z34__device_stub__shmem_reduce_kernelPiPKii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z19shmem_reduce_kernelPiPKii, %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_end7:
	.size	_Z34__device_stub__shmem_reduce_kernelPiPKii, .Lfunc_end7-_Z34__device_stub__shmem_reduce_kernelPiPKii
	.cfi_endproc
                                        # -- End function
	.globl	_Z6reducePiS_S_i                # -- Begin function _Z6reducePiS_S_i
	.type	_Z6reducePiS_S_i,@function
_Z6reducePiS_S_i:                       # @_Z6reducePiS_S_i
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %r12d
	movq	%rdx, %r13
	movq	%rsi, %rbx
	cvtsi2sd	%ecx, %xmm0
	movq	%rdi, %r14
	xorpd	%xmm1, %xmm1
	ucomisd	%xmm1, %xmm0
	jb	.LBB8_2
# %bb.1:
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB8_3
.LBB8_2:                                # %call.sqrt
	callq	sqrt
.LBB8_3:                                # %.split
	cvttsd2si	%xmm0, %eax
	testl	%eax, %eax
	je	.LBB8_4
# %bb.5:                                # %.preheader.i.i.preheader
	movl	$1, %edx
.LBB8_6:                                # %.preheader.i.i
                                        # =>This Inner Loop Header: Depth=1
	movl	%edx, %ecx
	leal	(%rcx,%rcx), %edx
	cmpl	%eax, %ecx
	jl	.LBB8_6
	jmp	.LBB8_7
.LBB8_4:
	movl	$1, %ecx
.LBB8_7:                                # %_Z15calc_num_threadi.exit
	movabsq	$4294967296, %rbp               # imm = 0x100000000
	leal	(%r12,%rcx), %eax
	decl	%eax
	cltd
	idivl	%ecx
	movl	%eax, %r15d
	movslq	%ecx, %rax
	leaq	(,%rax,4), %r8
	movq	%r15, %rdi
	btsq	$32, %rdi
	movl	%eax, %edx
	btsq	$32, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_9
# %bb.8:
	movq	%rbx, %rdi
	movq	%r13, %rsi
	movl	%r12d, %edx
	callq	_Z34__device_stub__shmem_reduce_kernelPiPKii
.LBB8_9:
	leaq	1(%rbp), %rdi
	movq	%rdi, %rdx
	testl	%r15d, %r15d
	je	.LBB8_13
# %bb.10:                               # %.preheader.i.preheader
	movl	$1, %ecx
.LBB8_11:                               # %.preheader.i
                                        # =>This Inner Loop Header: Depth=1
	movl	%ecx, %eax
	leal	(%rax,%rax), %ecx
	cmpl	%r15d, %eax
	jl	.LBB8_11
# %bb.12:                               # %_Z13round_up_pow2i.exit.loopexit
	movl	%eax, %edx
	orq	%rbp, %rdx
.LBB8_13:                               # %_Z13round_up_pow2i.exit
	movslq	%r15d, %r8
	shlq	$2, %r8
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	je	.LBB8_15
# %bb.14:
	addq	$8, %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
.LBB8_15:
	.cfi_def_cfa_offset 64
	movq	%r14, %rdi
	movq	%rbx, %rsi
	movl	%r15d, %edx
	addq	$8, %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
	jmp	_Z34__device_stub__shmem_reduce_kernelPiPKii # TAILCALL
.Lfunc_end8:
	.size	_Z6reducePiS_S_i, .Lfunc_end8-_Z6reducePiS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z36__device_stub__global_counter_kernelPiS_i # -- Begin function _Z36__device_stub__global_counter_kernelPiS_i
	.type	_Z36__device_stub__global_counter_kernelPiS_i,@function
_Z36__device_stub__global_counter_kernelPiS_i: # @_Z36__device_stub__global_counter_kernelPiS_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z21global_counter_kernelPiS_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end9:
	.size	_Z36__device_stub__global_counter_kernelPiS_i, .Lfunc_end9-_Z36__device_stub__global_counter_kernelPiS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z14global_counterPii           # -- Begin function _Z14global_counterPii
	.type	_Z14global_counterPii,@function
_Z14global_counterPii:                  # @_Z14global_counterPii
	.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
	movl	%esi, %ebx
	cvtsi2sd	%esi, %xmm0
	movq	%rdi, %r14
	xorpd	%xmm1, %xmm1
	ucomisd	%xmm1, %xmm0
	jb	.LBB10_2
# %bb.1:
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB10_3
.LBB10_2:                               # %call.sqrt
	callq	sqrt
.LBB10_3:                               # %.split
	cvttsd2si	%xmm0, %eax
	testl	%eax, %eax
	je	.LBB10_4
# %bb.5:                                # %.preheader.i.i.preheader
	movl	$1, %ecx
.LBB10_6:                               # %.preheader.i.i
                                        # =>This Inner Loop Header: Depth=1
	movl	%ecx, %ebp
	leal	(,%rbp,2), %ecx
	cmpl	%eax, %ebp
	jl	.LBB10_6
	jmp	.LBB10_7
.LBB10_4:
	movl	$1, %ebp
.LBB10_7:                               # %_Z15calc_num_threadi.exit
	leal	(%rbx,%rbp), %eax
	decl	%eax
	cltd
	idivl	%ebp
	movl	%eax, %r15d
	movslq	%ebx, %r12
	shlq	$2, %r12
	leaq	16(%rsp), %r13
	movq	%r13, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$44, %esi
	callq	hipMalloc
	movq	(%r13), %rdi
	movq	%r14, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	btsq	$32, %r15
	movl	%ebp, %edx
	btsq	$32, %rdx
	movq	%r15, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB10_9
# %bb.8:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	%ebx, %edx
	callq	_Z36__device_stub__global_counter_kernelPiS_i
.LBB10_9:
	movl	$40, %edi
	callq	malloc
	movq	%rax, %rbx
	movq	8(%rsp), %rsi
	movl	$40, %edx
	movq	%rax, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %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_end10:
	.size	_Z14global_counterPii, .Lfunc_end10-_Z14global_counterPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z35__device_stub__shmem_counter_kernelPiS_ii # -- Begin function _Z35__device_stub__shmem_counter_kernelPiS_ii
	.type	_Z35__device_stub__shmem_counter_kernelPiS_ii,@function
_Z35__device_stub__shmem_counter_kernelPiS_ii: # @_Z35__device_stub__shmem_counter_kernelPiS_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z20shmem_counter_kernelPiS_ii, %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_end11:
	.size	_Z35__device_stub__shmem_counter_kernelPiS_ii, .Lfunc_end11-_Z35__device_stub__shmem_counter_kernelPiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z13shmem_counterPii            # -- Begin function _Z13shmem_counterPii
	.type	_Z13shmem_counterPii,@function
_Z13shmem_counterPii:                   # @_Z13shmem_counterPii
	.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
	movl	%esi, %ebx
	cvtsi2sd	%esi, %xmm0
	movq	%rdi, 40(%rsp)                  # 8-byte Spill
	xorpd	%xmm1, %xmm1
	ucomisd	%xmm1, %xmm0
	jb	.LBB12_2
# %bb.1:
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB12_3
.LBB12_2:                               # %call.sqrt
	callq	sqrt
.LBB12_3:                               # %.split
	cvttsd2si	%xmm0, %eax
	testl	%eax, %eax
	je	.LBB12_4
# %bb.5:                                # %.preheader.i.i.preheader
	movl	$1, %ecx
.LBB12_6:                               # %.preheader.i.i
                                        # =>This Inner Loop Header: Depth=1
	movl	%ecx, %r15d
	leal	(%r15,%r15), %ecx
	cmpl	%eax, %r15d
	jl	.LBB12_6
	jmp	.LBB12_7
.LBB12_4:
	movl	$1, %r15d
.LBB12_7:                               # %_Z15calc_num_threadi.exit
	leal	(%rbx,%r15), %eax
	decl	%eax
	cltd
	idivl	%r15d
	movl	%eax, %r14d
	movslq	%ebx, %rbp
	shlq	$2, %rbp
	leaq	32(%rsp), %r12
	movq	%r12, %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leal	(%r14,%r14), %eax
	leal	(%rax,%rax,4), %eax
	movslq	%eax, %rsi
	shlq	$2, %rsi
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$40, %esi
	callq	hipMalloc
	movslq	%r14d, %r13
	shlq	$2, %r13
	leaq	24(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movl	$40, %edi
	callq	malloc
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	movq	(%r12), %rdi
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r14, %rdi
	btsq	$32, %rdi
	movl	%r15d, %edx
	btsq	$32, %rdx
	movl	$44, %r8d
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB12_8
# %bb.11:
	movq	32(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	%ebx, %edx
	movl	%r14d, %ecx
	callq	_Z35__device_stub__shmem_counter_kernelPiS_ii
.LBB12_8:                               # %.preheader
	xorl	%ebx, %ebx
	xorl	%r15d, %r15d
.LBB12_9:                               # =>This Inner Loop Header: Depth=1
	movq	8(%rsp), %rdi
	addq	%rbx, %rdi
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	addq	%r15, %rdx
	movl	%r14d, %ecx
	callq	_Z6reducePiS_S_i
	addq	%r13, %r15
	addq	$4, %rbx
	cmpq	$40, %rbx
	jne	.LBB12_9
# %bb.10:
	movq	8(%rsp), %rsi
	movl	$40, %edx
	movq	48(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rax
	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_end12:
	.size	_Z13shmem_counterPii, .Lfunc_end12-_Z13shmem_counterPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z17integrate_counterPii        # -- Begin function _Z17integrate_counterPii
	.type	_Z17integrate_counterPii,@function
_Z17integrate_counterPii:               # @_Z17integrate_counterPii
	.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	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %r13
	movslq	%esi, %r12
	leaq	(,%r12,4), %r15
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	%rsp, %r14
	movq	%r14, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movq	%r13, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r14), %rdi
	movq	(%rbx), %rsi
	movq	%r15, %rdx
	movl	$3, %ecx
	callq	hipMemcpy
	movq	(%r14), %rdi
	movq	(%rbx), %rsi
	movl	%r12d, %edx
	callq	_Z11prefix_scanPiS_i
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	(%rbx), %rsi
	movq	%rax, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%rbx), %rdi
	callq	hipFree
	movq	(%r14), %rdi
	callq	hipFree
	movq	%r12, %rax
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	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_end13:
	.size	_Z17integrate_counterPii, .Lfunc_end13-_Z17integrate_counterPii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	callq	_Z9check_devv
	leaq	20(%rsp), %r14
	movl	$0, (%r14)
	movq	%r14, %rdi
	callq	_Z9read_dataPi
	movq	%rax, %rbx
	leaq	64(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	leaq	56(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	(%r14), %ebp
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	_Z14global_counterPii
	movq	%rax, %r13
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r12), %rdi
	callq	hipEventSynchronize
	movq	(%r15), %rsi
	movq	(%r12), %rdx
	leaq	16(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	movl	$.L.str.9, %edx
	movq	%r13, %rdi
	movl	$10, %esi
	callq	_Z10print_filePiiPKc
	leaq	48(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	leaq	40(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	_Z13shmem_counterPii
	movq	%rax, %r12
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r15), %rdi
	callq	hipEventSynchronize
	movq	(%r13), %rsi
	movq	(%r15), %rdx
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	movl	$.L.str.10, %edx
	movq	%r12, %rdi
	movl	$10, %esi
	callq	_Z10print_filePiiPKc
	leaq	32(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	movq	(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%r12, %rdi
	movl	$10, %esi
	callq	_Z17integrate_counterPii
	movq	%rax, %r13
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r15), %rdi
	callq	hipEventSynchronize
	movq	(%rbp), %rsi
	movq	(%r15), %rdx
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	movl	$.L.str.11, %edx
	movq	%r13, %rdi
	movl	$10, %esi
	callq	_Z10print_filePiiPKc
	movq	%rbx, %rdi
	callq	free
	movq	8(%rsp), %rdi                   # 8-byte Reload
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	%r13, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$72, %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_end14:
	.size	main, .Lfunc_end14-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB15_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB15_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16prefix_scan_stepPiS_ii, %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	$_Z19shmem_reduce_kernelPiPKii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z21global_counter_kernelPiS_i, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z20shmem_counter_kernelPiS_ii, %esi
	movl	$.L__unnamed_4, %edx
	movl	$.L__unnamed_4, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end15:
	.size	__hip_module_ctor, .Lfunc_end15-__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	.LBB16_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
.LBB16_2:
	retq
.Lfunc_end16:
	.size	__hip_module_dtor, .Lfunc_end16-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"./inp.txt"
	.size	.L.str.1, 10

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

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

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

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

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

	.type	_Z16prefix_scan_stepPiS_ii,@object # @_Z16prefix_scan_stepPiS_ii
	.section	.rodata,"a",@progbits
	.globl	_Z16prefix_scan_stepPiS_ii
	.p2align	3, 0x0
_Z16prefix_scan_stepPiS_ii:
	.quad	_Z31__device_stub__prefix_scan_stepPiS_ii
	.size	_Z16prefix_scan_stepPiS_ii, 8

	.type	_Z19shmem_reduce_kernelPiPKii,@object # @_Z19shmem_reduce_kernelPiPKii
	.globl	_Z19shmem_reduce_kernelPiPKii
	.p2align	3, 0x0
_Z19shmem_reduce_kernelPiPKii:
	.quad	_Z34__device_stub__shmem_reduce_kernelPiPKii
	.size	_Z19shmem_reduce_kernelPiPKii, 8

	.type	_Z21global_counter_kernelPiS_i,@object # @_Z21global_counter_kernelPiS_i
	.globl	_Z21global_counter_kernelPiS_i
	.p2align	3, 0x0
_Z21global_counter_kernelPiS_i:
	.quad	_Z36__device_stub__global_counter_kernelPiS_i
	.size	_Z21global_counter_kernelPiS_i, 8

	.type	_Z20shmem_counter_kernelPiS_ii,@object # @_Z20shmem_counter_kernelPiS_ii
	.globl	_Z20shmem_counter_kernelPiS_ii
	.p2align	3, 0x0
_Z20shmem_counter_kernelPiS_ii:
	.quad	_Z35__device_stub__shmem_counter_kernelPiS_ii
	.size	_Z20shmem_counter_kernelPiS_ii, 8

	.type	.L.str.9,@object                # @.str.9
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.9:
	.asciz	"./q2a.txt"
	.size	.L.str.9, 10

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"./q2b.txt"
	.size	.L.str.10, 10

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"./q2c.txt"
	.size	.L.str.11, 10

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16prefix_scan_stepPiS_ii"
	.size	.L__unnamed_1, 27

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z19shmem_reduce_kernelPiPKii"
	.size	.L__unnamed_2, 30

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z21global_counter_kernelPiS_i"
	.size	.L__unnamed_3, 31

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"_Z20shmem_counter_kernelPiS_ii"
	.size	.L__unnamed_4, 31

	.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	"!! Error: no devices supporting CUDA."
	.size	.Lstr, 38

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"!! Error in opening data file "
	.size	.Lstr.1, 31

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"!! Error in opening output file "
	.size	.Lstr.2, 33

	.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 _Z31__device_stub__prefix_scan_stepPiS_ii
	.addrsig_sym _Z34__device_stub__shmem_reduce_kernelPiPKii
	.addrsig_sym _Z36__device_stub__global_counter_kernelPiS_i
	.addrsig_sym _Z35__device_stub__shmem_counter_kernelPiS_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z16prefix_scan_stepPiS_ii
	.addrsig_sym _Z19shmem_reduce_kernelPiPKii
	.addrsig_sym _Z21global_counter_kernelPiS_i
	.addrsig_sym _Z20shmem_counter_kernelPiS_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16prefix_scan_stepPiS_ii ; -- Begin function _Z16prefix_scan_stepPiS_ii
	.globl	_Z16prefix_scan_stepPiS_ii
	.p2align	8
	.type	_Z16prefix_scan_stepPiS_ii,@function
_Z16prefix_scan_stepPiS_ii:             ; @_Z16prefix_scan_stepPiS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[3:4], null, s15, s2, v[0:1]
	s_load_b64 s[2:3], s[0:1], 0x10
	v_lshl_add_u32 v0, v0, 2, 0
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[3:4]
	v_add_co_u32 v4, vcc_lo, s4, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v2, vcc_lo
	s_waitcnt lgkmcnt(0)
	v_cmp_le_i32_e64 s0, s3, v3
	v_cmp_gt_i32_e32 vcc_lo, s2, v3
	global_load_b32 v4, v[4:5], off
	s_and_b32 s0, s0, vcc_lo
	s_waitcnt vmcnt(0)
	ds_store_b32 v0, v4
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_subrev_nc_u32_e32 v3, s3, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v3, s0, s4, v3
	v_add_co_ci_u32_e64 v4, s0, s5, v4, s0
	global_load_b32 v3, v[3:4], off
	ds_load_b32 v4, v0
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_add_nc_u32_e32 v3, v4, v3
	ds_store_b32 v0, v3
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB0_4
; %bb.3:
	ds_load_b32 v3, v0
	v_add_co_u32 v0, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v2, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v3, off
.LBB0_4:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16prefix_scan_stepPiS_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 6
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z16prefix_scan_stepPiS_ii, .Lfunc_end0-_Z16prefix_scan_stepPiS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 300
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z19shmem_reduce_kernelPiPKii ; -- Begin function _Z19shmem_reduce_kernelPiPKii
	.globl	_Z19shmem_reduce_kernelPiPKii
	.p2align	8
	.type	_Z19shmem_reduce_kernelPiPKii,@function
_Z19shmem_reduce_kernelPiPKii:          ; @_Z19shmem_reduce_kernelPiPKii
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_mov_b32 s2, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s2, s3, v[0:1]
	s_cmp_lt_u32 s3, 2
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_add_co_u32 v2, vcc_lo, s6, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	global_load_b32 v3, v[2:3], off
	v_lshl_add_u32 v2, v0, 2, 0
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_5
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b32 s1, s[0:1], 0x10
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_lshr_b32 s6, s3, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v3, s6, v1
	v_cmp_gt_u32_e32 vcc_lo, s6, v0
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_u32_e64 s0, s1, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s7, vcc_lo, s0
	s_and_saveexec_b32 s0, s7
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	v_lshl_add_u32 v3, s6, 2, v2
	ds_load_b32 v3, v3
	ds_load_b32 v4, v2
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v3, v4, v3
	ds_store_b32 v2, v3
.LBB1_4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	s_cmp_lt_u32 s3, 4
	s_mov_b32 s3, s6
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB1_2
.LBB1_5:                                ; %._crit_edge
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB1_7
; %bb.6:
	v_mov_b32_e32 v0, 0
	s_mov_b32 s3, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[0:1], s[2:3], 2
	s_add_u32 s0, s4, s0
	ds_load_b32 v1, v0
	s_addc_u32 s1, s5, s1
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB1_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19shmem_reduce_kernelPiPKii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.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	_Z19shmem_reduce_kernelPiPKii, .Lfunc_end1-_Z19shmem_reduce_kernelPiPKii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 324
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; 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	_Z21global_counter_kernelPiS_i ; -- Begin function _Z21global_counter_kernelPiS_i
	.globl	_Z21global_counter_kernelPiS_i
	.p2align	8
	.type	_Z21global_counter_kernelPiS_i,@function
_Z21global_counter_kernelPiS_i:         ; @_Z21global_counter_kernelPiS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s3, s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB2_2
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_mov_b32_e32 v2, 1
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(0)
	v_mul_hi_i32 v0, 0x51eb851f, v0
	v_lshrrev_b32_e32 v1, 31, v0
	v_ashrrev_i32_e32 v0, 5, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v0, v1
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_atomic_add_u32 v[0:1], v2, off
.LBB2_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z21global_counter_kernelPiS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 3
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end2:
	.size	_Z21global_counter_kernelPiS_i, .Lfunc_end2-_Z21global_counter_kernelPiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 200
; NumSgprs: 18
; NumVgprs: 3
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 3
; Occupancy: 16
; WaveLimiterHint : 1
; 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	_Z20shmem_counter_kernelPiS_ii ; -- Begin function _Z20shmem_counter_kernelPiS_ii
	.globl	_Z20shmem_counter_kernelPiS_ii
	.p2align	8
	.type	_Z20shmem_counter_kernelPiS_ii,@function
_Z20shmem_counter_kernelPiS_ii:         ; @_Z20shmem_counter_kernelPiS_ii
; %bb.0:
	v_cmp_gt_u32_e32 vcc_lo, 10, v0
	v_lshl_add_u32 v3, v0, 2, 0
	s_mov_b32 s2, s15
	s_and_saveexec_b32 s3, vcc_lo
	s_cbranch_execz .LBB3_2
; %bb.1:
	v_mov_b32_e32 v1, 0
	ds_store_b32 v3, v1
.LBB3_2:
	s_or_b32 exec_lo, exec_lo, s3
	s_clause 0x2
	s_load_b32 s3, s[0:1], 0x24
	s_load_b64 s[8:9], s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	s_mov_b32 s1, exec_lo
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_b32 s0, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s2, s0, v[0:1]
	v_cmpx_gt_i32_e64 s8, v1
	s_cbranch_execz .LBB3_4
; %bb.3:
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v1, s0, s4, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v2, s0, s5, v2, s0
	global_load_b32 v1, v[1:2], off
	s_waitcnt vmcnt(0)
	v_mul_hi_i32 v1, 0x51eb851f, v1
	v_lshrrev_b32_e32 v2, 31, v1
	v_ashrrev_i32_e32 v1, 5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v2, 1 :: v_dual_add_nc_u32 v1, v1, v2
	v_lshl_add_u32 v1, v1, 2, 0
	ds_add_u32 v1, v2
.LBB3_4:
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB3_6
; %bb.5:
	v_mad_u64_u32 v[1:2], null, v0, s9, s[2:3]
	ds_load_b32 v3, v3
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_add_co_u32 v0, vcc_lo, s6, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v3, off
.LBB3_6:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z20shmem_counter_kernelPiS_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 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_end3:
	.size	_Z20shmem_counter_kernelPiS_ii, .Lfunc_end3-_Z20shmem_counter_kernelPiS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 316
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 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 scnt
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16prefix_scan_stepPiS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16prefix_scan_stepPiS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z19shmem_reduce_kernelPiPKii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19shmem_reduce_kernelPiPKii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z21global_counter_kernelPiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z21global_counter_kernelPiS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     3
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z20shmem_counter_kernelPiS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z20shmem_counter_kernelPiS_ii.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
