#include<stdio.h>
#include<assert.h>
#include<cuda.h>
#include<errno.h>
#include<math.h>
#include<sys/time.h>
#define MAX_VAL 10
#define BLOCK_WIDTH 256
#define MAX_SIZE 2048*2048*2
cudaError_t cuerr;
float* createArray(int size)
{
    float *temp;
    int err=0;
    errno = 0;
    temp = (float*) malloc (sizeof(float)*size);
    err = errno;
    if(err)
        printf("Error: %s, %d, %s", __FILE__, __LINE__, strerror(err));
    return temp;
}

void destroyArray(float* p)
{
    free(p);
}

void initArray(float* p, int size)
{
    for(int i=0; i<size; i++)
        p[i] =  rand()%MAX_VAL;
}

void copyArray(float *p, float *q, int size)
{
    for(int i=0;i<size;i++)
        q[i]=p[i];
}

void printArray(float *p, int size)
{
    printf("\n");
    for( int i=0; i< size; i++)
        printf("%4.2f ",p[i]);
}

void reduce(float* p, int size)
{
    for( size_t j=1;j<=size/2;j*=2)
    {
        for( size_t i=0;i<size/2;i++)
        {
            size_t ind = 2*i*j;
            if(ind < size)
                p[ind] = p[ind]+p[ind+j];
        }
        printArray(p,10);
    }
}

void reduce2(float* p, int size)
{
    for( size_t j=size/2;j>0;j/=2)
    {
        for( size_t i=0;i<size/2;i++)
        {
            if(i+j < size)
                p[i] = p[i]+p[i+j];
        }
    }
}

