#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <math.h>
#include <string.h>

void fd_init(int order, int nx, int nz, float dx, float dz);
void fd_init_cuda(int order, int nxe, int nze);
float *calc_coefs(int order);
static void makeo2 (float *coef,int order);
void read_input(char *file);
void free_memory();

#define sizeblock 32
#define PI (3.141592653589793)

char *file_path;
float *input_data, *output_data;

float *d_p;
float *d_laplace, *d_coefs_x, *d_coefs_z;

size_t mtxBufferLength, coefsBufferLength;

int gridx, gridz;
int nz, nx, nxb, nzb, nxe, nze, order;
float dz, dx;

static float dx2inv, dz2inv;
static float *coefs = NULL;
static float *coefs_z = NULL;
static float *coefs_x = NULL;

void read_input(char *file)
{
        FILE *fp;
        fp = fopen(file, "r");
        char *line = NULL;
        size_t len = 0;
        if (fp == NULL)
                exit(EXIT_FAILURE);
        while (getline(&line, &len, fp) != -1) {
                if(strstr(line,"tmpdir") != NULL)
                {
                        char *tok;
                        tok = strtok(line, "=");
                        tok = strtok(NULL,"=");
                        tok[strlen(tok) - 1] = '\0';
                        file_path = strdup(tok);
                }
                if(strstr(line,"nzb") != NULL)
                {
                        char *nzb_char;
                        nzb_char = strtok(line, "=");
                        nzb_char = strtok(NULL,"=");
                        nzb = atoi(nzb_char);
                }
                if(strstr(line,"nxb") != NULL)
                {
                        char *nxb_char;
                        nxb_char = strtok(line, "=");
                        nxb_char = strtok(NULL,"=");
                        nxb = atoi(nxb_char);
                }
                if(strstr(line,"nz") != NULL)
                {
                        char *nz_char;
                        nz_char = strtok(line, "=");
                        if (strlen(nz_char) <= 2)
                        {
                                nz_char = strtok(NULL,"=");
                                nz = atoi(nz_char);
                        }
                }
                if(strstr(line,"nx") != NULL)
                {
                        char *nx_char;
                        nx_char = strtok(line, "=");
                        if (strlen(nx_char) <= 2)
                        {
                                nx_char = strtok(NULL,"=");
                                nx = atoi(nx_char);
                        }
                }
                if(strstr(line,"dz") != NULL)
                {
                        char *dz_char;
                        dz_char = strtok(line, "=");
                        dz_char = strtok(NULL,"=");
                        dz = atof(dz_char);
                }
                if(strstr(line,"dx") != NULL)
                {
                        char *dx_char;
                        dx_char = strtok(line, "=");
                        dx_char = strtok(NULL,"=");
                        dx = atof(dx_char);
                }
                if(strstr(line,"order") != NULL)
                {
                        char *order_char;
                        order_char = strtok(line, "=");
                        order_char = strtok(NULL,"=");
                        order = atoi(order_char);
                }
        }
        free(line);
}

__global__ void kernel_lap(int order, int nx, int nz, float * __restrict__ p, float * __restrict__ lap, float * __restrict__ coefsx, float * __restrict__ coefsz)
{
        int half_order=order/2;
        int i =  half_order + blockIdx.x * blockDim.x + threadIdx.x; // Global row index
        int j =  half_order + blockIdx.y * blockDim.y + threadIdx.y; // Global column index
        int mult = i*nz;
        int aux;
        float acmx = 0, acmz = 0;

        if(i<nx - half_order)
        {
                if(j<nz - half_order)
                {
                        for(int io=0;io<=order;io++)
                        {
                                aux = io-half_order;
                                acmz += p[mult + j+aux]*coefsz[io];
                                acmx += p[(i+aux)*nz + j]*coefsx[io];
                        }
                        lap[mult +j] = acmz + acmx;
                        acmx = 0.0;
                        acmz = 0.0;
                }
        }

}

float *calc_coefs(int order)
{
        float *coef;

        coef = (float *)calloc(order+1,sizeof(float));
        switch(order)
        {
                case 2:
                        coef[0] = 1.;
                        coef[1] = -2.;
                        coef[2] = 1.;
                        break;
                case 4:
                        coef[0] = -1./12.;
                        coef[1] = 4./3.;
                        coef[2] = -5./2.;
                        coef[3] = 4./3.;
                        coef[4] = -1./12.;
                        break;
                case 6:
                        coef[0] = 1./90.;
                        coef[1] = -3./20.;
                        coef[2] = 3./2.;
                        coef[3] = -49./18.;
                        coef[4] = 3./2.;
                        coef[5] = -3./20.;
                        coef[6] = 1./90.;
                        break;
                case 8:

                        coef[0] = -1./560.;
                        coef[1] = 8./315.;
                        coef[2] = -1./5.;
                        coef[3] = 8./5.;
                        coef[4] = -205./72.;
                        coef[5] = 8./5.;
                        coef[6] = -1./5.;
                        coef[7] = 8./315.;
                        coef[8] = -1./560.;
                        break;
                default:
                        makeo2(coef,order);
        }

        return coef;
}

static void makeo2 (float *coef,int order)
{
        float h_beta, alpha1=0.0;
        float alpha2=0.0;
        float  central_term=0.0;
        float coef_filt=0;
        float arg=0.0;
        float  coef_wind=0.0;
        int msign,ix;

        float alpha = .54;
        float beta = 6.;
        h_beta = 0.5*beta;
        alpha1=2.*alpha-1.0;
        alpha2=2.*(1.0-alpha);
        central_term=0.0;

        msign=-1;

        for (ix=1; ix <= order/2; ix++){
                msign=-msign ;
                coef_filt = (2.*msign)/(ix*ix);
                arg = PI*ix/(2.*(order/2+2));
                coef_wind=pow((alpha1+alpha2*cos(arg)*cos(arg)),h_beta);
                coef[order/2+ix] = coef_filt*coef_wind;
                central_term = central_term + coef[order/2+ix];
                coef[order/2-ix] = coef[order/2+ix];
        }

        coef[order/2]  = -2.*central_term;

        return;
}

void fd_init_cuda(int order, int nxe, int nze)
{
        mtxBufferLength = (nxe*nze)*sizeof(float);
        coefsBufferLength = (order+1)*sizeof(float);

        // Create a Device pointers
        cudaMalloc(&d_p, mtxBufferLength);
        cudaMalloc(&d_laplace, mtxBufferLength);
        cudaMalloc(&d_coefs_x, coefsBufferLength);
        cudaMalloc(&d_coefs_z, coefsBufferLength);

        int div_x, div_z;
        // Set a Grid for the execution on the device
        int tx = ((nxe - 1) / 32 + 1) * 32;
        int tz = ((nze - 1) / 32 + 1) * 32;

        div_x = (float) tx/(float) sizeblock;
        div_z = (float) tz/(float) sizeblock;

        gridx = (int) ceil(div_x);
        gridz = (int) ceil(div_z);
}

void fd_init(int order, int nx, int nz, float dx, float dz)
{
        int io;
        dx2inv = (1./dx)*(1./dx);
        dz2inv = (1./dz)*(1./dz);

        coefs = calc_coefs(order);

        coefs_z = calc_coefs(order);
        coefs_x = calc_coefs(order);

        // pre calc coefs 8 d2 inv
        for (io = 0; io <= order; io++)
        {
                coefs_z[io] = dz2inv * coefs[io];
                coefs_x[io] = dx2inv * coefs[io];
        }

        fd_init_cuda(order,nx,nz);

        return;
}

void free_memory()
{
        free(coefs_z);
        free(coefs_x);
        free(file_path);
        free(input_data);
        free(output_data);
        cudaFree(d_p);
        cudaFree(d_laplace);
        cudaFree(d_coefs_x);
        cudaFree(d_coefs_z);
}

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

        printf("Local do arquivo: %s\n", file_path);
        printf("nzb = %i\n", nzb);
        printf("nzb = %i\n", nxb);
        printf("nz = %i\n", nz);
        printf("nx = %i\n", nx);
        printf("dz = %f\n", dz);
        printf("dx = %f\n", dx);
        printf("order = %i\n", order);

        nxe = nx + 2 * nxb;
        nze = nz + 2 * nzb;
        // initialization
        fd_init(order,nxe,nze,dx,dz);

        dim3 dimGrid(gridx, gridz);
        dim3 dimBlock(sizeblock, sizeblock);
        FILE *finput;

        if((finput = fopen(file_path, "rb")) == NULL)
                printf("Unable to open file!\n");
        else
                printf("Input successfully opened for reading.\n");

        input_data = (float*)malloc(mtxBufferLength);
        if(!input_data)
                printf("Input memory allocation error!\n");
        else
                printf("Input memory allocation was successful.\n");

        memset(input_data, 0, mtxBufferLength);

        if( fread(input_data, sizeof(float), nze*nxe, finput) != nze*nxe)
                printf("Input reading error!\n");

        else
                printf("Input reading was successful.\n");
        fclose(finput);

        // data copy
        cudaMemcpy(d_p, input_data, mtxBufferLength, cudaMemcpyHostToDevice);
        cudaMemcpy(d_coefs_x, coefs_x, coefsBufferLength, cudaMemcpyHostToDevice);
        cudaMemcpy(d_coefs_z, coefs_z, coefsBufferLength, cudaMemcpyHostToDevice);

        // kernel utilization
        kernel_lap<<<dimGrid, dimBlock>>>(order,nxe,nze,d_p,d_laplace,d_coefs_x,d_coefs_z);

        output_data = (float*)malloc(mtxBufferLength);
        if(!output_data)
                printf("Output memory allocation error!\n");
        else
                printf("Output memory allocation was successful.\n");
        memset(output_data, 0, mtxBufferLength);
        cudaMemcpy(output_data, d_laplace, mtxBufferLength, cudaMemcpyDeviceToHost);

        // Writing output
        FILE *foutput;
        if((foutput = fopen("../bin/output_cuda.bin", "wb")) == NULL)
                printf("Unable to open file!\n");
        else
                printf("Output successfully opened for writing.\n");

        if( fwrite(output_data, sizeof(float), nze*nxe, foutput) != nze*nxe)
                printf("Output writing error!\n");

        else
                printf("Output writing was successful.\n");
        fclose(foutput);

        // free memory device
        free_memory();
        return 0;
}

	.file	"tmpxft_00311b39_00000000-6_fd-source-code.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2036:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2036:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"tmpdir"
