#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
using namespace std;

__global__ void _3Dstencil_global(float *d_e,float *d_r,int X,int Y,int Z,int k){

    //int thread_id = threadIdx.x + blockIdx.x * blockDim.x;
    //printf("sou id %d || threadIdx.x %d || blockIdx.x %d || blockDim.x %d \n",thread_id,threadIdx.x ,blockIdx.x,blockDim.x);
    //int thread_id = threadIdx.x + threadIdx.y*blockDim.x + (blockIdx.x + blockIdx.y*gridDim.x)*blockDim.x*blockDim.y;
    //printf("sou id %d || threadIdx.x %d || blockIdx.x %d|| blockIdx.y %d || blockDim.x %d|| blockDim.y %d \n",thread_id,threadIdx.x ,blockIdx.x,blockIdx.y,blockDim.x,blockDim.y);
    int x,y;
    x = threadIdx.x + (blockIdx.x*blockDim.x);
    y = threadIdx.y + (blockIdx.y*blockDim.y);
    //printf("X = %d || Y = %d\n",x,y);
    for(int z=0;  z<Z;  z++)
    {           
        int h_r_i = x + ( y * (X) ) + ( z* (X*Y) );
        int h_e_i = h_r_i;
        d_r[h_r_i] = d_e[h_e_i];
        for(int lk =0;lk<(k/2);lk++)
            {
                if(x+lk >= X)
                    h_e_i = (x-lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                else
                    h_e_i = (x+lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];

                if(x-lk < 0)
                    h_e_i = (x+lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                else
                    h_e_i = (x-lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];


                if(y+lk >= Y)
                    h_e_i = (x) + ( (y-lk) * (X) ) + ( (z) * (X*Y) );
                else
                    h_e_i = (x) + ( (y+lk) * (X) ) + ( (z) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];

                if(y-lk < 0)
                    h_e_i = (x) + ( (y+lk) * (X) ) + ( (z) * (X*Y) );
                else
                    h_e_i = (x) + ( (y-lk) * (X) ) + ( (z) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];


                if(z+lk >= Z)
                    h_e_i = (x) + ( (y) * (X) ) + ( (z-lk) * (X*Y) );
                else
                    h_e_i = (x) + ( (y) * (X) ) + ( (z+lk) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];

                if(z-lk < 0)
                    h_e_i = (x) + ( (y) * (X) ) + ( (z+lk) * (X*Y) );
                else
                    h_e_i = (x) + ( (y) * (X) ) + ( (z-lk) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];

            }  
    }


}

/*
*argumentos
*1 - n_elementos
*2 - threads por bloco
*3 - n_blocos
*4 - print
*/
int main(int argc, char* argv[]) {

    float *h_e,*h_r,*h_r_test;
    float *d_e, *d_r;
    int size,tam,times;
    clock_t Ticks[2];

    

    

    times = 1;
    int X=8;
    int Y=8;
    int BX=8;
    int BY=8;
    int Z=4;
    int k=2;
    int GX=1;
    int GY=1;

    if(argc > 1)
    {
        X = atoi(argv[1]);
        BX=X;
    }
      
    if(argc > 2)
    {
        Y = atoi(argv[2]);
        BY = Y;
    }
      
    if(argc > 3)
      Z = atoi(argv[3]);
    if(argc > 4)
      k = atoi(argv[4]);

    if(X>32)
    {
        GX = ceil((float)X/(float)32);
        BX = 32;
    }
    if(Y>32)
    {
        GY = ceil((float)Y/(float)32);
        BY = 32;
    }
    
    
    dim3 block_dim(BX,BY,1);
    dim3 grid_dim(GX,GY,1);

    size = X * Y * Z * sizeof(float);
    tam = X * Y * Z;


    h_e = (float*) malloc(size);
    h_r = (float*) malloc(size);
    h_r_test = (float*) malloc(size);
    cudaMalloc(&d_e, size);
    cudaMalloc(&d_r, size);


    for (int i = 0; i < tam; i++) {
        h_e[i] = (float)(rand()%9000)/100.0;
        h_r[i] = 0;
    }

    /* Copy vectors from host memory to device memory */
    cudaMemcpy(d_e, h_e, size, cudaMemcpyHostToDevice);
    cudaMemcpy(d_r, h_r, size, cudaMemcpyHostToDevice);

    for(int t =0; t<times; t++)
    {

        for(int z=0;  z<Z;  z++)
        {
        
            for(int y=0;  y<Y;  y++)
            {
                for(int x=0;  x<X;  x++)
                {
                    
                    
                    int h_r_i = x + ( y * (X) ) + ( z* (X*Y) );
                        
                    int h_e_i = h_r_i;
                    h_r_test[h_r_i] = h_e[h_e_i];
                    for(int lk =0;lk<(k/2);lk++)
                        {
                            

                            
                            if(x+lk >= X)
                                h_e_i = (x-lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                            else
                                h_e_i = (x+lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];

                            if(x-lk < 0)
                                h_e_i = (x+lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                            else
                                h_e_i = (x-lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];


                            if(y+lk >= Y)
                                h_e_i = (x) + ( (y-lk) * (X) ) + ( (z) * (X*Y) );
                            else
                                h_e_i = (x) + ( (y+lk) * (X) ) + ( (z) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];

                            if(y-lk < 0)
                                h_e_i = (x) + ( (y+lk) * (X) ) + ( (z) * (X*Y) );
                            else
                                h_e_i = (x) + ( (y-lk) * (X) ) + ( (z) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];


                            if(z+lk >= Z)
                                h_e_i = (x) + ( (y) * (X) ) + ( (z-lk) * (X*Y) );
                            else
                                h_e_i = (x) + ( (y) * (X) ) + ( (z+lk) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];

                            if(z-lk < 0)
                                h_e_i = (x) + ( (y) * (X) ) + ( (z+lk) * (X*Y) );
                            else
                                h_e_i = (x) + ( (y) * (X) ) + ( (z-lk) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];

                        }  
                }
            }
            
        }

        for (int i = 0; i < tam; i++) 
        {
            h_e[i] = h_r_test[i];
        }

    }


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

    /******************
    *** Kernel Call ***
    *******************/
    //_3Dstencil_global<<<blks,th_p_blk>>>(d_e,d_r,X,Y,Z);
    _3Dstencil_global<<<grid_dim,block_dim>>>(d_e,d_r,X,Y,Z,k);

    cudaError_t err = cudaSuccess;
    err = cudaGetLastError();
    if (err != cudaSuccess)
    {
        fprintf(stderr, "Failed to launch _3Dstencil_global kernel (error code %s)!\n", cudaGetErrorString(err));
    }
    /******************
    *** Kernel Call ***
    *******************/



    cudaDeviceSynchronize();
    cudaEventRecord (stop, 0);
    cudaEventSynchronize (stop);
    float elapsedTime;
    cudaEventElapsedTime (&elapsedTime, start, stop);
    cudaEventDestroy(start);
    cudaEventDestroy(stop);

    
    Ticks[1] = clock();
    double Tempo = (Ticks[1] - Ticks[0]) * 1000.0 / CLOCKS_PER_SEC;
    printf("X %d || Y %d \nBX %d || BY %d\nZ %d \n",X,Y,BX,BY,Z);
    printf ("[%d,%.5f,%lf],\n", tam,elapsedTime,Tempo/1000.0);
 
    cudaMemcpy(h_r, d_r, size, cudaMemcpyDeviceToHost);

    bool certo=true;
    //printf("threads/blk %d -- blocks %d\n",th_p_blk,blks);
    for (int i = 0; i < 256; i++){
        //printf("%d - %d\n",h_z_res[i],h_z[i]);
        if(h_r_test[i] != h_r[i])
          certo=false;
    }
    if(!certo)
    printf("\n*****\n certo = %s\n*****\n", certo ? "true" : "false");

    cudaFree(d_e);
    cudaFree(d_r);
    std::free(h_e);
    std::free(h_r);
    std::free(h_r_test);

    return 0;
} /* main */


	.file	"tmpxft_002147ca_00000000-6_3DstencilGPUGlobalMemory.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2043:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2043:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z43__device_stub__Z17_3Dstencil_globalPfS_iiiiPfS_iiii
	.type	_Z43__device_stub__Z17_3Dstencil_globalPfS_iiiiPfS_iiii, @function
_Z43__device_stub__Z17_3Dstencil_globalPfS_iiiiPfS_iiii:
.LFB2065:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movl	%r9d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 136(%rsp)
	movq	%rsp, %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z17_3Dstencil_globalPfS_iiii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 192
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L2:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2065:
	.size	_Z43__device_stub__Z17_3Dstencil_globalPfS_iiiiPfS_iiii, .-_Z43__device_stub__Z17_3Dstencil_globalPfS_iiiiPfS_iiii
	.globl	_Z17_3Dstencil_globalPfS_iiii
	.type	_Z17_3Dstencil_globalPfS_iiii, @function
_Z17_3Dstencil_globalPfS_iiii:
.LFB2066:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z17_3Dstencil_globalPfS_iiiiPfS_iiii
	.cfi_endproc
.LFE2066:
	.size	_Z17_3Dstencil_globalPfS_iiii, .-_Z17_3Dstencil_globalPfS_iiii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	"Failed to launch _3Dstencil_global kernel (error code %s)!\n"
.LC6:
	.string	"X %d || Y %d \nBX %d || BY %d\nZ %d \n"
.LC7:
	.string	"[%d,%.5f,%lf],\n"
.LC8:
	.string	"false"
.LC9:
	.string	"\n*****\n certo = %s\n*****\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$184, %rsp
	.cfi_def_cfa_offset 240
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	cmpl	$1, %edi
	jle	.L44
	movl	%edi, %ebp
	movq	8(%rsi), %rdi
	movq	%rsi, %r13
	call	atoi@PLT
	movl	%eax, %ebx
	cmpl	$2, %ebp
	je	.L10
	movq	16(%r13), %rdi
	call	atoi@PLT
	movl	%eax, %r12d
	cmpl	$3, %ebp
	je	.L45
	movq	24(%r13), %rdi
	call	atoi@PLT
	movl	%eax, %r14d
	cmpl	$4, %ebp
	je	.L46
	movq	32(%r13), %rdi
	call	atoi@PLT
	movl	%eax, %ebp
	jmp	.L11
.L45:
	movl	$4, %r14d
.L46:
	movl	$2, %ebp
.L11:
	cmpl	$32, %ebx
	jg	.L42
	jmp	.L58
.L10:
	cmpl	$32, %eax
	jle	.L59
	movl	$8, %r12d
	movl	$4, %r14d
.L42:
	cvtsi2ssl	%ebx, %xmm0
	mulss	.LC0(%rip), %xmm0
	call	ceilf@PLT
	movl	$32, 32(%rsp)
	cvttss2sil	%xmm0, %r13d
	jmp	.L9
.L44:
	movl	$8, %r12d
	movl	$8, %ebx
	movl	$2, %ebp
	movl	$8, 32(%rsp)
	movl	$4, %r14d
	movl	$1, %r13d
	jmp	.L48
.L58:
	movl	%ebx, 32(%rsp)
	movl	$1, %r13d
.L9:
	cmpl	$32, %r12d
	jle	.L48
	cvtsi2ssl	%r12d, %xmm0
	mulss	.LC0(%rip), %xmm0
	call	ceilf@PLT
	movl	$32, 48(%rsp)
	cvttss2sil	%xmm0, %eax
	jmp	.L12
.L48:
	movl	%r12d, 48(%rsp)
	movl	$1, %eax
.L12:
	movl	32(%rsp), %ecx
	movl	%eax, 160(%rsp)
	movl	%ebx, %eax
	imull	%r12d, %eax
	movl	48(%rsp), %edx
	movl	%r13d, 156(%rsp)
	movl	%ecx, 144(%rsp)
	movl	%edx, 148(%rsp)
	movl	%eax, 24(%rsp)
	imull	%r14d, %eax
	movl	$1, 152(%rsp)
	movl	$1, 164(%rsp)
	movl	%eax, 36(%rsp)
	sall	$2, %eax
	cltq
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rsi
	leaq	112(%rsp), %rdi
	movq	%rax, %r15
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	120(%rsp), %rdi
	call	cudaMalloc@PLT
	xorl	%ecx, %ecx
.L13:
	cmpl	%ecx, 36(%rsp)
	jle	.L60
	movq	%rcx, 40(%rsp)
	call	rand@PLT
	movl	$9000, %esi
	movq	40(%rsp), %rcx
	cltd
	idivl	%esi
	movq	16(%rsp), %rax
	movl	$0x00000000, (%rax,%rcx,4)
	cvtsi2ssl	%edx, %xmm0
	divss	.LC1(%rip), %xmm0
	movss	%xmm0, 0(%r13,%rcx,4)
	incq	%rcx
	jmp	.L13
.L60:
	movq	8(%rsp), %rdx
	movq	112(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	120(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	%ebp, %eax
	movl	$2, %ecx
	xorl	%esi, %esi
	cltd
	movl	%esi, 80(%rsp)
	xorl	%r9d, %r9d
	idivl	%ecx
	movl	%eax, 84(%rsp)
.L15:
	cmpl	%r14d, %r9d
	jge	.L49
	movslq	80(%rsp), %rax
	xorl	%r8d, %r8d
	xorl	%edi, %edi
	movq	%rax, 88(%rsp)
.L34:
	cmpl	%r12d, %edi
	jge	.L31
	movl	80(%rsp), %eax
	movq	88(%rsp), %rcx
	leal	(%r8,%rax), %edx
	movslq	%r8d, %rax
	movl	%edx, 40(%rsp)
	addq	%rcx, %rax
	xorl	%ecx, %ecx
	movl	%edx, 52(%rsp)
	leaq	0(,%rax,4), %r10
.L32:
	cmpl	%ebx, %ecx
	jge	.L61
	movl	40(%rsp), %eax
	movl	%edx, 72(%rsp)
	movl	%edx, 76(%rsp)
	movss	0(%r13,%r10), %xmm0
	movl	%eax, 56(%rsp)
	movl	%eax, 60(%rsp)
	movl	52(%rsp), %eax
	movl	%eax, 64(%rsp)
	movl	%eax, 68(%rsp)
	xorl	%eax, %eax
.L16:
	cmpl	%eax, 84(%rsp)
	jle	.L62
	leal	(%rax,%rcx), %r11d
	movl	24(%rsp), %esi
	cmpl	%r11d, %ebx
	movl	56(%rsp), %r11d
	cmovg	60(%rsp), %r11d
	cmpl	%eax, %ecx
	movslq	%r11d, %r11
	addss	0(%r13,%r11,4), %xmm0
	movl	60(%rsp), %r11d
	cmovns	56(%rsp), %r11d
	movslq	%r11d, %r11
	addss	0(%r13,%r11,4), %xmm0
	leal	(%rax,%rdi), %r11d
	cmpl	%r11d, %r12d
	movl	64(%rsp), %r11d
	cmovg	68(%rsp), %r11d
	cmpl	%eax, %edi
	movslq	%r11d, %r11
	addss	0(%r13,%r11,4), %xmm0
	movl	68(%rsp), %r11d
	cmovns	64(%rsp), %r11d
	movslq	%r11d, %r11
	addss	0(%r13,%r11,4), %xmm0
	leal	(%rax,%r9), %r11d
	cmpl	%r11d, %r14d
	movl	72(%rsp), %r11d
	cmovg	76(%rsp), %r11d
	cmpl	%eax, %r9d
	movslq	%r11d, %r11
	addss	0(%r13,%r11,4), %xmm0
	movl	76(%rsp), %r11d
	cmovns	72(%rsp), %r11d
	addl	%esi, 76(%rsp)
	incl	%eax
	subl	%esi, 72(%rsp)
	movslq	%r11d, %r11
	addl	%ebx, 68(%rsp)
	subl	%ebx, 64(%rsp)
	addss	0(%r13,%r11,4), %xmm0
	incl	60(%rsp)
	decl	56(%rsp)
	jmp	.L16
.L62:
	movss	%xmm0, (%r15,%r10)
	incl	%ecx
	incl	%edx
	addq	$4, %r10
	incl	52(%rsp)
	incl	40(%rsp)
	jmp	.L32
.L61:
	incl	%edi
	addl	%ebx, %r8d
	jmp	.L34
.L31:
	movl	24(%rsp), %eax
	incl	%r9d
	addl	%eax, 80(%rsp)
	jmp	.L15
.L49:
	xorl	%eax, %eax
.L33:
	cmpl	%eax, 36(%rsp)
	jle	.L63
	movss	(%r15,%rax,4), %xmm0
	movss	%xmm0, 0(%r13,%rax,4)
	incq	%rax
	jmp	.L33
.L63:
	leaq	128(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	136(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	128(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	152(%rsp), %ecx
	xorl	%r9d, %r9d
	movq	144(%rsp), %rdx
	movq	156(%rsp), %rdi
	movl	164(%rsp), %esi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	movq	120(%rsp), %rsi
	movq	112(%rsp), %rdi
	movl	%ebp, %r9d
	movl	%r14d, %r8d
	movl	%r12d, %ecx
	movl	%ebx, %edx
	call	_Z43__device_stub__Z17_3Dstencil_globalPfS_iiiiPfS_iiii
.L36:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L37
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC3(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L37:
	call	cudaDeviceSynchronize@PLT
	movq	136(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	136(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	136(%rsp), %rdx
	leaq	108(%rsp), %rdi
	movq	128(%rsp), %rsi
	call	cudaEventElapsedTime@PLT
	movq	128(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	136(%rsp), %rdi
	call	cudaEventDestroy@PLT
	call	clock@PLT
	movl	%r12d, %ecx
	movl	%ebx, %edx
	movl	$2, %edi
	cvtsi2sdq	%rax, %xmm1
	mulsd	.LC4(%rip), %xmm1
	leaq	.LC6(%rip), %rsi
	divsd	.LC5(%rip), %xmm1
	movsd	%xmm1, 24(%rsp)
	pushq	%rax
	.cfi_def_cfa_offset 248
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 256
	movl	64(%rsp), %r9d
	movl	48(%rsp), %r8d
	call	__printf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 248
	popq	%rcx
	.cfi_def_cfa_offset 240
	leaq	.LC7(%rip), %rsi
	movl	36(%rsp), %edx
	movl	$2, %edi
	movb	$2, %al
	movsd	24(%rsp), %xmm1
	cvtss2sd	108(%rsp), %xmm0
	divsd	.LC4(%rip), %xmm1
	call	__printf_chk@PLT
	movq	8(%rsp), %rdx
	movq	120(%rsp), %rsi
	movl	$2, %ecx
	movq	16(%rsp), %rdi
	call	cudaMemcpy@PLT
	xorl	%eax, %eax
	movb	$1, %dl
.L40:
	movq	16(%rsp), %rbx
	movss	(%r15,%rax), %xmm0
	ucomiss	(%rbx,%rax), %xmm0
	jp	.L50
	je	.L38
.L50:
	xorl	%edx, %edx
.L38:
	addq	$4, %rax
	cmpq	$1024, %rax
	jne	.L40
	testb	%dl, %dl
	jne	.L41
	leaq	.LC8(%rip), %rdx
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L41:
	movq	112(%rsp), %rdi
	call	cudaFree@PLT
	movq	120(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	%r15, %rdi
	call	free@PLT
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	call	__stack_chk_fail@PLT
.L59:
	movl	%eax, 32(%rsp)
	movl	$8, %r12d
	movl	$1, %eax
	movl	$1, %r13d
	movl	$8, 48(%rsp)
	movl	$4, %r14d
	jmp	.L12
.L43:
	addq	$184, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z17_3Dstencil_globalPfS_iiii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2068:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z17_3Dstencil_globalPfS_iiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2068:
	.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
.LC0:
	.long	1023410176
	.align 4
.LC1:
	.long	1120403456
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	0
	.long	1083129856
	.align 8
.LC5:
	.long	0
	.long	1093567616
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
using namespace std;

__global__ void _3Dstencil_global(float *d_e,float *d_r,int X,int Y,int Z,int k){

    //int thread_id = threadIdx.x + blockIdx.x * blockDim.x;
    //printf("sou id %d || threadIdx.x %d || blockIdx.x %d || blockDim.x %d \n",thread_id,threadIdx.x ,blockIdx.x,blockDim.x);
    //int thread_id = threadIdx.x + threadIdx.y*blockDim.x + (blockIdx.x + blockIdx.y*gridDim.x)*blockDim.x*blockDim.y;
    //printf("sou id %d || threadIdx.x %d || blockIdx.x %d|| blockIdx.y %d || blockDim.x %d|| blockDim.y %d \n",thread_id,threadIdx.x ,blockIdx.x,blockIdx.y,blockDim.x,blockDim.y);
    int x,y;
    x = threadIdx.x + (blockIdx.x*blockDim.x);
    y = threadIdx.y + (blockIdx.y*blockDim.y);
    //printf("X = %d || Y = %d\n",x,y);
    for(int z=0;  z<Z;  z++)
    {           
        int h_r_i = x + ( y * (X) ) + ( z* (X*Y) );
        int h_e_i = h_r_i;
        d_r[h_r_i] = d_e[h_e_i];
        for(int lk =0;lk<(k/2);lk++)
            {
                if(x+lk >= X)
                    h_e_i = (x-lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                else
                    h_e_i = (x+lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];

                if(x-lk < 0)
                    h_e_i = (x+lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                else
                    h_e_i = (x-lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];


                if(y+lk >= Y)
                    h_e_i = (x) + ( (y-lk) * (X) ) + ( (z) * (X*Y) );
                else
                    h_e_i = (x) + ( (y+lk) * (X) ) + ( (z) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];

                if(y-lk < 0)
                    h_e_i = (x) + ( (y+lk) * (X) ) + ( (z) * (X*Y) );
                else
                    h_e_i = (x) + ( (y-lk) * (X) ) + ( (z) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];


                if(z+lk >= Z)
                    h_e_i = (x) + ( (y) * (X) ) + ( (z-lk) * (X*Y) );
                else
                    h_e_i = (x) + ( (y) * (X) ) + ( (z+lk) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];

                if(z-lk < 0)
                    h_e_i = (x) + ( (y) * (X) ) + ( (z+lk) * (X*Y) );
                else
                    h_e_i = (x) + ( (y) * (X) ) + ( (z-lk) * (X*Y) );
                d_r[h_r_i] += d_e[h_e_i];

            }  
    }


}

/*
*argumentos
*1 - n_elementos
*2 - threads por bloco
*3 - n_blocos
*4 - print
*/
int main(int argc, char* argv[]) {

    float *h_e,*h_r,*h_r_test;
    float *d_e, *d_r;
    int size,tam,times;
    clock_t Ticks[2];

    

    

    times = 1;
    int X=8;
    int Y=8;
    int BX=8;
    int BY=8;
    int Z=4;
    int k=2;
    int GX=1;
    int GY=1;

    if(argc > 1)
    {
        X = atoi(argv[1]);
        BX=X;
    }
      
    if(argc > 2)
    {
        Y = atoi(argv[2]);
        BY = Y;
    }
      
    if(argc > 3)
      Z = atoi(argv[3]);
    if(argc > 4)
      k = atoi(argv[4]);

    if(X>32)
    {
        GX = ceil((float)X/(float)32);
        BX = 32;
    }
    if(Y>32)
    {
        GY = ceil((float)Y/(float)32);
        BY = 32;
    }
    
    
    dim3 block_dim(BX,BY,1);
    dim3 grid_dim(GX,GY,1);

    size = X * Y * Z * sizeof(float);
    tam = X * Y * Z;


    h_e = (float*) malloc(size);
    h_r = (float*) malloc(size);
    h_r_test = (float*) malloc(size);
    hipMalloc(&d_e, size);
    hipMalloc(&d_r, size);


    for (int i = 0; i < tam; i++) {
        h_e[i] = (float)(rand()%9000)/100.0;
        h_r[i] = 0;
    }

    /* Copy vectors from host memory to device memory */
    hipMemcpy(d_e, h_e, size, hipMemcpyHostToDevice);
    hipMemcpy(d_r, h_r, size, hipMemcpyHostToDevice);

    for(int t =0; t<times; t++)
    {

        for(int z=0;  z<Z;  z++)
        {
        
            for(int y=0;  y<Y;  y++)
            {
                for(int x=0;  x<X;  x++)
                {
                    
                    
                    int h_r_i = x + ( y * (X) ) + ( z* (X*Y) );
                        
                    int h_e_i = h_r_i;
                    h_r_test[h_r_i] = h_e[h_e_i];
                    for(int lk =0;lk<(k/2);lk++)
                        {
                            

                            
                            if(x+lk >= X)
                                h_e_i = (x-lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                            else
                                h_e_i = (x+lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];

                            if(x-lk < 0)
                                h_e_i = (x+lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                            else
                                h_e_i = (x-lk) + ( (y) * (X) ) + ( (z) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];


                            if(y+lk >= Y)
                                h_e_i = (x) + ( (y-lk) * (X) ) + ( (z) * (X*Y) );
                            else
                                h_e_i = (x) + ( (y+lk) * (X) ) + ( (z) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];

                            if(y-lk < 0)
                                h_e_i = (x) + ( (y+lk) * (X) ) + ( (z) * (X*Y) );
                            else
                                h_e_i = (x) + ( (y-lk) * (X) ) + ( (z) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];


                            if(z+lk >= Z)
                                h_e_i = (x) + ( (y) * (X) ) + ( (z-lk) * (X*Y) );
                            else
                                h_e_i = (x) + ( (y) * (X) ) + ( (z+lk) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];

                            if(z-lk < 0)
                                h_e_i = (x) + ( (y) * (X) ) + ( (z+lk) * (X*Y) );
                            else
                                h_e_i = (x) + ( (y) * (X) ) + ( (z-lk) * (X*Y) );
                            h_r_test[h_r_i] += h_e[h_e_i];

                        }  
                }
            }
            
        }

        for (int i = 0; i < tam; i++) 
        {
            h_e[i] = h_r_test[i];
        }

    }


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

    /******************
    *** Kernel Call ***
    *******************/
    //_3Dstencil_global<<<blks,th_p_blk>>>(d_e,d_r,X,Y,Z);
    _3Dstencil_global<<<grid_dim,block_dim>>>(d_e,d_r,X,Y,Z,k);

    hipError_t err = hipSuccess;
    err = hipGetLastError();
    if (err != hipSuccess)
    {
        fprintf(stderr, "Failed to launch _3Dstencil_global kernel (error code %s)!\n", hipGetErrorString(err));
    }
    /******************
    *** Kernel Call ***
    *******************/



    hipDeviceSynchronize();
    hipEventRecord (stop, 0);
    hipEventSynchronize (stop);
    float elapsedTime;
    hipEventElapsedTime (&elapsedTime, start, stop);
    hipEventDestroy(start);
    hipEventDestroy(stop);

    
    Ticks[1] = clock();
    double Tempo = (Ticks[1] - Ticks[0]) * 1000.0 / CLOCKS_PER_SEC;
    printf("X %d || Y %d \nBX %d || BY %d\nZ %d \n",X,Y,BX,BY,Z);
    printf ("[%d,%.5f,%lf],\n", tam,elapsedTime,Tempo/1000.0);
 
    hipMemcpy(h_r, d_r, size, hipMemcpyDeviceToHost);

    bool certo=true;
    //printf("threads/blk %d -- blocks %d\n",th_p_blk,blks);
    for (int i = 0; i < 256; i++){
        //printf("%d - %d\n",h_z_res[i],h_z[i]);
        if(h_r_test[i] != h_r[i])
          certo=false;
    }
    if(!certo)
    printf("\n*****\n certo = %s\n*****\n", certo ? "true" : "false");

    hipFree(d_e);
    hipFree(d_r);
    std::free(h_e);
    std::free(h_r);
    std::free(h_r_test);

    return 0;
} /* main */


	.text
	.file	"3DstencilGPUGlobalMemory.hip"
	.globl	_Z32__device_stub___3Dstencil_globalPfS_iiii # -- Begin function _Z32__device_stub___3Dstencil_globalPfS_iiii
	.type	_Z32__device_stub___3Dstencil_globalPfS_iiii,@function
_Z32__device_stub___3Dstencil_globalPfS_iiii: # @_Z32__device_stub___3Dstencil_globalPfS_iiii
	.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	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	movq	%rsp, %r8
	movl	%r9d, (%r8)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%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	$_Z17_3Dstencil_globalPfS_iiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z32__device_stub___3Dstencil_globalPfS_iiii, .Lfunc_end0-_Z32__device_stub___3Dstencil_globalPfS_iiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x3d000000                      # float 0.03125
.LCPI1_1:
	.long	0x42c80000                      # float 100
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$232, %rsp
	.cfi_def_cfa_offset 288
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movabsq	$4294967296, %rax               # imm = 0x100000000
	cmpl	$2, %edi
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	jl	.LBB1_1
# %bb.2:
	movq	%rsi, %r15
	movl	%edi, %r12d
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r14d
	movl	$2, %r13d
	movl	$8, %eax
	cmpl	$2, %r12d
	je	.LBB1_3
# %bb.4:
	movq	16(%r15), %rdi
	callq	atoi
	cmpl	$4, %r12d
	jb	.LBB1_3
# %bb.5:
	movl	%eax, %ebp
	movq	24(%r15), %rdi
	callq	atoi
	movl	%eax, %ebx
	cmpl	$4, %r12d
	je	.LBB1_7
# %bb.6:
	movq	32(%r15), %rdi
	callq	atoi
	movl	%eax, %r13d
.LBB1_7:                                # %.thread285
	movl	%ebx, %r15d
	movl	%ebp, %eax
	jmp	.LBB1_8
.LBB1_1:
	movl	$2, %r13d
	movl	$4, %r15d
	movl	$1, %ebx
	movl	$8, %r12d
	movl	$8, %r14d
	movl	$8, %eax
	movl	$8, %ecx
	jmp	.LBB1_13
.LBB1_3:
	movl	$4, %r15d
.LBB1_8:                                # %.thread285
	movl	$1, %ebx
	movl	%r14d, %r12d
	cmpl	$33, %r14d
	jl	.LBB1_10
# %bb.9:
	cvtsi2ss	%r14d, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	movl	%eax, %ebx
	callq	ceilf@PLT
	movl	%ebx, %eax
	cvttss2si	%xmm0, %ebx
	movl	$32, %r12d
.LBB1_10:
	cmpl	$33, %eax
	jl	.LBB1_11
# %bb.12:
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	movl	%eax, %ebp
	callq	ceilf@PLT
	movl	%ebp, %eax
	cvttss2si	%xmm0, %ecx
	shlq	$32, %rcx
	movq	%rcx, 64(%rsp)                  # 8-byte Spill
	movl	$32, %ecx
	jmp	.LBB1_13
.LBB1_11:
	movl	%eax, %ecx
.LBB1_13:                               # %.thread300
	movq	%rcx, 24(%rsp)                  # 8-byte Spill
	movl	%r12d, 92(%rsp)                 # 4-byte Spill
	movl	%r12d, %ecx
	movq	%rcx, 160(%rsp)                 # 8-byte Spill
	movl	%ebx, %ecx
	movq	%rcx, 152(%rsp)                 # 8-byte Spill
	movl	%eax, 16(%rsp)                  # 4-byte Spill
	movl	%r14d, 12(%rsp)                 # 4-byte Spill
	imull	%r14d, %eax
	movl	%eax, 72(%rsp)                  # 4-byte Spill
	movl	%eax, %ebp
	movl	%r15d, 20(%rsp)                 # 4-byte Spill
	imull	%r15d, %ebp
	leal	(,%rbp,4), %eax
	movslq	%eax, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r15
	leaq	80(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	56(%rsp), %rdi
	movq	%rbx, 112(%rsp)                 # 8-byte Spill
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	%rbp, %rax
	movl	%eax, %ebp
	movq	%rax, 104(%rsp)                 # 8-byte Spill
	testl	%eax, %eax
	jle	.LBB1_16
# %bb.14:                               # %.lr.ph.preheader
	xorl	%ebx, %ebx
.LBB1_15:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1954687339, %rax, %rcx         # imm = 0x7482296B
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$44, %rcx
	addl	%edx, %ecx
	imull	$9000, %ecx, %ecx               # imm = 0x2328
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	divss	.LCPI1_1(%rip), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	movl	$0, (%r14,%rbx,4)
	incq	%rbx
	cmpq	%rbx, %rbp
	jne	.LBB1_15
.LBB1_16:                               # %.critedge
	movq	%rbp, 144(%rsp)                 # 8-byte Spill
	movq	24(%rsp), %rax                  # 8-byte Reload
	shlq	$32, %rax
	movq	%rax, 136(%rsp)                 # 8-byte Spill
	movq	80(%rsp), %rdi
	movq	%r12, %rsi
	movq	112(%rsp), %rbx                 # 8-byte Reload
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	56(%rsp), %rdi
	movq	%r14, 120(%rsp)                 # 8-byte Spill
	movq	%r14, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	cmpl	$0, 20(%rsp)                    # 4-byte Folded Reload
	movl	72(%rsp), %ecx                  # 4-byte Reload
	jle	.LBB1_29
# %bb.17:                               # %.preheader316.lr.ph
	movl	%r13d, %eax
	shrl	$31, %eax
	addl	%r13d, %eax
	sarl	%eax
	movl	%eax, 96(%rsp)                  # 4-byte Spill
	movl	20(%rsp), %eax                  # 4-byte Reload
	movq	%rax, 168(%rsp)                 # 8-byte Spill
	movl	16(%rsp), %eax                  # 4-byte Reload
	movq	%rax, 176(%rsp)                 # 8-byte Spill
	movl	12(%rsp), %edx                  # 4-byte Reload
	xorl	%eax, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movq	%r15, 192(%rsp)                 # 8-byte Spill
	movl	%r13d, 100(%rsp)                # 4-byte Spill
	movq	%rdx, 184(%rsp)                 # 8-byte Spill
	movl	16(%rsp), %ebp                  # 4-byte Reload
	movl	12(%rsp), %r14d                 # 4-byte Reload
.LBB1_18:                               # %.preheader316
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_20 Depth 2
                                        #       Child Loop BB1_22 Depth 3
                                        #         Child Loop BB1_24 Depth 4
	cmpl	$0, 16(%rsp)                    # 4-byte Folded Reload
	jle	.LBB1_28
# %bb.19:                               # %.preheader315.lr.ph
                                        #   in Loop: Header=BB1_18 Depth=1
	movl	%ecx, %esi
	imull	32(%rsp), %esi                  # 4-byte Folded Reload
	xorl	%eax, %eax
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	movq	%rsi, 200(%rsp)                 # 8-byte Spill
.LBB1_20:                               # %.preheader315
                                        #   Parent Loop BB1_18 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_22 Depth 3
                                        #         Child Loop BB1_24 Depth 4
	cmpl	$0, 12(%rsp)                    # 4-byte Folded Reload
	jle	.LBB1_27
# %bb.21:                               # %.lr.ph321
                                        #   in Loop: Header=BB1_20 Depth=2
	movl	12(%rsp), %eax                  # 4-byte Reload
	movl	%eax, %edi
	imull	40(%rsp), %edi                  # 4-byte Folded Reload
	leal	(%rdi,%rsi), %r11d
	xorl	%r8d, %r8d
	movq	%rdi, 208(%rsp)                 # 8-byte Spill
.LBB1_22:                               #   Parent Loop BB1_18 Depth=1
                                        #     Parent Loop BB1_20 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB1_24 Depth 4
	leaq	(%r8,%rdi), %rax
	leaq	(%rax,%rsi), %r9
	movss	(%r12,%r9,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%r15,%r9,4)
	cmpl	$2, %r13d
	jl	.LBB1_26
# %bb.23:                               # %.lr.ph319
                                        #   in Loop: Header=BB1_22 Depth=3
	movq	%r9, 216(%rsp)                  # 8-byte Spill
	leal	(%rsi,%r8), %r15d
	movl	%r8d, %esi
	movq	%r8, 72(%rsp)                   # 8-byte Spill
	movl	%r8d, %r13d
	movq	40(%rsp), %rdx                  # 8-byte Reload
	movl	%edx, %r10d
	movl	%edx, %r9d
	movq	32(%rsp), %rdx                  # 8-byte Reload
	movl	%edx, %r8d
                                        # kill: def $edx killed $edx killed $rdx
	movl	96(%rsp), %ebx                  # 4-byte Reload
.LBB1_24:                               #   Parent Loop BB1_18 Depth=1
                                        #     Parent Loop BB1_20 Depth=2
                                        #       Parent Loop BB1_22 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	cmpl	%r14d, %esi
	movl	%r13d, %edi
	cmovll	%esi, %edi
	addl	%r11d, %edi
	movslq	%edi, %rdi
	addss	(%r12,%rdi,4), %xmm0
	testl	%r13d, %r13d
	movl	%r13d, %edi
	cmovsl	%esi, %edi
	addl	%r11d, %edi
	movslq	%edi, %rdi
	addss	(%r12,%rdi,4), %xmm0
	cmpl	%ebp, %r10d
	movl	%r9d, %edi
	cmovll	%r10d, %edi
	imull	%r14d, %edi
	addl	%r15d, %edi
	movslq	%edi, %rdi
	addss	(%r12,%rdi,4), %xmm0
	testl	%r9d, %r9d
	movl	%r9d, %edi
	cmovsl	%r10d, %edi
	imull	%r14d, %edi
	addl	%r15d, %edi
	movslq	%edi, %rdi
	addss	(%r12,%rdi,4), %xmm0
	cmpl	20(%rsp), %r8d                  # 4-byte Folded Reload
	movl	%edx, %edi
	cmovll	%r8d, %edi
	imull	%ecx, %edi
	addl	%eax, %edi
	movslq	%edi, %rdi
	addss	(%r12,%rdi,4), %xmm0
	testl	%edx, %edx
	movl	%edx, %edi
	cmovsl	%r8d, %edi
	imull	%ecx, %edi
	addl	%eax, %edi
	movslq	%edi, %rdi
	addss	(%r12,%rdi,4), %xmm0
	decl	%edx
	incl	%r8d
	decl	%r9d
	incl	%r10d
	decl	%r13d
	incl	%esi
	decl	%ebx
	jne	.LBB1_24
# %bb.25:                               # %._crit_edge
                                        #   in Loop: Header=BB1_22 Depth=3
	movq	192(%rsp), %r15                 # 8-byte Reload
	movq	216(%rsp), %rax                 # 8-byte Reload
	movss	%xmm0, (%r15,%rax,4)
	movl	100(%rsp), %r13d                # 4-byte Reload
	movq	184(%rsp), %rdx                 # 8-byte Reload
	movq	200(%rsp), %rsi                 # 8-byte Reload
	movq	208(%rsp), %rdi                 # 8-byte Reload
	movq	72(%rsp), %r8                   # 8-byte Reload
.LBB1_26:                               #   in Loop: Header=BB1_22 Depth=3
	incq	%r8
	cmpq	%rdx, %r8
	jne	.LBB1_22
.LBB1_27:                               # %._crit_edge322
                                        #   in Loop: Header=BB1_20 Depth=2
	movq	40(%rsp), %rdi                  # 8-byte Reload
	incq	%rdi
	movq	%rdi, %rax
	movq	%rdi, 40(%rsp)                  # 8-byte Spill
	cmpq	176(%rsp), %rdi                 # 8-byte Folded Reload
	jne	.LBB1_20
.LBB1_28:                               # %._crit_edge324
                                        #   in Loop: Header=BB1_18 Depth=1
	movq	32(%rsp), %rsi                  # 8-byte Reload
	incq	%rsi
	movq	%rsi, %rax
	movq	%rsi, 32(%rsp)                  # 8-byte Spill
	cmpq	168(%rsp), %rsi                 # 8-byte Folded Reload
	jne	.LBB1_18
.LBB1_29:                               # %.preheader
	movq	136(%rsp), %rbx                 # 8-byte Reload
	addq	160(%rsp), %rbx                 # 8-byte Folded Reload
	movq	152(%rsp), %rax                 # 8-byte Reload
	orq	%rax, 64(%rsp)                  # 8-byte Folded Spill
	cmpl	$0, 104(%rsp)                   # 4-byte Folded Reload
	movq	144(%rsp), %rdx                 # 8-byte Reload
	jle	.LBB1_31
# %bb.30:                               # %.lr.ph327.preheader
	shlq	$2, %rdx
	movq	%r12, %rdi
	movq	%r15, %rsi
	callq	memcpy@PLT
.LBB1_31:                               # %._crit_edge328
	leaq	128(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventCreate
	leaq	48(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r14), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	64(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_33
# %bb.32:
	movq	80(%rsp), %rdi
	movq	56(%rsp), %rsi
	movl	12(%rsp), %edx                  # 4-byte Reload
	movl	16(%rsp), %ecx                  # 4-byte Reload
	movl	20(%rsp), %r8d                  # 4-byte Reload
	movl	%r13d, %r9d
	callq	_Z32__device_stub___3Dstencil_globalPfS_iiii
.LBB1_33:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_34
.LBB1_35:
	callq	hipDeviceSynchronize
	movq	48(%rsp), %rdi
	xorl	%ebx, %ebx
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	48(%rsp), %rdi
	callq	hipEventSynchronize
	movq	128(%rsp), %rsi
	movq	48(%rsp), %rdx
	leaq	228(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	movq	128(%rsp), %rdi
	callq	hipEventDestroy
	movq	48(%rsp), %rdi
	callq	hipEventDestroy
	callq	clock
	movl	$.L.str.1, %edi
	movl	12(%rsp), %esi                  # 4-byte Reload
	movl	16(%rsp), %edx                  # 4-byte Reload
	movl	92(%rsp), %ecx                  # 4-byte Reload
	movq	24(%rsp), %r8                   # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	movl	20(%rsp), %r9d                  # 4-byte Reload
	xorl	%eax, %eax
	callq	printf
	cvtss2sd	(%r14), %xmm0
	movl	$.L.str.2, %edi
	xorps	%xmm1, %xmm1
	movq	104(%rsp), %rsi                 # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	movb	$2, %al
	callq	printf
	movq	56(%rsp), %rsi
	movq	120(%rsp), %r14                 # 8-byte Reload
	movq	%r14, %rdi
	movq	112(%rsp), %rdx                 # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movb	$1, %al
	xorl	%ecx, %ecx
.LBB1_36:                               # =>This Inner Loop Header: Depth=1
	movss	(%r15,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%r14,%rcx,4), %xmm0
	movzbl	%al, %eax
	cmovnel	%ebx, %eax
	cmovpl	%ebx, %eax
	incq	%rcx
	cmpq	$256, %rcx                      # imm = 0x100
	jne	.LBB1_36
# %bb.37:
	testb	$1, %al
	jne	.LBB1_39
# %bb.38:
	movl	$.L.str.3, %edi
	movl	$.L.str.5, %esi
	xorl	%eax, %eax
	callq	printf
.LBB1_39:
	movq	80(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	%r12, %rdi
	callq	free
	movq	120(%rsp), %rdi                 # 8-byte Reload
	callq	free
	movq	%r15, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$232, %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
.LBB1_34:
	.cfi_def_cfa_offset 288
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_35
.Lfunc_end1:
	.size	main, .Lfunc_end1-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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z17_3Dstencil_globalPfS_iiii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z17_3Dstencil_globalPfS_iiii,@object # @_Z17_3Dstencil_globalPfS_iiii
	.section	.rodata,"a",@progbits
	.globl	_Z17_3Dstencil_globalPfS_iiii
	.p2align	3, 0x0
_Z17_3Dstencil_globalPfS_iiii:
	.quad	_Z32__device_stub___3Dstencil_globalPfS_iiii
	.size	_Z17_3Dstencil_globalPfS_iiii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Failed to launch _3Dstencil_global kernel (error code %s)!\n"
	.size	.L.str, 60

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"X %d || Y %d \nBX %d || BY %d\nZ %d \n"
	.size	.L.str.1, 36

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"[%d,%.5f,%lf],\n"
	.size	.L.str.2, 16

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\n*****\n certo = %s\n*****\n"
	.size	.L.str.3, 26

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"false"
	.size	.L.str.5, 6

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

	.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 _Z32__device_stub___3Dstencil_globalPfS_iiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z17_3Dstencil_globalPfS_iiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z17_3Dstencil_globalPfS_iiii ; -- Begin function _Z17_3Dstencil_globalPfS_iiii
	.globl	_Z17_3Dstencil_globalPfS_iiii
	.p2align	8
	.type	_Z17_3Dstencil_globalPfS_iiii,@function
_Z17_3Dstencil_globalPfS_iiii:          ; @_Z17_3Dstencil_globalPfS_iiii
; %bb.0:
	s_load_b128 s[4:7], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s6, 1
	s_cbranch_scc1 .LBB0_6
; %bb.1:                                ; %.lr.ph169
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b128 s[8:11], s[0:1], 0x0
	v_bfe_u32 v3, v0, 10, 10
	s_lshr_b32 s0, s7, 31
	v_and_b32_e32 v0, 0x3ff, v0
	s_add_i32 s0, s7, s0
	s_mov_b32 s3, 0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s1, s2, 16
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s1, v[3:4]
	s_ashr_i32 s1, s0, 1
	s_and_b32 s0, s2, 0xffff
	s_cmp_gt_i32 s7, 1
	s_mul_i32 s2, s5, s4
	v_mad_u64_u32 v[2:3], null, s14, s0, v[0:1]
	v_mul_lo_u32 v6, v1, s4
	s_cselect_b32 s0, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v3, 0, 1, s0
	v_cmp_ne_u32_e64 s0, 1, v3
	s_delay_alu instid0(VALU_DEP_3)
	v_add_nc_u32_e32 v0, v6, v2
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	s_mul_i32 s7, s3, s2
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v3, s7, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v7, vcc_lo, s8, v3
	v_add_co_ci_u32_e32 v8, vcc_lo, s9, v4, vcc_lo
	v_add_co_u32 v3, vcc_lo, s10, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s11, v4, vcc_lo
	global_load_b32 v8, v[7:8], off
	s_and_b32 vcc_lo, exec_lo, s0
	s_waitcnt vmcnt(0)
	global_store_b32 v[3:4], v8, off
	s_cbranch_vccnz .LBB0_5
; %bb.3:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_add_nc_u32_e32 v7, s7, v6
	v_add_nc_u32_e32 v5, s7, v2
	s_mov_b32 s7, 0
	s_mov_b32 s12, 0
.LBB0_4:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_nc_u32_e32 v11, s12, v2
	v_add_nc_u32_e32 v12, s7, v2
	s_add_i32 s13, s3, s12
	s_add_i32 s14, s3, s7
	s_cmp_lt_i32 s13, s6
	v_cmp_gt_i32_e32 vcc_lo, s4, v11
	s_cselect_b32 s15, s13, s14
	s_cmp_lt_i32 s14, 0
	s_cselect_b32 s13, s13, s14
	v_cndmask_b32_e32 v9, v12, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v9, v7, v9
	v_ashrrev_i32_e32 v10, 31, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	v_add_co_u32 v9, vcc_lo, s8, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v10, vcc_lo, s9, v10, vcc_lo
	v_cmp_gt_i32_e32 vcc_lo, 0, v12
	global_load_b32 v13, v[9:10], off
	v_dual_cndmask_b32 v9, v12, v11 :: v_dual_add_nc_u32 v12, s12, v1
	s_add_i32 s12, s12, 1
	v_add_nc_u32_e32 v9, v7, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v10, 31, v9
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v9, vcc_lo, s8, v9
	v_add_co_ci_u32_e32 v10, vcc_lo, s9, v10, vcc_lo
	v_cmp_gt_i32_e32 vcc_lo, s5, v12
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v11, v13, v8
	v_add_nc_u32_e32 v13, s7, v1
	s_add_i32 s7, s7, -1
	s_cmp_eq_u32 s1, s12
	global_store_b32 v[3:4], v11, off
	global_load_b32 v10, v[9:10], off
	v_cndmask_b32_e32 v14, v13, v12, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[8:9], null, v14, s4, v[5:6]
	v_ashrrev_i32_e32 v9, 31, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[8:9], 2, v[8:9]
	v_add_co_u32 v8, vcc_lo, s8, v8
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v9, vcc_lo, s9, v9, vcc_lo
	v_cmp_gt_i32_e32 vcc_lo, 0, v13
	v_cndmask_b32_e32 v12, v13, v12, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v10, v11, v10
	global_store_b32 v[3:4], v10, off
	global_load_b32 v11, v[8:9], off
	v_mad_u64_u32 v[8:9], null, v12, s4, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v8
	v_lshlrev_b64 v[8:9], 2, v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v8, vcc_lo, s8, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s9, v9, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v10, v10, v11
	global_store_b32 v[3:4], v10, off
	global_load_b32 v11, v[8:9], off
	v_mad_u64_u32 v[8:9], null, s15, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v8
	v_lshlrev_b64 v[8:9], 2, v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v8, vcc_lo, s8, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s9, v9, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v10, v10, v11
	global_store_b32 v[3:4], v10, off
	global_load_b32 v11, v[8:9], off
	v_mad_u64_u32 v[8:9], null, s13, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v8
	v_lshlrev_b64 v[8:9], 2, v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v8, vcc_lo, s8, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s9, v9, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v10, v10, v11
	global_store_b32 v[3:4], v10, off
	global_load_b32 v8, v[8:9], off
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v8, v10, v8
	global_store_b32 v[3:4], v8, off
	s_cbranch_scc0 .LBB0_4
.LBB0_5:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s3, s3, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s3, s6
	s_cbranch_scc0 .LBB0_2
.LBB0_6:                                ; %._crit_edge170
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z17_3Dstencil_globalPfS_iiii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 15
		.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	_Z17_3Dstencil_globalPfS_iiii, .Lfunc_end0-_Z17_3Dstencil_globalPfS_iiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 760
; NumSgprs: 18
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 15
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.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:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z17_3Dstencil_globalPfS_iiii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z17_3Dstencil_globalPfS_iiii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
