#include <stdio.h>
#define NX 256
#define NY 256
#define DX (5./(float)NX)
#define DY (5./(float)NY)
#define N_ITERATIONS 100000
#define N_THREADS_X 32
#define N_THREADS_Y 32
#define N_BLOCKS_X (NX + N_THREADS_X - 1)/N_THREADS_X
#define N_BLOCKS_Y (NY + N_THREADS_Y - 1)/N_THREADS_Y


#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
   if (code != cudaSuccess)
   {
      fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

// Solves the Poisson equation via the Jacobi Method
// $$\nabla^2 \phi = f$$

float f(float x, float y)
{
  return exp(-x*x-y*y);
}

float top_bc = 0;
float bottom_bc = 0;
float left_bc = 0;
float right_bc = 2;

__global__ void iteratePoisson(float* d_source, float* d_V1, float* d_V2)
{
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    int j = blockIdx.y * blockDim.y + threadIdx.y;
    int n = j * NX + i;
    // printf("%d %d %d %d\n", i, j, n, i > 0);
    if ((i>0) && (i < NX-1) && (j>0) && (j < NY-1)) { //TODO: see what can be done about boundaries
        int n_top = (j-1) * NX + i;
        int n_bot = (j+1) * NX + i;
        int n_left = j * NX + (i-1);
        int n_right = j * NX + (i+1);
        //TODO: rewrite above in terms of n?

        // d_V1[n] = n;
        d_V1[n] = 0.25f * (d_V2[n_top] + d_V2[n_bot] + d_V2[n_left] + d_V2[n_right]) +\
            d_source[n] * DX * DY;
            //TODO: check above for consistency. Does this need factor of 4?
    }
}

int main()
{
    float *h_source = (float *)malloc(NX*NY*sizeof(float));
    float *h_V = (float *)malloc(NX*NY*sizeof(float));


    float x;
    float y;

    for(int j =0; j<NY; j++){
        for (int i = 0; i < NX; i++){
            int n = NX*j + i;

            x = i*DX - NX/2 * DX;
            y = j*DY - NY/2 * DY;
            h_source[n] = f(x,y);  //TODO: set up source term

            if (j == 0){ // top row
                h_V[n] = top_bc;
            }
            else if (j==NY-1){ //bottom row
                h_V[n] = bottom_bc;
            }
            else if (i==0){ //left column
                h_V[n] = left_bc;
            }
            else if (i==NX-1){
                h_V[n] = right_bc;
            }
        }
    }


    float *d_source;
    float *d_V1;
    float *d_V2;

    //allocate GPU memory
    gpuErrchk(cudaMalloc((void **)&d_source, NX*NY*sizeof(float)));
    gpuErrchk(cudaMalloc((void **)&d_V1, NX*NY*sizeof(float)));
    gpuErrchk(cudaMalloc((void **)&d_V2, NX*NY*sizeof(float)));

    // copy V1, V2 from host to device
    gpuErrchk(cudaMemcpy(d_source, h_source, NX*NY*sizeof(float), cudaMemcpyHostToDevice));
    gpuErrchk(cudaMemcpy(d_V1, h_V, NX*NY*sizeof(float), cudaMemcpyHostToDevice));
    gpuErrchk(cudaMemcpy(d_V2, h_V, NX*NY*sizeof(float), cudaMemcpyHostToDevice));
    // gpuErrchk(cudaPeekAtLastError());

    printf("Blocks: %d\nThreads: %d\n", N_BLOCKS_X*N_BLOCKS_Y, N_THREADS_X*N_THREADS_Y);
    printf("Iteration %5d", 0);
    dim3 blocks(N_BLOCKS_X, N_BLOCKS_Y);
    dim3 threads(N_THREADS_X, N_THREADS_Y);
    gpuErrchk(cudaPeekAtLastError());
    gpuErrchk(cudaDeviceSynchronize());


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

    gpuErrchk(cudaEventRecord(start, NULL));
    for (int i = 0; i < N_ITERATIONS; i += 2)
    {
        printf("\rIteration %5d", i);
        iteratePoisson<<<blocks, threads>>>(d_source, d_V1, d_V2);
        gpuErrchk(cudaPeekAtLastError());
        gpuErrchk(cudaDeviceSynchronize());
        iteratePoisson<<<blocks, threads>>>(d_source, d_V2, d_V1);
        gpuErrchk(cudaPeekAtLastError());
        gpuErrchk(cudaDeviceSynchronize());
    }
    gpuErrchk(cudaEventRecord(stop, NULL));




    //copy V2 from device to host as final value
    gpuErrchk(cudaMemcpy(h_source, d_source, NX*NY*sizeof(float), cudaMemcpyDeviceToHost));
    gpuErrchk(cudaMemcpy(h_V, d_V2, NX*NY*sizeof(float), cudaMemcpyDeviceToHost));
    gpuErrchk(cudaFree(d_source));
    gpuErrchk(cudaFree(d_V1));
    gpuErrchk(cudaFree(d_V2));

    float msecTotal = 0.0f;
    gpuErrchk(cudaEventElapsedTime(&msecTotal, start, stop));
    printf("Elapsed time: %f ms", msecTotal);
    
    FILE* file_V1 = fopen("V1.dat", "w");
    FILE* file_source = fopen("source.dat", "w");

    for(int j =0; j<NY; j++){
        for (int i = 0; i < NX; i++){
            int n = NX*j + i;

            x = i*DX - NX/2 * DX;
            y = j*DY - NY/2 * DY;

            fprintf(file_V1, "%d %d %.3f %.3f %.3f\n", i, j, x, y, h_V[n]);
            fprintf(file_source, "%d %d %.3f %.3f %.3f\n", i, j, x, y, h_source[n]);
        }
    }
    //free GPU arrays
    free(h_V);
    free(h_source);

    //write data out
    printf("\nFinished!\n");
}

	.file	"tmpxft_0036fa56_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata._Z9gpuAssert9cudaErrorPKcib.str1.1,"aMS",@progbits,1
.LC0:
	.string	"GPUassert: %s %s %d\n"
	.section	.text._Z9gpuAssert9cudaErrorPKcib,"axG",@progbits,_Z9gpuAssert9cudaErrorPKcib,comdat
	.weak	_Z9gpuAssert9cudaErrorPKcib
	.type	_Z9gpuAssert9cudaErrorPKcib, @function
_Z9gpuAssert9cudaErrorPKcib:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L8
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movl	%edx, 12(%rsp)
	movq	%rsi, (%rsp)
	call	cudaGetErrorString@PLT
	movl	12(%rsp), %r9d
	movq	(%rsp), %r8
	leaq	.LC0(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	testb	%bpl, %bpl
	je	.L2
	movl	%ebx, %edi
	call	exit@PLT
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z9gpuAssert9cudaErrorPKcib, .-_Z9gpuAssert9cudaErrorPKcib
	.text
	.globl	_Z1fff
	.type	_Z1fff, @function
_Z1fff:
.LFB2028:
	.cfi_startproc
	endbr64
	mulss	%xmm1, %xmm1
	movaps	%xmm0, %xmm2
	xorps	.LC1(%rip), %xmm2
	mulss	%xmm2, %xmm0
	subss	%xmm1, %xmm0
	jmp	expf@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z1fff, .-_Z1fff
	.globl	_Z38__device_stub__Z14iteratePoissonPfS_S_PfS_S_
	.type	_Z38__device_stub__Z14iteratePoissonPfS_S_PfS_S_, @function
_Z38__device_stub__Z14iteratePoissonPfS_S_PfS_S_:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z14iteratePoissonPfS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L13:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z38__device_stub__Z14iteratePoissonPfS_S_PfS_S_, .-_Z38__device_stub__Z14iteratePoissonPfS_S_PfS_S_
	.globl	_Z14iteratePoissonPfS_S_
	.type	_Z14iteratePoissonPfS_S_, @function
_Z14iteratePoissonPfS_S_:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z14iteratePoissonPfS_S_PfS_S_
	.cfi_endproc
.LFE2055:
	.size	_Z14iteratePoissonPfS_S_, .-_Z14iteratePoissonPfS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC4:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/StanczakDominik/cuda_poisson/master/main.cu"
.LC5:
	.string	"Blocks: %d\nThreads: %d\n"
.LC6:
	.string	"Iteration %5d"
.LC7:
	.string	"\rIteration %5d"
.LC9:
	.string	"Elapsed time: %f ms"
.LC10:
	.string	"w"
.LC11:
	.string	"V1.dat"
.LC12:
	.string	"source.dat"
.LC13:
	.string	"%d %d %.3f %.3f %.3f\n"
.LC14:
	.string	"\nFinished!\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$262144, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	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	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$262144, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movq	%rax, %rbx
.L19:
	cvtsi2sdl	%r13d, %xmm1
	mulsd	.LC2(%rip), %xmm1
	movq	%r13, %r12
	xorl	%r14d, %r14d
	subsd	.LC3(%rip), %xmm1
	salq	$10, %r12
	cvtsd2ss	%xmm1, %xmm1
.L24:
	cvtsi2sdl	%r14d, %xmm0
	mulsd	.LC2(%rip), %xmm0
	movss	%xmm1, 32(%rsp)
	subsd	.LC3(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	call	_Z1fff
	testq	%r13, %r13
	movss	32(%rsp), %xmm1
	movss	%xmm0, 0(%rbp,%r12)
	movss	top_bc(%rip), %xmm0
	je	.L37
	movss	bottom_bc(%rip), %xmm0
	cmpq	$255, %r13
	je	.L37
	movss	left_bc(%rip), %xmm0
	testl	%r14d, %r14d
	je	.L37
	cmpl	$255, %r14d
	jne	.L21
	movss	right_bc(%rip), %xmm0
.L37:
	movss	%xmm0, (%rbx,%r12)
.L21:
	incl	%r14d
	addq	$4, %r12
	cmpl	$256, %r14d
	jne	.L24
	incq	%r13
	cmpq	$256, %r13
	jne	.L19
	leaq	56(%rsp), %rdi
	movl	$262144, %esi
	xorl	%r13d, %r13d
	leaq	.LC4(%rip), %r12
	leaq	.LC7(%rip), %r14
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$94, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	64(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$95, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	72(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$96, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	56(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$262144, %edx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$99, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	64(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$262144, %edx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$100, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	72(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$262144, %edx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$101, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$1024, %ecx
	movl	$71, %edx
	xorl	%eax, %eax
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	xorl	%edx, %edx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$1, 104(%rsp)
	movabsq	$34359738376, %rax
	movq	%rax, 96(%rsp)
	movabsq	$137438953504, %rax
	movq	%rax, 108(%rsp)
	movl	$1, 116(%rsp)
	call	cudaPeekAtLastError@PLT
	movl	$1, %ecx
	movl	$108, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	call	cudaDeviceSynchronize@PLT
	movl	$1, %ecx
	movl	$109, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	80(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$1, %ecx
	movl	$113, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	88(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$1, %ecx
	movl	$115, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$1, %ecx
	movl	$117, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
.L28:
	movl	%r13d, %edx
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	116(%rsp), %ecx
	movl	104(%rsp), %esi
	xorl	%r9d, %r9d
	movq	108(%rsp), %rdx
	movq	96(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	movq	72(%rsp), %rdx
	movq	64(%rsp), %rsi
	movq	56(%rsp), %rdi
	call	_Z38__device_stub__Z14iteratePoissonPfS_S_PfS_S_
.L26:
	call	cudaPeekAtLastError@PLT
	movl	$1, %ecx
	movl	$122, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	call	cudaDeviceSynchronize@PLT
	movl	$1, %ecx
	movl	$123, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	116(%rsp), %ecx
	movl	104(%rsp), %esi
	xorl	%r9d, %r9d
	movq	108(%rsp), %rdx
	movq	96(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	64(%rsp), %rdx
	movq	72(%rsp), %rsi
	movq	56(%rsp), %rdi
	call	_Z38__device_stub__Z14iteratePoissonPfS_S_PfS_S_
.L27:
	call	cudaPeekAtLastError@PLT
	movl	$1, %ecx
	movq	%r12, %rsi
	addl	$2, %r13d
	movl	%eax, %edi
	movl	$125, %edx
	call	_Z9gpuAssert9cudaErrorPKcib
	call	cudaDeviceSynchronize@PLT
	movl	$1, %ecx
	movl	$126, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	cmpl	$100000, %r13d
	jne	.L28
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%r15d, %r15d
	call	cudaEventRecord@PLT
	movq	%r12, %rsi
	movl	$1, %ecx
	movl	$128, %edx
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	movl	$262144, %edx
	call	cudaMemcpy@PLT
	movq	%r12, %rsi
	movl	$1, %ecx
	movl	$134, %edx
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	72(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$262144, %edx
	call	cudaMemcpy@PLT
	movq	%r12, %rsi
	movl	$1, %ecx
	movl	$135, %edx
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r12, %rsi
	movl	$1, %ecx
	movl	$136, %edx
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r12, %rsi
	movl	$1, %ecx
	movl	$137, %edx
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$138, %edx
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	leaq	52(%rsp), %rdi
	movl	$0x00000000, 52(%rsp)
	call	cudaEventElapsedTime@PLT
	movl	$1, %ecx
	movl	$141, %edx
	movq	%r12, %rsi
	movl	%eax, %edi
	leaq	.LC10(%rip), %r12
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	52(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%r12, %rsi
	leaq	.LC11(%rip), %rdi
	call	fopen@PLT
	movq	%r12, %rsi
	leaq	.LC12(%rip), %rdi
	movq	%rax, 8(%rsp)
	call	fopen@PLT
	movq	%rax, 16(%rsp)
.L29:
	cvtsi2sdl	%r15d, %xmm1
	movq	%r15, %r12
	movl	%r15d, 32(%rsp)
	xorl	%r13d, %r13d
	mulsd	.LC2(%rip), %xmm1
	salq	$10, %r12
	subsd	.LC3(%rip), %xmm1
	leaq	(%rbx,%r12), %r14
	addq	%rbp, %r12
	cvtsd2ss	%xmm1, %xmm1
	cvtss2sd	%xmm1, %xmm1
.L30:
	cvtsi2sdl	%r13d, %xmm0
	movl	32(%rsp), %r8d
	movl	%r13d, %ecx
	movb	$3, %al
	movq	8(%rsp), %rdi
	movl	$2, %esi
	movl	%r13d, 36(%rsp)
	leaq	.LC13(%rip), %rdx
	mulsd	.LC2(%rip), %xmm0
	cvtss2sd	(%r14,%r13,4), %xmm2
	movsd	%xmm1, 24(%rsp)
	subsd	.LC3(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movsd	%xmm0, 40(%rsp)
	call	__fprintf_chk@PLT
	movl	32(%rsp), %r8d
	movl	36(%rsp), %ecx
	movb	$3, %al
	movsd	24(%rsp), %xmm1
	movq	16(%rsp), %rdi
	cvtss2sd	(%r12,%r13,4), %xmm2
	incq	%r13
	movsd	40(%rsp), %xmm0
	leaq	.LC13(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	cmpq	$256, %r13
	movsd	24(%rsp), %xmm1
	jne	.L30
	incq	%r15
	cmpq	$256, %r15
	jne	.L29
	movq	%rbx, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC14(%rip), %rsi
	call	__printf_chk@PLT
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L32
	call	__stack_chk_fail@PLT
.L32:
	addq	$136, %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
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC15:
	.string	"_Z14iteratePoissonPfS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14iteratePoissonPfS_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
.LFE2057:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	right_bc
	.data
	.align 4
	.type	right_bc, @object
	.size	right_bc, 4
right_bc:
	.long	1073741824
	.globl	left_bc
	.bss
	.align 4
	.type	left_bc, @object
	.size	left_bc, 4
left_bc:
	.zero	4
	.globl	bottom_bc
	.align 4
	.type	bottom_bc, @object
	.size	bottom_bc, 4
bottom_bc:
	.zero	4
	.globl	top_bc
	.align 4
	.type	top_bc, @object
	.size	top_bc, 4
top_bc:
	.zero	4
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	0
	.long	1066663936
	.align 8
.LC3:
	.long	0
	.long	1074003968
	.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>
#define NX 256
#define NY 256
#define DX (5./(float)NX)
#define DY (5./(float)NY)
#define N_ITERATIONS 100000
#define N_THREADS_X 32
#define N_THREADS_Y 32
#define N_BLOCKS_X (NX + N_THREADS_X - 1)/N_THREADS_X
#define N_BLOCKS_Y (NY + N_THREADS_Y - 1)/N_THREADS_Y


#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(hipError_t code, const char *file, int line, bool abort=true)
{
   if (code != hipSuccess)
   {
      fprintf(stderr,"GPUassert: %s %s %d\n", hipGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

// Solves the Poisson equation via the Jacobi Method
// $$\nabla^2 \phi = f$$

float f(float x, float y)
{
  return exp(-x*x-y*y);
}

float top_bc = 0;
float bottom_bc = 0;
float left_bc = 0;
float right_bc = 2;

__global__ void iteratePoisson(float* d_source, float* d_V1, float* d_V2)
{
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    int j = blockIdx.y * blockDim.y + threadIdx.y;
    int n = j * NX + i;
    // printf("%d %d %d %d\n", i, j, n, i > 0);
    if ((i>0) && (i < NX-1) && (j>0) && (j < NY-1)) { //TODO: see what can be done about boundaries
        int n_top = (j-1) * NX + i;
        int n_bot = (j+1) * NX + i;
        int n_left = j * NX + (i-1);
        int n_right = j * NX + (i+1);
        //TODO: rewrite above in terms of n?

        // d_V1[n] = n;
        d_V1[n] = 0.25f * (d_V2[n_top] + d_V2[n_bot] + d_V2[n_left] + d_V2[n_right]) +\
            d_source[n] * DX * DY;
            //TODO: check above for consistency. Does this need factor of 4?
    }
}

int main()
{
    float *h_source = (float *)malloc(NX*NY*sizeof(float));
    float *h_V = (float *)malloc(NX*NY*sizeof(float));


    float x;
    float y;

    for(int j =0; j<NY; j++){
        for (int i = 0; i < NX; i++){
            int n = NX*j + i;

            x = i*DX - NX/2 * DX;
            y = j*DY - NY/2 * DY;
            h_source[n] = f(x,y);  //TODO: set up source term

            if (j == 0){ // top row
                h_V[n] = top_bc;
            }
            else if (j==NY-1){ //bottom row
                h_V[n] = bottom_bc;
            }
            else if (i==0){ //left column
                h_V[n] = left_bc;
            }
            else if (i==NX-1){
                h_V[n] = right_bc;
            }
        }
    }


    float *d_source;
    float *d_V1;
    float *d_V2;

    //allocate GPU memory
    gpuErrchk(hipMalloc((void **)&d_source, NX*NY*sizeof(float)));
    gpuErrchk(hipMalloc((void **)&d_V1, NX*NY*sizeof(float)));
    gpuErrchk(hipMalloc((void **)&d_V2, NX*NY*sizeof(float)));

    // copy V1, V2 from host to device
    gpuErrchk(hipMemcpy(d_source, h_source, NX*NY*sizeof(float), hipMemcpyHostToDevice));
    gpuErrchk(hipMemcpy(d_V1, h_V, NX*NY*sizeof(float), hipMemcpyHostToDevice));
    gpuErrchk(hipMemcpy(d_V2, h_V, NX*NY*sizeof(float), hipMemcpyHostToDevice));
    // gpuErrchk(cudaPeekAtLastError());

    printf("Blocks: %d\nThreads: %d\n", N_BLOCKS_X*N_BLOCKS_Y, N_THREADS_X*N_THREADS_Y);
    printf("Iteration %5d", 0);
    dim3 blocks(N_BLOCKS_X, N_BLOCKS_Y);
    dim3 threads(N_THREADS_X, N_THREADS_Y);
    gpuErrchk(hipPeekAtLastError());
    gpuErrchk(hipDeviceSynchronize());


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

    gpuErrchk(hipEventRecord(start, NULL));
    for (int i = 0; i < N_ITERATIONS; i += 2)
    {
        printf("\rIteration %5d", i);
        iteratePoisson<<<blocks, threads>>>(d_source, d_V1, d_V2);
        gpuErrchk(hipPeekAtLastError());
        gpuErrchk(hipDeviceSynchronize());
        iteratePoisson<<<blocks, threads>>>(d_source, d_V2, d_V1);
        gpuErrchk(hipPeekAtLastError());
        gpuErrchk(hipDeviceSynchronize());
    }
    gpuErrchk(hipEventRecord(stop, NULL));




    //copy V2 from device to host as final value
    gpuErrchk(hipMemcpy(h_source, d_source, NX*NY*sizeof(float), hipMemcpyDeviceToHost));
    gpuErrchk(hipMemcpy(h_V, d_V2, NX*NY*sizeof(float), hipMemcpyDeviceToHost));
    gpuErrchk(hipFree(d_source));
    gpuErrchk(hipFree(d_V1));
    gpuErrchk(hipFree(d_V2));

    float msecTotal = 0.0f;
    gpuErrchk(hipEventElapsedTime(&msecTotal, start, stop));
    printf("Elapsed time: %f ms", msecTotal);
    
    FILE* file_V1 = fopen("V1.dat", "w");
    FILE* file_source = fopen("source.dat", "w");

    for(int j =0; j<NY; j++){
        for (int i = 0; i < NX; i++){
            int n = NX*j + i;

            x = i*DX - NX/2 * DX;
            y = j*DY - NY/2 * DY;

            fprintf(file_V1, "%d %d %.3f %.3f %.3f\n", i, j, x, y, h_V[n]);
            fprintf(file_source, "%d %d %.3f %.3f %.3f\n", i, j, x, y, h_source[n]);
        }
    }
    //free GPU arrays
    free(h_V);
    free(h_source);

    //write data out
    printf("\nFinished!\n");
}

	.text
	.file	"main.hip"
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z1fff
.LCPI0_0:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.text
	.globl	_Z1fff
	.type	_Z1fff,@function
_Z1fff:                                 # @_Z1fff
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movaps	.LCPI0_0(%rip), %xmm2           # xmm2 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
	xorps	%xmm0, %xmm2
	mulss	%xmm0, %xmm2
	mulss	%xmm1, %xmm1
	subss	%xmm1, %xmm2
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm2, %xmm0
	callq	exp
	cvtsd2ss	%xmm0, %xmm0
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z1fff, .Lfunc_end0-_Z1fff
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__iteratePoissonPfS_S_ # -- Begin function _Z29__device_stub__iteratePoissonPfS_S_
	.type	_Z29__device_stub__iteratePoissonPfS_S_,@function
_Z29__device_stub__iteratePoissonPfS_S_: # @_Z29__device_stub__iteratePoissonPfS_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	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z14iteratePoissonPfS_S_, %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_end1:
	.size	_Z29__device_stub__iteratePoissonPfS_S_, .Lfunc_end1-_Z29__device_stub__iteratePoissonPfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI2_0:
	.quad	0x3f94000000000000              # double 0.01953125
.LCPI2_1:
	.quad	0xc004000000000000              # double -2.5
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI2_2:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.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	$88, %rsp
	.cfi_def_cfa_offset 144
	.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	$262144, %edi                   # imm = 0x40000
	callq	malloc
	movq	%rax, %r13
	movl	$262144, %edi                   # imm = 0x40000
	callq	malloc
	xorl	%r15d, %r15d
	movsd	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI2_1(%rip), %xmm2           # xmm2 = mem[0],zero
	movl	$1024, %r12d                    # imm = 0x400
	movq	%r13, 56(%rsp)                  # 8-byte Spill
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	movq	%rax, %rbp
.LBB2_1:                                # %.preheader124
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_2 Depth 2
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r15d, %xmm0
	mulsd	%xmm1, %xmm0
	addsd	%xmm2, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	mulss	%xmm0, %xmm0
	movss	%xmm0, 24(%rsp)                 # 4-byte Spill
	movzbl	%r15b, %ebx
	xorl	%r14d, %r14d
.LBB2_2:                                #   Parent Loop BB2_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r14d, %xmm0
	mulsd	%xmm1, %xmm0
	addsd	%xmm2, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movaps	%xmm0, %xmm1
	xorps	.LCPI2_2(%rip), %xmm1
	mulss	%xmm0, %xmm1
	subss	24(%rsp), %xmm1                 # 4-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	callq	exp
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r13,%r14,4)
	testb	%r15b, %r15b
	je	.LBB2_3
# %bb.34:                               #   in Loop: Header=BB2_2 Depth=2
	cmpl	$255, %ebx
	jne	.LBB2_36
# %bb.35:                               #   in Loop: Header=BB2_2 Depth=2
	movl	$bottom_bc, %eax
	jmp	.LBB2_4
.LBB2_3:                                #   in Loop: Header=BB2_2 Depth=2
	movl	$top_bc, %eax
.LBB2_4:                                # %.sink.split
                                        #   in Loop: Header=BB2_2 Depth=2
	movsd	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI2_1(%rip), %xmm2           # xmm2 = mem[0],zero
.LBB2_40:                               # %.sink.split
                                        #   in Loop: Header=BB2_2 Depth=2
	movss	(%rax), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rbp,%r14,4)
.LBB2_41:                               #   in Loop: Header=BB2_2 Depth=2
	incq	%r14
	cmpq	$256, %r14                      # imm = 0x100
	jne	.LBB2_2
	jmp	.LBB2_42
.LBB2_36:                               #   in Loop: Header=BB2_2 Depth=2
	testb	%r14b, %r14b
	movsd	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI2_1(%rip), %xmm2           # xmm2 = mem[0],zero
	je	.LBB2_37
# %bb.38:                               #   in Loop: Header=BB2_2 Depth=2
	movzbl	%r14b, %eax
	cmpl	$255, %eax
	jne	.LBB2_41
# %bb.39:                               #   in Loop: Header=BB2_2 Depth=2
	movl	$right_bc, %eax
	jmp	.LBB2_40
.LBB2_37:                               #   in Loop: Header=BB2_2 Depth=2
	movl	$left_bc, %eax
	jmp	.LBB2_40
.LBB2_42:                               #   in Loop: Header=BB2_1 Depth=1
	incq	%r15
	addq	%r12, %rbp
	addq	%r12, %r13
	cmpq	$256, %r15                      # imm = 0x100
	jne	.LBB2_1
# %bb.5:
	leaq	16(%rsp), %rdi
	movl	$262144, %esi                   # imm = 0x40000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB2_6
# %bb.8:                                # %_Z9gpuAssert10hipError_tPKcib.exit
	leaq	32(%rsp), %rdi
	movl	$262144, %esi                   # imm = 0x40000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB2_9
# %bb.10:                               # %_Z9gpuAssert10hipError_tPKcib.exit76
	leaq	8(%rsp), %rdi
	movl	$262144, %esi                   # imm = 0x40000
	callq	hipMalloc
	testl	%eax, %eax
	movq	56(%rsp), %rbx                  # 8-byte Reload
	movq	48(%rsp), %r14                  # 8-byte Reload
	jne	.LBB2_11
# %bb.12:                               # %_Z9gpuAssert10hipError_tPKcib.exit78
	movq	16(%rsp), %rdi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_13
# %bb.14:                               # %_Z9gpuAssert10hipError_tPKcib.exit80
	movq	32(%rsp), %rdi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_15
# %bb.16:                               # %_Z9gpuAssert10hipError_tPKcib.exit82
	movq	8(%rsp), %rdi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_17
# %bb.18:                               # %_Z9gpuAssert10hipError_tPKcib.exit84
	movl	$.L.str.1, %edi
	movl	$71, %esi
	movl	$1024, %edx                     # imm = 0x400
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.2, %edi
	xorl	%esi, %esi
	xorl	%eax, %eax
	callq	printf
	callq	hipPeekAtLastError
	testl	%eax, %eax
	jne	.LBB2_19
# %bb.20:                               # %_Z9gpuAssert10hipError_tPKcib.exit86
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB2_21
# %bb.22:                               # %_Z9gpuAssert10hipError_tPKcib.exit88
	leaq	72(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB2_23
# %bb.24:                               # %_Z9gpuAssert10hipError_tPKcib.exit90
	leaq	64(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB2_25
# %bb.26:                               # %_Z9gpuAssert10hipError_tPKcib.exit92
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB2_33
# %bb.27:                               # %_Z9gpuAssert10hipError_tPKcib.exit94.preheader.preheader
	movabsq	$137438953504, %r15             # imm = 0x2000000020
	movl	$-2, %ebp
	movabsq	$34359738376, %r12              # imm = 0x800000008
.LBB2_28:                               # %_Z9gpuAssert10hipError_tPKcib.exit94.preheader
                                        # =>This Inner Loop Header: Depth=1
	addl	$2, %ebp
	movl	$.L.str.3, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_30
# %bb.29:                               #   in Loop: Header=BB2_28 Depth=1
	movq	16(%rsp), %rdi
	movq	32(%rsp), %rsi
	movq	8(%rsp), %rdx
	callq	_Z29__device_stub__iteratePoissonPfS_S_
.LBB2_30:                               #   in Loop: Header=BB2_28 Depth=1
	callq	hipPeekAtLastError
	testl	%eax, %eax
	jne	.LBB2_31
# %bb.58:                               # %_Z9gpuAssert10hipError_tPKcib.exit110
                                        #   in Loop: Header=BB2_28 Depth=1
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB2_59
# %bb.60:                               # %_Z9gpuAssert10hipError_tPKcib.exit112
                                        #   in Loop: Header=BB2_28 Depth=1
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_62
# %bb.61:                               #   in Loop: Header=BB2_28 Depth=1
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	32(%rsp), %rdx
	callq	_Z29__device_stub__iteratePoissonPfS_S_
.LBB2_62:                               #   in Loop: Header=BB2_28 Depth=1
	callq	hipPeekAtLastError
	testl	%eax, %eax
	jne	.LBB2_63
# %bb.64:                               # %_Z9gpuAssert10hipError_tPKcib.exit114
                                        #   in Loop: Header=BB2_28 Depth=1
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB2_65
# %bb.43:                               # %_Z9gpuAssert10hipError_tPKcib.exit94
                                        #   in Loop: Header=BB2_28 Depth=1
	cmpl	$99998, %ebp                    # imm = 0x1869E
	jb	.LBB2_28
# %bb.44:
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB2_45
# %bb.46:                               # %_Z9gpuAssert10hipError_tPKcib.exit96
	movq	16(%rsp), %rsi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_47
# %bb.48:                               # %_Z9gpuAssert10hipError_tPKcib.exit98
	movq	8(%rsp), %rsi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_49
# %bb.50:                               # %_Z9gpuAssert10hipError_tPKcib.exit100
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB2_51
# %bb.52:                               # %_Z9gpuAssert10hipError_tPKcib.exit102
	movq	32(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB2_53
# %bb.54:                               # %_Z9gpuAssert10hipError_tPKcib.exit104
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB2_55
# %bb.56:                               # %_Z9gpuAssert10hipError_tPKcib.exit106
	leaq	44(%rsp), %rdi
	movl	$0, (%rdi)
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdx
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB2_57
# %bb.66:                               # %_Z9gpuAssert10hipError_tPKcib.exit108
	cvtss2sd	44(%rsp), %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.5, %edi
	movl	$.L.str.6, %esi
	callq	fopen
	movq	%rax, %r15
	movl	$.L.str.7, %edi
	movl	$.L.str.6, %esi
	callq	fopen
	movq	%rax, %r12
	xorl	%r13d, %r13d
	movsd	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI2_1(%rip), %xmm2           # xmm2 = mem[0],zero
.LBB2_67:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_68 Depth 2
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r13d, %xmm0
	mulsd	%xmm1, %xmm0
	addsd	%xmm2, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	xorl	%ebp, %ebp
.LBB2_68:                               #   Parent Loop BB2_67 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebp, %xmm0
	mulsd	%xmm1, %xmm0
	addsd	%xmm2, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movsd	%xmm0, 80(%rsp)                 # 8-byte Spill
	xorps	%xmm2, %xmm2
	cvtss2sd	(%r14,%rbp,4), %xmm2
	movl	$.L.str.8, %esi
	movq	%r15, %rdi
	movl	%ebp, %edx
	movl	%r13d, %ecx
	movsd	24(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movb	$3, %al
	callq	fprintf
	xorps	%xmm2, %xmm2
	cvtss2sd	(%rbx,%rbp,4), %xmm2
	movl	$.L.str.8, %esi
	movq	%r12, %rdi
	movl	%ebp, %edx
	movl	%r13d, %ecx
	movsd	80(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movsd	24(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movb	$3, %al
	callq	fprintf
	movsd	.LCPI2_1(%rip), %xmm2           # xmm2 = mem[0],zero
	movsd	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero
	incq	%rbp
	cmpq	$256, %rbp                      # imm = 0x100
	jne	.LBB2_68
# %bb.69:                               #   in Loop: Header=BB2_67 Depth=1
	incq	%r13
	movl	$1024, %eax                     # imm = 0x400
	addq	%rax, %rbx
	addq	%rax, %r14
	cmpq	$256, %r13                      # imm = 0x100
	jne	.LBB2_67
# %bb.70:
	movq	48(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	56(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%eax, %eax
	addq	$88, %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_65:
	.cfi_def_cfa_offset 144
	movl	%eax, %r13d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$128, %r8d
	jmp	.LBB2_32
.LBB2_63:
	movl	%eax, %r13d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$127, %r8d
	jmp	.LBB2_32
.LBB2_59:
	movl	%eax, %r13d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$125, %r8d
	jmp	.LBB2_32
.LBB2_31:
	movl	%eax, %r13d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$124, %r8d
.LBB2_32:
	xorl	%eax, %eax
	callq	fprintf
	movl	%r13d, %edi
	callq	exit
.LBB2_6:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$96, %r8d
	jmp	.LBB2_7
.LBB2_9:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$97, %r8d
	jmp	.LBB2_7
.LBB2_11:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$98, %r8d
	jmp	.LBB2_7
.LBB2_13:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$101, %r8d
	jmp	.LBB2_7
.LBB2_15:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$102, %r8d
	jmp	.LBB2_7
.LBB2_17:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$103, %r8d
	jmp	.LBB2_7
.LBB2_19:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$110, %r8d
	jmp	.LBB2_7
.LBB2_21:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$111, %r8d
	jmp	.LBB2_7
.LBB2_23:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$115, %r8d
	jmp	.LBB2_7
.LBB2_25:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$117, %r8d
	jmp	.LBB2_7
.LBB2_33:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$119, %r8d
	jmp	.LBB2_7
.LBB2_45:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$130, %r8d
	jmp	.LBB2_7
.LBB2_47:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$136, %r8d
	jmp	.LBB2_7
.LBB2_49:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$137, %r8d
	jmp	.LBB2_7
.LBB2_51:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$138, %r8d
	jmp	.LBB2_7
.LBB2_53:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$139, %r8d
	jmp	.LBB2_7
.LBB2_55:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$140, %r8d
	jmp	.LBB2_7
.LBB2_57:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$143, %r8d
.LBB2_7:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebp, %edi
	callq	exit
.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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14iteratePoissonPfS_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_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	top_bc,@object                  # @top_bc
	.bss
	.globl	top_bc
	.p2align	2, 0x0
top_bc:
	.long	0x00000000                      # float 0
	.size	top_bc, 4

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

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

	.type	right_bc,@object                # @right_bc
	.data
	.globl	right_bc
	.p2align	2, 0x0
right_bc:
	.long	0x40000000                      # float 2
	.size	right_bc, 4

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/StanczakDominik/cuda_poisson/master/main.hip"
	.size	.L.str, 107

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Blocks: %d\nThreads: %d\n"
	.size	.L.str.1, 24

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Iteration %5d"
	.size	.L.str.2, 14

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\rIteration %5d"
	.size	.L.str.3, 15

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Elapsed time: %f ms"
	.size	.L.str.4, 20

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"V1.dat"
	.size	.L.str.5, 7

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"source.dat"
	.size	.L.str.7, 11

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

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"GPUassert: %s %s %d\n"
	.size	.L.str.10, 21

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

	.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	"\nFinished!"
	.size	.Lstr, 11

	.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__iteratePoissonPfS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14iteratePoissonPfS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14iteratePoissonPfS_S_ ; -- Begin function _Z14iteratePoissonPfS_S_
	.globl	_Z14iteratePoissonPfS_S_
	.p2align	8
	.type	_Z14iteratePoissonPfS_S_,@function
_Z14iteratePoissonPfS_S_:               ; @_Z14iteratePoissonPfS_S_
; %bb.0:
	s_load_b32 s2, s[0:1], 0x24
	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_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, -1, v0
	v_add_nc_u32_e32 v3, -1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_max_u32_e32 v3, v2, v3
	v_cmpx_gt_u32_e32 0xfe, v3
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_dual_mov_b32 v4, 0 :: v_dual_lshlrev_b32 v9, 8, v1
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_dual_mov_b32 v6, v4 :: v_dual_add_nc_u32 v5, v9, v0
	v_add_nc_u32_e32 v1, v9, v2
	v_add_co_u32 v9, s2, v0, v9
	v_add_nc_u32_e32 v3, 0xffffff00, v5
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	v_add_co_ci_u32_e64 v10, null, 0, 0, s2
	v_lshlrev_b64 v[2:3], 2, v[3:4]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v7, vcc_lo, s4, v5
	v_add_co_ci_u32_e32 v8, vcc_lo, s5, v6, vcc_lo
	global_load_b32 v11, v[7:8], off
	v_add_co_u32 v7, vcc_lo, s0, v2
	v_mov_b32_e32 v2, v4
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v3, vcc_lo
	v_lshlrev_b64 v[3:4], 2, v[9:10]
	s_delay_alu instid0(VALU_DEP_3)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	global_load_b32 v7, v[7:8], off
	v_add_co_u32 v2, vcc_lo, s0, v3
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v4, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_clause 0x2
	global_load_b32 v4, v[2:3], off offset:1024
	global_load_b32 v8, v[0:1], off
	global_load_b32 v2, v[2:3], off offset:4
	s_waitcnt vmcnt(4)
	v_cvt_f64_f32_e32 v[0:1], v11
	s_waitcnt vmcnt(2)
	v_add_f32_e32 v3, v7, v4
	s_waitcnt vmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f32_e32 v3, v3, v8
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v2, v3, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v2, 0x3e800000, v2
	v_mul_f64 v[0:1], 0x3f940000, v[0:1]
	v_cvt_f64_f32_e32 v[2:3], v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[0:1], 0x3f940000, v[0:1], v[2:3]
	v_cvt_f32_f64_e32 v2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s6, v5
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v6, vcc_lo
	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 _Z14iteratePoissonPfS_S_
		.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 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	_Z14iteratePoissonPfS_S_, .Lfunc_end0-_Z14iteratePoissonPfS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 420
; 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:
      - .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:     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:           _Z14iteratePoissonPfS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14iteratePoissonPfS_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