.LC2:
	.string	"="
.LC3:
	.string	"nzb"
.LC4:
	.string	"nxb"
.LC5:
	.string	"nz"
.LC6:
	.string	"nx"
.LC7:
	.string	"dz"
.LC8:
	.string	"dx"
.LC9:
	.string	"order"
	.text
	.globl	_Z10read_inputPc
	.type	_Z10read_inputPc, @function
_Z10read_inputPc:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	xorl	%edx, %edx
	movq	%rdx, 24(%rsp)
	movq	%rax, %rbp
	movq	%rdx, 32(%rsp)
	testq	%rax, %rax
	jne	.L15
	movl	$1, %edi
	call	exit@PLT
.L16:
	movq	%r12, %rsi
	movq	%rdi, 8(%rsp)
	call	strstr@PLT
	testq	%rax, %rax
	je	.L4
	leaq	.LC2(%rip), %rbx
	movq	8(%rsp), %rdi
	movq	%rbx, %rsi
	call	strtok@PLT
	movq	%rbx, %rsi
	xorl	%edi, %edi
	call	strtok@PLT
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	strlen@PLT
	movq	%rbx, %rdi
	movb	$0, -1(%rbx,%rax)
	call	strdup@PLT
	movq	%rax, file_path(%rip)
.L4:
	movq	24(%rsp), %r13
	leaq	.LC3(%rip), %rsi
	movq	%r13, %rdi
	call	strstr@PLT
	testq	%rax, %rax
	je	.L5
	leaq	.LC2(%rip), %rbx
	movq	%r13, %rdi
	movq	%rbx, %rsi
	call	strtok@PLT
	movq	%rbx, %rsi
	xorl	%edi, %edi
	call	strtok@PLT
	movq	%rax, %rdi
	call	atoi@PLT
	movl	%eax, nzb(%rip)
.L5:
	movq	24(%rsp), %r13
	leaq	.LC4(%rip), %rsi
	movq	%r13, %rdi
	call	strstr@PLT
	testq	%rax, %rax
	je	.L6
	leaq	.LC2(%rip), %rbx
	movq	%r13, %rdi
	movq	%rbx, %rsi
	call	strtok@PLT
	movq	%rbx, %rsi
	xorl	%edi, %edi
	call	strtok@PLT
	movq	%rax, %rdi
	call	atoi@PLT
	movl	%eax, nxb(%rip)
.L6:
	movq	24(%rsp), %r13
	leaq	.LC5(%rip), %rsi
	movq	%r13, %rdi
	call	strstr@PLT
	testq	%rax, %rax
	jne	.L38
.L8:
	movq	24(%rsp), %r13
	leaq	.LC6(%rip), %rsi
	movq	%r13, %rdi
	call	strstr@PLT
	testq	%rax, %rax
	jne	.L39
.L11:
	movq	24(%rsp), %r13
	leaq	.LC7(%rip), %rsi
	movq	%r13, %rdi
	call	strstr@PLT
	testq	%rax, %rax
	je	.L13
	leaq	.LC2(%rip), %rbx
	movq	%r13, %rdi
	movq	%rbx, %rsi
	call	strtok@PLT
	movq	%rbx, %rsi
	xorl	%edi, %edi
	call	strtok@PLT
	movq	%rax, %rdi
	call	atof@PLT
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, dz(%rip)
.L13:
	movq	24(%rsp), %r13
	leaq	.LC8(%rip), %rsi
	movq	%r13, %rdi
	call	strstr@PLT
	testq	%rax, %rax
	je	.L14
	leaq	.LC2(%rip), %rbx
	movq	%r13, %rdi
	movq	%rbx, %rsi
	call	strtok@PLT
	movq	%rbx, %rsi
	xorl	%edi, %edi
	call	strtok@PLT
	movq	%rax, %rdi
	call	atof@PLT
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, dx(%rip)
.L14:
	movq	24(%rsp), %r13
	leaq	.LC9(%rip), %rsi
	movq	%r13, %rdi
	call	strstr@PLT
	testq	%rax, %rax
	je	.L15
	leaq	.LC2(%rip), %rbx
	movq	%r13, %rdi
	movq	%rbx, %rsi
	call	strtok@PLT
	movq	%rbx, %rsi
	xorl	%edi, %edi
	call	strtok@PLT
	movq	%rax, %rdi
	call	atoi@PLT
	movl	%eax, order(%rip)
.L15:
	leaq	24(%rsp), %rdi
	leaq	32(%rsp), %rsi
	movq	%rbp, %rdx
	call	getline@PLT
	movq	24(%rsp), %rdi
	incq	%rax
	jne	.L16
	jmp	.L40
.L38:
	leaq	.LC2(%rip), %rbx
	movq	%r13, %rdi
	movq	%rbx, %rsi
	call	strtok@PLT
	movq	%rax, %rdi
	call	strlen@PLT
	cmpq	$2, %rax
	ja	.L8
	movq	%rbx, %rsi
	xorl	%edi, %edi
	call	strtok@PLT
	movq	%rax, %rdi
	call	atoi@PLT
	movl	%eax, nz(%rip)
	jmp	.L8
.L39:
	leaq	.LC2(%rip), %rbx
	movq	%r13, %rdi
	movq	%rbx, %rsi
	call	strtok@PLT
	movq	%rax, %rdi
	call	strlen@PLT
	cmpq	$2, %rax
	ja	.L11
	movq	%rbx, %rsi
	xorl	%edi, %edi
	call	strtok@PLT
	movq	%rax, %rdi
	call	atoi@PLT
	movl	%eax, nx(%rip)
	jmp	.L11
.L40:
	call	free@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z10read_inputPc, .-_Z10read_inputPc
	.globl	_Z10calc_coefsi
	.type	_Z10calc_coefsi, @function
_Z10calc_coefsi:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$4, %esi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edi, %ebp
	incl	%edi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%edi, %rdi
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	calloc@PLT
	movq	%rax, %rbx
	cmpl	$6, %ebp
	je	.L42
	jg	.L43
	cmpl	$2, %ebp
	je	.L44
	cmpl	$4, %ebp
	je	.L45
	jmp	.L46
.L43:
	cmpl	$8, %ebp
	je	.L47
.L46:
	movl	%ebp, %eax
	movl	$2, %ecx
	xorps	%xmm2, %xmm2
	movl	$1, %r12d
	cltd
	orl	$-1, %r14d
	idivl	%ecx
	cltq
	movq	%rax, %rbp
	leal	2(%rax), %r15d
	leaq	(%rbx,%rax,4), %r13
	jmp	.L48
.L44:
	movabsq	$-4611686017362034688, %rax
	movl	$0x3f800000, 8(%rbx)
	movq	%rax, (%rbx)
	jmp	.L41
.L45:
	movabsq	$4587666825028479659, %rax
	movl	$0xbdaaaaab, 16(%rbx)
	movq	%rax, (%rbx)
	addq	$41243989, %rax
	movq	%rax, 8(%rbx)
	jmp	.L41
.L42:
	movabsq	$-4748595444371289247, %rax
	movl	$0x3c360b61, 24(%rbx)
	movq	%rax, (%rbx)
	movabsq	$-4598675616525451264, %rax
	movq	%rax, 8(%rbx)
	movabsq	$-4748595444311916544, %rax
	movq	%rax, 16(%rbx)
	jmp	.L41
.L47:
	movabsq	$4382016738513522337, %rax
	movl	$0xbaea0ea1, 32(%rbx)
	movq	%rax, (%rbx)
	movabsq	$4597274503671499981, %rax
	movq	%rax, 8(%rbx)
	addq	$32074775, %rax
	movq	%rax, 16(%rbx)
	movabsq	$4382016738570325197, %rax
	movq	%rax, 24(%rbx)
	jmp	.L41
.L48:
	cmpl	%r12d, %ebp
	jl	.L52
	cvtsi2sdl	%r15d, %xmm1
	movss	%xmm2, 12(%rsp)
	negl	%r14d
	cvtsi2sdl	%r12d, %xmm0
	mulsd	.LC15(%rip), %xmm0
	addsd	%xmm1, %xmm1
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	call	cosf@PLT
	movaps	%xmm0, %xmm1
	movss	.LC16(%rip), %xmm0
	mulss	%xmm1, %xmm0
	mulss	%xmm1, %xmm0
	movss	.LC18(%rip), %xmm1
	addss	.LC17(%rip), %xmm0
	call	powf@PLT
	movl	%r12d, %eax
	movss	12(%rsp), %xmm2
	imull	%r12d, %eax
	movaps	%xmm0, %xmm1
	cvtsi2sdl	%r14d, %xmm0
	cvtsi2sdl	%eax, %xmm3
	imulq	$-4, %r12, %rax
	addsd	%xmm0, %xmm0
	divsd	%xmm3, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	mulss	%xmm1, %xmm0
	movss	%xmm0, 0(%r13,%r12,4)
	addss	%xmm0, %xmm2
	incq	%r12
	movss	%xmm0, 0(%r13,%rax)
	jmp	.L48
.L52:
	mulss	.LC19(%rip), %xmm2
	movss	%xmm2, 0(%r13)
.L41:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z10calc_coefsi, .-_Z10calc_coefsi
	.globl	_Z12fd_init_cudaiii
	.type	_Z12fd_init_cudaiii, @function
