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

typedef struct {
    int *array;
    size_t used;
    size_t size;
} Array;

void initArray(Array *a, size_t initialSize) {
    a->array = (int*) malloc(initialSize * sizeof(int));
    a->used = 0;
    a->size = initialSize;
}

void insertArray(Array *a, int element) {
    if (a->used == a->size) {
        a->size += 1;
        a->array =(int*) realloc(a->array, a->size * sizeof(int));
    }
    a->array[a->used++] = element;
}
Array initArrayA(){
    FILE *fp;
    char str[50000];
    Array a;
    initArray(&a, 1);

    /* opening file for reading */
    fp = fopen("inp.txt" , "r");
    if(fp == NULL) {
        printf("%s","error");
        return a;
    }
    while( fgets (str, 50000, fp)!=NULL ) {
        /* writing content to stdout */
//        printf("%s\n", str);
        char* token;
        char* rest = str;

        while ((token = strtok_r(rest, " , ", &rest)))
            insertArray(&a, atoi(token));
    }
    fclose(fp);
    return a;
}
__global__ void global_reduce_kernel(int * d_out, int * d_in, int size)
{
    int myId = threadIdx.x + blockDim.x * blockIdx.x;
    int tid  = threadIdx.x;
    // do reduction in global mem
    for (unsigned int s = blockDim.x / 2; s > 0; s >>= 1)
    {
        if (tid < s && tid+s < size && tid < size)
        {
            if ( d_in[myId] > d_in[myId + s]){
                d_in[myId]= d_in[myId + s];
            }
        }
        __syncthreads();
    }

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

__global__ void shmem_reduce_kernel(int * d_out, int * d_in, int size)
{
    // sdata is allocated in the kernel call: 3rd arg to <<<b, t, shmem>>>
    extern __shared__ float 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 >>= 1)
    {
        if (tid < s && tid+s < size && tid < size)
        {
            if ( sdata[tid] > sdata[tid + s]){
                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];
    }
}

void reduce(int * d_out, int * d_intermediate, int * d_in,
            int size, bool usesSharedMemory)
{
    // assumes that size is not greater than maxThreadsPerBlock^2
    // and that size is a multiple of maxThreadsPerBlock
    const int maxThreadsPerBlock = 512;
    int threads = maxThreadsPerBlock;
    int blocks = ceil(float(size) / float(maxThreadsPerBlock));

    if (usesSharedMemory)
    {
        shmem_reduce_kernel<<<blocks, threads, threads * sizeof(int)>>>
                (d_intermediate, d_in, size);
    }
    else
    {
        global_reduce_kernel<<<blocks, threads>>>
                (d_intermediate, d_in,size);
    }

    // now we're down to one block left, so reduce it
    threads = blocks; // launch one thread for each block in prev step
    blocks = 1;
    if (usesSharedMemory)
    {
        shmem_reduce_kernel<<<blocks, threads, threads * sizeof(int)>>>
                (d_out, d_intermediate, size);
    }
    else
    {
        global_reduce_kernel<<<blocks, threads>>>
                (d_out, d_intermediate,size);
    }
}

__global__ void getlastdigit(int *d_out, int *d_in, int size) {
    int index = threadIdx.x + blockIdx.x * blockDim.x;
    if (index < size)
        d_out[index] = (d_in[index] % 10);
//    int idx = threadIdx.x;

}

int main(int argc, char **argv)
{
    FILE *q1a;
    FILE *q1b;
    q1a = fopen("q1a.txt", "w");
    q1b = fopen("q1b.txt", "w");

    int deviceCount;
    cudaGetDeviceCount(&deviceCount);
    if (deviceCount == 0) {
        fprintf(q1a, "error: no devices supporting CUDA.\n");
        exit(EXIT_FAILURE);
    }
    int dev = 0;
    cudaSetDevice(dev);

    cudaDeviceProp devProps;
    if (cudaGetDeviceProperties(&devProps, dev) == 0)
    {
        fprintf(q1a,"Using device %d:\n", dev);
        fprintf(q1a,"%s; global mem: %dB; compute v%d.%d; clock: %d kHz\n",
               devProps.name, (int)devProps.totalGlobalMem,
               (int)devProps.major, (int)devProps.minor,
               (int)devProps.clockRate);
    }
    Array A = initArrayA();
    int * h_in = A.array;
    const int ARRAY_SIZE = A.size;
    const int ARRAY_BYTES = A.size * sizeof(int);


//    int min = 0;
    fprintf(q1a,"array size is %d\n", ARRAY_SIZE);
//    clock_t t;
//    t = clock();
//    fprintf(q1a,"\n\nRUNNING PROBLEM 1 PART A\n\n" );
//    for(int i = 0; i < ARRAY_SIZE; i++) {
//        if (min > h_in[i]){
//            min = h_in[i];
//        }
//    }
//    t = clock() - t;
//    double time_taken = ((double)t)/(CLOCKS_PER_SEC/1000); // calculate the elapsed time
//    fprintf("The host took %f ms to execute\n", time_taken);
//    fprintf("min at host: %d\n", min);

    // declare GPU memory pointers
    int * d_in, * d_intermediate, * d_out;

    // allocate GPU memory
    cudaMalloc((void **) &d_in, ARRAY_BYTES);
    cudaMalloc((void **) &d_intermediate, ARRAY_BYTES); // overallocated
    cudaMalloc((void **) &d_out, sizeof(int));

    // transfer the input array to the GPU
    cudaMemcpy(d_in, h_in, ARRAY_BYTES, cudaMemcpyHostToDevice);

    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);

    cudaEvent_t start2, stop2;
    cudaEventCreate(&start2);
    cudaEventCreate(&stop2);

    fprintf(q1a,"Running global reduce for min\n");
    cudaEventRecord(start, 0);
    reduce(d_out, d_intermediate, d_in, ARRAY_SIZE, false);
    cudaEventRecord(stop, 0);

    cudaEventSynchronize(stop);
    float elapsedTime;
    cudaEventElapsedTime(&elapsedTime, start, stop);
    int h_out;
    cudaMemcpy(&h_out, d_out, sizeof(int), cudaMemcpyDeviceToHost);
    fprintf(q1a,"average time elapsed in ms: %f\n", elapsedTime);
    fprintf(q1a,"min returned by device: %d\n", h_out);

    fprintf(q1a,"Running reduce with shared mem\n");
    cudaEventRecord(start2, 0);
    reduce(d_out, d_intermediate, d_in, ARRAY_SIZE, true);
    cudaEventRecord(stop2, 0);
    cudaEventSynchronize(stop2);
    float elapsedTime2;
    cudaEventElapsedTime(&elapsedTime2, start2, stop2);
    int h_out2;
    cudaMemcpy(&h_out2, d_out, sizeof(int), cudaMemcpyDeviceToHost);
    fprintf(q1a,"average time elapsed in ms: %f\n", elapsedTime2);
    fprintf(q1a,"min returned by device: %d\n", h_out2);

    // free GPU memory allocation
    cudaFree(d_in);
    cudaFree(d_intermediate);
    cudaFree(d_out);

//    fprintf("\n\nRUNNING PROBLEM 1 PART B\n\n" );

    cudaGetDeviceCount(&deviceCount);
    if (deviceCount == 0) {
        fprintf(q1b, "error: no devices supporting CUDA.\n");
        exit(EXIT_FAILURE);
    }
    dev = 0;
    cudaSetDevice(dev);

//    cudaDeviceProp devProps;
    if (cudaGetDeviceProperties(&devProps, dev) == 0) {
        fprintf(q1b,"Using device %d:\n", dev);
        fprintf(q1b,"%s; global mem: %dB; compute v%d.%d; clock: %d kHz\n",
               devProps.name, (int) devProps.totalGlobalMem,
               (int) devProps.major, (int) devProps.minor,
               (int) devProps.clockRate);
    }

    int h2_out[ARRAY_SIZE];

    fprintf(q1b,"array size is %d\n", ARRAY_SIZE);

//    fprintf(q1b,"%s\n", "From Host:");
//
//    for (int i = 0; i < ARRAY_SIZE; i++) {
//            fprintf(q1b,"%d, ", (h_in[i] % 10));
//    }
    fprintf(q1b,"\n%s\n\n", "From Device:");

    int *d2_in;
    int *d2_out;

    // allocate GPU memory
    cudaMalloc((void **) &d2_in, ARRAY_BYTES);
    cudaMalloc((void **) &d2_out, ARRAY_BYTES);

    // transfer the array to the GPU
    cudaMemcpy(d2_in, h_in, ARRAY_BYTES, cudaMemcpyHostToDevice);

    // launch the kernel
    int M = 256;
    getlastdigit<<<(ARRAY_SIZE + M-1) / M,M>>>(d2_out, d2_in,ARRAY_SIZE );

    // copy back the result array to the CPU
    cudaMemcpy(h2_out, d2_out, ARRAY_BYTES, cudaMemcpyDeviceToHost);

    // print out the resulting array
    for (int i = 0; i < ARRAY_SIZE; i++) {
        if (i< ARRAY_SIZE) {
            fprintf(q1b,"%d, ", h2_out[i]);
        }
    }
    cudaFree(d2_in);
    cudaFree(d2_out);
    fprintf(q1b,"\n");

    return 0;
}
	.file	"tmpxft_003a93d6_00000000-6_q1.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z9initArrayP5Arraym
	.type	_Z9initArrayP5Arraym, @function
