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

__global__ void _copy_dr_to_de(int *d_e,int *d_r,int X,int Y){
    int x,y;
    x = threadIdx.x + (blockIdx.x*blockDim.x);
    y = threadIdx.y + (blockIdx.y*blockDim.y);
    int h_r_i = x + ( y * (X) );
    if(x<X && y<Y)
    d_e[h_r_i] = d_r[h_r_i];
}
__global__ void _2Dstencil_global(int *d_e,int *d_r,float *c_coeff,int X,int Y,int k){

    int x,y,h_e_i,h_r_i,temp;
    x = threadIdx.x + (blockIdx.x*blockDim.x);
    y = threadIdx.y + (blockIdx.y*blockDim.y);
    h_r_i = x + ( y * (X) );
    temp = d_e[h_r_i]*c_coeff[0];
    for(int lk = 1;lk<(k/2)+1;lk++)
    {
        if(x+lk < X)
        {
            h_e_i = (x+lk) + ( (y) * (X) );
            temp += d_e[h_e_i]*c_coeff[lk];
        }
        if(x-lk >= 0)
        {
            h_e_i = (x-lk) + ( (y) * (X) );
            temp += d_e[h_e_i]*c_coeff[lk];
        }
        if(y+lk < Y)
        {
            h_e_i = (x) + ( (y+lk) * (X) );
            temp += d_e[h_e_i]*c_coeff[lk];
        }
        if(y-lk >= 0)
        {
            h_e_i = (x) + ( (y-lk) * (X) );
            temp += d_e[h_e_i]*c_coeff[lk];
        }
    }
    d_r[h_r_i] = temp;  
}


int main(int argc, char* argv[]) {

int *h_e,*h_r;
int *d_e, *d_r;
int size,tam;
int X=32;
int Y=32;
int k=4;
int times = 1;
int BX=32;
int BY=32;
int GX=1;
int GY=1;
float *c_coeff,*d_c_coeff;
if(argc > 1)
{
    X = atoi(argv[1]);
    Y = X;
}
if(argc > 2)
{
    k = atoi(argv[2]);
}

if(argc > 3)
{
    times = atoi(argv[3]);
}


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 * sizeof(int);
tam = X * Y;


h_e = (int*) malloc(size);
h_r = (int*) malloc(size);
c_coeff = (float*)malloc((k/2+1)*sizeof(float));
cudaMalloc(&d_e, size);
cudaMalloc(&d_r, size);
cudaMalloc(&d_c_coeff,(k/2+1)*sizeof(float));

printf("\n coefs \n");
for(int i=0;i<(k/2+1);i++)
{
    c_coeff[i]=(float)((k/2+1)-i)/(float)(k/2+1);
   
}
for(int i=0;i<(k/2+1);i++)
{
    printf(" %f",c_coeff[i]);
}
printf("\n coefs \n");


FILE *arq;
arq = fopen("entrada.txt", "rt");
for(int i=0;i<X;i++)
    for(int j=0;j<Y;j++)
        fscanf(arq," %d",&h_e[i+j*X]);
fclose(arq);


/* Copy vectors from host memory to device memory */
cudaMemcpy(d_e, h_e, size, cudaMemcpyHostToDevice);
cudaMemcpy(d_c_coeff, c_coeff, (k/2+1)*sizeof(float), cudaMemcpyHostToDevice);


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);
for(int t=0;t<times;t++)
{
_2Dstencil_global<<<grid_dim,block_dim>>>(d_e,d_r,d_c_coeff,X,Y,k);
_copy_dr_to_de<<<grid_dim,block_dim>>>(d_e,d_r,X,Y);
}
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);


    printf("X %d || Y %d \nBX %d || BY %d \n",X,Y,BX,BY);
    printf ("[%d,%.5f],\n", tam,elapsedTime);
 
    cudaMemcpy(h_r, d_r, size, cudaMemcpyDeviceToHost);

    
arq = fopen("resultado.txt", "wt");
for(int i=0;i<X;i++)
{
    for(int j=0;j<Y;j++)
    {
      fprintf(arq," %d",h_r[i+j*X]);
    }
    fprintf(arq,"\n");
}
fclose(arq);


    cudaFree(d_e);
    cudaFree(d_r);
    cudaFree(d_c_coeff);
    std::free(h_e);
    std::free(h_r);
    std::free(c_coeff);

    return 0;
} /* main */


	.file	"tmpxft_002a2572_00000000-6_2DstencilGPUGlobalMemoryBlankBorder.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	_Z38__device_stub__Z14_copy_dr_to_dePiS_iiPiS_ii
	.type	_Z38__device_stub__Z14_copy_dr_to_dePiS_iiPiS_ii, @function