_Z12fd_init_cudaiii:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %ebp
	imull	%edx, %esi
	incl	%edi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movslq	%edi, %rdi
	movl	%edx, %ebx
	pushq	%rax
	.cfi_def_cfa_offset 32
	salq	$2, %rdi
	movslq	%esi, %rsi
	movq	%rdi, coefsBufferLength(%rip)
	leaq	d_p(%rip), %rdi
	salq	$2, %rsi
	movq	%rsi, mtxBufferLength(%rip)
	call	cudaMalloc@PLT
	movq	mtxBufferLength(%rip), %rsi
	leaq	d_laplace(%rip), %rdi
	call	cudaMalloc@PLT
	movq	coefsBufferLength(%rip), %rsi
	leaq	d_coefs_x(%rip), %rdi
	call	cudaMalloc@PLT
	movq	coefsBufferLength(%rip), %rsi
	leaq	d_coefs_z(%rip), %rdi
	call	cudaMalloc@PLT
	leal	-1(%rbp), %eax
	movl	$32, %ecx
	movss	.LC20(%rip), %xmm1
	cltd
	idivl	%ecx
	incl	%eax
	sall	$5, %eax
	cvtsi2ssl	%eax, %xmm0
	mulss	%xmm1, %xmm0
	cvttss2sil	%xmm0, %eax
	movl	%eax, gridx(%rip)
	leal	-1(%rbx), %eax
	cltd
	idivl	%ecx
	incl	%eax
	sall	$5, %eax
	cvtsi2ssl	%eax, %xmm0
	mulss	%xmm1, %xmm0
	cvttss2sil	%xmm0, %eax
	movl	%eax, gridz(%rip)
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z12fd_init_cudaiii, .-_Z12fd_init_cudaiii
	.globl	_Z7fd_initiiiff
	.type	_Z7fd_initiiiff, @function
_Z7fd_initiiiff:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movsd	.LC21(%rip), %xmm2
	movl	%esi, 12(%rsp)
	movaps	%xmm2, %xmm3
	divsd	%xmm0, %xmm3
	divsd	%xmm1, %xmm2
	mulsd	%xmm3, %xmm3
	cvtsd2ss	%xmm3, %xmm3
	movss	%xmm3, 8(%rsp)
	mulsd	%xmm2, %xmm2
	cvtsd2ss	%xmm2, %xmm2
	movss	%xmm2, 4(%rsp)
	call	_Z10calc_coefsi
	movl	%ebx, %edi
	movq	%rax, %r13
	call	_Z10calc_coefsi
	movl	%ebx, %edi
	movq	%rax, _ZL7coefs_z(%rip)
	movq	%rax, %r14
	call	_Z10calc_coefsi
	movss	4(%rsp), %xmm2
	movss	8(%rsp), %xmm3
	xorl	%edx, %edx
	movq	%rax, _ZL7coefs_x(%rip)
	movl	12(%rsp), %esi
.L56:
	cmpl	%edx, %ebx
	jl	.L59
	movss	0(%r13,%rdx,4), %xmm0
	mulss	%xmm2, %xmm0
	movss	%xmm0, (%r14,%rdx,4)
	movss	0(%r13,%rdx,4), %xmm0
	mulss	%xmm3, %xmm0
	movss	%xmm0, (%rax,%rdx,4)
	incq	%rdx
	jmp	.L56
.L59:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	movl	%r12d, %edx
	movl	%ebx, %edi
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	_Z12fd_init_cudaiii
	.cfi_endproc
.LFE2031:
	.size	_Z7fd_initiiiff, .-_Z7fd_initiiiff
	.globl	_Z11free_memoryv
	.type	_Z11free_memoryv, @function