_Z9initArrayP5Arraym:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	leaq	0(,%rsi,4), %rdi
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	malloc@PLT
	xorl	%edx, %edx
	movq	%rbp, 16(%rbx)
	movq	%rax, (%rbx)
	movq	%rdx, 8(%rbx)
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z9initArrayP5Arraym, .-_Z9initArrayP5Arraym
	.globl	_Z11insertArrayP5Arrayi
	.type	_Z11insertArrayP5Arrayi, @function
_Z11insertArrayP5Arrayi:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 32
	movq	16(%rdi), %rsi
	cmpq	%rsi, 8(%rdi)
	jne	.L5
	incq	%rsi
	movq	(%rdi), %rdi
	movq	%rsi, 16(%rbx)
	salq	$2, %rsi
	call	realloc@PLT
	movq	%rax, (%rbx)
.L5:
	movq	8(%rbx), %rax
	movq	(%rbx), %rdx
	leaq	1(%rax), %rcx
	movq	%rcx, 8(%rbx)
	movl	%ebp, (%rdx,%rax,4)
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z11insertArrayP5Arrayi, .-_Z11insertArrayP5Arrayi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"inp.txt"
.LC2:
	.string	"error"
.LC3:
	.string	"%s"
.LC4:
	.string	" , "
	.text
	.globl	_Z10initArrayAv
	.type	_Z10initArrayAv, @function