void createArrayDevice(float **p, int size)
{
    cuerr = cudaSuccess;
    cuerr = cudaMalloc(p, sizeof(float)*size);
    if (cuerr != cudaSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, cudaGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

void transferToDevice(float *hostptr, float *deviceptr, int size)
{
    cuerr = cudaSuccess;
    cuerr = cudaMemcpy(deviceptr, hostptr, sizeof(float)*size, cudaMemcpyHostToDevice);
    if (cuerr != cudaSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, cudaGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

void transferFromDevice(float *hostptr, float *deviceptr, int size)
{
    cuerr = cudaSuccess;
    cuerr = cudaMemcpy(hostptr, deviceptr, sizeof(float)*size, cudaMemcpyDeviceToHost);
    if (cuerr != cudaSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, cudaGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

    __global__
void reduceKernel(float *p, int size, float *con)
{
    __shared__ float localblock[BLOCK_WIDTH*2];
    int tx = threadIdx.x;
    int in = blockIdx.x * blockDim.x + tx;
    localblock[tx*2] = p[in*2];
    localblock[tx*2+1] = p[in*2+1];
    __syncthreads();

    for( int it=1; it<= (BLOCK_WIDTH*2)/2; it*=2)
    {
        int ind = 2 * tx * it;
        if(ind < blockDim.x*2)
            localblock[ind] = localblock[ind]+localblock[ind+it];
        __syncthreads();
    }
    p[in]=localblock[tx];
    if(tx == 0) con[blockIdx.x] = localblock[tx];
}

void preduce(float *p, int size, float *con)
{
    //dim3 gridProp(ceil(size/(BLOCK_WIDTH*2)),1,1);
    dim3 gridProp((int)ceil(size/(BLOCK_WIDTH*2)),1,1);
    dim3 blockProp(BLOCK_WIDTH,1,1);
    printf("\nRunnig Kernel with %d thpb, %d bpg\n", BLOCK_WIDTH, (int)ceil(size/(BLOCK_WIDTH*2)));
    cuerr = cudaSuccess;
    reduceKernel<<<gridProp,blockProp>>>(p, size, con);
    if (cuerr != cudaSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, cudaGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

    __global__
void reduceKernel2(float *p, int size)
{
    __shared__ float localblock[BLOCK_WIDTH*2];
    int tx = blockIdx.x * blockDim.x + threadIdx.x;
    localblock[tx*2] = p[tx*2];
    localblock[tx*2+1] = p[tx*2+1];
    __syncthreads();

    for( int it=size/2; it>0; it/=2)
    {
        if(tx+it < blockDim.x*2)
            localblock[tx] = localblock[tx]+localblock[tx+it];
        __syncthreads();
    }
    p[tx] = localblock[tx]; 
}

void preduce2(float *p, int size)
{
    //dim3 gridProp(ceil(size/(BLOCK_WIDTH*2)),1,1);
    dim3 gridProp(1,1,1);
    dim3 blockProp(BLOCK_WIDTH,1,1);
    printf("Runnig Kernel with %d thpb, %d bpg\n", BLOCK_WIDTH, (int)ceil(size/(BLOCK_WIDTH*2)));
    cuerr = cudaSuccess;
    reduceKernel2<<<gridProp,blockProp>>>(p, size);
    if (cuerr != cudaSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, cudaGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

int main()
{
    float *A,*B,*C;
    int Asize = MAX_SIZE;
    struct timeval as,ae,bs,be,ad,bd; 
    cudaEvent_t custart, cuend;
    float timeelap;
    cudaEventCreate(&custart);
    cudaEventCreate(&cuend);

    float *container;
    int csize = (MAX_SIZE/(BLOCK_WIDTH*2));

        
    A = createArray(Asize);
    assert(A != NULL);
    B = createArray(Asize);
    assert(B != NULL);
    C = createArray(Asize);
    assert(C != NULL);
    container = createArray(csize);
    assert(container != NULL);

    for( int i=0;i<csize;i++)
        container[i] = 0; 

    initArray(A, Asize);
    copyArray(A, B, Asize);
    copyArray(A, C, Asize); 

    gettimeofday(&as,NULL);
    reduce(A, Asize);
    gettimeofday(&ae,NULL);
    //printf("\nA[0] is %f\n",A[0]);
    //printArray(A, Asize);

    gettimeofday(&bs,NULL);
    reduce2(B, Asize);
    gettimeofday(&be,NULL);
    //printf("\nB[0] is %f\n",B[0]);

    float *dA, *dB, *dcont;
    createArrayDevice(&dA, Asize);
    createArrayDevice(&dcont, csize);

    printArray(C,10);
    cudaEventRecord(custart);
    transferToDevice(C, dA, Asize);
    preduce(dA, Asize, dcont);
    cudaEventRecord(cuend);

    cudaEventSynchronize(cuend);
    cudaDeviceSynchronize();

    cudaEventElapsedTime(&timeelap, custart, cuend);
    transferFromDevice(C, dA, Asize);
    transferFromDevice(container, dcont, csize);

    printf("\n[");
    float finsum=0;
    for( int i=0;i<csize;i++)
        finsum += (float)container[i];
        printf("%f", finsum);
    printf("]\n");
    printArray(C,10);
    printf("\nC[0] is %f\n",C[0]);

    destroyArray(A);
    destroyArray(B);

    timersub(&ae, &as, &ad);
    timersub(&be, &bs, &bd);

    printf(" %f reduce\n", (float)(ad.tv_sec*1000)+(ad.tv_usec/1000));
    printf(" %f reduce2\n",(float)(bd.tv_sec*1000)+(bd.tv_usec/1000));
    printf(" %f preduce2\n", timeelap);
    return 0;
}
/*
   If the array size spans multiple blocks
   create MAX_SIZE/BLOCK_WIDTH array
   This array will store value from each block
   rerun reduction on this array or use CPU to calcualte the final value 
 */

	.file	"tmpxft_0022d0fb_00000000-6_reduction.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2042:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2042:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/indrajeet307/CudaExperiments/master/reduce/reduction.cu"
.LC1:
	.string	"Error: %s, %d, %s"
	.text
	.globl	_Z11createArrayi
	.type	_Z11createArrayi, @function
_Z11createArrayi:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 32
	call	__errno_location@PLT
	xorl	%esi, %esi
	movslq	%ebx, %rdi
	movl	%esi, (%rax)
	movq	%rax, %rbp
	salq	$2, %rdi
	call	malloc@PLT
	movl	0(%rbp), %edi
	movq	%rax, %rbx
	testl	%edi, %edi
	je	.L2
	call	strerror@PLT
	movl	$19, %ecx
	movl	$2, %edi
	leaq	.LC0(%rip), %rdx
	movq	%rax, %r8
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L2:
	movq	%rbx, %rax
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z11createArrayi, .-_Z11createArrayi
	.globl	_Z12destroyArrayPf
	.type	_Z12destroyArrayPf, @function
_Z12destroyArrayPf:
.LFB2028:
	.cfi_startproc
	endbr64
	jmp	free@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z12destroyArrayPf, .-_Z12destroyArrayPf
	.globl	_Z9initArrayPfi
	.type	_Z9initArrayPfi, @function
_Z9initArrayPfi:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$10, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rdx
	.cfi_def_cfa_offset 48
.L11:
	cmpl	%ebx, %ebp
	jle	.L14
	call	rand@PLT
	cltd
	idivl	%r13d
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L11
.L14:
	popq	%rax
	.cfi_def_cfa_offset 40
	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	_Z9initArrayPfi, .-_Z9initArrayPfi
	.globl	_Z9copyArrayPfS_i
	.type	_Z9copyArrayPfS_i, @function
_Z9copyArrayPfS_i:
.LFB2030:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L16:
	cmpl	%eax, %edx
	jle	.L18
	movss	(%rdi,%rax,4), %xmm0
	movss	%xmm0, (%rsi,%rax,4)
	incq	%rax
	jmp	.L16
.L18:
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z9copyArrayPfS_i, .-_Z9copyArrayPfS_i
	.section	.rodata.str1.1
.LC2:
	.string	"\n"
.LC3:
	.string	"%4.2f "
	.text
	.globl	_Z10printArrayPfi
	.type	_Z10printArrayPfi, @function
_Z10printArrayPfi:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%eax, %eax
	leaq	.LC3(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	movl	$2, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%esi, %ebp
	leaq	.LC2(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rdx
	.cfi_def_cfa_offset 48
	call	__printf_chk@PLT
.L20:
	cmpl	%ebx, %ebp
	jle	.L23
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%r12,%rbx,4), %xmm0
	call	__printf_chk@PLT
	incq	%rbx
	jmp	.L20
.L23:
	popq	%rax
	.cfi_def_cfa_offset 40
	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
.LFE2031:
	.size	_Z10printArrayPfi, .-_Z10printArrayPfi
	.globl	_Z6reducePfi
	.type	_Z6reducePfi, @function
_Z6reducePfi:
.LFB2032:
	.cfi_startproc
	endbr64
	movl	%esi, %eax
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$2, %ecx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movslq	%esi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 48
	cltd
	idivl	%ecx
	movl	$1, %edx
	movslq	%eax, %r12
.L25:
	cmpq	%rdx, %r12
	jb	.L24
	leaq	0(,%rdx,8), %rdi
	movq	%rbp, %rcx
	xorl	%esi, %esi
	xorl	%eax, %eax
	leaq	(%rdx,%rdx), %r13
.L29:
	cmpq	%r12, %rax
	jnb	.L31
	cmpq	%rbx, %rsi
	jnb	.L26
	movss	(%rcx), %xmm0
	addss	(%rcx,%rdx,4), %xmm0
	movss	%xmm0, (%rcx)
.L26:
	incq	%rax
	addq	%rdi, %rcx
	addq	%r13, %rsi
	jmp	.L29
.L31:
	movl	$10, %esi
	movq	%rbp, %rdi
	call	_Z10printArrayPfi
	movq	%r13, %rdx
	jmp	.L25
.L24:
	popq	%rax
	.cfi_def_cfa_offset 40
	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
.LFE2032:
	.size	_Z6reducePfi, .-_Z6reducePfi
	.globl	_Z7reduce2Pfi
	.type	_Z7reduce2Pfi, @function
_Z7reduce2Pfi:
.LFB2033:
	.cfi_startproc
	endbr64
	movl	%esi, %eax
	movl	$2, %ecx
	movslq	%esi, %rsi
	cltd
	idivl	%ecx
	cltq
	movq	%rax, %rcx
.L33:
	testq	%rcx, %rcx
	je	.L38
	movq	%rcx, %r8
	xorl	%edx, %edx
.L36:
	cmpq	%rax, %rdx
	jnb	.L39
	cmpq	%rsi, %r8
	jnb	.L34
	movss	(%rdi,%rdx,4), %xmm0
	addss	(%rdi,%r8,4), %xmm0
	movss	%xmm0, (%rdi,%rdx,4)
.L34:
	incq	%rdx
	incq	%r8
	jmp	.L36
.L39:
	shrq	%rcx
	jmp	.L33
.L38:
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z7reduce2Pfi, .-_Z7reduce2Pfi
	.section	.rodata.str1.1
.LC4:
	.string	"%s, %d.\n %s."
	.text
	.globl	_Z17createArrayDevicePPfi
	.type	_Z17createArrayDevicePPfi, @function
_Z17createArrayDevicePPfi:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%rdx
	.cfi_def_cfa_offset 16
	movslq	%esi, %rsi
	xorl	%ecx, %ecx
	salq	$2, %rsi
	movl	%ecx, cuerr(%rip)
	call	cudaMalloc@PLT
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	je	.L40
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$79, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L40:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z17createArrayDevicePPfi, .-_Z17createArrayDevicePPfi
	.globl	_Z16transferToDevicePfS_i
	.type	_Z16transferToDevicePfS_i, @function
_Z16transferToDevicePfS_i:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%rcx
	.cfi_def_cfa_offset 16
	movq	%rdi, %rax
	movslq	%edx, %rdx
	movq	%rsi, %rdi
	xorl	%esi, %esi
	salq	$2, %rdx
	movl	$1, %ecx
	movl	%esi, cuerr(%rip)
	movq	%rax, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	je	.L43
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$90, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L43:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2035:
	.size	_Z16transferToDevicePfS_i, .-_Z16transferToDevicePfS_i
	.globl	_Z18transferFromDevicePfS_i
	.type	_Z18transferFromDevicePfS_i, @function
_Z18transferFromDevicePfS_i:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%rcx
	.cfi_def_cfa_offset 16
	movslq	%edx, %rdx
	xorl	%r8d, %r8d
	movl	$2, %ecx
	salq	$2, %rdx
	movl	%r8d, cuerr(%rip)
	call	cudaMemcpy@PLT
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	je	.L46
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$101, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L46:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z18transferFromDevicePfS_i, .-_Z18transferFromDevicePfS_i
	.globl	_Z35__device_stub__Z12reduceKernelPfiS_PfiS_
	.type	_Z35__device_stub__Z12reduceKernelPfiS_PfiS_, @function
_Z35__device_stub__Z12reduceKernelPfiS_PfiS_:
.LFB2064:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L49
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z12reduceKernelPfiS_(%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
.L49:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L51
	call	__stack_chk_fail@PLT
.L51:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2064:
	.size	_Z35__device_stub__Z12reduceKernelPfiS_PfiS_, .-_Z35__device_stub__Z12reduceKernelPfiS_PfiS_
	.globl	_Z12reduceKernelPfiS_
	.type	_Z12reduceKernelPfiS_, @function
_Z12reduceKernelPfiS_:
.LFB2065:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z12reduceKernelPfiS_PfiS_
	.cfi_endproc
.LFE2065:
	.size	_Z12reduceKernelPfiS_, .-_Z12reduceKernelPfiS_
	.section	.rodata.str1.1
.LC5:
	.string	"\nRunnig Kernel with %d thpb, %d bpg\n"
	.text
	.globl	_Z7preducePfiS_
	.type	_Z7preducePfiS_, @function
_Z7preducePfiS_:
.LFB2037:
	.cfi_startproc
	endbr64
	movl	%esi, %eax
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$512, %ecx
	movq	%rdx, %r12
	cltd
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	movl	$2, %edi
	idivl	%ecx
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	movl	$256, %edx
	movl	%esi, %ebx
	leaq	.LC5(%rip), %rsi
	movl	$1, 28(%rsp)
	movl	%eax, %ecx
	movl	%eax, 8(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 12(%rsp)
	addq	$255, %rax
	movq	%rax, 20(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	28(%rsp), %ecx
	movq	20(%rsp), %rdx
	xorl	%eax, %eax
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%eax, cuerr(%rip)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L55
	movq	%r12, %rdx
	movl	%ebx, %esi
	movq	%rbp, %rdi
	call	_Z35__device_stub__Z12reduceKernelPfiS_PfiS_
.L55:
	movl	cuerr(%rip), %edi
	testl	%edi, %edi
	je	.L54
	call	cudaGetErrorString@PLT
	movl	$137, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L54:
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2037:
	.size	_Z7preducePfiS_, .-_Z7preducePfiS_
	.section	.rodata.str1.1
.LC7:
	.string	"\n["
.LC8:
	.string	"%f"
.LC9:
	.string	"]\n"
.LC10:
	.string	"\nC[0] is %f\n"
.LC11:
	.string	" %f reduce\n"
.LC12:
	.string	" %f reduce2\n"
.LC13:
	.string	" %f preduce2\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2039:
	.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
	subq	$120, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$8388608, %edi
	call	_Z11createArrayi
	movl	$8388608, %edi
	movq	%rax, %rbp
	call	_Z11createArrayi
	movl	$8388608, %edi
	movq	%rax, %r13
	call	_Z11createArrayi
	movl	$16384, %edi
	movq	%rax, %rbx
	call	_Z11createArrayi
	movl	$16384, %ecx
	movl	$8388608, %esi
	movq	%rax, %r12
	xorl	%eax, %eax
	movq	%r12, %rdi
	rep stosl
	movq	%rbp, %rdi
	call	_Z9initArrayPfi
	movl	$8388608, %edx
	movq	%rbp, %rdi
	movq	%r13, %rsi
	call	_Z9copyArrayPfS_i
	movq	%rbx, %rsi
	call	_Z9copyArrayPfS_i
	xorl	%esi, %esi
	leaq	40(%rsp), %rdi
	call	gettimeofday@PLT
	movl	$8388608, %esi
	movq	%rbp, %rdi
	call	_Z6reducePfi
	xorl	%esi, %esi
	leaq	56(%rsp), %rdi
	call	gettimeofday@PLT
	xorl	%esi, %esi
	leaq	72(%rsp), %rdi
	call	gettimeofday@PLT
	movl	$8388608, %esi
	movq	%r13, %rdi
	call	_Z7reduce2Pfi
	xorl	%esi, %esi
	leaq	88(%rsp), %rdi
	call	gettimeofday@PLT
	leaq	24(%rsp), %rdi
	movl	$8388608, %esi
	call	_Z17createArrayDevicePPfi
	leaq	32(%rsp), %rdi
	movl	$16384, %esi
	call	_Z17createArrayDevicePPfi
	movl	$10, %esi
	movq	%rbx, %rdi
	call	_Z10printArrayPfi
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	24(%rsp), %rsi
	movl	$8388608, %edx
	movq	%rbx, %rdi
	call	_Z16transferToDevicePfS_i
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	$8388608, %esi
	call	_Z7preducePfiS_
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	16(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	call	cudaDeviceSynchronize@PLT
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	leaq	4(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	24(%rsp), %rsi
	movl	$8388608, %edx
	movq	%rbx, %rdi
	call	_Z18transferFromDevicePfS_i
	movq	32(%rsp), %rsi
	movl	$16384, %edx
	movq	%r12, %rdi
	call	_Z18transferFromDevicePfS_i
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L59:
	addss	(%r12,%rax,4), %xmm0
	incq	%rax
	cmpq	$16384, %rax
	jne	.L59
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$10, %esi
	movq	%rbx, %rdi
	call	_Z10printArrayPfi
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC10(%rip), %rsi
	cvtss2sd	(%rbx), %xmm0
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	56(%rsp), %rdx
	movq	64(%rsp), %rax
	subq	40(%rsp), %rdx
	subq	48(%rsp), %rax
	jns	.L60
	decq	%rdx
	addq	$1000000, %rax
.L60:
	movq	88(%rsp), %r12
	movq	96(%rsp), %rbx
	subq	72(%rsp), %r12
	subq	80(%rsp), %rbx
	jns	.L61
	decq	%r12
	addq	$1000000, %rbx
.L61:
	imulq	$1000, %rdx, %rdx
	movl	$1000, %ebp
	movl	$2, %edi
	leaq	.LC11(%rip), %rsi
	cvtsi2ssq	%rdx, %xmm0
	cqto
	idivq	%rbp
	cvtsi2ssq	%rax, %xmm1
	movb	$1, %al
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	imulq	$1000, %r12, %rax
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	cvtsi2ssq	%rax, %xmm0
	movq	%rbx, %rax
	cqto
	idivq	%rbp
	cvtsi2ssq	%rax, %xmm1
	movb	$1, %al
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	leaq	.LC13(%rip), %rsi
	movb	$1, %al
	cvtss2sd	4(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L62
	call	__stack_chk_fail@PLT
.L62:
	addq	$120, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.LFE2039:
	.size	main, .-main
	.text
	.globl	_Z34__device_stub__Z13reduceKernel2PfiPfi
	.type	_Z34__device_stub__Z13reduceKernel2PfiPfi, @function
_Z34__device_stub__Z13reduceKernel2PfiPfi:
.LFB2066:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L65
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z13reduceKernel2Pfi(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L65:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L67
	call	__stack_chk_fail@PLT
.L67:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2066:
	.size	_Z34__device_stub__Z13reduceKernel2PfiPfi, .-_Z34__device_stub__Z13reduceKernel2PfiPfi
	.globl	_Z13reduceKernel2Pfi
	.type	_Z13reduceKernel2Pfi, @function
_Z13reduceKernel2Pfi:
.LFB2067:
	.cfi_startproc
	endbr64
	jmp	_Z34__device_stub__Z13reduceKernel2PfiPfi
	.cfi_endproc
.LFE2067:
	.size	_Z13reduceKernel2Pfi, .-_Z13reduceKernel2Pfi
	.section	.rodata.str1.1
.LC14:
	.string	"Runnig Kernel with %d thpb, %d bpg\n"
	.text
	.globl	_Z8preduce2Pfi
	.type	_Z8preduce2Pfi, @function
_Z8preduce2Pfi:
.LFB2038:
	.cfi_startproc
	endbr64
	movabsq	$4294967297, %rax
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	$512, %ecx
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	$2, %edi
	movl	%esi, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 64
	movq	%rax, 8(%rsp)
	addq	$255, %rax
	movq	%rax, 20(%rsp)
	movl	%esi, %eax
	leaq	.LC14(%rip), %rsi
	cltd
	movl	$1, 16(%rsp)
	idivl	%ecx
	movl	$1, 28(%rsp)
	movl	$256, %edx
	movl	%eax, %ecx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	28(%rsp), %ecx
	movq	20(%rsp), %rdx
	xorl	%eax, %eax
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%eax, cuerr(%rip)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L71
	movl	%ebx, %esi
	movq	%rbp, %rdi
	call	_Z34__device_stub__Z13reduceKernel2PfiPfi
.L71:
	movl	cuerr(%rip), %edi
	testl	%edi, %edi
	je	.L70
	call	cudaGetErrorString@PLT
	movl	$170, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L70:
	addq	$40, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2038:
	.size	_Z8preduce2Pfi, .-_Z8preduce2Pfi
	.section	.rodata.str1.1
.LC15:
	.string	"_Z13reduceKernel2Pfi"
.LC16:
	.string	"_Z12reduceKernelPfiS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2069:
	.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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z13reduceKernel2Pfi(%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	.LC16(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z12reduceKernelPfiS_(%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
.LFE2069:
	.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
	.globl	cuerr
	.bss
	.align 4
	.type	cuerr, @object
	.size	cuerr, 4
cuerr:
	.zero	4
	.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<assert.h>
#include<hip/hip_runtime.h>
#include<errno.h>
#include<math.h>
#include<sys/time.h>
#define MAX_VAL 10
#define BLOCK_WIDTH 256
#define MAX_SIZE 2048*2048*2
hipError_t cuerr;
float* createArray(int size)
{
    float *temp;
    int err=0;
    errno = 0;
    temp = (float*) malloc (sizeof(float)*size);
    err = errno;
    if(err)
        printf("Error: %s, %d, %s", __FILE__, __LINE__, strerror(err));
    return temp;
}

void destroyArray(float* p)
{
    free(p);
}

void initArray(float* p, int size)
{
    for(int i=0; i<size; i++)
        p[i] =  rand()%MAX_VAL;
}

void copyArray(float *p, float *q, int size)
{
    for(int i=0;i<size;i++)
        q[i]=p[i];
}

void printArray(float *p, int size)
{
    printf("\n");
    for( int i=0; i< size; i++)
        printf("%4.2f ",p[i]);
}

void reduce(float* p, int size)
{
    for( size_t j=1;j<=size/2;j*=2)
    {
        for( size_t i=0;i<size/2;i++)
        {
            size_t ind = 2*i*j;
            if(ind < size)
                p[ind] = p[ind]+p[ind+j];
        }
        printArray(p,10);
    }
}

void reduce2(float* p, int size)
{
    for( size_t j=size/2;j>0;j/=2)
    {
        for( size_t i=0;i<size/2;i++)
        {
            if(i+j < size)
                p[i] = p[i]+p[i+j];
        }
    }
}

void createArrayDevice(float **p, int size)
{
    cuerr = hipSuccess;
    cuerr = hipMalloc(p, sizeof(float)*size);
    if (cuerr != hipSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, hipGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

void transferToDevice(float *hostptr, float *deviceptr, int size)
{
    cuerr = hipSuccess;
    cuerr = hipMemcpy(deviceptr, hostptr, sizeof(float)*size, hipMemcpyHostToDevice);
    if (cuerr != hipSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, hipGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

void transferFromDevice(float *hostptr, float *deviceptr, int size)
{
    cuerr = hipSuccess;
    cuerr = hipMemcpy(hostptr, deviceptr, sizeof(float)*size, hipMemcpyDeviceToHost);
    if (cuerr != hipSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, hipGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

    __global__
void reduceKernel(float *p, int size, float *con)
{
    __shared__ float localblock[BLOCK_WIDTH*2];
    int tx = threadIdx.x;
    int in = blockIdx.x * blockDim.x + tx;
    localblock[tx*2] = p[in*2];
    localblock[tx*2+1] = p[in*2+1];
    __syncthreads();

    for( int it=1; it<= (BLOCK_WIDTH*2)/2; it*=2)
    {
        int ind = 2 * tx * it;
        if(ind < blockDim.x*2)
            localblock[ind] = localblock[ind]+localblock[ind+it];
        __syncthreads();
    }
    p[in]=localblock[tx];
    if(tx == 0) con[blockIdx.x] = localblock[tx];
}

void preduce(float *p, int size, float *con)
{
    //dim3 gridProp(ceil(size/(BLOCK_WIDTH*2)),1,1);
    dim3 gridProp((int)ceil(size/(BLOCK_WIDTH*2)),1,1);
    dim3 blockProp(BLOCK_WIDTH,1,1);
    printf("\nRunnig Kernel with %d thpb, %d bpg\n", BLOCK_WIDTH, (int)ceil(size/(BLOCK_WIDTH*2)));
    cuerr = hipSuccess;
    reduceKernel<<<gridProp,blockProp>>>(p, size, con);
    if (cuerr != hipSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, hipGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

    __global__
void reduceKernel2(float *p, int size)
{
    __shared__ float localblock[BLOCK_WIDTH*2];
    int tx = blockIdx.x * blockDim.x + threadIdx.x;
    localblock[tx*2] = p[tx*2];
    localblock[tx*2+1] = p[tx*2+1];
    __syncthreads();

    for( int it=size/2; it>0; it/=2)
    {
        if(tx+it < blockDim.x*2)
            localblock[tx] = localblock[tx]+localblock[tx+it];
        __syncthreads();
    }
    p[tx] = localblock[tx]; 
}

void preduce2(float *p, int size)
{
    //dim3 gridProp(ceil(size/(BLOCK_WIDTH*2)),1,1);
    dim3 gridProp(1,1,1);
    dim3 blockProp(BLOCK_WIDTH,1,1);
    printf("Runnig Kernel with %d thpb, %d bpg\n", BLOCK_WIDTH, (int)ceil(size/(BLOCK_WIDTH*2)));
    cuerr = hipSuccess;
    reduceKernel2<<<gridProp,blockProp>>>(p, size);
    if (cuerr != hipSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, hipGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

int main()
{
    float *A,*B,*C;
    int Asize = MAX_SIZE;
    struct timeval as,ae,bs,be,ad,bd; 
    hipEvent_t custart, cuend;
    float timeelap;
    hipEventCreate(&custart);
    hipEventCreate(&cuend);

    float *container;
    int csize = (MAX_SIZE/(BLOCK_WIDTH*2));

        
    A = createArray(Asize);
    assert(A != NULL);
    B = createArray(Asize);
    assert(B != NULL);
    C = createArray(Asize);
    assert(C != NULL);
    container = createArray(csize);
    assert(container != NULL);

    for( int i=0;i<csize;i++)
        container[i] = 0; 

    initArray(A, Asize);
    copyArray(A, B, Asize);
    copyArray(A, C, Asize); 

    gettimeofday(&as,NULL);
    reduce(A, Asize);
    gettimeofday(&ae,NULL);
    //printf("\nA[0] is %f\n",A[0]);
    //printArray(A, Asize);

    gettimeofday(&bs,NULL);
    reduce2(B, Asize);
    gettimeofday(&be,NULL);
    //printf("\nB[0] is %f\n",B[0]);

    float *dA, *dB, *dcont;
    createArrayDevice(&dA, Asize);
    createArrayDevice(&dcont, csize);

    printArray(C,10);
    hipEventRecord(custart);
    transferToDevice(C, dA, Asize);
    preduce(dA, Asize, dcont);
    hipEventRecord(cuend);

    hipEventSynchronize(cuend);
    hipDeviceSynchronize();

    hipEventElapsedTime(&timeelap, custart, cuend);
    transferFromDevice(C, dA, Asize);
    transferFromDevice(container, dcont, csize);

    printf("\n[");
    float finsum=0;
    for( int i=0;i<csize;i++)
        finsum += (float)container[i];
        printf("%f", finsum);
    printf("]\n");
    printArray(C,10);
    printf("\nC[0] is %f\n",C[0]);

    destroyArray(A);
    destroyArray(B);

    timersub(&ae, &as, &ad);
    timersub(&be, &bs, &bd);

    printf(" %f reduce\n", (float)(ad.tv_sec*1000)+(ad.tv_usec/1000));
    printf(" %f reduce2\n",(float)(bd.tv_sec*1000)+(bd.tv_usec/1000));
    printf(" %f preduce2\n", timeelap);
    return 0;
}
/*
   If the array size spans multiple blocks
   create MAX_SIZE/BLOCK_WIDTH array
   This array will store value from each block
   rerun reduction on this array or use CPU to calcualte the final value 
 */

	.text
	.file	"reduction.hip"
	.globl	_Z11createArrayi                # -- Begin function _Z11createArrayi
	.type	_Z11createArrayi,@function
_Z11createArrayi:                       # @_Z11createArrayi
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edi, %ebx
	callq	__errno_location
	movl	$0, (%rax)
	movslq	%ebx, %rdi
	shlq	$2, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	malloc                          # TAILCALL
.Lfunc_end0:
	.size	_Z11createArrayi, .Lfunc_end0-_Z11createArrayi
	.cfi_endproc
                                        # -- End function
	.globl	_Z12destroyArrayPf              # -- Begin function _Z12destroyArrayPf
	.type	_Z12destroyArrayPf,@function
_Z12destroyArrayPf:                     # @_Z12destroyArrayPf
	.cfi_startproc
# %bb.0:
	jmp	free                            # TAILCALL
.Lfunc_end1:
	.size	_Z12destroyArrayPf, .Lfunc_end1-_Z12destroyArrayPf
	.cfi_endproc
                                        # -- End function
	.globl	_Z9initArrayPfi                 # -- Begin function _Z9initArrayPfi
	.type	_Z9initArrayPfi,@function
_Z9initArrayPfi:                        # @_Z9initArrayPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB2_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB2_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB2_4:                                # %._crit_edge
	retq
.Lfunc_end2:
	.size	_Z9initArrayPfi, .Lfunc_end2-_Z9initArrayPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z9copyArrayPfS_i               # -- Begin function _Z9copyArrayPfS_i
	.type	_Z9copyArrayPfS_i,@function
_Z9copyArrayPfS_i:                      # @_Z9copyArrayPfS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB3_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%edx, %eax
	xorl	%ecx, %ecx
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rsi,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB3_2
.LBB3_3:                                # %._crit_edge
	retq
.Lfunc_end3:
	.size	_Z9copyArrayPfS_i, .Lfunc_end3-_Z9copyArrayPfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z10printArrayPfi               # -- Begin function _Z10printArrayPfi
	.type	_Z10printArrayPfi,@function
_Z10printArrayPfi:                      # @_Z10printArrayPfi
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movq	%rdi, %rbx
	movl	$10, %edi
	callq	putchar@PLT
	testl	%ebp, %ebp
	jle	.LBB4_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r14d
	xorl	%r15d, %r15d
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r15,4), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB4_2
.LBB4_3:                                # %._crit_edge
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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_end4:
	.size	_Z10printArrayPfi, .Lfunc_end4-_Z10printArrayPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z6reducePfi                    # -- Begin function _Z6reducePfi
	.type	_Z6reducePfi,@function
_Z6reducePfi:                           # @_Z6reducePfi
	.cfi_startproc
# %bb.0:
                                        # kill: def $esi killed $esi def $rsi
	leal	1(%rsi), %eax
	cmpl	$3, %eax
	jb	.LBB5_8
# %bb.1:                                # %.preheader.lr.ph
	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	%esi, %eax
	shrl	$31, %eax
	addl	%esi, %eax
	sarl	%eax
	movslq	%eax, %r14
	movslq	%esi, %r15
	cmpq	$1, %r14
	movq	%r14, %r12
	adcq	$0, %r12
	movl	$1, %r13d
.LBB5_2:                                # %.lr.ph.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_3 Depth 2
	leaq	(%rbx,%r13,4), %rax
	addq	%r13, %r13
	xorl	%ecx, %ecx
	movq	%r12, %rdx
.LBB5_3:                                # %.lr.ph
                                        #   Parent Loop BB5_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpq	%r15, %rcx
	jae	.LBB5_5
# %bb.4:                                #   in Loop: Header=BB5_3 Depth=2
	movss	(%rbx,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	addss	(%rax,%rcx,4), %xmm0
	movss	%xmm0, (%rbx,%rcx,4)
.LBB5_5:                                #   in Loop: Header=BB5_3 Depth=2
	addq	%r13, %rcx
	decq	%rdx
	jne	.LBB5_3
# %bb.6:                                # %._crit_edge
                                        #   in Loop: Header=BB5_2 Depth=1
	movq	%rbx, %rdi
	movl	$10, %esi
	callq	_Z10printArrayPfi
	cmpq	%r14, %r13
	jbe	.LBB5_2
# %bb.7:
	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
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
.LBB5_8:                                # %._crit_edge23
	retq
.Lfunc_end5:
	.size	_Z6reducePfi, .Lfunc_end5-_Z6reducePfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z7reduce2Pfi                   # -- Begin function _Z7reduce2Pfi
	.type	_Z7reduce2Pfi,@function
_Z7reduce2Pfi:                          # @_Z7reduce2Pfi
	.cfi_startproc
# %bb.0:
                                        # kill: def $esi killed $esi def $rsi
	leal	1(%rsi), %eax
	cmpl	$3, %eax
	jb	.LBB6_7
# %bb.1:                                # %.preheader.lr.ph
	movl	%esi, %eax
	shrl	$31, %eax
	addl	%esi, %eax
	sarl	%eax
	movslq	%eax, %rcx
	movslq	%esi, %rax
	cmpq	$1, %rcx
	movq	%rcx, %rdx
	adcq	$0, %rdx
.LBB6_2:                                # %.lr.ph.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_3 Depth 2
	leaq	(%rdi,%rcx,4), %rsi
	xorl	%r8d, %r8d
.LBB6_3:                                # %.lr.ph
                                        #   Parent Loop BB6_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leaq	(%rcx,%r8), %r9
	cmpq	%rax, %r9
	jae	.LBB6_5
# %bb.4:                                #   in Loop: Header=BB6_3 Depth=2
	movss	(%rdi,%r8,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	addss	(%rsi,%r8,4), %xmm0
	movss	%xmm0, (%rdi,%r8,4)
.LBB6_5:                                #   in Loop: Header=BB6_3 Depth=2
	incq	%r8
	cmpq	%r8, %rdx
	jne	.LBB6_3
# %bb.6:                                # %._crit_edge
                                        #   in Loop: Header=BB6_2 Depth=1
	movq	%rcx, %rsi
	shrq	%rsi
	cmpq	$2, %rcx
	movq	%rsi, %rcx
	jae	.LBB6_2
.LBB6_7:                                # %._crit_edge20
	retq
.Lfunc_end6:
	.size	_Z7reduce2Pfi, .Lfunc_end6-_Z7reduce2Pfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z17createArrayDevicePPfi       # -- Begin function _Z17createArrayDevicePPfi
	.type	_Z17createArrayDevicePPfi,@function
_Z17createArrayDevicePPfi:              # @_Z17createArrayDevicePPfi
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	$0, cuerr(%rip)
	movslq	%esi, %rsi
	shlq	$2, %rsi
	callq	hipMalloc
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	jne	.LBB7_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB7_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$79, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end7:
	.size	_Z17createArrayDevicePPfi, .Lfunc_end7-_Z17createArrayDevicePPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z16transferToDevicePfS_i       # -- Begin function _Z16transferToDevicePfS_i
	.type	_Z16transferToDevicePfS_i,@function
_Z16transferToDevicePfS_i:              # @_Z16transferToDevicePfS_i
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rax
	movl	$0, cuerr(%rip)
	movslq	%edx, %rdx
	shlq	$2, %rdx
	movq	%rsi, %rdi
	movq	%rax, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	jne	.LBB8_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB8_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$90, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end8:
	.size	_Z16transferToDevicePfS_i, .Lfunc_end8-_Z16transferToDevicePfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z18transferFromDevicePfS_i     # -- Begin function _Z18transferFromDevicePfS_i
	.type	_Z18transferFromDevicePfS_i,@function
_Z18transferFromDevicePfS_i:            # @_Z18transferFromDevicePfS_i
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	$0, cuerr(%rip)
	movslq	%edx, %rdx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	jne	.LBB9_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB9_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$101, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end9:
	.size	_Z18transferFromDevicePfS_i, .Lfunc_end9-_Z18transferFromDevicePfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z27__device_stub__reduceKernelPfiS_ # -- Begin function _Z27__device_stub__reduceKernelPfiS_
	.type	_Z27__device_stub__reduceKernelPfiS_,@function
_Z27__device_stub__reduceKernelPfiS_:   # @_Z27__device_stub__reduceKernelPfiS_
	.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	12(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	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	$_Z12reduceKernelPfiS_, %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_end10:
	.size	_Z27__device_stub__reduceKernelPfiS_, .Lfunc_end10-_Z27__device_stub__reduceKernelPfiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z7preducePfiS_                 # -- Begin function _Z7preducePfiS_
	.type	_Z7preducePfiS_,@function
_Z7preducePfiS_:                        # @_Z7preducePfiS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %rbx
	movl	%esi, %r14d
	leal	511(%r14), %edx
	testl	%esi, %esi
	cmovnsl	%esi, %edx
	movq	%rdi, %r15
	sarl	$9, %edx
	movq	%rdx, %r12
	btsq	$32, %r12
	movl	$.L.str.5, %edi
	movl	$256, %esi                      # imm = 0x100
                                        # kill: def $edx killed $edx killed $rdx
	xorl	%eax, %eax
	callq	printf
	movl	$0, cuerr(%rip)
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$256, %rdx                      # imm = 0x100
	movq	%r12, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB11_2
# %bb.1:
	movq	%r15, %rdi
	movl	%r14d, %esi
	movq	%rbx, %rdx
	callq	_Z27__device_stub__reduceKernelPfiS_
.LBB11_2:
	movl	cuerr(%rip), %edi
	testl	%edi, %edi
	jne	.LBB11_4
# %bb.3:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB11_4:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rbx
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$137, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end11:
	.size	_Z7preducePfiS_, .Lfunc_end11-_Z7preducePfiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z28__device_stub__reduceKernel2Pfi # -- Begin function _Z28__device_stub__reduceKernel2Pfi
	.type	_Z28__device_stub__reduceKernel2Pfi,@function
_Z28__device_stub__reduceKernel2Pfi:    # @_Z28__device_stub__reduceKernel2Pfi
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z13reduceKernel2Pfi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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_end12:
	.size	_Z28__device_stub__reduceKernel2Pfi, .Lfunc_end12-_Z28__device_stub__reduceKernel2Pfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z8preduce2Pfi                  # -- Begin function _Z8preduce2Pfi
	.type	_Z8preduce2Pfi,@function
_Z8preduce2Pfi:                         # @_Z8preduce2Pfi
	.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
	leal	511(%rbx), %edx
	testl	%esi, %esi
	cmovnsl	%esi, %edx
	sarl	$9, %edx
	movl	$.L.str.6, %edi
	movl	$256, %esi                      # imm = 0x100
	xorl	%eax, %eax
	callq	printf
	movl	$0, cuerr(%rip)
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	leaq	255(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB13_2
# %bb.1:
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_Z28__device_stub__reduceKernel2Pfi
.LBB13_2:
	movl	cuerr(%rip), %edi
	testl	%edi, %edi
	jne	.LBB13_4
# %bb.3:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB13_4:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rbx
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$170, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end13:
	.size	_Z8preduce2Pfi, .Lfunc_end13-_Z8preduce2Pfi
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:                                # %.lr.ph.i.preheader
	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	$120, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	callq	__errno_location
	movq	%rax, %r13
	movl	$33554432, %edi                 # imm = 0x2000000
	callq	malloc
	movq	%rax, %rbx
	movl	$33554432, %edi                 # imm = 0x2000000
	callq	malloc
	movq	%rax, %r14
	movl	$33554432, %edi                 # imm = 0x2000000
	callq	malloc
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movl	$1, %edi
	movl	$65536, %esi                    # imm = 0x10000
	callq	calloc@PLT
	movq	%rax, %r12
	movl	$0, (%r13)
	xorl	%r13d, %r13d
.LBB14_1:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%rbx,%r13,4)
	incq	%r13
	cmpq	$8388608, %r13                  # imm = 0x800000
	jne	.LBB14_1
# %bb.2:                                # %.lr.ph.i54.preheader
	movl	$33554432, %edx                 # imm = 0x2000000
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	memcpy@PLT
	movl	$33554432, %edx                 # imm = 0x2000000
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	%rbx, %rsi
	callq	memcpy@PLT
	leaq	96(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	%rbx, %rdi
	movl	$8388608, %esi                  # imm = 0x800000
	callq	_Z6reducePfi
	leaq	80(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	leaq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	$4194304, %eax                  # imm = 0x400000
.LBB14_3:                               # %.lr.ph.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB14_4 Depth 2
	leaq	(%r14,%rax,4), %rcx
	xorl	%edx, %edx
.LBB14_4:                               #   Parent Loop BB14_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r14,%rdx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	addss	(%rcx,%rdx,4), %xmm0
	movss	%xmm0, (%r14,%rdx,4)
	incq	%rdx
	cmpq	$4194304, %rdx                  # imm = 0x400000
	jne	.LBB14_4
# %bb.5:                                # %._crit_edge.i
                                        #   in Loop: Header=BB14_3 Depth=1
	movq	%rax, %rcx
	shrq	%rcx
	cmpq	$2, %rax
	movq	%rcx, %rax
	jae	.LBB14_3
# %bb.6:                                # %_Z7reduce2Pfi.exit
	xorl	%ebp, %ebp
	leaq	48(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	leaq	112(%rsp), %r15
	movq	%r15, %rdi
	movl	$8388608, %esi                  # imm = 0x800000
	callq	_Z17createArrayDevicePPfi
	leaq	32(%rsp), %rdi
	movl	$16384, %esi                    # imm = 0x4000
	callq	_Z17createArrayDevicePPfi
	movq	8(%rsp), %r13                   # 8-byte Reload
	movq	%r13, %rdi
	movl	$10, %esi
	callq	_Z10printArrayPfi
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r15), %rsi
	movq	%r13, %rdi
	movl	$8388608, %edx                  # imm = 0x800000
	callq	_Z16transferToDevicePfS_i
	movq	(%r15), %rdi
	leaq	32(%rsp), %rax
	movq	(%rax), %rdx
	movl	$8388608, %esi                  # imm = 0x800000
	callq	_Z7preducePfiS_
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	callq	hipDeviceSynchronize
	movq	40(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	28(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	(%r15), %rsi
	movq	%r13, %rdi
	movl	$8388608, %edx                  # imm = 0x800000
	callq	_Z18transferFromDevicePfS_i
	leaq	32(%rsp), %rax
	movq	(%rax), %rsi
	movq	%r12, %rdi
	movl	$16384, %edx                    # imm = 0x4000
	callq	_Z18transferFromDevicePfS_i
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	xorps	%xmm0, %xmm0
.LBB14_7:                               # =>This Inner Loop Header: Depth=1
	addss	(%r12,%rbp,4), %xmm0
	incq	%rbp
	cmpq	$16384, %rbp                    # imm = 0x4000
	jne	.LBB14_7
# %bb.8:
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	8(%rsp), %r15                   # 8-byte Reload
	movq	%r15, %rdi
	movl	$10, %esi
	callq	_Z10printArrayPfi
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str.10, %edi
	movb	$1, %al
	callq	printf
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	80(%rsp), %rcx
	movq	88(%rsp), %rdx
	subq	96(%rsp), %rcx
	subq	104(%rsp), %rdx
	movl	$1000000, %ebx                  # imm = 0xF4240
	leaq	(%rdx,%rbx), %rax
	movq	%rdx, %rsi
	sarq	$63, %rsi
	addq	%rcx, %rsi
	testq	%rdx, %rdx
	cmovnsq	%rdx, %rax
	movq	48(%rsp), %rcx
	movq	56(%rsp), %rdx
	subq	64(%rsp), %rcx
	subq	72(%rsp), %rdx
	addq	%rdx, %rbx
	movq	%rdx, %r14
	sarq	$63, %r14
	addq	%rcx, %r14
	testq	%rdx, %rdx
	cmovnsq	%rdx, %rbx
	imulq	$1000, %rsi, %rcx               # imm = 0x3E8
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rcx, %xmm0
	movabsq	$2361183241434822607, %r15      # imm = 0x20C49BA5E353F7CF
	imulq	%r15
	movq	%rdx, %rax
	shrq	$63, %rax
	sarq	$7, %rdx
	addq	%rax, %rdx
	cvtsi2ss	%rdx, %xmm1
	addss	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	imulq	$1000, %r14, %rax               # imm = 0x3E8
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	movq	%rbx, %rax
	imulq	%r15
	movq	%rdx, %rax
	shrq	$63, %rax
	sarq	$7, %rdx
	addq	%rax, %rdx
	xorps	%xmm1, %xmm1
	cvtsi2ss	%rdx, %xmm1
	addss	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.12, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	28(%rsp), %xmm0
	movl	$.L.str.13, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$120, %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	$_Z12reduceKernelPfiS_, %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	$_Z13reduceKernel2Pfi, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_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	cuerr,@object                   # @cuerr
	.bss
	.globl	cuerr
	.p2align	2, 0x0
cuerr:
	.long	0                               # 0x0
	.size	cuerr, 4

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/indrajeet307/CudaExperiments/master/reduce/reduction.hip"
	.size	.L.str.1, 119

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%s, %d.\n %s."
	.size	.L.str.4, 13

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

	.type	.L.str.5,@object                # @.str.5
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.5:
	.asciz	"\nRunnig Kernel with %d thpb, %d bpg\n"
	.size	.L.str.5, 37

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

	.type	.L.str.6,@object                # @.str.6
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.6:
	.asciz	"Runnig Kernel with %d thpb, %d bpg\n"
	.size	.L.str.6, 36

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"\n["
	.size	.L.str.7, 3

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

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"\nC[0] is %f\n"
	.size	.L.str.10, 13

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	" %f reduce\n"
	.size	.L.str.11, 12

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	" %f reduce2\n"
	.size	.L.str.12, 13

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	" %f preduce2\n"
	.size	.L.str.13, 14

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

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z13reduceKernel2Pfi"
	.size	.L__unnamed_2, 21

	.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	"]"
	.size	.Lstr, 2

	.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 _Z27__device_stub__reduceKernelPfiS_
	.addrsig_sym _Z28__device_stub__reduceKernel2Pfi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z12reduceKernelPfiS_
	.addrsig_sym _Z13reduceKernel2Pfi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12reduceKernelPfiS_   ; -- Begin function _Z12reduceKernelPfiS_
	.globl	_Z12reduceKernelPfiS_
	.p2align	8
	.type	_Z12reduceKernelPfiS_,@function
_Z12reduceKernelPfiS_:                  ; @_Z12reduceKernelPfiS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x24
	s_load_b64 s[4:5], s[0:1], 0x0
	s_mov_b32 s2, s15
	v_lshlrev_b32_e32 v5, 1, v0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s6, s3, 0xffff
	s_mov_b32 s3, 1
	v_mad_u64_u32 v[1:2], null, s2, s6, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b32_e32 v2, 1, v1
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	v_lshlrev_b32_e32 v2, 3, v0
	v_add_co_u32 v3, vcc_lo, s4, v3
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	s_lshl_b32 s4, s6, 1
	global_load_b64 v[6:7], v[3:4], off
	s_waitcnt vmcnt(0)
	ds_store_b64 v2, v[6:7]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	v_mul_lo_u32 v6, s3, v5
	s_mov_b32 s5, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e64 s4, v6
	s_cbranch_execz .LBB0_3
; %bb.2:                                ;   in Loop: Header=BB0_1 Depth=1
	v_lshlrev_b32_e32 v7, 2, v6
	v_add_lshl_u32 v6, v6, s3, 2
	ds_load_b32 v8, v7
	ds_load_b32 v6, v6
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v6, v8, v6
	ds_store_b32 v7, v6
.LBB0_3:                                ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
	s_lshl_b32 s5, s3, 1
	s_cmpk_gt_u32 s3, 0x80
	s_mov_b32 s3, s5
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_1
; %bb.4:
	v_lshlrev_b32_e32 v5, 2, v0
	s_mov_b32 s3, 0
	s_mov_b32 s4, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v2, v2, v5
	ds_load_b32 v5, v2
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_co_u32 v1, vcc_lo, v3, v1
	v_sub_co_ci_u32_e32 v2, vcc_lo, v4, v2, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[1:2], v5, off
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_6
; %bb.5:
	s_load_b64 s[0:1], s[0:1], 0x10
	s_lshl_b64 s[2:3], s[2:3], 2
	v_mov_b32_e32 v0, 0
	s_waitcnt lgkmcnt(0)
	s_add_u32 s0, s0, s2
	s_addc_u32 s1, s1, s3
	global_store_b32 v0, v5, s[0:1]
.LBB0_6:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12reduceKernelPfiS_
		.amdhsa_group_segment_fixed_size 2048
		.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 9
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z12reduceKernelPfiS_, .Lfunc_end0-_Z12reduceKernelPfiS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 368
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z13reduceKernel2Pfi    ; -- Begin function _Z13reduceKernel2Pfi
	.globl	_Z13reduceKernel2Pfi
	.p2align	8
	.type	_Z13reduceKernel2Pfi,@function
_Z13reduceKernel2Pfi:                   ; @_Z13reduceKernel2Pfi
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x1c
	s_load_b64 s[4:5], s[0:1], 0x0
	s_load_b32 s0, s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_cmp_lt_i32 s0, 2
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_lshlrev_b32_e32 v2, 1, v1
	v_lshlrev_b32_e32 v0, 3, v1
	v_lshlrev_b32_e32 v5, 2, v1
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	v_ashrrev_i32_e32 v2, 31, v1
	v_add_co_u32 v3, vcc_lo, s4, v3
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	global_load_b64 v[6:7], v[3:4], off
	s_waitcnt vmcnt(0)
	ds_store_b64 v0, v[6:7]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_5
; %bb.1:                                ; %.lr.ph
	v_sub_nc_u32_e32 v6, v0, v5
	s_lshl_b32 s1, s2, 1
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_lshr_b32 s2, s0, 1
	s_mov_b32 s3, exec_lo
	v_add_nc_u32_e32 v7, s2, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e64 s1, v7
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	v_lshl_add_u32 v7, s2, 2, v6
	ds_load_b32 v8, v6
	ds_load_b32 v7, v7
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v7, v8, v7
	ds_store_b32 v6, v7
.LBB1_4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_cmp_lt_u32 s0, 4
	s_mov_b32 s0, s2
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB1_2
.LBB1_5:                                ; %._crit_edge
	v_sub_nc_u32_e32 v0, v0, v5
	ds_load_b32 v5, v0
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_co_u32 v0, vcc_lo, v3, v0
	v_sub_co_ci_u32_e32 v1, vcc_lo, v4, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v5, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13reduceKernel2Pfi
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 9
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z13reduceKernel2Pfi, .Lfunc_end1-_Z13reduceKernel2Pfi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 312
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.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
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .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: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z12reduceKernelPfiS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12reduceKernelPfiS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13reduceKernel2Pfi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z13reduceKernel2Pfi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