_Z11free_memoryv:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	_ZL7coefs_z(%rip), %rdi
	call	free@PLT
	movq	_ZL7coefs_x(%rip), %rdi
	call	free@PLT
	movq	file_path(%rip), %rdi
	call	free@PLT
	movq	input_data(%rip), %rdi
	call	free@PLT
	movq	output_data(%rip), %rdi
	call	free@PLT
	movq	d_p(%rip), %rdi
	call	cudaFree@PLT
	movq	d_laplace(%rip), %rdi
	call	cudaFree@PLT
	movq	d_coefs_x(%rip), %rdi
	call	cudaFree@PLT
	movq	d_coefs_z(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	cudaFree@PLT
	.cfi_endproc
.LFE2032:
	.size	_Z11free_memoryv, .-_Z11free_memoryv
	.globl	_Z39__device_stub__Z10kernel_lapiiiPfS_S_S_iiiPfS_S_S_
	.type	_Z39__device_stub__Z10kernel_lapiiiPfS_S_S_iiiPfS_S_S_, @function
_Z39__device_stub__Z10kernel_lapiiiPfS_S_S_iiiPfS_S_S_:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movl	%edi, 12(%rsp)
	leaq	64(%rsp), %rdi
	movl	%esi, 8(%rsp)
	leaq	76(%rsp), %rsi
	movl	%edx, 4(%rsp)
	leaq	48(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rax
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 152(%rsp)
	movq	192(%rsp), %rax
	movq	%r8, 24(%rsp)
	movq	%rax, 40(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%r9, 32(%rsp)
	movq	%rax, 64(%rsp)
	movl	$1, 72(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L62
	pushq	56(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z10kernel_lapiiiPfS_S_S_(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 208
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L62:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L64
	call	__stack_chk_fail@PLT
.L64:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z39__device_stub__Z10kernel_lapiiiPfS_S_S_iiiPfS_S_S_, .-_Z39__device_stub__Z10kernel_lapiiiPfS_S_S_iiiPfS_S_S_
	.globl	_Z10kernel_lapiiiPfS_S_S_
	.type	_Z10kernel_lapiiiPfS_S_S_, @function
_Z10kernel_lapiiiPfS_S_S_:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z10kernel_lapiiiPfS_S_S_iiiPfS_S_S_
	.cfi_endproc
.LFE2059:
	.size	_Z10kernel_lapiiiPfS_S_S_, .-_Z10kernel_lapiiiPfS_S_S_
	.section	.rodata.str1.1
.LC22:
	.string	"Local do arquivo: %s\n"
.LC23:
	.string	"nzb = %i\n"
.LC24:
	.string	"nz = %i\n"
.LC25:
	.string	"nx = %i\n"
.LC26:
	.string	"dz = %f\n"
.LC27:
	.string	"dx = %f\n"
.LC28:
	.string	"order = %i\n"
.LC29:
	.string	"rb"
.LC30:
	.string	"Unable to open file!\n"
.LC31:
	.string	"Input successfully opened for reading.\n"
.LC32:
	.string	"Input memory allocation error!\n"
.LC33:
	.string	"Input memory allocation was successful.\n"
.LC34:
	.string	"Input reading error!\n"
.LC35:
	.string	"Input reading was successful.\n"
.LC36:
	.string	"Output memory allocation error!\n"
.LC37:
	.string	"Output memory allocation was successful.\n"
.LC38:
	.string	"wb"
.LC39:
	.string	"../bin/output_cuda.bin"
.LC40:
	.string	"Output successfully opened for writing.\n"
.LC41:
	.string	"Output writing error!\n"
.LC42:
	.string	"Output writing was successful.\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	.LC23(%rip), %rbx
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	8(%rsi), %rdi
	call	_Z10read_inputPc
	movq	file_path(%rip), %rdx
	leaq	.LC22(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	nzb(%rip), %edx
	movq	%rbx, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	nxb(%rip), %edx
	movq	%rbx, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	nz(%rip), %edx
	leaq	.LC24(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	nx(%rip), %edx
	leaq	.LC25(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC26(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	cvtss2sd	dz(%rip), %xmm0
	call	__printf_chk@PLT
	movb	$1, %al
	leaq	.LC27(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	dx(%rip), %xmm0
	call	__printf_chk@PLT
	movl	order(%rip), %edx
	leaq	.LC28(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	nxb(%rip), %edx
	movl	nx(%rip), %eax
	movss	dz(%rip), %xmm1
	movss	dx(%rip), %xmm0
	leal	(%rax,%rdx,2), %esi
	movl	nz(%rip), %eax
	movl	nzb(%rip), %edx
	movl	order(%rip), %edi
	movl	%esi, nxe(%rip)
	leal	(%rax,%rdx,2), %edx
	movl	%edx, nze(%rip)
	call	_Z7fd_initiiiff
	movl	gridx(%rip), %eax
	movq	file_path(%rip), %rdi
	leaq	.LC29(%rip), %rsi
	movl	$1, 16(%rsp)
	movl	%eax, 8(%rsp)
	movl	gridz(%rip), %eax
	movl	$1, 28(%rsp)
	movl	%eax, 12(%rsp)
	movabsq	$137438953504, %rax
	movq	%rax, 20(%rsp)
	call	fopen@PLT
	leaq	.LC30(%rip), %rsi
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.L82
	leaq	.LC31(%rip), %rsi
.L82:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	mtxBufferLength(%rip), %rdi
	call	malloc@PLT
	leaq	.LC32(%rip), %rsi
	movl	$2, %edi
	movq	%rax, input_data(%rip)
	testq	%rax, %rax
	je	.L83
	leaq	.LC33(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
.L83:
	call	__printf_chk@PLT
	xorl	%eax, %eax
	movl	$4, %edx
	orq	$-1, %rsi
	movq	mtxBufferLength(%rip), %rcx
	movq	input_data(%rip), %rdi
	movq	%rbx, %r8
	rep stosb
	movl	nze(%rip), %ecx
	imull	nxe(%rip), %ecx
	movq	input_data(%rip), %rdi
	movslq	%ecx, %rcx
	call	__fread_chk@PLT
	leaq	.LC34(%rip), %rsi
	movq	%rax, %rdx
	movl	nze(%rip), %eax
	imull	nxe(%rip), %eax
	cltq
	cmpq	%rdx, %rax
	jne	.L84
	leaq	.LC35(%rip), %rsi
.L84:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	mtxBufferLength(%rip), %rdx
	movl	$1, %ecx
	movq	input_data(%rip), %rsi
	movq	d_p(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	coefsBufferLength(%rip), %rdx
	movl	$1, %ecx
	movq	_ZL7coefs_x(%rip), %rsi
	movq	d_coefs_x(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	coefsBufferLength(%rip), %rdx
	movl	$1, %ecx
	movq	_ZL7coefs_z(%rip), %rsi
	movq	d_coefs_z(%rip), %rdi
	call	cudaMemcpy@PLT
	movl	28(%rsp), %ecx
	movl	16(%rsp), %esi
	xorl	%r9d, %r9d
	movq	20(%rsp), %rdx
	movq	8(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L74
	movq	d_p(%rip), %rcx
	movl	nze(%rip), %edx
	pushq	%rax
	.cfi_def_cfa_offset 56
	pushq	d_coefs_z(%rip)
	.cfi_def_cfa_offset 64
	movq	d_coefs_x(%rip), %r9
	movq	d_laplace(%rip), %r8
	movl	nxe(%rip), %esi
	movl	order(%rip), %edi
	call	_Z39__device_stub__Z10kernel_lapiiiPfS_S_S_iiiPfS_S_S_
	popq	%rdx
	.cfi_def_cfa_offset 56
	popq	%rcx
	.cfi_def_cfa_offset 48
.L74:
	movq	mtxBufferLength(%rip), %rdi
	call	malloc@PLT
	leaq	.LC36(%rip), %rsi
	movl	$2, %edi
	movq	%rax, output_data(%rip)
	testq	%rax, %rax
	je	.L85
	leaq	.LC37(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
.L85:
	call	__printf_chk@PLT
	movq	mtxBufferLength(%rip), %rcx
	movq	output_data(%rip), %rdi
	xorl	%eax, %eax
	rep stosb
	movl	$2, %ecx
	movq	mtxBufferLength(%rip), %rdx
	movq	d_laplace(%rip), %rsi
	movq	output_data(%rip), %rdi
	call	cudaMemcpy@PLT
	leaq	.LC38(%rip), %rsi
	leaq	.LC39(%rip), %rdi
	call	fopen@PLT
	leaq	.LC30(%rip), %rsi
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.L86
	leaq	.LC40(%rip), %rsi
.L86:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	nze(%rip), %edx
	movl	$4, %esi
	movq	%rbx, %rcx
	imull	nxe(%rip), %edx
	movq	output_data(%rip), %rdi
	movslq	%edx, %rdx
	call	fwrite@PLT
	leaq	.LC41(%rip), %rsi
	movq	%rax, %rdx
	movl	nze(%rip), %eax
	imull	nxe(%rip), %eax
	cltq
	cmpq	%rdx, %rax
	jne	.L87
	leaq	.LC42(%rip), %rsi
.L87:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	call	_Z11free_memoryv
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	main, .-main
	.section	.rodata.str1.1
.LC43:
	.string	"_Z10kernel_lapiiiPfS_S_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.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	.LC43(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z10kernel_lapiiiPfS_S_S_(%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
.LFE2061:
	.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
	.local	_ZL7coefs_x
	.comm	_ZL7coefs_x,8,8
	.local	_ZL7coefs_z
	.comm	_ZL7coefs_z,8,8
	.globl	dx
	.bss
	.align 4
	.type	dx, @object
	.size	dx, 4
dx:
	.zero	4
	.globl	dz
	.align 4
	.type	dz, @object
	.size	dz, 4
dz:
	.zero	4
	.globl	order
	.align 4
	.type	order, @object
	.size	order, 4
order:
	.zero	4
	.globl	nze
	.align 4
	.type	nze, @object
	.size	nze, 4
nze:
	.zero	4
	.globl	nxe
	.align 4
	.type	nxe, @object
	.size	nxe, 4
nxe:
	.zero	4
	.globl	nzb
	.align 4
	.type	nzb, @object
	.size	nzb, 4
nzb:
	.zero	4
	.globl	nxb
	.align 4
	.type	nxb, @object
	.size	nxb, 4
nxb:
	.zero	4
	.globl	nx
	.align 4
	.type	nx, @object
	.size	nx, 4
nx:
	.zero	4
	.globl	nz
	.align 4
	.type	nz, @object
	.size	nz, 4
nz:
	.zero	4
	.globl	gridz
	.align 4
	.type	gridz, @object
	.size	gridz, 4
gridz:
	.zero	4
	.globl	gridx
	.align 4
	.type	gridx, @object
	.size	gridx, 4
gridx:
	.zero	4
	.globl	coefsBufferLength
	.align 8
	.type	coefsBufferLength, @object
	.size	coefsBufferLength, 8
coefsBufferLength:
	.zero	8
	.globl	mtxBufferLength
	.align 8
	.type	mtxBufferLength, @object
	.size	mtxBufferLength, 8
mtxBufferLength:
	.zero	8
	.globl	d_coefs_z
	.align 8
	.type	d_coefs_z, @object
	.size	d_coefs_z, 8
d_coefs_z:
	.zero	8
	.globl	d_coefs_x
	.align 8
	.type	d_coefs_x, @object
	.size	d_coefs_x, 8
d_coefs_x:
	.zero	8
	.globl	d_laplace
	.align 8
	.type	d_laplace, @object
	.size	d_laplace, 8
d_laplace:
	.zero	8
	.globl	d_p
	.align 8
	.type	d_p, @object
	.size	d_p, 8
d_p:
	.zero	8
	.globl	output_data
	.align 8
	.type	output_data, @object
	.size	output_data, 8
output_data:
	.zero	8
	.globl	input_data
	.align 8
	.type	input_data, @object
	.size	input_data, 8
input_data:
	.zero	8
	.globl	file_path
	.align 8
	.type	file_path, @object
	.size	file_path, 8
file_path:
	.zero	8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC15:
	.long	1413754136
	.long	1074340347
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC16:
	.long	1064011038
	.align 4
.LC17:
	.long	1034147600
	.align 4
.LC18:
	.long	1077936128
	.align 4
.LC19:
	.long	-1073741824
	.align 4
.LC20:
	.long	1023410176
	.section	.rodata.cst8
	.align 8
.LC21:
	.long	0
	.long	1072693248
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

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

void fd_init(int order, int nx, int nz, float dx, float dz);
void fd_init_cuda(int order, int nxe, int nze);
float *calc_coefs(int order);
static void makeo2 (float *coef,int order);
void read_input(char *file);
void free_memory();

#define sizeblock 32
#define PI (3.141592653589793)

char *file_path;
float *input_data, *output_data;

float *d_p;
float *d_laplace, *d_coefs_x, *d_coefs_z;

size_t mtxBufferLength, coefsBufferLength;

int gridx, gridz;
int nz, nx, nxb, nzb, nxe, nze, order;
float dz, dx;

static float dx2inv, dz2inv;
static float *coefs = NULL;
static float *coefs_z = NULL;
static float *coefs_x = NULL;

void read_input(char *file)
{
        FILE *fp;
        fp = fopen(file, "r");
        char *line = NULL;
        size_t len = 0;
        if (fp == NULL)
                exit(EXIT_FAILURE);
        while (getline(&line, &len, fp) != -1) {
                if(strstr(line,"tmpdir") != NULL)
                {
                        char *tok;
                        tok = strtok(line, "=");
                        tok = strtok(NULL,"=");
                        tok[strlen(tok) - 1] = '\0';
                        file_path = strdup(tok);
                }
                if(strstr(line,"nzb") != NULL)
                {
                        char *nzb_char;
                        nzb_char = strtok(line, "=");
                        nzb_char = strtok(NULL,"=");
                        nzb = atoi(nzb_char);
                }
                if(strstr(line,"nxb") != NULL)
                {
                        char *nxb_char;
                        nxb_char = strtok(line, "=");
                        nxb_char = strtok(NULL,"=");
                        nxb = atoi(nxb_char);
                }
                if(strstr(line,"nz") != NULL)
                {
                        char *nz_char;
                        nz_char = strtok(line, "=");
                        if (strlen(nz_char) <= 2)
                        {
                                nz_char = strtok(NULL,"=");
                                nz = atoi(nz_char);
                        }
                }
                if(strstr(line,"nx") != NULL)
                {
                        char *nx_char;
                        nx_char = strtok(line, "=");
                        if (strlen(nx_char) <= 2)
                        {
                                nx_char = strtok(NULL,"=");
                                nx = atoi(nx_char);
                        }
                }
                if(strstr(line,"dz") != NULL)
                {
                        char *dz_char;
                        dz_char = strtok(line, "=");
                        dz_char = strtok(NULL,"=");
                        dz = atof(dz_char);
                }
                if(strstr(line,"dx") != NULL)
                {
                        char *dx_char;
                        dx_char = strtok(line, "=");
                        dx_char = strtok(NULL,"=");
                        dx = atof(dx_char);
                }
                if(strstr(line,"order") != NULL)
                {
                        char *order_char;
                        order_char = strtok(line, "=");
                        order_char = strtok(NULL,"=");
                        order = atoi(order_char);
                }
        }
        free(line);
}

__global__ void kernel_lap(int order, int nx, int nz, float * __restrict__ p, float * __restrict__ lap, float * __restrict__ coefsx, float * __restrict__ coefsz)
{
        int half_order=order/2;
        int i =  half_order + blockIdx.x * blockDim.x + threadIdx.x; // Global row index
        int j =  half_order + blockIdx.y * blockDim.y + threadIdx.y; // Global column index
        int mult = i*nz;
        int aux;
        float acmx = 0, acmz = 0;

        if(i<nx - half_order)
        {
                if(j<nz - half_order)
                {
                        for(int io=0;io<=order;io++)
                        {
                                aux = io-half_order;
                                acmz += p[mult + j+aux]*coefsz[io];
                                acmx += p[(i+aux)*nz + j]*coefsx[io];
                        }
                        lap[mult +j] = acmz + acmx;
                        acmx = 0.0;
                        acmz = 0.0;
                }
        }

}

float *calc_coefs(int order)
{
        float *coef;

        coef = (float *)calloc(order+1,sizeof(float));
        switch(order)
        {
                case 2:
                        coef[0] = 1.;
                        coef[1] = -2.;
                        coef[2] = 1.;
                        break;
                case 4:
                        coef[0] = -1./12.;
                        coef[1] = 4./3.;
                        coef[2] = -5./2.;
                        coef[3] = 4./3.;
                        coef[4] = -1./12.;
                        break;
                case 6:
                        coef[0] = 1./90.;
                        coef[1] = -3./20.;
                        coef[2] = 3./2.;
                        coef[3] = -49./18.;
                        coef[4] = 3./2.;
                        coef[5] = -3./20.;
                        coef[6] = 1./90.;
                        break;
                case 8:

                        coef[0] = -1./560.;
                        coef[1] = 8./315.;
                        coef[2] = -1./5.;
                        coef[3] = 8./5.;
                        coef[4] = -205./72.;
                        coef[5] = 8./5.;
                        coef[6] = -1./5.;
                        coef[7] = 8./315.;
                        coef[8] = -1./560.;
                        break;
                default:
                        makeo2(coef,order);
        }

        return coef;
}

static void makeo2 (float *coef,int order)
{
        float h_beta, alpha1=0.0;
        float alpha2=0.0;
        float  central_term=0.0;
        float coef_filt=0;
        float arg=0.0;
        float  coef_wind=0.0;
        int msign,ix;

        float alpha = .54;
        float beta = 6.;
        h_beta = 0.5*beta;
        alpha1=2.*alpha-1.0;
        alpha2=2.*(1.0-alpha);
        central_term=0.0;

        msign=-1;

        for (ix=1; ix <= order/2; ix++){
                msign=-msign ;
                coef_filt = (2.*msign)/(ix*ix);
                arg = PI*ix/(2.*(order/2+2));
                coef_wind=pow((alpha1+alpha2*cos(arg)*cos(arg)),h_beta);
                coef[order/2+ix] = coef_filt*coef_wind;
                central_term = central_term + coef[order/2+ix];
                coef[order/2-ix] = coef[order/2+ix];
        }

        coef[order/2]  = -2.*central_term;

        return;
}

void fd_init_cuda(int order, int nxe, int nze)
{
        mtxBufferLength = (nxe*nze)*sizeof(float);
        coefsBufferLength = (order+1)*sizeof(float);

        // Create a Device pointers
        hipMalloc(&d_p, mtxBufferLength);
        hipMalloc(&d_laplace, mtxBufferLength);
        hipMalloc(&d_coefs_x, coefsBufferLength);
        hipMalloc(&d_coefs_z, coefsBufferLength);

        int div_x, div_z;
        // Set a Grid for the execution on the device
        int tx = ((nxe - 1) / 32 + 1) * 32;
        int tz = ((nze - 1) / 32 + 1) * 32;

        div_x = (float) tx/(float) sizeblock;
        div_z = (float) tz/(float) sizeblock;

        gridx = (int) ceil(div_x);
        gridz = (int) ceil(div_z);
}

void fd_init(int order, int nx, int nz, float dx, float dz)
{
        int io;
        dx2inv = (1./dx)*(1./dx);
        dz2inv = (1./dz)*(1./dz);

        coefs = calc_coefs(order);

        coefs_z = calc_coefs(order);
        coefs_x = calc_coefs(order);

        // pre calc coefs 8 d2 inv
        for (io = 0; io <= order; io++)
        {
                coefs_z[io] = dz2inv * coefs[io];
                coefs_x[io] = dx2inv * coefs[io];
        }

        fd_init_cuda(order,nx,nz);

        return;
}

void free_memory()
{
        free(coefs_z);
        free(coefs_x);
        free(file_path);
        free(input_data);
        free(output_data);
        hipFree(d_p);
        hipFree(d_laplace);
        hipFree(d_coefs_x);
        hipFree(d_coefs_z);
}

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

        printf("Local do arquivo: %s\n", file_path);
        printf("nzb = %i\n", nzb);
        printf("nzb = %i\n", nxb);
        printf("nz = %i\n", nz);
        printf("nx = %i\n", nx);
        printf("dz = %f\n", dz);
        printf("dx = %f\n", dx);
        printf("order = %i\n", order);

        nxe = nx + 2 * nxb;
        nze = nz + 2 * nzb;
        // initialization
        fd_init(order,nxe,nze,dx,dz);

        dim3 dimGrid(gridx, gridz);
        dim3 dimBlock(sizeblock, sizeblock);
        FILE *finput;

        if((finput = fopen(file_path, "rb")) == NULL)
                printf("Unable to open file!\n");
        else
                printf("Input successfully opened for reading.\n");

        input_data = (float*)malloc(mtxBufferLength);
        if(!input_data)
                printf("Input memory allocation error!\n");
        else
                printf("Input memory allocation was successful.\n");

        memset(input_data, 0, mtxBufferLength);

        if( fread(input_data, sizeof(float), nze*nxe, finput) != nze*nxe)
                printf("Input reading error!\n");

        else
                printf("Input reading was successful.\n");
        fclose(finput);

        // data copy
        hipMemcpy(d_p, input_data, mtxBufferLength, hipMemcpyHostToDevice);
        hipMemcpy(d_coefs_x, coefs_x, coefsBufferLength, hipMemcpyHostToDevice);
        hipMemcpy(d_coefs_z, coefs_z, coefsBufferLength, hipMemcpyHostToDevice);

        // kernel utilization
        kernel_lap<<<dimGrid, dimBlock>>>(order,nxe,nze,d_p,d_laplace,d_coefs_x,d_coefs_z);

        output_data = (float*)malloc(mtxBufferLength);
        if(!output_data)
                printf("Output memory allocation error!\n");
        else
                printf("Output memory allocation was successful.\n");
        memset(output_data, 0, mtxBufferLength);
        hipMemcpy(output_data, d_laplace, mtxBufferLength, hipMemcpyDeviceToHost);

        // Writing output
        FILE *foutput;
        if((foutput = fopen("../bin/output_cuda.bin", "wb")) == NULL)
                printf("Unable to open file!\n");
        else
                printf("Output successfully opened for writing.\n");

        if( fwrite(output_data, sizeof(float), nze*nxe, foutput) != nze*nxe)
                printf("Output writing error!\n");

        else
                printf("Output writing was successful.\n");
        fclose(foutput);

        // free memory device
        free_memory();
        return 0;
}

	.text
	.file	"fd-source-code.hip"
	.globl	_Z10read_inputPc                # -- Begin function _Z10read_inputPc
	.type	_Z10read_inputPc,@function
_Z10read_inputPc:                       # @_Z10read_inputPc
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %rbx
	xorl	%eax, %eax
	movq	%rax, 8(%rsp)
	movq	%rax, 16(%rsp)
	testq	%rbx, %rbx
	je	.LBB0_23
# %bb.1:                                # %.preheader
	leaq	8(%rsp), %rdi
	leaq	16(%rsp), %rsi
	movq	%rbx, %rdx
	callq	getline
	cmpq	$-1, %rax
	je	.LBB0_22
# %bb.2:
	leaq	8(%rsp), %r14
	leaq	16(%rsp), %r15
.LBB0_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	8(%rsp), %r12
	movl	$.L.str.1, %esi
	movq	%r12, %rdi
	callq	strstr
	testq	%rax, %rax
	je	.LBB0_5
# %bb.4:                                #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	movq	%r12, %rdi
	callq	strtok
	movl	$.L.str.2, %esi
	xorl	%edi, %edi
	callq	strtok
	movq	%rax, %r12
	movq	%rax, %rdi
	callq	strlen
	movb	$0, -1(%r12,%rax)
	movq	%r12, %rdi
	callq	strdup
	movq	%rax, file_path(%rip)
	movq	8(%rsp), %r12
.LBB0_5:                                #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.3, %esi
	movq	%r12, %rdi
	callq	strstr
	testq	%rax, %rax
	je	.LBB0_7
# %bb.6:                                #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	movq	%r12, %rdi
	callq	strtok
	movl	$.L.str.2, %esi
	xorl	%edi, %edi
	callq	strtok
	movq	%rax, %rdi
	callq	atoi
	movl	%eax, nzb(%rip)
	movq	8(%rsp), %r12
.LBB0_7:                                #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.4, %esi
	movq	%r12, %rdi
	callq	strstr
	testq	%rax, %rax
	je	.LBB0_9
# %bb.8:                                #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	movq	%r12, %rdi
	callq	strtok
	movl	$.L.str.2, %esi
	xorl	%edi, %edi
	callq	strtok
	movq	%rax, %rdi
	callq	atoi
	movl	%eax, nxb(%rip)
	movq	8(%rsp), %r12
.LBB0_9:                                #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.5, %esi
	movq	%r12, %rdi
	callq	strstr
	testq	%rax, %rax
	je	.LBB0_12
# %bb.10:                               #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	movq	%r12, %rdi
	callq	strtok
	movq	%rax, %rdi
	callq	strlen
	cmpq	$2, %rax
	ja	.LBB0_12
# %bb.11:                               #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	xorl	%edi, %edi
	callq	strtok
	movq	%rax, %rdi
	callq	atoi
	movl	%eax, nz(%rip)
.LBB0_12:                               #   in Loop: Header=BB0_3 Depth=1
	movq	8(%rsp), %r12
	movl	$.L.str.6, %esi
	movq	%r12, %rdi
	callq	strstr
	testq	%rax, %rax
	je	.LBB0_15
# %bb.13:                               #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	movq	%r12, %rdi
	callq	strtok
	movq	%rax, %rdi
	callq	strlen
	cmpq	$2, %rax
	ja	.LBB0_15
# %bb.14:                               #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	xorl	%edi, %edi
	callq	strtok
	movq	%rax, %rdi
	callq	atoi
	movl	%eax, nx(%rip)
.LBB0_15:                               #   in Loop: Header=BB0_3 Depth=1
	movq	8(%rsp), %r12
	movl	$.L.str.7, %esi
	movq	%r12, %rdi
	callq	strstr
	testq	%rax, %rax
	je	.LBB0_17
# %bb.16:                               #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	movq	%r12, %rdi
	callq	strtok
	movl	$.L.str.2, %esi
	xorl	%edi, %edi
	callq	strtok
	movq	%rax, %rdi
	callq	atof
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, dz(%rip)
	movq	8(%rsp), %r12
.LBB0_17:                               #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.8, %esi
	movq	%r12, %rdi
	callq	strstr
	testq	%rax, %rax
	je	.LBB0_19
# %bb.18:                               #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	movq	%r12, %rdi
	callq	strtok
	movl	$.L.str.2, %esi
	xorl	%edi, %edi
	callq	strtok
	movq	%rax, %rdi
	callq	atof
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, dx(%rip)
	movq	8(%rsp), %r12
.LBB0_19:                               #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.9, %esi
	movq	%r12, %rdi
	callq	strstr
	testq	%rax, %rax
	je	.LBB0_21
# %bb.20:                               #   in Loop: Header=BB0_3 Depth=1
	movl	$.L.str.2, %esi
	movq	%r12, %rdi
	callq	strtok
	movl	$.L.str.2, %esi
	xorl	%edi, %edi
	callq	strtok
	movq	%rax, %rdi
	callq	atoi
	movl	%eax, order(%rip)
.LBB0_21:                               #   in Loop: Header=BB0_3 Depth=1
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%rbx, %rdx
	callq	getline
	cmpq	$-1, %rax
	jne	.LBB0_3
.LBB0_22:                               # %._crit_edge
	movq	8(%rsp), %rdi
	callq	free
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB0_23:
	.cfi_def_cfa_offset 64
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z10read_inputPc, .Lfunc_end0-_Z10read_inputPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__kernel_lapiiiPfS_S_S_ # -- Begin function _Z25__device_stub__kernel_lapiiiPfS_S_S_
	.type	_Z25__device_stub__kernel_lapiiiPfS_S_S_,@function
_Z25__device_stub__kernel_lapiiiPfS_S_S_: # @_Z25__device_stub__kernel_lapiiiPfS_S_S_
	.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	$160, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	20(%rsp), %rax
	movl	%edi, (%rax)
	leaq	16(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	56(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	48(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	40(%rsp), %r8
	movq	%r9, (%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	208(%rsp), %rax
	movq	%rax, 48(%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	$_Z10kernel_lapiiiPfS_S_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	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	_Z25__device_stub__kernel_lapiiiPfS_S_S_, .Lfunc_end1-_Z25__device_stub__kernel_lapiiiPfS_S_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z10calc_coefsi
.LCPI2_0:
	.long	0xbaea0ea1                      # float -0.0017857143
	.long	0x3cd00d01                      # float 0.0253968257
	.long	0xbe4ccccd                      # float -0.200000003
	.long	0x3fcccccd                      # float 1.60000002
.LCPI2_1:
	.long	0xc03638e4                      # float -2.84722233
	.long	0x3fcccccd                      # float 1.60000002
	.long	0xbe4ccccd                      # float -0.200000003
	.long	0x3cd00d01                      # float 0.0253968257
.LCPI2_3:
	.long	0x3c360b61                      # float 0.0111111114
	.long	0xbe19999a                      # float -0.150000006
	.long	0x3fc00000                      # float 1.5
	.long	0xc02e38e4                      # float -2.72222233
.LCPI2_5:
	.long	0xbdaaaaab                      # float -0.0833333358
	.long	0x3faaaaab                      # float 1.33333337
	.long	0xc0200000                      # float -2.5
	.long	0x3faaaaab                      # float 1.33333337
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI2_2:
	.long	0xbaea0ea1                      # float -0.0017857143
.LCPI2_4:
	.long	0x3c360b61                      # float 0.0111111114
.LCPI2_6:
	.long	0xbdaaaaab                      # float -0.0833333358
.LCPI2_7:
	.long	0x3f800000                      # float 1
.LCPI2_9:
	.long	0x3f6b851e                      # float 0.919999957
.LCPI2_10:
	.long	0x3da3d710                      # float 0.0800000429
.LCPI2_11:
	.long	0x40400000                      # float 3
.LCPI2_12:
	.long	0xc0000000                      # float -2
.LCPI2_13:
	.long	0x80000000                      # float -0
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI2_8:
	.quad	0x400921fb54442d18              # double 3.1415926535897931
	.text
	.globl	_Z10calc_coefsi
	.type	_Z10calc_coefsi,@function
_Z10calc_coefsi:                        # @_Z10calc_coefsi
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edi, %r14d
	leal	1(%r14), %eax
	movslq	%eax, %rdi
	movl	$4, %esi
	callq	calloc
	leal	-2(%r14), %ecx
	cmpl	$6, %ecx
	ja	.LBB2_6
# %bb.1:
	jmpq	*.LJTI2_0(,%rcx,8)
.LBB2_2:
	movabsq	$-4611686017362034688, %rcx     # imm = 0xC00000003F800000
	movq	%rcx, (%rax)
	movss	.LCPI2_7(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movl	$2, %ecx
	jmp	.LBB2_11
.LBB2_4:
	movapd	.LCPI2_3(%rip), %xmm0           # xmm0 = [1.11111114E-2,-1.50000006E-1,1.5E+0,-2.72222233E+0]
	movupd	%xmm0, (%rax)
	movabsq	$-4748595444311916544, %rcx     # imm = 0xBE19999A3FC00000
	movq	%rcx, 16(%rax)
	movss	.LCPI2_4(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movl	$6, %ecx
	jmp	.LBB2_11
.LBB2_3:
	movapd	.LCPI2_5(%rip), %xmm0           # xmm0 = [-8.33333358E-2,1.33333337E+0,-2.5E+0,1.33333337E+0]
	movupd	%xmm0, (%rax)
	movss	.LCPI2_6(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movl	$4, %ecx
	jmp	.LBB2_11
.LBB2_5:
	movaps	.LCPI2_0(%rip), %xmm0           # xmm0 = [-1.7857143E-3,2.53968257E-2,-2.00000003E-1,1.60000002E+0]
	movups	%xmm0, (%rax)
	movapd	.LCPI2_1(%rip), %xmm0           # xmm0 = [-2.84722233E+0,1.60000002E+0,-2.00000003E-1,2.53968257E-2]
	movupd	%xmm0, 16(%rax)
	movss	.LCPI2_2(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movl	$8, %ecx
	jmp	.LBB2_11
.LBB2_6:
	movl	%r14d, %r15d
	shrl	$31, %r15d
	addl	%r14d, %r15d
	sarl	%r15d
	cmpl	$1, %r14d
	jg	.LBB2_8
# %bb.7:                                # %.._crit_edge_crit_edge.i
	movslq	%r15d, %rcx
	movss	.LCPI2_13(%rip), %xmm1          # xmm1 = mem[0],zero,zero,zero
	jmp	.LBB2_11
.LBB2_8:                                # %.lr.ph.i
	leal	2(%r15), %ecx
	cvtsi2sd	%ecx, %xmm0
	addsd	%xmm0, %xmm0
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	movl	%r15d, %ecx
	incl	%r15d
	leaq	(%rax,%rcx,4), %r12
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	leaq	(%rax,%rcx,4), %r13
	addq	$-4, %r13
	xorps	%xmm1, %xmm1
	movl	$1, %ebp
	movl	$-1, %eax
	movl	$1, %r14d
.LBB2_9:                                # =>This Inner Loop Header: Depth=1
	movss	%xmm1, 12(%rsp)                 # 4-byte Spill
	movl	%eax, %ebx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebp, %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r14d, %xmm1
	movl	%r14d, %eax
	imull	%r14d, %eax
	xorps	%xmm2, %xmm2
	cvtsi2sd	%eax, %xmm2
	addsd	%xmm0, %xmm0
	divsd	%xmm2, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	mulsd	.LCPI2_8(%rip), %xmm1
	divsd	32(%rsp), %xmm1                 # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	callq	cosf
	mulss	.LCPI2_9(%rip), %xmm0
	movss	%xmm0, (%rsp)                   # 4-byte Spill
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	callq	cosf
	mulss	(%rsp), %xmm0                   # 4-byte Folded Reload
	addss	.LCPI2_10(%rip), %xmm0
	movss	.LCPI2_11(%rip), %xmm1          # xmm1 = mem[0],zero,zero,zero
	callq	powf
	movss	12(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	mulss	8(%rsp), %xmm0                  # 4-byte Folded Reload
	movss	%xmm0, (%r12,%r14,4)
	addss	%xmm0, %xmm1
	movss	%xmm0, (%r13)
	incq	%r14
	addq	$-4, %r13
	movl	%ebp, %eax
	movl	%ebx, %ebp
	cmpq	%r14, %r15
	jne	.LBB2_9
# %bb.10:                               # %._crit_edge.loopexit.i
	mulss	.LCPI2_12(%rip), %xmm1
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	16(%rsp), %rcx                  # 8-byte Reload
.LBB2_11:                               # %_ZL6makeo2Pfi.exit
	movss	%xmm1, (%rax,%rcx,4)
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z10calc_coefsi, .Lfunc_end2-_Z10calc_coefsi
	.cfi_endproc
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
.LJTI2_0:
	.quad	.LBB2_2
	.quad	.LBB2_6
	.quad	.LBB2_3
	.quad	.LBB2_6
	.quad	.LBB2_4
	.quad	.LBB2_6
	.quad	.LBB2_5
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z12fd_init_cudaiii
.LCPI3_0:
	.long	0x3d000000                      # float 0.03125
	.text
	.globl	_Z12fd_init_cudaiii
	.type	_Z12fd_init_cudaiii,@function
_Z12fd_init_cudaiii:                    # @_Z12fd_init_cudaiii
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%edx, %ebx
	movl	%esi, %r14d
	movl	%edx, %eax
	imull	%esi, %eax
	movslq	%eax, %rsi
	shlq	$2, %rsi
	movq	%rsi, mtxBufferLength(%rip)
	movslq	%edi, %rax
	leaq	4(,%rax,4), %rax
	movq	%rax, coefsBufferLength(%rip)
	movl	$d_p, %edi
	callq	hipMalloc
	movq	mtxBufferLength(%rip), %rsi
	movl	$d_laplace, %edi
	callq	hipMalloc
	movq	coefsBufferLength(%rip), %rsi
	movl	$d_coefs_x, %edi
	callq	hipMalloc
	movq	coefsBufferLength(%rip), %rsi
	movl	$d_coefs_z, %edi
	callq	hipMalloc
	leal	-1(%r14), %eax
	addl	$30, %r14d
	testl	%eax, %eax
	cmovnsl	%eax, %r14d
	andl	$-32, %r14d
	addl	$32, %r14d
	leal	-1(%rbx), %eax
	addl	$30, %ebx
	testl	%eax, %eax
	cmovnsl	%eax, %ebx
	andl	$-32, %ebx
	addl	$32, %ebx
	cvtsi2ss	%r14d, %xmm0
	movss	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	cvttss2si	%xmm0, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebx, %xmm0
	mulss	%xmm1, %xmm0
	cvttss2si	%xmm0, %ecx
	movl	%eax, gridx(%rip)
	movl	%ecx, gridz(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z12fd_init_cudaiii, .Lfunc_end3-_Z12fd_init_cudaiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z7fd_initiiiff
.LCPI4_0:
	.quad	0x3ff0000000000000              # double 1
	.text
	.globl	_Z7fd_initiiiff
	.type	_Z7fd_initiiiff,@function
_Z7fd_initiiiff:                        # @_Z7fd_initiiiff
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%esi, %ebp
	cvtss2sd	%xmm0, %xmm0
	movsd	.LCPI4_0(%rip), %xmm2           # xmm2 = mem[0],zero
	movapd	%xmm2, %xmm3
	divsd	%xmm0, %xmm3
	mulsd	%xmm3, %xmm3
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm3, %xmm0
	movl	%edi, %r14d
	movss	%xmm0, _ZL6dx2inv(%rip)
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	divsd	%xmm0, %xmm2
	mulsd	%xmm2, %xmm2
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm2, %xmm0
	movss	%xmm0, _ZL6dz2inv(%rip)
	callq	_Z10calc_coefsi
	movq	%rax, _ZL5coefs(%rip)
	movl	%r14d, %edi
	callq	_Z10calc_coefsi
	movq	%rax, _ZL7coefs_z(%rip)
	movl	%r14d, %edi
	callq	_Z10calc_coefsi
	movq	%rax, _ZL7coefs_x(%rip)
	testl	%r14d, %r14d
	js	.LBB4_3
# %bb.1:                                # %.lr.ph
	movss	_ZL6dz2inv(%rip), %xmm0         # xmm0 = mem[0],zero,zero,zero
	movq	_ZL5coefs(%rip), %rcx
	movq	_ZL7coefs_z(%rip), %rdx
	movss	_ZL6dx2inv(%rip), %xmm1         # xmm1 = mem[0],zero,zero,zero
	leal	1(%r14), %esi
	xorl	%edi, %edi
.LBB4_2:                                # =>This Inner Loop Header: Depth=1
	movss	(%rcx,%rdi,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	mulss	%xmm0, %xmm2
	movss	%xmm2, (%rdx,%rdi,4)
	movss	(%rcx,%rdi,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm2
	movss	%xmm2, (%rax,%rdi,4)
	incq	%rdi
	cmpq	%rdi, %rsi
	jne	.LBB4_2
.LBB4_3:                                # %._crit_edge
	movl	%r14d, %edi
	movl	%ebp, %esi
	movl	%ebx, %edx
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	_Z12fd_init_cudaiii             # TAILCALL
.Lfunc_end4:
	.size	_Z7fd_initiiiff, .Lfunc_end4-_Z7fd_initiiiff
	.cfi_endproc
                                        # -- End function
	.globl	_Z11free_memoryv                # -- Begin function _Z11free_memoryv
	.type	_Z11free_memoryv,@function
_Z11free_memoryv:                       # @_Z11free_memoryv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	_ZL7coefs_z(%rip), %rdi
	callq	free
	movq	_ZL7coefs_x(%rip), %rdi
	callq	free
	movq	file_path(%rip), %rdi
	callq	free
	movq	input_data(%rip), %rdi
	callq	free
	movq	output_data(%rip), %rdi
	callq	free
	movq	d_p(%rip), %rdi
	callq	hipFree
	movq	d_laplace(%rip), %rdi
	callq	hipFree
	movq	d_coefs_x(%rip), %rdi
	callq	hipFree
	movq	d_coefs_z(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	hipFree                         # TAILCALL
.Lfunc_end5:
	.size	_Z11free_memoryv, .Lfunc_end5-_Z11free_memoryv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	8(%rsi), %rdi
	callq	_Z10read_inputPc
	movq	file_path(%rip), %rsi
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	movl	nzb(%rip), %esi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movl	nxb(%rip), %esi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movl	nz(%rip), %esi
	movl	$.L.str.12, %edi
	xorl	%eax, %eax
	callq	printf
	movl	nx(%rip), %esi
	movl	$.L.str.13, %edi
	xorl	%eax, %eax
	callq	printf
	cvtss2sd	dz(%rip), %xmm0
	movl	$.L.str.14, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	dx(%rip), %xmm0
	movl	$.L.str.15, %edi
	movb	$1, %al
	callq	printf
	movl	order(%rip), %esi
	movl	$.L.str.16, %edi
	xorl	%eax, %eax
	callq	printf
	movl	nxb(%rip), %esi
	addl	%esi, %esi
	addl	nx(%rip), %esi
	movl	%esi, nxe(%rip)
	movl	nzb(%rip), %edx
	addl	%edx, %edx
	addl	nz(%rip), %edx
	movl	%edx, nze(%rip)
	movl	order(%rip), %edi
	movss	dx(%rip), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	dz(%rip), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	callq	_Z7fd_initiiiff
	movl	gridx(%rip), %eax
	movl	gridz(%rip), %ebx
	shlq	$32, %rbx
	orq	%rax, %rbx
	movq	file_path(%rip), %rdi
	movl	$.L.str.17, %esi
	callq	fopen
	movq	%rax, %r14
	testq	%rax, %rax
	movl	$.Lstr.9, %r15d
	movl	$.Lstr, %edi
	cmoveq	%r15, %rdi
	callq	puts@PLT
	movq	mtxBufferLength(%rip), %rdi
	callq	malloc
	movq	%rax, input_data(%rip)
	testq	%rax, %rax
	movl	$.Lstr.2, %eax
	movl	$.Lstr.3, %edi
	cmoveq	%rax, %rdi
	callq	puts@PLT
	movq	input_data(%rip), %rdi
	movq	mtxBufferLength(%rip), %rdx
	xorl	%esi, %esi
	callq	memset@PLT
	movq	input_data(%rip), %rdi
	movslq	nze(%rip), %rax
	movslq	nxe(%rip), %rdx
	imulq	%rax, %rdx
	movl	$4, %esi
	movq	%r14, %rcx
	callq	fread
	movslq	nze(%rip), %rcx
	movslq	nxe(%rip), %rdx
	imulq	%rcx, %rdx
	cmpq	%rdx, %rax
	movl	$.Lstr.4, %eax
	movl	$.Lstr.5, %edi
	cmoveq	%rax, %rdi
	callq	puts@PLT
	movq	%r14, %rdi
	callq	fclose
	movq	d_p(%rip), %rdi
	movq	input_data(%rip), %rsi
	movq	mtxBufferLength(%rip), %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	d_coefs_x(%rip), %rdi
	movq	_ZL7coefs_x(%rip), %rsi
	movq	coefsBufferLength(%rip), %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	d_coefs_z(%rip), %rdi
	movq	_ZL7coefs_z(%rip), %rsi
	movq	coefsBufferLength(%rip), %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movq	%rbx, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_2
# %bb.1:
	movl	order(%rip), %edi
	movl	nxe(%rip), %esi
	movl	nze(%rip), %edx
	movq	d_p(%rip), %rcx
	movq	d_laplace(%rip), %r8
	movq	d_coefs_x(%rip), %r9
	movq	d_coefs_z(%rip), %rax
	movq	%rax, (%rsp)
	callq	_Z25__device_stub__kernel_lapiiiPfS_S_S_
.LBB6_2:
	movq	mtxBufferLength(%rip), %rdi
	callq	malloc
	movq	%rax, output_data(%rip)
	testq	%rax, %rax
	movl	$.Lstr.6, %eax
	movl	$.Lstr.7, %edi
	cmoveq	%rax, %rdi
	callq	puts@PLT
	movq	output_data(%rip), %rdi
	movq	mtxBufferLength(%rip), %rdx
	xorl	%esi, %esi
	callq	memset@PLT
	movq	output_data(%rip), %rdi
	movq	d_laplace(%rip), %rsi
	movq	mtxBufferLength(%rip), %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.26, %edi
	movl	$.L.str.27, %esi
	callq	fopen
	movq	%rax, %rbx
	testq	%rax, %rax
	movl	$.Lstr.8, %edi
	cmoveq	%r15, %rdi
	callq	puts@PLT
	movq	output_data(%rip), %rdi
	movslq	nze(%rip), %rax
	movslq	nxe(%rip), %rdx
	imulq	%rax, %rdx
	movl	$4, %esi
	movq	%rbx, %rcx
	callq	fwrite
	movslq	nze(%rip), %rcx
	movslq	nxe(%rip), %rdx
	imulq	%rcx, %rdx
	cmpq	%rdx, %rax
	movl	$.Lstr.10, %eax
	movl	$.Lstr.11, %edi
	cmoveq	%rax, %rdi
	callq	puts@PLT
	movq	%rbx, %rdi
	callq	fclose
	callq	_Z11free_memoryv
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	main, .Lfunc_end6-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	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10kernel_lapiiiPfS_S_S_, %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_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	file_path,@object               # @file_path
	.bss
	.globl	file_path
	.p2align	3, 0x0
file_path:
	.quad	0
	.size	file_path, 8

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

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

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

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

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

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

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

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

	.type	gridx,@object                   # @gridx
	.globl	gridx
	.p2align	2, 0x0
gridx:
	.long	0                               # 0x0
	.size	gridx, 4

	.type	gridz,@object                   # @gridz
	.globl	gridz
	.p2align	2, 0x0
gridz:
	.long	0                               # 0x0
	.size	gridz, 4

	.type	nz,@object                      # @nz
	.globl	nz
	.p2align	2, 0x0
nz:
	.long	0                               # 0x0
	.size	nz, 4

	.type	nx,@object                      # @nx
	.globl	nx
	.p2align	2, 0x0
nx:
	.long	0                               # 0x0
	.size	nx, 4

	.type	nxb,@object                     # @nxb
	.globl	nxb
	.p2align	2, 0x0
nxb:
	.long	0                               # 0x0
	.size	nxb, 4

	.type	nzb,@object                     # @nzb
	.globl	nzb
	.p2align	2, 0x0
nzb:
	.long	0                               # 0x0
	.size	nzb, 4

	.type	nxe,@object                     # @nxe
	.globl	nxe
	.p2align	2, 0x0
nxe:
	.long	0                               # 0x0
	.size	nxe, 4

	.type	nze,@object                     # @nze
	.globl	nze
	.p2align	2, 0x0
nze:
	.long	0                               # 0x0
	.size	nze, 4

	.type	order,@object                   # @order
	.globl	order
	.p2align	2, 0x0
order:
	.long	0                               # 0x0
	.size	order, 4

	.type	dz,@object                      # @dz
	.globl	dz
	.p2align	2, 0x0
dz:
	.long	0x00000000                      # float 0
	.size	dz, 4

	.type	dx,@object                      # @dx
	.globl	dx
	.p2align	2, 0x0
dx:
	.long	0x00000000                      # float 0
	.size	dx, 4

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"r"
	.size	.L.str, 2

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"tmpdir"
	.size	.L.str.1, 7

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

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

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

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

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

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

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"order"
	.size	.L.str.9, 6

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

	.type	_ZL6dx2inv,@object              # @_ZL6dx2inv
	.local	_ZL6dx2inv
	.comm	_ZL6dx2inv,4,4
	.type	_ZL6dz2inv,@object              # @_ZL6dz2inv
	.local	_ZL6dz2inv
	.comm	_ZL6dz2inv,4,4
	.type	_ZL5coefs,@object               # @_ZL5coefs
	.local	_ZL5coefs
	.comm	_ZL5coefs,8,8
	.type	_ZL7coefs_z,@object             # @_ZL7coefs_z
	.local	_ZL7coefs_z
	.comm	_ZL7coefs_z,8,8
	.type	_ZL7coefs_x,@object             # @_ZL7coefs_x
	.local	_ZL7coefs_x
	.comm	_ZL7coefs_x,8,8
	.type	.L.str.10,@object               # @.str.10
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.10:
	.asciz	"Local do arquivo: %s\n"
	.size	.L.str.10, 22

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"nzb = %i\n"
	.size	.L.str.11, 10

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"nz = %i\n"
	.size	.L.str.12, 9

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"nx = %i\n"
	.size	.L.str.13, 9

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"dz = %f\n"
	.size	.L.str.14, 9

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"dx = %f\n"
	.size	.L.str.15, 9

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"order = %i\n"
	.size	.L.str.16, 12

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

	.type	.L.str.26,@object               # @.str.26
.L.str.26:
	.asciz	"../bin/output_cuda.bin"
	.size	.L.str.26, 23

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10kernel_lapiiiPfS_S_S_"
	.size	.L__unnamed_1, 26

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

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Input successfully opened for reading."
	.size	.Lstr, 39

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Input memory allocation error!"
	.size	.Lstr.2, 31

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Input memory allocation was successful."
	.size	.Lstr.3, 40

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Input reading was successful."
	.size	.Lstr.4, 30

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"Input reading error!"
	.size	.Lstr.5, 21

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"Output memory allocation error!"
	.size	.Lstr.6, 32

	.type	.Lstr.7,@object                 # @str.7
.Lstr.7:
	.asciz	"Output memory allocation was successful."
	.size	.Lstr.7, 41

	.type	.Lstr.8,@object                 # @str.8
.Lstr.8:
	.asciz	"Output successfully opened for writing."
	.size	.Lstr.8, 40

	.type	.Lstr.9,@object                 # @str.9
.Lstr.9:
	.asciz	"Unable to open file!"
	.size	.Lstr.9, 21

	.type	.Lstr.10,@object                # @str.10
.Lstr.10:
	.asciz	"Output writing was successful."
	.size	.Lstr.10, 31

	.type	.Lstr.11,@object                # @str.11
.Lstr.11:
	.asciz	"Output writing error!"
	.size	.Lstr.11, 22

	.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 _Z25__device_stub__kernel_lapiiiPfS_S_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym d_p
	.addrsig_sym d_laplace
	.addrsig_sym d_coefs_x
	.addrsig_sym d_coefs_z
	.addrsig_sym _Z10kernel_lapiiiPfS_S_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10kernel_lapiiiPfS_S_S_ ; -- Begin function _Z10kernel_lapiiiPfS_S_S_
	.globl	_Z10kernel_lapiiiPfS_S_S_
	.p2align	8
	.type	_Z10kernel_lapiiiPfS_S_S_,@function
_Z10kernel_lapiiiPfS_S_S_:              ; @_Z10kernel_lapiiiPfS_S_S_
; %bb.0:
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b32 s2, s[0:1], 0x3c
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s4, 31
	s_and_b32 s7, s2, 0xffff
	s_add_i32 s3, s4, s3
	s_lshr_b32 s2, s2, 16
	s_ashr_i32 s3, s3, 1
	s_mul_i32 s14, s14, s7
	v_add_nc_u32_e32 v2, s3, v1
	s_mul_i32 s15, s15, s2
	v_add3_u32 v3, s14, s3, v0
	s_sub_i32 s2, s5, s3
	s_sub_i32 s3, s6, s3
	v_add_nc_u32_e32 v4, s15, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s2, v3
	v_cmp_gt_i32_e64 s2, s3, v4
	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_6
; %bb.1:                                ; %.preheader
	s_load_b64 s[8:9], s[0:1], 0x18
	v_mul_lo_u32 v5, v3, s6
	v_mov_b32_e32 v3, 0
	s_cmp_lt_i32 s4, 0
	s_cbranch_scc1 .LBB0_5
; %bb.2:                                ; %.lr.ph.preheader
	s_clause 0x1
	s_load_b64 s[10:11], s[0:1], 0x10
	s_load_b128 s[0:3], s[0:1], 0x20
	v_dual_mov_b32 v7, 0 :: v_dual_add_nc_u32 v0, s14, v0
	v_mov_b32_e32 v6, 0
	s_add_i32 s4, s4, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v3, s6, v0
	v_add3_u32 v0, v1, v5, s15
	v_add3_u32 v2, v2, v3, s15
.LBB0_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v1, 31, v0
	v_ashrrev_i32_e32 v3, 31, v2
	s_add_i32 s4, s4, -1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[8:9], 2, v[0:1]
	v_lshlrev_b64 v[10:11], 2, v[2:3]
	v_add_nc_u32_e32 v2, s6, v2
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v8, vcc_lo, s10, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s11, v9, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_u32 v10, vcc_lo, s10, v10
	v_add_co_ci_u32_e32 v11, vcc_lo, s11, v11, vcc_lo
	s_clause 0x1
	global_load_b32 v1, v[8:9], off
	global_load_b32 v3, v[10:11], off
	s_load_b32 s5, s[2:3], 0x0
	s_load_b32 s7, s[0:1], 0x0
	s_add_u32 s2, s2, 4
	s_addc_u32 s3, s3, 0
	v_add_nc_u32_e32 v0, 1, v0
	s_add_u32 s0, s0, 4
	s_addc_u32 s1, s1, 0
	s_cmp_eq_u32 s4, 0
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_dual_fmac_f32 v6, s5, v1 :: v_dual_fmac_f32 v7, s7, v3
	s_cbranch_scc0 .LBB0_3
; %bb.4:                                ; %._crit_edge.loopexit
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v3, v7, v6
.LBB0_5:                                ; %Flow
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v5, v4
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s8, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s9, v1, vcc_lo
	global_store_b32 v[0:1], v3, off
.LBB0_6:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10kernel_lapiiiPfS_S_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.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 12
		.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	_Z10kernel_lapiiiPfS_S_S_, .Lfunc_end0-_Z10kernel_lapiiiPfS_S_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 444
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; 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:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .actual_access:  read_only
        .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  write_only
        .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  read_only
        .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  read_only
        .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         52
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         60
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         62
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         64
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         66
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         68
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         70
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         112
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10kernel_lapiiiPfS_S_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10kernel_lapiiiPfS_S_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