_Z10initArrayAv:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-49152(%rsp), %r11
	.cfi_def_cfa 11, 49192
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$872, %rsp
	.cfi_def_cfa_offset 50064
	movl	$1, %esi
	leaq	.LC4(%rip), %r12
	movq	%fs:40, %rax
	movq	%rax, 50008(%rsp)
	xorl	%eax, %eax
	movq	%rdi, %rbx
	call	_Z9initArrayP5Arraym
	leaq	.LC0(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	call	fopen@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L9
	leaq	.LC2(%rip), %rdx
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L8
.L9:
	leaq	8(%rsp), %r13
	movq	%rbp, %rcx
	movl	$50000, %edx
	movl	$50000, %esi
	movq	%r13, %rdi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L18
	movq	%r13, (%rsp)
.L11:
	movq	(%rsp), %rdi
	movq	%rsp, %rdx
	movq	%r12, %rsi
	call	strtok_r@PLT
	movq	%rax, %rdi
	testq	%rax, %rax
	je	.L9
	call	atoi@PLT
	movq	%rbx, %rdi
	movl	%eax, %esi
	call	_Z11insertArrayP5Arrayi
	jmp	.L11
.L18:
	movq	%rbp, %rdi
	call	fclose@PLT
.L8:
	movq	50008(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$50024, %rsp
	.cfi_def_cfa_offset 40
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z10initArrayAv, .-_Z10initArrayAv
	.globl	_Z43__device_stub__Z20global_reduce_kernelPiS_iPiS_i
	.type	_Z43__device_stub__Z20global_reduce_kernelPiS_iPiS_i, @function
_Z43__device_stub__Z20global_reduce_kernelPiS_iPiS_i:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z20global_reduce_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
.L19:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z43__device_stub__Z20global_reduce_kernelPiS_iPiS_i, .-_Z43__device_stub__Z20global_reduce_kernelPiS_iPiS_i
	.globl	_Z20global_reduce_kernelPiS_i
	.type	_Z20global_reduce_kernelPiS_i, @function
_Z20global_reduce_kernelPiS_i:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z20global_reduce_kernelPiS_iPiS_i
	.cfi_endproc
.LFE2057:
	.size	_Z20global_reduce_kernelPiS_i, .-_Z20global_reduce_kernelPiS_i
	.globl	_Z42__device_stub__Z19shmem_reduce_kernelPiS_iPiS_i
	.type	_Z42__device_stub__Z19shmem_reduce_kernelPiS_iPiS_i, @function
_Z42__device_stub__Z19shmem_reduce_kernelPiS_iPiS_i:
.LFB2058:
	.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	.L24
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z19shmem_reduce_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
.L24:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z42__device_stub__Z19shmem_reduce_kernelPiS_iPiS_i, .-_Z42__device_stub__Z19shmem_reduce_kernelPiS_iPiS_i
	.globl	_Z19shmem_reduce_kernelPiS_i
	.type	_Z19shmem_reduce_kernelPiS_i, @function
_Z19shmem_reduce_kernelPiS_i:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z19shmem_reduce_kernelPiS_iPiS_i
	.cfi_endproc
.LFE2059:
	.size	_Z19shmem_reduce_kernelPiS_i, .-_Z19shmem_reduce_kernelPiS_i
	.globl	_Z6reducePiS_S_ib
	.type	_Z6reducePiS_S_ib, @function
_Z6reducePiS_S_ib:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	cvtsi2ssl	%ecx, %xmm0
	movl	%r8d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	mulss	.LC5(%rip), %xmm0
	call	ceilf@PLT
	testb	%r15b, %r15b
	movabsq	$4294967808, %rdx
	movabsq	$4294967297, %rax
	cvttss2sil	%xmm0, %ebp
	movq	%rdx, 20(%rsp)
	movl	$0, %r9d
	movl	$1, 28(%rsp)
	movq	%rax, 12(%rsp)
	movl	%ebp, 8(%rsp)
	je	.L30
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	movl	$2048, %r8d
	movl	$1, %ecx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movl	%ebx, %edx
	movq	%r14, %rsi
	movq	%r12, %rdi
	call	_Z42__device_stub__Z19shmem_reduce_kernelPiS_iPiS_i
.L31:
	movl	%ebp, 20(%rsp)
	movslq	%ebp, %rbp
	xorl	%r9d, %r9d
	movl	$1, %esi
	leaq	0(,%rbp,4), %r8
	movl	$1, 16(%rsp)
	movabsq	$4294967297, %rdi
	movq	%rdi, 24(%rsp)
	movl	28(%rsp), %ecx
	movq	20(%rsp), %rdx
	movq	%rdi, 8(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%ebx, %edx
	movq	%r12, %rsi
	movq	%r13, %rdi
	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
	jmp	_Z42__device_stub__Z19shmem_reduce_kernelPiS_iPiS_i
.L30:
	.cfi_restore_state
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	xorl	%r8d, %r8d
	movl	$1, %ecx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	movl	%ebx, %edx
	movq	%r14, %rsi
	movq	%r12, %rdi
	call	_Z43__device_stub__Z20global_reduce_kernelPiS_iPiS_i
.L34:
	movl	%ebp, 20(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movl	$1, 16(%rsp)
	movq	%rdi, 24(%rsp)
	movl	28(%rsp), %ecx
	movq	20(%rsp), %rdx
	movq	%rdi, 8(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%ebx, %edx
	movq	%r12, %rsi
	movq	%r13, %rdi
	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
	jmp	_Z43__device_stub__Z20global_reduce_kernelPiS_iPiS_i
.L29:
	.cfi_restore_state
	addq	$40, %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
.LFE2030:
	.size	_Z6reducePiS_S_ib, .-_Z6reducePiS_S_ib
	.globl	_Z35__device_stub__Z12getlastdigitPiS_iPiS_i
	.type	_Z35__device_stub__Z12getlastdigitPiS_iPiS_i, @function
_Z35__device_stub__Z12getlastdigitPiS_iPiS_i:
.LFB2060:
	.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	.L41
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z12getlastdigitPiS_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
.L41:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	call	__stack_chk_fail@PLT
.L43:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2060:
	.size	_Z35__device_stub__Z12getlastdigitPiS_iPiS_i, .-_Z35__device_stub__Z12getlastdigitPiS_iPiS_i
	.globl	_Z12getlastdigitPiS_i
	.type	_Z12getlastdigitPiS_i, @function
_Z12getlastdigitPiS_i:
.LFB2061:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z12getlastdigitPiS_iPiS_i
	.cfi_endproc
.LFE2061:
	.size	_Z12getlastdigitPiS_i, .-_Z12getlastdigitPiS_i
	.section	.rodata.str1.1
.LC6:
	.string	"w"
.LC7:
	.string	"q1a.txt"
.LC8:
	.string	"q1b.txt"
.LC9:
	.string	"error: no devices supporting CUDA.\n"
.LC10:
	.string	"Using device %d:\n"
.LC11:
	.string	"%s; global mem: %dB; compute v%d.%d; clock: %d kHz\n"
.LC12:
	.string	"array size is %d\n"
.LC13:
	.string	"Running global reduce for min\n"
.LC14:
	.string	"average time elapsed in ms: %f\n"
.LC15:
	.string	"min returned by device: %d\n"
.LC16:
	.string	"Running reduce with shared mem\n"
.LC17:
	.string	"From Device:"
.LC18:
	.string	"\n%s\n\n"
.LC19:
	.string	"%d, "
.LC20:
	.string	"\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC7(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	leaq	.LC6(%rip), %r12
	pushq	%rbx
	movq	%r12, %rsi
	subq	$1240, %rsp
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	fopen@PLT
	movq	%r12, %rsi
	leaq	.LC8(%rip), %rdi
	movq	%rax, %rbx
	call	fopen@PLT
	movq	%rax, -1248(%rbp)
	leaq	-1228(%rbp), %rax
	movq	%rax, %rdi
	movq	%rax, -1272(%rbp)
	call	cudaGetDeviceCount@PLT
	cmpl	$0, -1228(%rbp)
	jne	.L47
	leaq	.LC9(%rip), %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	jmp	.L62
.L47:
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	leaq	-1088(%rbp), %rax
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, -1256(%rbp)
	call	cudaGetDeviceProperties_v2@PLT
	testl	%eax, %eax
	jne	.L48
	xorl	%ecx, %ecx
	leaq	.LC10(%rip), %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	call	__fprintf_chk@PLT
	movl	-740(%rbp), %eax
	movl	$2, %esi
	movq	%rbx, %rdi
	movq	-1256(%rbp), %rcx
	movl	-800(%rbp), %r8d
	leaq	.LC11(%rip), %rdx
	pushq	%rax
	movl	-724(%rbp), %eax
	pushq	%rax
	movl	-728(%rbp), %r9d
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	popq	%rcx
	popq	%rsi
.L48:
	leaq	-1112(%rbp), %rdi
	leaq	.LC14(%rip), %r15
	call	_Z10initArrayAv
	movq	-1096(%rbp), %r12
	movl	$2, %esi
	movq	%rbx, %rdi
	movq	-1112(%rbp), %rax
	leaq	.LC12(%rip), %rdx
	leaq	.LC15(%rip), %r14
	movl	%r12d, %ecx
	movl	%r12d, %r13d
	movq	%rax, -1264(%rbp)
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	leal	0(,%r12,4), %eax
	leaq	-1208(%rbp), %rdi
	cltq
	movq	%rax, %rsi
	movq	%rax, -1240(%rbp)
	call	cudaMalloc@PLT
	movq	-1240(%rbp), %rsi
	leaq	-1200(%rbp), %rdi
	call	cudaMalloc@PLT
	leaq	-1192(%rbp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movq	-1240(%rbp), %rdx
	movl	$1, %ecx
	movq	-1264(%rbp), %rsi
	movq	-1208(%rbp), %rdi
	call	cudaMemcpy@PLT
	leaq	-1184(%rbp), %rdi
	call	cudaEventCreate@PLT
	leaq	-1176(%rbp), %rdi
	call	cudaEventCreate@PLT
	leaq	-1168(%rbp), %rdi
	call	cudaEventCreate@PLT
	leaq	-1160(%rbp), %rdi
	call	cudaEventCreate@PLT
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	.LC13(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	-1184(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	-1208(%rbp), %rdx
	xorl	%r8d, %r8d
	movl	%r12d, %ecx
	movq	-1200(%rbp), %rsi
	movq	-1192(%rbp), %rdi
	call	_Z6reducePiS_S_ib
	movq	-1176(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	-1176(%rbp), %rdi
	call	cudaEventSynchronize@PLT
	movq	-1176(%rbp), %rdx
	movq	-1184(%rbp), %rsi
	leaq	-1224(%rbp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	$2, %ecx
	movl	$4, %edx
	movq	-1192(%rbp), %rsi
	leaq	-1220(%rbp), %rdi
	call	cudaMemcpy@PLT
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	cvtss2sd	-1224(%rbp), %xmm0
	call	__fprintf_chk@PLT
	movl	-1220(%rbp), %ecx
	movq	%r14, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	movq	%rbx, %rdi
	call	__fprintf_chk@PLT
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	.LC16(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	-1168(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	-1208(%rbp), %rdx
	movl	%r12d, %ecx
	movq	-1200(%rbp), %rsi
	movq	-1192(%rbp), %rdi
	movl	$1, %r8d
	call	_Z6reducePiS_S_ib
	movq	-1160(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	-1160(%rbp), %rdi
	call	cudaEventSynchronize@PLT
	movq	-1160(%rbp), %rdx
	movq	-1168(%rbp), %rsi
	leaq	-1216(%rbp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	$2, %ecx
	movl	$4, %edx
	movq	-1192(%rbp), %rsi
	leaq	-1212(%rbp), %rdi
	call	cudaMemcpy@PLT
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	cvtss2sd	-1216(%rbp), %xmm0
	call	__fprintf_chk@PLT
	movl	-1212(%rbp), %ecx
	movq	%r14, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	movq	%rbx, %rdi
	call	__fprintf_chk@PLT
	movq	-1208(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1200(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1192(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1272(%rbp), %rdi
	call	cudaGetDeviceCount@PLT
	cmpl	$0, -1228(%rbp)
	jne	.L49
	movq	-1248(%rbp), %rdi
	leaq	.LC9(%rip), %rdx
	movl	$2, %esi
.L62:
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L49:
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movq	-1256(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaGetDeviceProperties_v2@PLT
	testl	%eax, %eax
	jne	.L50
	movq	-1248(%rbp), %rdi
	xorl	%ecx, %ecx
	movl	$2, %esi
	leaq	.LC10(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	-740(%rbp), %eax
	movl	-800(%rbp), %r8d
	leaq	.LC11(%rip), %rdx
	movq	-1256(%rbp), %rcx
	movq	-1248(%rbp), %rdi
	movl	$2, %esi
	pushq	%rax
	movl	-724(%rbp), %eax
	pushq	%rax
	movl	-728(%rbp), %r9d
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	popq	%rax
	popq	%rdx
.L50:
	movslq	%r12d, %rax
	movq	%rsp, %rcx
	leaq	15(,%rax,4), %rdx
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L51:
	cmpq	%rcx, %rsp
	je	.L52
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L51
.L52:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L53
	orq	$0, -8(%rsp,%rax)
.L53:
	movq	-1248(%rbp), %rdi
	movl	%r13d, %ecx
	xorl	%eax, %eax
	movq	%rsp, %rbx
	leaq	.LC12(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	-1248(%rbp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC17(%rip), %rcx
	leaq	.LC18(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	-1240(%rbp), %rsi
	leaq	-1152(%rbp), %rdi
	call	cudaMalloc@PLT
	movq	-1240(%rbp), %rsi
	leaq	-1144(%rbp), %rdi
	call	cudaMalloc@PLT
	movq	-1240(%rbp), %rdx
	movl	$1, %ecx
	movq	-1264(%rbp), %rsi
	movq	-1152(%rbp), %rdi
	call	cudaMemcpy@PLT
	movl	$256, %esi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	leal	255(%r12), %eax
	movl	$16777217, %ecx
	movl	$1, -1116(%rbp)
	cltd
	salq	$8, %rcx
	idivl	%esi
	movq	%rcx, -1124(%rbp)
	movq	%rcx, %rdx
	movl	$1, %ecx
	movl	%eax, -1136(%rbp)
	movabsq	$4294967297, %rax
	movq	%rax, -1132(%rbp)
	movq	-1136(%rbp), %rdi
	movl	-1128(%rbp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L54
	movq	-1152(%rbp), %rsi
	movq	-1144(%rbp), %rdi
	movl	%r13d, %edx
	call	_Z35__device_stub__Z12getlastdigitPiS_iPiS_i
.L54:
	movq	-1240(%rbp), %rdx
	movq	-1144(%rbp), %rsi
	movq	%rbx, %rdi
	xorl	%r12d, %r12d
	movl	$2, %ecx
	leaq	.LC19(%rip), %r14
	call	cudaMemcpy@PLT
.L55:
	cmpl	%r12d, %r13d
	jle	.L63
	movl	(%rbx,%r12,4), %ecx
	movq	-1248(%rbp), %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L55
.L63:
	movq	-1152(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1144(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1248(%rbp), %rdi
	xorl	%eax, %eax
	leaq	.LC20(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L57
	call	__stack_chk_fail@PLT
.L57:
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC21:
	.string	"_Z12getlastdigitPiS_i"
.LC22:
	.string	"_Z19shmem_reduce_kernelPiS_i"
.LC23:
	.string	"_Z20global_reduce_kernelPiS_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2063:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC21(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z12getlastdigitPiS_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC22(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z19shmem_reduce_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	.LC23(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z20global_reduce_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
	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
.LFE2063:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC5:
	.long	989855744
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

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

typedef struct {
    int *array;
    size_t used;
    size_t size;
} Array;

void initArray(Array *a, size_t initialSize) {
    a->array = (int*) malloc(initialSize * sizeof(int));
    a->used = 0;
    a->size = initialSize;
}

void insertArray(Array *a, int element) {
    if (a->used == a->size) {
        a->size += 1;
        a->array =(int*) realloc(a->array, a->size * sizeof(int));
    }
    a->array[a->used++] = element;
}
Array initArrayA(){
    FILE *fp;
    char str[50000];
    Array a;
    initArray(&a, 1);

    /* opening file for reading */
    fp = fopen("inp.txt" , "r");
    if(fp == NULL) {
        printf("%s","error");
        return a;
    }
    while( fgets (str, 50000, fp)!=NULL ) {
        /* writing content to stdout */
//        printf("%s\n", str);
        char* token;
        char* rest = str;

        while ((token = strtok_r(rest, " , ", &rest)))
            insertArray(&a, atoi(token));
    }
    fclose(fp);
    return a;
}
__global__ void global_reduce_kernel(int * d_out, int * d_in, int size)
{
    int myId = threadIdx.x + blockDim.x * blockIdx.x;
    int tid  = threadIdx.x;
    // do reduction in global mem
    for (unsigned int s = blockDim.x / 2; s > 0; s >>= 1)
    {
        if (tid < s && tid+s < size && tid < size)
        {
            if ( d_in[myId] > d_in[myId + s]){
                d_in[myId]= d_in[myId + s];
            }
        }
        __syncthreads();
    }

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

__global__ void shmem_reduce_kernel(int * d_out, int * d_in, int size)
{
    // sdata is allocated in the kernel call: 3rd arg to <<<b, t, shmem>>>
    extern __shared__ float 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 >>= 1)
    {
        if (tid < s && tid+s < size && tid < size)
        {
            if ( sdata[tid] > sdata[tid + s]){
                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];
    }
}

void reduce(int * d_out, int * d_intermediate, int * d_in,
            int size, bool usesSharedMemory)
{
    // assumes that size is not greater than maxThreadsPerBlock^2
    // and that size is a multiple of maxThreadsPerBlock
    const int maxThreadsPerBlock = 512;
    int threads = maxThreadsPerBlock;
    int blocks = ceil(float(size) / float(maxThreadsPerBlock));

    if (usesSharedMemory)
    {
        shmem_reduce_kernel<<<blocks, threads, threads * sizeof(int)>>>
                (d_intermediate, d_in, size);
    }
    else
    {
        global_reduce_kernel<<<blocks, threads>>>
                (d_intermediate, d_in,size);
    }

    // now we're down to one block left, so reduce it
    threads = blocks; // launch one thread for each block in prev step
    blocks = 1;
    if (usesSharedMemory)
    {
        shmem_reduce_kernel<<<blocks, threads, threads * sizeof(int)>>>
                (d_out, d_intermediate, size);
    }
    else
    {
        global_reduce_kernel<<<blocks, threads>>>
                (d_out, d_intermediate,size);
    }
}

__global__ void getlastdigit(int *d_out, int *d_in, int size) {
    int index = threadIdx.x + blockIdx.x * blockDim.x;
    if (index < size)
        d_out[index] = (d_in[index] % 10);
//    int idx = threadIdx.x;

}

int main(int argc, char **argv)
{
    FILE *q1a;
    FILE *q1b;
    q1a = fopen("q1a.txt", "w");
    q1b = fopen("q1b.txt", "w");

    int deviceCount;
    hipGetDeviceCount(&deviceCount);
    if (deviceCount == 0) {
        fprintf(q1a, "error: no devices supporting CUDA.\n");
        exit(EXIT_FAILURE);
    }
    int dev = 0;
    hipSetDevice(dev);

    hipDeviceProp_t devProps;
    if (hipGetDeviceProperties(&devProps, dev) == 0)
    {
        fprintf(q1a,"Using device %d:\n", dev);
        fprintf(q1a,"%s; global mem: %dB; compute v%d.%d; clock: %d kHz\n",
               devProps.name, (int)devProps.totalGlobalMem,
               (int)devProps.major, (int)devProps.minor,
               (int)devProps.clockRate);
    }
    Array A = initArrayA();
    int * h_in = A.array;
    const int ARRAY_SIZE = A.size;
    const int ARRAY_BYTES = A.size * sizeof(int);


//    int min = 0;
    fprintf(q1a,"array size is %d\n", ARRAY_SIZE);
//    clock_t t;
//    t = clock();
//    fprintf(q1a,"\n\nRUNNING PROBLEM 1 PART A\n\n" );
//    for(int i = 0; i < ARRAY_SIZE; i++) {
//        if (min > h_in[i]){
//            min = h_in[i];
//        }
//    }
//    t = clock() - t;
//    double time_taken = ((double)t)/(CLOCKS_PER_SEC/1000); // calculate the elapsed time
//    fprintf("The host took %f ms to execute\n", time_taken);
//    fprintf("min at host: %d\n", min);

    // declare GPU memory pointers
    int * d_in, * d_intermediate, * d_out;

    // allocate GPU memory
    hipMalloc((void **) &d_in, ARRAY_BYTES);
    hipMalloc((void **) &d_intermediate, ARRAY_BYTES); // overallocated
    hipMalloc((void **) &d_out, sizeof(int));

    // transfer the input array to the GPU
    hipMemcpy(d_in, h_in, ARRAY_BYTES, hipMemcpyHostToDevice);

    hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);

    hipEvent_t start2, stop2;
    hipEventCreate(&start2);
    hipEventCreate(&stop2);

    fprintf(q1a,"Running global reduce for min\n");
    hipEventRecord(start, 0);
    reduce(d_out, d_intermediate, d_in, ARRAY_SIZE, false);
    hipEventRecord(stop, 0);

    hipEventSynchronize(stop);
    float elapsedTime;
    hipEventElapsedTime(&elapsedTime, start, stop);
    int h_out;
    hipMemcpy(&h_out, d_out, sizeof(int), hipMemcpyDeviceToHost);
    fprintf(q1a,"average time elapsed in ms: %f\n", elapsedTime);
    fprintf(q1a,"min returned by device: %d\n", h_out);

    fprintf(q1a,"Running reduce with shared mem\n");
    hipEventRecord(start2, 0);
    reduce(d_out, d_intermediate, d_in, ARRAY_SIZE, true);
    hipEventRecord(stop2, 0);
    hipEventSynchronize(stop2);
    float elapsedTime2;
    hipEventElapsedTime(&elapsedTime2, start2, stop2);
    int h_out2;
    hipMemcpy(&h_out2, d_out, sizeof(int), hipMemcpyDeviceToHost);
    fprintf(q1a,"average time elapsed in ms: %f\n", elapsedTime2);
    fprintf(q1a,"min returned by device: %d\n", h_out2);

    // free GPU memory allocation
    hipFree(d_in);
    hipFree(d_intermediate);
    hipFree(d_out);

//    fprintf("\n\nRUNNING PROBLEM 1 PART B\n\n" );

    hipGetDeviceCount(&deviceCount);
    if (deviceCount == 0) {
        fprintf(q1b, "error: no devices supporting CUDA.\n");
        exit(EXIT_FAILURE);
    }
    dev = 0;
    hipSetDevice(dev);

//    cudaDeviceProp devProps;
    if (hipGetDeviceProperties(&devProps, dev) == 0) {
        fprintf(q1b,"Using device %d:\n", dev);
        fprintf(q1b,"%s; global mem: %dB; compute v%d.%d; clock: %d kHz\n",
               devProps.name, (int) devProps.totalGlobalMem,
               (int) devProps.major, (int) devProps.minor,
               (int) devProps.clockRate);
    }

    int h2_out[ARRAY_SIZE];

    fprintf(q1b,"array size is %d\n", ARRAY_SIZE);

//    fprintf(q1b,"%s\n", "From Host:");
//
//    for (int i = 0; i < ARRAY_SIZE; i++) {
//            fprintf(q1b,"%d, ", (h_in[i] % 10));
//    }
    fprintf(q1b,"\n%s\n\n", "From Device:");

    int *d2_in;
    int *d2_out;

    // allocate GPU memory
    hipMalloc((void **) &d2_in, ARRAY_BYTES);
    hipMalloc((void **) &d2_out, ARRAY_BYTES);

    // transfer the array to the GPU
    hipMemcpy(d2_in, h_in, ARRAY_BYTES, hipMemcpyHostToDevice);

    // launch the kernel
    int M = 256;
    getlastdigit<<<(ARRAY_SIZE + M-1) / M,M>>>(d2_out, d2_in,ARRAY_SIZE );

    // copy back the result array to the CPU
    hipMemcpy(h2_out, d2_out, ARRAY_BYTES, hipMemcpyDeviceToHost);

    // print out the resulting array
    for (int i = 0; i < ARRAY_SIZE; i++) {
        if (i< ARRAY_SIZE) {
            fprintf(q1b,"%d, ", h2_out[i]);
        }
    }
    hipFree(d2_in);
    hipFree(d2_out);
    fprintf(q1b,"\n");

    return 0;
}
	.text
	.file	"q1.hip"
	.globl	_Z9initArrayP5Arraym            # -- Begin function _Z9initArrayP5Arraym
	.type	_Z9initArrayP5Arraym,@function
_Z9initArrayP5Arraym:                   # @_Z9initArrayP5Arraym
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	leaq	(,%rsi,4), %rdi
	callq	malloc
	movq	%rax, (%r14)
	movq	$0, 8(%r14)
	movq	%rbx, 16(%r14)
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z9initArrayP5Arraym, .Lfunc_end0-_Z9initArrayP5Arraym
	.cfi_endproc
                                        # -- End function
	.globl	_Z11insertArrayP5Arrayi         # -- Begin function _Z11insertArrayP5Arrayi
	.type	_Z11insertArrayP5Arrayi,@function
_Z11insertArrayP5Arrayi:                # @_Z11insertArrayP5Arrayi
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%esi, %ebx
	movq	%rdi, %r14
	movq	(%rdi), %rax
	movq	8(%rdi), %rcx
	cmpq	16(%rdi), %rcx
	jne	.LBB1_2
# %bb.1:
	leaq	1(%rcx), %rdx
	movq	%rdx, 16(%r14)
	leaq	4(,%rcx,4), %rsi
	movq	%rax, %rdi
	callq	realloc
	movq	%rax, (%r14)
	movq	8(%r14), %rcx
.LBB1_2:
	leaq	1(%rcx), %rdx
	movq	%rdx, 8(%r14)
	movl	%ebx, (%rax,%rcx,4)
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z11insertArrayP5Arrayi, .Lfunc_end1-_Z11insertArrayP5Arrayi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10initArrayAv                 # -- Begin function _Z10initArrayAv
	.type	_Z10initArrayAv,@function
_Z10initArrayAv:                        # @_Z10initArrayAv
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$50024, %rsp                    # imm = 0xC368
	.cfi_def_cfa_offset 50064
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	$4, %edi
	callq	malloc
	movq	%rax, (%rbx)
	movq	$0, 8(%rbx)
	movq	$1, 16(%rbx)
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB2_9
# %bb.1:                                # %.preheader
	movq	%rax, %r14
	leaq	16(%rsp), %r15
	movq	%r15, %rdi
	movl	$50000, %esi                    # imm = 0xC350
	movq	%rax, %rdx
	callq	fgets
	testq	%rax, %rax
	je	.LBB2_7
# %bb.2:
	leaq	8(%rsp), %r12
.LBB2_3:                                # %.lr.ph7
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_5 Depth 2
	movq	%r15, 8(%rsp)
	movl	$.L.str.4, %esi
	movq	%r15, %rdi
.LBB2_5:                                # %.lr.ph
                                        #   Parent Loop BB2_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r12, %rdx
	callq	strtok_r
	testq	%rax, %rax
	je	.LBB2_6
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB2_5 Depth=2
	movq	%rax, %rdi
	callq	atoi
	movq	%rbx, %rdi
	movl	%eax, %esi
	callq	_Z11insertArrayP5Arrayi
	movq	8(%rsp), %rdi
	movl	$.L.str.4, %esi
	jmp	.LBB2_5
.LBB2_6:                                # %._crit_edge
                                        #   in Loop: Header=BB2_3 Depth=1
	movq	%r15, %rdi
	movl	$50000, %esi                    # imm = 0xC350
	movq	%r14, %rdx
	callq	fgets
	testq	%rax, %rax
	jne	.LBB2_3
.LBB2_7:                                # %._crit_edge8
	movq	%r14, %rdi
	callq	fclose
	jmp	.LBB2_8
.LBB2_9:
	movl	$.L.str.2, %edi
	movl	$.L.str.3, %esi
	xorl	%eax, %eax
	callq	printf
.LBB2_8:                                # %._crit_edge8
	movq	%rbx, %rax
	addq	$50024, %rsp                    # imm = 0xC368
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z10initArrayAv, .Lfunc_end2-_Z10initArrayAv
	.cfi_endproc
                                        # -- End function
	.globl	_Z35__device_stub__global_reduce_kernelPiS_i # -- Begin function _Z35__device_stub__global_reduce_kernelPiS_i
	.type	_Z35__device_stub__global_reduce_kernelPiS_i,@function
_Z35__device_stub__global_reduce_kernelPiS_i: # @_Z35__device_stub__global_reduce_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	$_Z20global_reduce_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_end3:
	.size	_Z35__device_stub__global_reduce_kernelPiS_i, .Lfunc_end3-_Z35__device_stub__global_reduce_kernelPiS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z34__device_stub__shmem_reduce_kernelPiS_i # -- Begin function _Z34__device_stub__shmem_reduce_kernelPiS_i
	.type	_Z34__device_stub__shmem_reduce_kernelPiS_i,@function
_Z34__device_stub__shmem_reduce_kernelPiS_i: # @_Z34__device_stub__shmem_reduce_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	$_Z19shmem_reduce_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_end4:
	.size	_Z34__device_stub__shmem_reduce_kernelPiS_i, .Lfunc_end4-_Z34__device_stub__shmem_reduce_kernelPiS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z6reducePiS_S_ib
.LCPI5_0:
	.long	0x3b000000                      # float 0.001953125
	.text
	.globl	_Z6reducePiS_S_ib
	.type	_Z6reducePiS_S_ib,@function
_Z6reducePiS_S_ib:                      # @_Z6reducePiS_S_ib
	.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	%r8d, %r15d
	movl	%ecx, %ebx
	movq	%rdx, %rbp
	movq	%rsi, 8(%rsp)                   # 8-byte Spill
	cvtsi2ss	%ecx, %xmm0
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	movabsq	$4294967297, %r12               # imm = 0x100000001
	mulss	.LCPI5_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r14d
	leaq	(%r14,%r12), %r13
	decq	%r13
	leaq	511(%r12), %rdx
	testl	%r15d, %r15d
	je	.LBB5_5
# %bb.1:
	movl	$2048, %r8d                     # imm = 0x800
	movq	%r13, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_3
# %bb.2:
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	%rbp, %rsi
	movl	%ebx, %edx
	callq	_Z34__device_stub__shmem_reduce_kernelPiS_i
.LBB5_3:
	movslq	%r14d, %r8
	shlq	$2, %r8
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_8
# %bb.4:
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movl	%ebx, %edx
	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	_Z34__device_stub__shmem_reduce_kernelPiS_i # TAILCALL
.LBB5_5:
	.cfi_def_cfa_offset 80
	movq	%r13, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_7
# %bb.6:
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	%rbp, %rsi
	movl	%ebx, %edx
	callq	_Z35__device_stub__global_reduce_kernelPiS_i
.LBB5_7:
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	je	.LBB5_9
.LBB5_8:
	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
.LBB5_9:
	.cfi_def_cfa_offset 80
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movl	%ebx, %edx
	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	_Z35__device_stub__global_reduce_kernelPiS_i # TAILCALL
.Lfunc_end5:
	.size	_Z6reducePiS_S_ib, .Lfunc_end5-_Z6reducePiS_S_ib
	.cfi_endproc
                                        # -- End function
	.globl	_Z27__device_stub__getlastdigitPiS_i # -- Begin function _Z27__device_stub__getlastdigitPiS_i
	.type	_Z27__device_stub__getlastdigitPiS_i,@function
_Z27__device_stub__getlastdigitPiS_i:   # @_Z27__device_stub__getlastdigitPiS_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	$_Z12getlastdigitPiS_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_end6:
	.size	_Z27__device_stub__getlastdigitPiS_i, .Lfunc_end6-_Z27__device_stub__getlastdigitPiS_i
	.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
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$1624, %rsp                     # imm = 0x658
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movl	$.L.str.5, %edi
	movl	$.L.str.6, %esi
	callq	fopen
	movq	%rax, %r13
	movl	$.L.str.7, %edi
	movl	$.L.str.6, %esi
	callq	fopen
	movq	%rax, %rbx
	leaq	-84(%rbp), %r14
	movq	%r14, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%r14)
	je	.LBB7_1
# %bb.3:
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	-1664(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	testl	%eax, %eax
	jne	.LBB7_5
# %bb.4:
	movl	$.L.str.9, %esi
	movq	%r13, %rdi
	xorl	%edx, %edx
	xorl	%eax, %eax
	callq	fprintf
	leaq	-1664(%rbp), %rdx
	movl	360(%rdx), %r8d
	movl	364(%rdx), %r9d
	movl	288(%rdx), %ecx
	movl	348(%rdx), %r10d
	subq	$8, %rsp
	movl	$.L.str.10, %esi
	movq	%r13, %rdi
	xorl	%eax, %eax
	pushq	%r10
	callq	fprintf
	addq	$16, %rsp
.LBB7_5:
	leaq	-192(%rbp), %r14
	movq	%r14, %rdi
	callq	_Z10initArrayAv
	movq	(%r14), %r12
	movq	16(%r14), %rdx
	movq	%rdx, -48(%rbp)                 # 8-byte Spill
	leal	(,%rdx,4), %r15d
	movl	$.L.str.11, %esi
	movq	%r13, %rdi
                                        # kill: def $edx killed $edx killed $rdx
	xorl	%eax, %eax
	callq	fprintf
	movslq	%r15d, %r15
	leaq	-80(%rbp), %r14
	movq	%r14, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	-72(%rbp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	-136(%rbp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	%r12, -104(%rbp)                # 8-byte Spill
	movq	%r12, %rsi
	movq	%r15, -112(%rbp)                # 8-byte Spill
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	-168(%rbp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	leaq	-160(%rbp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	leaq	-128(%rbp), %rdi
	callq	hipEventCreate
	leaq	-120(%rbp), %rdi
	callq	hipEventCreate
	movl	$.L.str.12, %edi
	movl	$30, %esi
	movl	$1, %edx
	movq	%r13, %rcx
	callq	fwrite@PLT
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	-136(%rbp), %r14
	movq	(%r14), %rdi
	leaq	-72(%rbp), %rax
	movq	(%rax), %rsi
	leaq	-80(%rbp), %rax
	movq	(%rax), %rdx
	movq	-48(%rbp), %rcx                 # 8-byte Reload
                                        # kill: def $ecx killed $ecx killed $rcx
	xorl	%r8d, %r8d
	callq	_Z6reducePiS_S_ib
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r15), %rdi
	callq	hipEventSynchronize
	movq	(%r12), %rsi
	movq	(%r15), %rdx
	leaq	-152(%rbp), %r15
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movq	(%r14), %rsi
	leaq	-148(%rbp), %r12
	movl	$4, %edx
	movq	%r12, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str.13, %esi
	movq	%r13, %rdi
	movb	$1, %al
	callq	fprintf
	movl	(%r12), %edx
	movl	$.L.str.14, %esi
	movq	%r13, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.15, %edi
	movl	$31, %esi
	movl	$1, %edx
	movq	%r13, %rcx
	callq	fwrite@PLT
	leaq	-128(%rbp), %r15
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r14), %rdi
	leaq	-72(%rbp), %rax
	movq	(%rax), %rsi
	leaq	-80(%rbp), %rax
	movq	(%rax), %rdx
	movq	-48(%rbp), %rcx                 # 8-byte Reload
                                        # kill: def $ecx killed $ecx killed $rcx
	movl	$1, %r8d
	callq	_Z6reducePiS_S_ib
	leaq	-120(%rbp), %r12
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r12), %rdi
	callq	hipEventSynchronize
	movq	(%r15), %rsi
	movq	(%r12), %rdx
	leaq	-144(%rbp), %r15
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movq	(%r14), %rsi
	leaq	-140(%rbp), %r12
	movl	$4, %edx
	movq	%r12, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str.13, %esi
	movq	%r13, %rdi
	movb	$1, %al
	callq	fprintf
	movl	(%r12), %edx
	movl	$.L.str.14, %esi
	movq	%r13, %rdi
	xorl	%eax, %eax
	callq	fprintf
	leaq	-80(%rbp), %rax
	movq	(%rax), %rdi
	callq	hipFree
	leaq	-72(%rbp), %rax
	movq	(%rax), %rdi
	callq	hipFree
	movq	(%r14), %rdi
	callq	hipFree
	leaq	-84(%rbp), %r15
	movq	%r15, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%r15)
	je	.LBB7_6
# %bb.7:
	movq	-48(%rbp), %r14                 # 8-byte Reload
	movl	%r14d, %r13d
	xorl	%edi, %edi
	callq	hipSetDevice
	leaq	-1664(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	testl	%eax, %eax
	jne	.LBB7_9
# %bb.8:
	movl	$.L.str.9, %esi
	movq	%rbx, %rdi
	xorl	%edx, %edx
	xorl	%eax, %eax
	callq	fprintf
	leaq	-1664(%rbp), %rdx
	movl	360(%rdx), %r8d
	movl	364(%rdx), %r9d
	movl	288(%rdx), %ecx
	movl	348(%rdx), %r10d
	subq	$8, %rsp
	movl	$.L.str.10, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	pushq	%r10
	callq	fprintf
	addq	$16, %rsp
.LBB7_9:
	movq	%rsp, -96(%rbp)                 # 8-byte Spill
	movq	%rsp, %r12
	leaq	15(,%r13,4), %rax
	andq	$-16, %rax
	subq	%rax, %r12
	movq	%r12, %rsp
	movl	$.L.str.11, %esi
	movq	%rbx, %rdi
	movl	%r14d, %edx
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.16, %esi
	movl	$.L.str.17, %edx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	leaq	-64(%rbp), %rdi
	movq	-112(%rbp), %r15                # 8-byte Reload
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	-56(%rbp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	-64(%rbp), %rax
	movq	(%rax), %rdi
	movq	-104(%rbp), %rsi                # 8-byte Reload
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leal	255(%r14), %eax
	leal	510(%r14), %edi
	testl	%eax, %eax
	cmovnsl	%eax, %edi
	sarl	$8, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$256, %rdx                      # imm = 0x100
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB7_11
# %bb.10:
	movq	-56(%rbp), %rdi
	movq	-64(%rbp), %rsi
	movl	%r14d, %edx
	callq	_Z27__device_stub__getlastdigitPiS_i
.LBB7_11:
	movq	-56(%rbp), %rsi
	movq	%r12, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%r14d, %r14d
	jle	.LBB7_14
# %bb.12:                               # %.lr.ph.preheader
	xorl	%r14d, %r14d
.LBB7_13:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r12,%r14,4), %edx
	movl	$.L.str.18, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r14
	cmpq	%r14, %r13
	jne	.LBB7_13
.LBB7_14:                               # %._crit_edge
	movq	-64(%rbp), %rdi
	callq	hipFree
	movq	-56(%rbp), %rdi
	callq	hipFree
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movq	-96(%rbp), %rsp                 # 8-byte Reload
	xorl	%eax, %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.LBB7_1:
	.cfi_def_cfa %rbp, 16
	movl	$.L.str.8, %edi
	movl	$35, %esi
	movl	$1, %edx
	movq	%r13, %rcx
	jmp	.LBB7_2
.LBB7_6:
	movl	$.L.str.8, %edi
	movl	$35, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
.LBB7_2:
	callq	fwrite@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end7:
	.size	main, .Lfunc_end7-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	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z20global_reduce_kernelPiS_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z19shmem_reduce_kernelPiS_i, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12getlastdigitPiS_i, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__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	.LBB9_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
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"inp.txt"
	.size	.L.str, 8

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

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

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

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

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

	.type	_Z19shmem_reduce_kernelPiS_i,@object # @_Z19shmem_reduce_kernelPiS_i
	.globl	_Z19shmem_reduce_kernelPiS_i
	.p2align	3, 0x0
_Z19shmem_reduce_kernelPiS_i:
	.quad	_Z34__device_stub__shmem_reduce_kernelPiS_i
	.size	_Z19shmem_reduce_kernelPiS_i, 8

	.type	_Z12getlastdigitPiS_i,@object   # @_Z12getlastdigitPiS_i
	.globl	_Z12getlastdigitPiS_i
	.p2align	3, 0x0
_Z12getlastdigitPiS_i:
	.quad	_Z27__device_stub__getlastdigitPiS_i
	.size	_Z12getlastdigitPiS_i, 8

	.type	.L.str.5,@object                # @.str.5
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.5:
	.asciz	"q1a.txt"
	.size	.L.str.5, 8

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"q1b.txt"
	.size	.L.str.7, 8

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"error: no devices supporting CUDA.\n"
	.size	.L.str.8, 36

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Using device %d:\n"
	.size	.L.str.9, 18

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"%s; global mem: %dB; compute v%d.%d; clock: %d kHz\n"
	.size	.L.str.10, 52

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"array size is %d\n"
	.size	.L.str.11, 18

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Running global reduce for min\n"
	.size	.L.str.12, 31

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"average time elapsed in ms: %f\n"
	.size	.L.str.13, 32

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"min returned by device: %d\n"
	.size	.L.str.14, 28

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Running reduce with shared mem\n"
	.size	.L.str.15, 32

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"\n%s\n\n"
	.size	.L.str.16, 6

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"From Device:"
	.size	.L.str.17, 13

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z20global_reduce_kernelPiS_i"
	.size	.L__unnamed_1, 30

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z19shmem_reduce_kernelPiS_i"
	.size	.L__unnamed_2, 29

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z12getlastdigitPiS_i"
	.size	.L__unnamed_3, 22

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

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z35__device_stub__global_reduce_kernelPiS_i
	.addrsig_sym _Z34__device_stub__shmem_reduce_kernelPiS_i
	.addrsig_sym _Z27__device_stub__getlastdigitPiS_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z20global_reduce_kernelPiS_i
	.addrsig_sym _Z19shmem_reduce_kernelPiS_i
	.addrsig_sym _Z12getlastdigitPiS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z20global_reduce_kernelPiS_i ; -- Begin function _Z20global_reduce_kernelPiS_i
	.globl	_Z20global_reduce_kernelPiS_i
	.p2align	8
	.type	_Z20global_reduce_kernelPiS_i,@function
_Z20global_reduce_kernelPiS_i:          ; @_Z20global_reduce_kernelPiS_i
; %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_cbranch_scc1 .LBB0_6
; %bb.1:                                ; %.lr.ph
	s_load_b32 s8, s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_mov_b32_e32 v6, 0
	v_add_co_u32 v3, vcc_lo, s6, v3
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s7, v4, vcc_lo
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, s8, v0
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s9, s3
	s_lshr_b32 s3, s3, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, s3, v0
	v_cmp_gt_u32_e64 s0, s3, v0
	v_cmp_gt_u32_e64 s1, s8, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s0, s1
	s_and_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_5
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	v_add_nc_u32_e32 v5, s3, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[7:8], 2, v[5:6]
	v_add_co_u32 v7, s0, s6, v7
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v8, s0, s7, v8, s0
	s_clause 0x1
	global_load_b32 v9, v[3:4], off
	global_load_b32 v5, v[7:8], off
	s_waitcnt vmcnt(0)
	v_cmp_gt_i32_e64 s0, v9, v5
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	global_store_b32 v[3:4], v5, off
.LBB0_5:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_cmp_lt_u32 s9, 4
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_2
.LBB0_6:                                ; %._crit_edge
	s_mov_b32 s3, 0
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_8
; %bb.7:
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_lshl_b64 s[0:1], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_add_u32 s0, s4, s0
	s_addc_u32 s1, s5, s1
	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
	global_load_b32 v0, v[0:1], off
	v_mov_b32_e32 v1, 0
	s_waitcnt vmcnt(0)
	global_store_b32 v1, v0, s[0:1]
.LBB0_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z20global_reduce_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 10
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z20global_reduce_kernelPiS_i, .Lfunc_end0-_Z20global_reduce_kernelPiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 372
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 10
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z19shmem_reduce_kernelPiS_i ; -- Begin function _Z19shmem_reduce_kernelPiS_i
	.globl	_Z19shmem_reduce_kernelPiS_i
	.p2align	8
	.type	_Z19shmem_reduce_kernelPiS_i,@function
_Z19shmem_reduce_kernelPiS_i:           ; @_Z19shmem_reduce_kernelPiS_i
; %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[1:2], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s6, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v2, vcc_lo
	global_load_b32 v2, v[1:2], off
	v_lshl_add_u32 v1, v0, 2, 0
	s_waitcnt vmcnt(0)
	v_cvt_f32_i32_e32 v2, v2
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_7
; %bb.1:                                ; %.lr.ph
	s_load_b32 s1, s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, s1, v0
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s6, s3
	s_lshr_b32 s3, s3, 1
	s_mov_b32 s7, exec_lo
	v_cmpx_gt_u32_e64 s3, v0
	s_cbranch_execz .LBB1_6
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_nc_u32_e32 v2, s3, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_u32_e64 s0, s1, v2
	s_and_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB1_6
; %bb.4:                                ;   in Loop: Header=BB1_2 Depth=1
	v_lshl_add_u32 v2, s3, 2, v1
	ds_load_b32 v3, v1
	ds_load_b32 v2, v2
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_f32_e64 s0, v3, v2
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB1_6
; %bb.5:                                ;   in Loop: Header=BB1_2 Depth=1
	ds_store_b32 v1, v2
.LBB1_6:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s7
	s_cmp_lt_u32 s6, 4
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB1_2
.LBB1_7:                                ; %._crit_edge
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB1_9
; %bb.8:
	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)
	v_cvt_i32_f32_e32 v1, v1
	global_store_b32 v0, v1, s[0:1]
.LBB1_9:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19shmem_reduce_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 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_end1:
	.size	_Z19shmem_reduce_kernelPiS_i, .Lfunc_end1-_Z19shmem_reduce_kernelPiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 364
; 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
	.protected	_Z12getlastdigitPiS_i   ; -- Begin function _Z12getlastdigitPiS_i
	.globl	_Z12getlastdigitPiS_i
	.p2align	8
	.type	_Z12getlastdigitPiS_i,@function
_Z12getlastdigitPiS_i:                  ; @_Z12getlastdigitPiS_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_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	v_mul_hi_i32 v3, 0x66666667, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v4, 31, v3
	v_ashrrev_i32_e32 v3, 2, v3
	v_add_nc_u32_e32 v3, v3, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, v3, 10
	v_sub_nc_u32_e32 v2, v2, v3
	global_store_b32 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 _Z12getlastdigitPiS_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 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_end2:
	.size	_Z12getlastdigitPiS_i, .Lfunc_end2-_Z12getlastdigitPiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 192
; 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
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         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:           _Z20global_reduce_kernelPiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z20global_reduce_kernelPiS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .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_kernelPiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19shmem_reduce_kernelPiS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .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:           _Z12getlastdigitPiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12getlastdigitPiS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