_Z38__device_stub__Z14_copy_dr_to_dePiS_iiPiS_ii:
.LFB2065:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z14_copy_dr_to_dePiS_ii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2065:
	.size	_Z38__device_stub__Z14_copy_dr_to_dePiS_iiPiS_ii, .-_Z38__device_stub__Z14_copy_dr_to_dePiS_iiPiS_ii
	.globl	_Z14_copy_dr_to_dePiS_ii
	.type	_Z14_copy_dr_to_dePiS_ii, @function
_Z14_copy_dr_to_dePiS_ii:
.LFB2066:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z14_copy_dr_to_dePiS_iiPiS_ii
	.cfi_endproc
.LFE2066:
	.size	_Z14_copy_dr_to_dePiS_ii, .-_Z14_copy_dr_to_dePiS_ii
	.globl	_Z44__device_stub__Z17_2Dstencil_globalPiS_PfiiiPiS_Pfiii
	.type	_Z44__device_stub__Z17_2Dstencil_globalPiS_PfiiiPiS_Pfiii, @function
_Z44__device_stub__Z17_2Dstencil_globalPiS_PfiiiPiS_Pfiii:
.LFB2067:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z17_2Dstencil_globalPiS_Pfiii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L8:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2067:
	.size	_Z44__device_stub__Z17_2Dstencil_globalPiS_PfiiiPiS_Pfiii, .-_Z44__device_stub__Z17_2Dstencil_globalPiS_PfiiiPiS_Pfiii
	.globl	_Z17_2Dstencil_globalPiS_Pfiii
	.type	_Z17_2Dstencil_globalPiS_Pfiii, @function
_Z17_2Dstencil_globalPiS_Pfiii:
.LFB2068:
	.cfi_startproc
	endbr64
	jmp	_Z44__device_stub__Z17_2Dstencil_globalPiS_PfiiiPiS_Pfiii
	.cfi_endproc
.LFE2068:
	.size	_Z17_2Dstencil_globalPiS_Pfiii, .-_Z17_2Dstencil_globalPiS_Pfiii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"\n coefs \n"
.LC2:
	.string	" %f"
.LC3:
	.string	"rt"
.LC4:
	.string	"entrada.txt"
.LC5:
	.string	" %d"
.LC6:
	.string	"Failed to launch _3Dstencil_global kernel (error code %s)!\n"
.LC7:
	.string	"X %d || Y %d \nBX %d || BY %d \n"
.LC8:
	.string	"[%d,%.5f],\n"
.LC9:
	.string	"wt"
.LC10:
	.string	"resultado.txt"
.LC11:
	.string	"\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	$152, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	cmpl	$1, %edi
	jle	.L31
	movl	%edi, %r14d
	movq	8(%rsi), %rdi
	movq	%rsi, %r13
	call	atoi@PLT
	movl	%eax, %ebx
	cmpl	$2, %r14d
	je	.L32
	movq	16(%r13), %rdi
	movl	$1, %r12d
	call	atoi@PLT
	movl	%eax, %ebp
	cmpl	$3, %r14d
	je	.L15
	movq	24(%r13), %rdi
	call	atoi@PLT
	movl	%eax, %r12d
	jmp	.L15
.L32:
	movl	$4, %ebp
	movl	$1, %r12d
.L15:
	movl	$1, %eax
	cmpl	$32, %ebx
	jle	.L14
	cvtsi2ssl	%ebx, %xmm0
	mulss	.LC0(%rip), %xmm0
	call	ceilf@PLT
	cvttss2sil	%xmm0, %eax
	jmp	.L14
.L31:
	movl	$32, %ebx
	movl	$1, %r12d
	movl	$4, %ebp
	movl	$1, %eax
.L14:
	movabsq	$137438953504, %rcx
	movl	%eax, 124(%rsp)
	movl	%eax, 128(%rsp)
	movl	%ebx, %eax
	imull	%ebx, %eax
	movq	%rcx, 112(%rsp)
	movl	$1, 120(%rsp)
	movl	$1, 132(%rsp)
	movl	%eax, 56(%rsp)
	sall	$2, %eax
	cltq
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	movl	$2, %ecx
	movq	%rax, 32(%rsp)
	movl	%ebp, %eax
	cltd
	idivl	%ecx
	leal	1(%rax), %r15d
	movl	%eax, %r13d
	movslq	%r15d, %rax
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	(%rsp), %rsi
	leaq	72(%rsp), %rdi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rsi
	leaq	88(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
.L16:
	cmpl	%eax, %r13d
	jl	.L42
	movl	%r15d, %edx
	cvtsi2ssl	%r15d, %xmm1
	movq	8(%rsp), %rcx
	subl	%eax, %edx
	cvtsi2ssl	%edx, %xmm0
	divss	%xmm1, %xmm0
	movss	%xmm0, (%rcx,%rax,4)
	incq	%rax
	jmp	.L16
.L42:
	xorl	%r14d, %r14d
	leaq	.LC2(%rip), %r15
.L18:
	cmpl	%r14d, %r13d
	jl	.L43
	movq	8(%rsp), %rax
	movq	%r15, %rsi
	movl	$2, %edi
	cvtss2sd	(%rax,%r14,4), %xmm0
	movb	$1, %al
	incq	%r14
	call	__printf_chk@PLT
	jmp	.L18
.L43:
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	movslq	%ebx, %r13
	xorl	%r14d, %r14d
	movl	$2, %edi
	salq	$2, %r13
	call	__printf_chk@PLT
	leaq	.LC4(%rip), %rdi
	leaq	.LC3(%rip), %rsi
	call	fopen@PLT
	movq	24(%rsp), %r15
	movq	%rax, %rdi
.L20:
	cmpl	%ebx, %r14d
	jge	.L44
	movq	%r15, %rdx
	xorl	%r9d, %r9d
.L21:
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rsi
	movl	%r9d, 60(%rsp)
	movq	%rdx, 48(%rsp)
	movq	%rdi, 40(%rsp)
	call	__isoc23_fscanf@PLT
	movl	60(%rsp), %r9d
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rdi
	incl	%r9d
	addq	%r13, %rdx
	cmpl	%ebx, %r9d
	jne	.L21
	incl	%r14d
	addq	$4, %r15
	jmp	.L20
.L44:
	call	fclose@PLT
	movq	(%rsp), %rdx
	movq	24(%rsp), %rsi
	xorl	%r14d, %r14d
	movq	72(%rsp), %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$1, %ecx
	movq	88(%rsp), %rdi
	call	cudaMemcpy@PLT
	leaq	96(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	104(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	96(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
.L22:
	cmpl	%r12d, %r14d
	jge	.L45
	movl	120(%rsp), %ecx
	movq	112(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	124(%rsp), %rdi
	movl	132(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	movl	%ebp, %r9d
	movl	%ebx, %r8d
	movq	72(%rsp), %rdi
	movl	%ebx, %ecx
	call	_Z44__device_stub__Z17_2Dstencil_globalPiS_PfiiiPiS_Pfiii
.L23:
	movl	120(%rsp), %ecx
	movq	112(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	124(%rsp), %rdi
	movl	132(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	movq	80(%rsp), %rsi
	movq	72(%rsp), %rdi
	movl	%ebx, %ecx
	movl	%ebx, %edx
	call	_Z38__device_stub__Z14_copy_dr_to_dePiS_iiPiS_ii
.L24:
	incl	%r14d
	jmp	.L22
.L45:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L26
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC6(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L26:
	call	cudaDeviceSynchronize@PLT
	movq	104(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%r14d, %r14d
	leaq	.LC5(%rip), %r12
	call	cudaEventRecord@PLT
	movq	104(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	104(%rsp), %rdx
	movq	96(%rsp), %rsi
	leaq	68(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	96(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	104(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	$32, %r9d
	movl	%ebx, %ecx
	movl	%ebx, %edx
	movl	$32, %r8d
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	56(%rsp), %edx
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC8(%rip), %rsi
	cvtss2sd	68(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	(%rsp), %rdx
	movq	80(%rsp), %rsi
	movl	$2, %ecx
	movq	32(%rsp), %rdi
	call	cudaMemcpy@PLT
	leaq	.LC9(%rip), %rsi
	leaq	.LC10(%rip), %rdi
	call	fopen@PLT
	movq	%rax, (%rsp)
.L27:
	cmpl	%r14d, %ebx
	jle	.L46
	movq	32(%rsp), %rax
	xorl	%r15d, %r15d
	leaq	(%rax,%r14,4), %rbp
.L28:
	movl	0(%rbp), %ecx
	movq	(%rsp), %rdi
	movq	%r12, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	incl	%r15d
	addq	%r13, %rbp
	call	__fprintf_chk@PLT
	cmpl	%ebx, %r15d
	jne	.L28
	movq	(%rsp), %rdi
	leaq	.LC11(%rip), %rdx
	xorl	%eax, %eax
	incq	%r14
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L27
.L46:
	movq	(%rsp), %rdi
	call	fclose@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$152, %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
.LC12:
	.string	"_Z17_2Dstencil_globalPiS_Pfiii"
.LC13:
	.string	"_Z14_copy_dr_to_dePiS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2070:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC12(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z17_2Dstencil_globalPiS_Pfiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC13(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z14_copy_dr_to_dePiS_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2070:
	.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
	.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 _copy_dr_to_de(int *d_e,int *d_r,int X,int Y){
    int x,y;
    x = threadIdx.x + (blockIdx.x*blockDim.x);
    y = threadIdx.y + (blockIdx.y*blockDim.y);
    int h_r_i = x + ( y * (X) );
    if(x<X && y<Y)
    d_e[h_r_i] = d_r[h_r_i];
}
__global__ void _2Dstencil_global(int *d_e,int *d_r,float *c_coeff,int X,int Y,int k){

    int x,y,h_e_i,h_r_i,temp;
    x = threadIdx.x + (blockIdx.x*blockDim.x);
    y = threadIdx.y + (blockIdx.y*blockDim.y);
    h_r_i = x + ( y * (X) );
    temp = d_e[h_r_i]*c_coeff[0];
    for(int lk = 1;lk<(k/2)+1;lk++)
    {
        if(x+lk < X)
        {
            h_e_i = (x+lk) + ( (y) * (X) );
            temp += d_e[h_e_i]*c_coeff[lk];
        }
        if(x-lk >= 0)
        {
            h_e_i = (x-lk) + ( (y) * (X) );
            temp += d_e[h_e_i]*c_coeff[lk];
        }
        if(y+lk < Y)
        {
            h_e_i = (x) + ( (y+lk) * (X) );
            temp += d_e[h_e_i]*c_coeff[lk];
        }
        if(y-lk >= 0)
        {
            h_e_i = (x) + ( (y-lk) * (X) );
            temp += d_e[h_e_i]*c_coeff[lk];
        }
    }
    d_r[h_r_i] = temp;  
}


int main(int argc, char* argv[]) {

int *h_e,*h_r;
int *d_e, *d_r;
int size,tam;
int X=32;
int Y=32;
int k=4;
int times = 1;
int BX=32;
int BY=32;
int GX=1;
int GY=1;
float *c_coeff,*d_c_coeff;
if(argc > 1)
{
    X = atoi(argv[1]);
    Y = X;
}
if(argc > 2)
{
    k = atoi(argv[2]);
}

if(argc > 3)
{
    times = atoi(argv[3]);
}


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 * sizeof(int);
tam = X * Y;


h_e = (int*) malloc(size);
h_r = (int*) malloc(size);
c_coeff = (float*)malloc((k/2+1)*sizeof(float));
hipMalloc(&d_e, size);
hipMalloc(&d_r, size);
hipMalloc(&d_c_coeff,(k/2+1)*sizeof(float));

printf("\n coefs \n");
for(int i=0;i<(k/2+1);i++)
{
    c_coeff[i]=(float)((k/2+1)-i)/(float)(k/2+1);
   
}
for(int i=0;i<(k/2+1);i++)
{
    printf(" %f",c_coeff[i]);
}
printf("\n coefs \n");


FILE *arq;
arq = fopen("entrada.txt", "rt");
for(int i=0;i<X;i++)
    for(int j=0;j<Y;j++)
        fscanf(arq," %d",&h_e[i+j*X]);
fclose(arq);


/* Copy vectors from host memory to device memory */
hipMemcpy(d_e, h_e, size, hipMemcpyHostToDevice);
hipMemcpy(d_c_coeff, c_coeff, (k/2+1)*sizeof(float), hipMemcpyHostToDevice);


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);
for(int t=0;t<times;t++)
{
_2Dstencil_global<<<grid_dim,block_dim>>>(d_e,d_r,d_c_coeff,X,Y,k);
_copy_dr_to_de<<<grid_dim,block_dim>>>(d_e,d_r,X,Y);
}
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);


    printf("X %d || Y %d \nBX %d || BY %d \n",X,Y,BX,BY);
    printf ("[%d,%.5f],\n", tam,elapsedTime);
 
    hipMemcpy(h_r, d_r, size, hipMemcpyDeviceToHost);

    
arq = fopen("resultado.txt", "wt");
for(int i=0;i<X;i++)
{
    for(int j=0;j<Y;j++)
    {
      fprintf(arq," %d",h_r[i+j*X]);
    }
    fprintf(arq,"\n");
}
fclose(arq);


    hipFree(d_e);
    hipFree(d_r);
    hipFree(d_c_coeff);
    std::free(h_e);
    std::free(h_r);
    std::free(c_coeff);

    return 0;
} /* main */


	.text
	.file	"2DstencilGPUGlobalMemoryBlankBorder.hip"
	.globl	_Z29__device_stub___copy_dr_to_dePiS_ii # -- Begin function _Z29__device_stub___copy_dr_to_dePiS_ii
	.type	_Z29__device_stub___copy_dr_to_dePiS_ii,@function
_Z29__device_stub___copy_dr_to_dePiS_ii: # @_Z29__device_stub___copy_dr_to_dePiS_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z14_copy_dr_to_dePiS_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z29__device_stub___copy_dr_to_dePiS_ii, .Lfunc_end0-_Z29__device_stub___copy_dr_to_dePiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z32__device_stub___2Dstencil_globalPiS_Pfiii # -- Begin function _Z32__device_stub___2Dstencil_globalPiS_Pfiii
	.type	_Z32__device_stub___2Dstencil_globalPiS_Pfiii,@function
_Z32__device_stub___2Dstencil_globalPiS_Pfiii: # @_Z32__device_stub___2Dstencil_globalPiS_Pfiii
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%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	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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_2Dstencil_globalPiS_Pfiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z32__device_stub___2Dstencil_globalPiS_Pfiii, .Lfunc_end1-_Z32__device_stub___2Dstencil_globalPiS_Pfiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x3d000000                      # float 0.03125
	.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	$136, %rsp
	.cfi_def_cfa_offset 192
	.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, %rbx               # imm = 0x100000000
	cmpl	$2, %edi
	jl	.LBB2_1
# %bb.2:
	movq	%rsi, %r12
	movl	%edi, %r13d
	movl	$1, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movl	$1, %r15d
	movl	$4, %r14d
	cmpl	$2, %r13d
	je	.LBB2_5
# %bb.3:
	movq	16(%r12), %rdi
	callq	atoi
	movl	%eax, %r14d
	cmpl	$4, %r13d
	jb	.LBB2_5
# %bb.4:
	movq	24(%r12), %rdi
	callq	atoi
	movl	%eax, %r15d
.LBB2_5:                                # %.thread130
	cmpl	$33, %ebp
	movl	%r15d, (%rsp)                   # 4-byte Spill
	jl	.LBB2_6
# %bb.7:
	cvtsi2ss	%ebp, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	shlq	$32, %rax
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	jmp	.LBB2_8
.LBB2_1:
	movl	$1, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movq	%rbx, 40(%rsp)                  # 8-byte Spill
	movl	$4, %r14d
	movl	$32, %ebp
	movl	$1, (%rsp)                      # 4-byte Folded Spill
	jmp	.LBB2_8
.LBB2_6:
	movq	%rbx, 40(%rsp)                  # 8-byte Spill
.LBB2_8:                                # %.thread130.thread
	movl	%ebp, %eax
	imull	%eax, %eax
	movq	%rax, 112(%rsp)                 # 8-byte Spill
	leal	(,%rax,4), %eax
	movslq	%eax, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	movl	%r14d, %r12d
	movl	%r14d, %r15d
	shrl	$31, %r15d
	addl	%r14d, %r15d
	sarl	%r15d
	movslq	%r15d, %rax
	leaq	4(,%rax,4), %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r14
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movq	%rbx, 120(%rsp)                 # 8-byte Spill
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	72(%rsp), %rdi
	movq	%r13, 104(%rsp)                 # 8-byte Spill
	movq	%r13, %rsi
	callq	hipMalloc
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	%r12d, 4(%rsp)                  # 4-byte Spill
	cmpl	$-1, %r12d
	jl	.LBB2_14
# %bb.9:                                # %.lr.ph
	incl	%r15d
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15d, %xmm0
	movl	%r15d, %r12d
	xorl	%eax, %eax
.LBB2_10:                               # =>This Inner Loop Header: Depth=1
	xorps	%xmm1, %xmm1
	cvtsi2ss	%r15d, %xmm1
	divss	%xmm0, %xmm1
	movss	%xmm1, (%r14,%rax,4)
	incq	%rax
	decl	%r15d
	cmpq	%rax, %r12
	jne	.LBB2_10
# %bb.11:                               # %.preheader147
	cmpl	$-1, 4(%rsp)                    # 4-byte Folded Reload
	jl	.LBB2_14
# %bb.12:                               # %.lr.ph152.preheader
	xorl	%ebx, %ebx
.LBB2_13:                               # %.lr.ph152
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rbx,4), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	incq	%rbx
	cmpq	%rbx, %r12
	jne	.LBB2_13
.LBB2_14:                               # %._crit_edge
	movq	%r14, 88(%rsp)                  # 8-byte Spill
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.L.str.2, %edi
	movl	$.L.str.3, %esi
	callq	fopen
	movq	%rax, %r13
	movl	%ebp, %eax
	movl	%ebp, 84(%rsp)                  # 4-byte Spill
	testl	%ebp, %ebp
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	jle	.LBB2_19
# %bb.15:                               # %.preheader146.lr.ph
	leaq	(,%rax,4), %rbx
	movq	56(%rsp), %r14                  # 8-byte Reload
	xorl	%r12d, %r12d
.LBB2_16:                               # %.lr.ph154.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_17 Depth 2
	movq	%rax, %rbp
	movq	%r14, %r15
.LBB2_17:                               # %.lr.ph154
                                        #   Parent Loop BB2_16 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$.L.str.4, %esi
	movq	%r13, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	%rbx, %r15
	decq	%rbp
	jne	.LBB2_17
# %bb.18:                               # %._crit_edge155
                                        #   in Loop: Header=BB2_16 Depth=1
	incq	%r12
	addq	$4, %r14
	movq	64(%rsp), %rax                  # 8-byte Reload
	cmpq	%rax, %r12
	jne	.LBB2_16
.LBB2_19:                               # %._crit_edge157
	movq	%r13, %rdi
	callq	fclose
	movq	24(%rsp), %rdi
	movq	56(%rsp), %rsi                  # 8-byte Reload
	movq	120(%rsp), %r12                 # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	72(%rsp), %rdi
	movq	88(%rsp), %rsi                  # 8-byte Reload
	movq	104(%rsp), %rdx                 # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	96(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	(%rsp), %r15d                   # 4-byte Reload
	testl	%r15d, %r15d
	movl	84(%rsp), %ebx                  # 4-byte Reload
	movq	40(%rsp), %r14                  # 8-byte Reload
	movl	4(%rsp), %ebp                   # 4-byte Reload
	jle	.LBB2_26
# %bb.20:                               # %.lr.ph160.preheader
	orq	32(%rsp), %r14                  # 8-byte Folded Reload
	movabsq	$137438953504, %r13             # imm = 0x2000000020
.LBB2_21:                               # %.lr.ph160
                                        # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_23
# %bb.22:                               #   in Loop: Header=BB2_21 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	72(%rsp), %rdx
	movl	%ebx, %ecx
	movl	%ebx, %r8d
	movl	%ebp, %r9d
	callq	_Z32__device_stub___2Dstencil_globalPiS_Pfiii
.LBB2_23:                               #   in Loop: Header=BB2_21 Depth=1
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_25
# %bb.24:                               #   in Loop: Header=BB2_21 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	%ebx, %edx
	movl	%ebx, %ecx
	callq	_Z29__device_stub___copy_dr_to_dePiS_ii
.LBB2_25:                               #   in Loop: Header=BB2_21 Depth=1
	decl	%r15d
	jne	.LBB2_21
.LBB2_26:                               # %._crit_edge161
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_27
.LBB2_28:
	callq	hipDeviceSynchronize
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	96(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	132(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	movq	96(%rsp), %rdi
	callq	hipEventDestroy
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	movl	$.L.str.6, %edi
	movl	%ebx, %esi
	movl	%ebx, %edx
	movl	$32, %ecx
	movl	$32, %r8d
	xorl	%eax, %eax
	callq	printf
	cvtss2sd	(%r14), %xmm0
	movl	$.L.str.7, %edi
	movq	112(%rsp), %rsi                 # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	movb	$1, %al
	callq	printf
	movq	16(%rsp), %rsi
	movq	48(%rsp), %rdi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.8, %edi
	movl	$.L.str.9, %esi
	callq	fopen
	movq	%rax, %r14
	testl	%ebx, %ebx
	movq	64(%rsp), %r12                  # 8-byte Reload
	jle	.LBB2_33
# %bb.29:                               # %.preheader.lr.ph
	leaq	(,%r12,4), %rbx
	movq	48(%rsp), %r15                  # 8-byte Reload
	xorl	%r13d, %r13d
.LBB2_30:                               # %.lr.ph163.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_31 Depth 2
	movq	%r15, %rbp
.LBB2_31:                               # %.lr.ph163
                                        #   Parent Loop BB2_30 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rbp), %edx
	movl	$.L.str.4, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	addq	%rbx, %rbp
	decq	%r12
	jne	.LBB2_31
# %bb.32:                               # %._crit_edge164
                                        #   in Loop: Header=BB2_30 Depth=1
	movl	$10, %edi
	movq	%r14, %rsi
	callq	fputc@PLT
	incq	%r13
	addq	$4, %r15
	movq	64(%rsp), %r12                  # 8-byte Reload
	cmpq	%r12, %r13
	jne	.LBB2_30
.LBB2_33:                               # %._crit_edge166
	movq	%r14, %rdi
	callq	fclose
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	72(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	48(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	88(%rsp), %rdi                  # 8-byte Reload
	callq	free
	xorl	%eax, %eax
	addq	$136, %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
.LBB2_27:
	.cfi_def_cfa_offset 192
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.5, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB2_28
.Lfunc_end2:
	.size	main, .Lfunc_end2-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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14_copy_dr_to_dePiS_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z17_2Dstencil_globalPiS_Pfiii, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z14_copy_dr_to_dePiS_ii,@object # @_Z14_copy_dr_to_dePiS_ii
	.section	.rodata,"a",@progbits
	.globl	_Z14_copy_dr_to_dePiS_ii
	.p2align	3, 0x0
_Z14_copy_dr_to_dePiS_ii:
	.quad	_Z29__device_stub___copy_dr_to_dePiS_ii
	.size	_Z14_copy_dr_to_dePiS_ii, 8

	.type	_Z17_2Dstencil_globalPiS_Pfiii,@object # @_Z17_2Dstencil_globalPiS_Pfiii
	.globl	_Z17_2Dstencil_globalPiS_Pfiii
	.p2align	3, 0x0
_Z17_2Dstencil_globalPiS_Pfiii:
	.quad	_Z32__device_stub___2Dstencil_globalPiS_Pfiii
	.size	_Z17_2Dstencil_globalPiS_Pfiii, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	" %f"
	.size	.L.str.1, 4

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"entrada.txt"
	.size	.L.str.2, 12

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Failed to launch _3Dstencil_global kernel (error code %s)!\n"
	.size	.L.str.5, 60

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

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"resultado.txt"
	.size	.L.str.8, 14

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14_copy_dr_to_dePiS_ii"
	.size	.L__unnamed_1, 25

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z17_2Dstencil_globalPiS_Pfiii"
	.size	.L__unnamed_2, 31

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

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

	.type	.Lstr.1,@object                 # @str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr.1:
	.asciz	"\n coefs "
	.size	.Lstr.1, 9

	.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 _Z29__device_stub___copy_dr_to_dePiS_ii
	.addrsig_sym _Z32__device_stub___2Dstencil_globalPiS_Pfiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14_copy_dr_to_dePiS_ii
	.addrsig_sym _Z17_2Dstencil_globalPiS_Pfiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14_copy_dr_to_dePiS_ii ; -- Begin function _Z14_copy_dr_to_dePiS_ii
	.globl	_Z14_copy_dr_to_dePiS_ii
	.p2align	8
	.type	_Z14_copy_dr_to_dePiS_ii,@function
_Z14_copy_dr_to_dePiS_ii:               ; @_Z14_copy_dr_to_dePiS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b64 s[4:5], s[0:1], 0x10
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s2, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s3, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s4, v0
	v_cmp_gt_i32_e64 s2, s5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x0
	v_mad_u64_u32 v[2:3], null, v1, s4, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14_copy_dr_to_dePiS_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z14_copy_dr_to_dePiS_ii, .Lfunc_end0-_Z14_copy_dr_to_dePiS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 200
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 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
	.protected	_Z17_2Dstencil_globalPiS_Pfiii ; -- Begin function _Z17_2Dstencil_globalPiS_Pfiii
	.globl	_Z17_2Dstencil_globalPiS_Pfiii
	.p2align	8
	.type	_Z17_2Dstencil_globalPiS_Pfiii,@function
_Z17_2Dstencil_globalPiS_Pfiii:         ; @_Z17_2Dstencil_globalPiS_Pfiii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x18
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v5, 0x3ff, v0
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[2:3], null, s15, s3, v[1:2]
	s_mul_i32 s14, s14, s2
	s_load_b32 s2, s[0:1], 0x0
	s_cmp_lt_i32 s6, 2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, v2, s4
	v_add3_u32 v0, s14, v5, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s8, v0
	v_add_co_ci_u32_e32 v7, vcc_lo, s9, v1, vcc_lo
	global_load_b32 v4, v[6:7], off
	s_waitcnt vmcnt(0)
	v_cvt_f32_i32_e32 v4, v4
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v4, s2, v4
	v_cvt_i32_f32_e32 v6, v4
	s_cbranch_scc1 .LBB1_11
; %bb.1:                                ; %.lr.ph.preheader
	v_add_nc_u32_e32 v7, -1, v2
	v_add_nc_u32_e32 v8, 1, v2
	v_add_nc_u32_e32 v10, v5, v3
	s_lshr_b32 s2, s6, 1
	s_add_u32 s0, s0, 4
	v_mad_u64_u32 v[2:3], null, s4, v7, v[5:6]
	v_mad_u64_u32 v[3:4], null, s4, v8, v[5:6]
	v_add_nc_u32_e32 v4, -1, v5
	v_add_nc_u32_e32 v9, -1, v10
	v_add_nc_u32_e32 v10, 1, v10
	v_add_nc_u32_e32 v5, 1, v5
	s_addc_u32 s1, s1, 0
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v11, s14, v5
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_i32_e64 s4, v11
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_nc_u32_e32 v11, s14, v10
	s_load_b32 s6, s[0:1], 0x0
	v_cvt_f32_i32_e32 v6, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v12, 31, v11
	v_lshlrev_b64 v[11:12], 2, v[11:12]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v11, vcc_lo, s8, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, s9, v12, vcc_lo
	global_load_b32 v11, v[11:12], off
	s_waitcnt vmcnt(0)
	v_cvt_f32_i32_e32 v11, v11
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, s6, v11
	v_cvt_i32_f32_e32 v6, v6
.LBB1_4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	v_add_nc_u32_e32 v11, s14, v4
	s_mov_b32 s3, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_lt_i32_e32 -1, v11
	s_cbranch_execz .LBB1_6
; %bb.5:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_nc_u32_e32 v11, s14, v9
	s_load_b32 s6, s[0:1], 0x0
	v_cvt_f32_i32_e32 v6, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v12, 31, v11
	v_lshlrev_b64 v[11:12], 2, v[11:12]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v11, vcc_lo, s8, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, s9, v12, vcc_lo
	global_load_b32 v11, v[11:12], off
	s_waitcnt vmcnt(0)
	v_cvt_f32_i32_e32 v11, v11
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, s6, v11
	v_cvt_i32_f32_e32 v6, v6
.LBB1_6:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_i32_e64 s5, v8
	s_cbranch_execz .LBB1_8
; %bb.7:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_nc_u32_e32 v11, s14, v3
	s_load_b32 s6, s[0:1], 0x0
	v_cvt_f32_i32_e32 v6, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v12, 31, v11
	v_lshlrev_b64 v[11:12], 2, v[11:12]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v11, vcc_lo, s8, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, s9, v12, vcc_lo
	global_load_b32 v11, v[11:12], off
	s_waitcnt vmcnt(0)
	v_cvt_f32_i32_e32 v11, v11
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, s6, v11
	v_cvt_i32_f32_e32 v6, v6
.LBB1_8:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 s3, exec_lo
	v_cmpx_lt_i32_e32 -1, v7
	s_cbranch_execz .LBB1_10
; %bb.9:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_nc_u32_e32 v11, s14, v2
	s_load_b32 s6, s[0:1], 0x0
	v_cvt_f32_i32_e32 v6, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v12, 31, v11
	v_lshlrev_b64 v[11:12], 2, v[11:12]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v11, vcc_lo, s8, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, s9, v12, vcc_lo
	global_load_b32 v11, v[11:12], off
	s_waitcnt vmcnt(0)
	v_cvt_f32_i32_e32 v11, v11
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, s6, v11
	v_cvt_i32_f32_e32 v6, v6
.LBB1_10:                               ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_add_i32 s2, s2, -1
	v_add_nc_u32_e32 v7, -1, v7
	v_subrev_nc_u32_e32 v2, s4, v2
	v_add_nc_u32_e32 v3, s4, v3
	v_add_nc_u32_e32 v8, 1, v8
	v_add_nc_u32_e32 v4, -1, v4
	v_add_nc_u32_e32 v9, -1, v9
	v_add_nc_u32_e32 v10, 1, v10
	v_add_nc_u32_e32 v5, 1, v5
	s_add_u32 s0, s0, 4
	s_addc_u32 s1, s1, 0
	s_cmp_eq_u32 s2, 0
	s_cbranch_scc0 .LBB1_2
.LBB1_11:                               ; %Flow106
	v_add_co_u32 v0, vcc_lo, s10, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v1, vcc_lo
	global_store_b32 v[0:1], v6, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z17_2Dstencil_globalPiS_Pfiii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 13
		.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	_Z17_2Dstencil_globalPiS_Pfiii, .Lfunc_end1-_Z17_2Dstencil_globalPiS_Pfiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 740
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; 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:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14_copy_dr_to_dePiS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14_copy_dr_to_dePiS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z17_2Dstencil_globalPiS_Pfiii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z17_2Dstencil_globalPiS_Pfiii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
