#include <stdio.h>
#include <stdlib.h>
// these are just for timing measurments
#include <time.h>
// Computes minimum in a 3D volume, at each output point
// To compile it with nvcc execute: nvcc -O2 -o grid3d grid3d.cu
//define the window size (cubic volume) and the data set size
#define WSIZE 6
#define DATAXSIZE 100
#define DATAYSIZE 100
#define DATAZSIZE 20
//define the chunk sizes that each threadblock will work on
#define BLKXSIZE 8
#define BLKYSIZE 8
#define BLKZSIZE 8

// for cuda error checking
#define cudaCheckErrors(msg) \
    do { \
        cudaError_t __err = cudaGetLastError(); \
        if (__err != cudaSuccess) { \
            fprintf(stderr, "Fatal error: %s (%s at %s:%d)\n", \
                msg, cudaGetErrorString(__err), \
                __FILE__, __LINE__); \
            fprintf(stderr, "*** FAILED - ABORTING\n"); \
            return 1; \
        } \
    } while (0)
// device function to compute 3D volume minimum at each output point
__global__ void cmp_win(int knode[][DATAYSIZE][DATAXSIZE], const int kcell[][DATAYSIZE+(WSIZE-1)][DATAXSIZE+(WSIZE-1)])
{
    __shared__ int smem[(BLKZSIZE + (WSIZE-1))][(BLKYSIZE + (WSIZE-1))][(BLKXSIZE + (WSIZE-1))];
    int tempnode, i, j, k;
    int idx = blockIdx.x*blockDim.x + threadIdx.x;
    int idy = blockIdx.y*blockDim.y + threadIdx.y;
    int idz = blockIdx.z*blockDim.z + threadIdx.z;
    if ((idx < (DATAXSIZE+WSIZE-1)) && (idy < (DATAYSIZE+WSIZE-1)) && (idz < (DATAZSIZE+WSIZE-1))){
      smem[threadIdx.z][threadIdx.y][threadIdx.x]=kcell[idz][idy][idx];
      if ((threadIdx.z > (BLKZSIZE - WSIZE)) && (idz < DATAZSIZE))
        smem[threadIdx.z + (WSIZE-1)][threadIdx.y][threadIdx.x] = kcell[idz + (WSIZE-1)][idy][idx];
      if ((threadIdx.y > (BLKYSIZE - WSIZE)) && (idy < DATAYSIZE))
        smem[threadIdx.z][threadIdx.y + (WSIZE-1)][threadIdx.x] = kcell[idz][idy+(WSIZE-1)][idx];
      if ((threadIdx.x > (BLKXSIZE - WSIZE)) && (idx < DATAXSIZE))
        smem[threadIdx.z][threadIdx.y][threadIdx.x + (WSIZE-1)] = kcell[idz][idy][idx+(WSIZE-1)];
      if ((threadIdx.z > (BLKZSIZE - WSIZE)) && (threadIdx.y > (BLKYSIZE - WSIZE)) && (idz < DATAZSIZE) && (idy < DATAYSIZE))
        smem[threadIdx.z + (WSIZE-1)][threadIdx.y + (WSIZE-1)][threadIdx.x] = kcell[idz+(WSIZE-1)][idy+(WSIZE-1)][idx];
      if ((threadIdx.z > (BLKZSIZE - WSIZE)) && (threadIdx.x > (BLKXSIZE - WSIZE)) && (idz < DATAZSIZE) && (idx < DATAXSIZE))
        smem[threadIdx.z + (WSIZE-1)][threadIdx.y][threadIdx.x + (WSIZE-1)] = kcell[idz+(WSIZE-1)][idy][idx+(WSIZE-1)];
      if ((threadIdx.y > (BLKYSIZE - WSIZE)) && (threadIdx.x > (BLKXSIZE - WSIZE)) && (idy < DATAYSIZE) && (idx < DATAXSIZE))
        smem[threadIdx.z][threadIdx.y + (WSIZE-1)][threadIdx.x + (WSIZE-1)] = kcell[idz][idy+(WSIZE-1)][idx+(WSIZE-1)];
      if ((threadIdx.z > (BLKZSIZE - WSIZE)) && (threadIdx.y > (BLKYSIZE - WSIZE)) && (threadIdx.x > (BLKXSIZE - WSIZE)) && (idz < DATAZSIZE) && (idy < DATAYSIZE) && (idx < DATAXSIZE))
        smem[threadIdx.z+(WSIZE-1)][threadIdx.y+(WSIZE-1)][threadIdx.x+(WSIZE-1)] = kcell[idz+(WSIZE-1)][idy+(WSIZE-1)][idx+(WSIZE-1)];
      }
    __syncthreads();
    if ((idx < DATAXSIZE) && (idy < DATAYSIZE) && (idz < DATAZSIZE)){
      tempnode = knode[idz][idy][idx];
      for (i=0; i<WSIZE; i++)
        for (j=0; j<WSIZE; j++)
          for (k=0; k<WSIZE; k++)
          if (smem[threadIdx.z + i][threadIdx.y + j][threadIdx.x + k] < tempnode)
            tempnode = smem[threadIdx.z + i][threadIdx.y + j][threadIdx.x + k];
      knode[idz][idy][idx] = tempnode;
      }
}

int main(int argc, char *argv[])
{
    typedef int cRarray[DATAYSIZE+WSIZE-1][DATAXSIZE+WSIZE-1];
    typedef int nRarray[DATAYSIZE][DATAXSIZE];
    int i, j, k, u, v, w, temphnode;
    const dim3 blockSize(BLKXSIZE, BLKYSIZE, BLKZSIZE);
    const dim3 gridSize(((DATAXSIZE+BLKXSIZE-1)/BLKXSIZE), ((DATAYSIZE+BLKYSIZE-1)/BLKYSIZE), ((DATAZSIZE+BLKZSIZE-1)/BLKZSIZE));
// these are just for timing
    clock_t t0, t1, t2, t3;
    double t1sum=0.0f;
    double t2sum=0.0f;
    double t3sum=0.0f;
// overall data set sizes
    const int nx = DATAXSIZE;
    const int ny = DATAYSIZE;
    const int nz = DATAZSIZE;
// window (cubic minimization volume) dimensions
    const int wx = WSIZE;
    const int wy = WSIZE;
    const int wz = WSIZE;
// pointers for data set storage via malloc
    nRarray *hnode; // storage for result computed on host
    nRarray *node, *d_node;  // storage for result computed on device
    cRarray *cell, *d_cell;  // storage for input
// start timing
    t0 = clock();
// allocate storage for data set
    if ((cell = (cRarray *)malloc(((nx+(wx-1))*(ny+(wy-1))*(nz+(wz-1)))*sizeof(int))) == 0) {fprintf(stderr,"malloc Fail \n"); return 1;}
    if ((node = (nRarray *)malloc((nx*ny*nz)*sizeof(int))) == 0) {fprintf(stderr,"malloc Fail \n"); return 1; }
    if ((hnode = (nRarray *)malloc((nx*ny*nz)*sizeof(int))) == 0) {fprintf(stderr, "malloc Fail \n"); return 1; }
// synthesize data
    for(i=0; i<(nz+(wz-1)); i++)
      for(j=0; j<(ny+(wy-1)); j++)
        for (k=0; k<(nx+(wx-1)); k++){
          cell[i][j][k] = rand(); // unless we use a seed this will produce the same sequence all the time
          if ((i<nz) && (j<ny) && (k<nx)) {
            node[i][j][k]  = RAND_MAX;
            hnode[i][j][k] = RAND_MAX;
            }
          }
    t1 = clock();
    t1sum = ((double)(t1-t0))/CLOCKS_PER_SEC;
    printf("Init took %3.2f seconds.  Begin compute\n", t1sum);
// allocate GPU device buffers
    cudaMalloc((void **) &d_cell, (((nx+(wx-1))*(ny+(wy-1))*(nz+(wz-1)))*sizeof(int)));
    cudaCheckErrors("Failed to allocate device buffer");
    cudaMalloc((void **) &d_node, ((nx*ny*nz)*sizeof(int)));
    cudaCheckErrors("Failed to allocate device buffer2");
// copy data to GPU
    cudaMemcpy(d_node, node, ((nx*ny*nz)*sizeof(int)), cudaMemcpyHostToDevice);
    cudaCheckErrors("CUDA memcpy failure");
    cudaMemcpy(d_cell, cell, (((nx+(wx-1))*(ny+(wy-1))*(nz+(wz-1)))*sizeof(int)), cudaMemcpyHostToDevice);
    cudaCheckErrors("CUDA memcpy2 failure");

    cmp_win<<<gridSize,blockSize>>>(d_node, d_cell);
    cudaCheckErrors("Kernel launch failure");
// copy output data back to host

    cudaMemcpy(node, d_node, ((nx*ny*nz)*sizeof(int)), cudaMemcpyDeviceToHost);
    cudaCheckErrors("CUDA memcpy3 failure");
    t2 = clock();
    t2sum = ((double)(t2-t1))/CLOCKS_PER_SEC;
    printf(" Device compute took %3.2f seconds.  Beginning host compute.\n", t2sum);
// now compute the same result on the host
    for (u=0; u<nz; u++)
      for (v=0; v<ny; v++)
        for (w=0; w<nx; w++){
          temphnode = hnode[u][v][w];
          for (i=0; i<wz; i++)
            for (j=0; j<wy; j++)
              for (k=0; k<wx; k++)
                if (temphnode > cell[i+u][j+v][k+w]) temphnode = cell[i+u][j+v][k+w];
          hnode[u][v][w] = temphnode;
          }
    t3 = clock();
    t3sum = ((double)(t3-t2))/CLOCKS_PER_SEC;
    printf(" Host compute took %3.2f seconds.  Comparing results.\n", t3sum);
// and compare for accuracy
    for (i=0; i<nz; i++)
      for (j=0; j<ny; j++)
        for (k=0; k<nx; k++)
          if (hnode[i][j][k] != node[i][j][k]) {
            printf("Mismatch at x= %d, y= %d, z= %d  Host= %d, Device = %d\n", i, j, k, hnode[i][j][k], node[i][j][k]);
            return 1;
            }
    printf("Results match!\n");
    free(cell);
    free(node);
    cudaFree(d_cell);
    cudaCheckErrors("cudaFree fail");
    cudaFree(d_node);
    cudaCheckErrors("cudaFree fail");
    return 0;
}

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

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z49__device_stub__Z7cmp_winPA100_A100_iPA105_A105_KiPA100_A100_iPA105_A105_Ki
	.type	_Z49__device_stub__Z7cmp_winPA100_A100_iPA105_A105_KiPA100_A100_iPA105_A105_Ki, @function
_Z49__device_stub__Z7cmp_winPA100_A100_iPA105_A105_KiPA100_A100_iPA105_A105_Ki:
.LFB2052:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z7cmp_winPA100_A100_iPA105_A105_Ki(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L2:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z49__device_stub__Z7cmp_winPA100_A100_iPA105_A105_KiPA100_A100_iPA105_A105_Ki, .-_Z49__device_stub__Z7cmp_winPA100_A100_iPA105_A105_KiPA100_A100_iPA105_A105_Ki
	.globl	_Z7cmp_winPA100_A100_iPA105_A105_Ki
	.type	_Z7cmp_winPA100_A100_iPA105_A105_Ki, @function
_Z7cmp_winPA100_A100_iPA105_A105_Ki:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z49__device_stub__Z7cmp_winPA100_A100_iPA105_A105_KiPA100_A100_iPA105_A105_Ki
	.cfi_endproc
.LFE2053:
	.size	_Z7cmp_winPA100_A100_iPA105_A105_Ki, .-_Z7cmp_winPA100_A100_iPA105_A105_Ki
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"malloc Fail \n"
.LC2:
	.string	"Init took %3.2f seconds.  Begin compute\n"
.LC3:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/issamsaid/cuda-quickies/master/max_filter/main.cu"
.LC4:
	.string	"Failed to allocate device buffer"
.LC5:
	.string	"Fatal error: %s (%s at %s:%d)\n"
.LC6:
	.string	"*** FAILED - ABORTING\n"
.LC7:
	.string	"Failed to allocate device buffer2"
.LC8:
	.string	"CUDA memcpy failure"
.LC9:
	.string	"CUDA memcpy2 failure"
.LC10:
	.string	"Kernel launch failure"
.LC11:
	.string	"CUDA memcpy3 failure"
.LC12:
	.string	" Device compute took %3.2f seconds.  Beginning host compute.\n"
.LC13:
	.string	" Host compute took %3.2f seconds.  Comparing results.\n"
.LC14:
	.string	"Mismatch at x= %d, y= %d, z= %d  Host= %d, Device = %d\n"
.LC15:
	.string	"Results match!\n"
.LC16:
	.string	"cudaFree fail"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	movabsq	$34359738376, %rax
	movl	$8, 72(%rsp)
	movl	$3, 84(%rsp)
	movq	%rax, 64(%rsp)
	movabsq	$55834574861, %rax
	movq	%rax, 76(%rsp)
	call	clock@PLT
	movl	$1102500, %edi
	movq	%rax, %r13
	call	malloc@PLT
	movq	%rax, 8(%rsp)
	testq	%rax, %rax
	je	.L58
	movl	$800000, %edi
	call	malloc@PLT
	movq	%rax, (%rsp)
	testq	%rax, %rax
	jne	.L11
.L58:
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
.L59:
	call	__fprintf_chk@PLT
.L10:
	movl	$1, %eax
	jmp	.L8
.L11:
	movl	$800000, %edi
	call	malloc@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.L13
	movq	8(%rsp), %rcx
	movq	(%rsp), %rsi
	movq	%rax, %rdi
	xorl	%r14d, %r14d
	jmp	.L14
.L13:
	leaq	.LC0(%rip), %rdx
	jmp	.L60
.L19:
	imulq	$400, %rbp, %r12
	xorl	%r15d, %r15d
.L16:
	movq	%rcx, 40(%rsp)
	movq	%rdi, 32(%rsp)
	movq	%rsi, 24(%rsp)
	movq	%rdx, 16(%rsp)
	call	rand@PLT
	cmpl	$19, %r14d
	movq	16(%rsp), %rdx
	movq	24(%rsp), %rsi
	setle	%r8b
	cmpl	$99, %ebp
	movq	32(%rsp), %rdi
	movq	40(%rsp), %rcx
	movl	%eax, (%rdx,%r12)
	setle	%al
	testb	%al, %r8b
	jne	.L63
.L15:
	incl	%r15d
	addq	$4, %r12
	cmpl	$105, %r15d
	jne	.L16
	incq	%rbp
	addq	$20, %rdx
	cmpq	$105, %rbp
	jne	.L19
	incl	%r14d
	addq	$40000, %rsi
	addq	$40000, %rdi
	addq	$44100, %rcx
	cmpl	$25, %r14d
	je	.L18
.L14:
	movq	%rcx, %rdx
	xorl	%ebp, %ebp
	jmp	.L19
.L63:
	cmpl	$99, %r15d
	jg	.L15
	movl	$2147483647, (%rsi,%r12)
	movl	$2147483647, (%rdi,%r12)
	jmp	.L15
.L18:
	call	clock@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rbp
	subq	%r13, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC1(%rip), %xmm0
	call	__printf_chk@PLT
	leaq	56(%rsp), %rdi
	movl	$1102500, %esi
	call	cudaMalloc@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L20
	call	cudaGetErrorString@PLT
	leaq	.LC3(%rip), %r9
	leaq	.LC4(%rip), %rcx
	movq	%rax, %r8
	pushq	%rax
	.cfi_remember_state
	.cfi_def_cfa_offset 168
	pushq	$111
	.cfi_def_cfa_offset 176
	jmp	.L62
.L20:
	.cfi_restore_state
	leaq	48(%rsp), %rdi
	movl	$800000, %esi
	call	cudaMalloc@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	leaq	.LC3(%rip), %r9
	pushq	%r15
	.cfi_remember_state
	.cfi_def_cfa_offset 168
	leaq	.LC7(%rip), %rcx
	pushq	$113
	.cfi_def_cfa_offset 176
	movq	%rax, %r8
	jmp	.L62
.L21:
	.cfi_restore_state
	movq	48(%rsp), %rdi
	movq	(%rsp), %rsi
	movl	$1, %ecx
	movl	$800000, %edx
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L22
	call	cudaGetErrorString@PLT
	leaq	.LC3(%rip), %r9
	pushq	%r14
	.cfi_remember_state
	.cfi_def_cfa_offset 168
	leaq	.LC8(%rip), %rcx
	pushq	$116
	.cfi_def_cfa_offset 176
	movq	%rax, %r8
	jmp	.L62
.L22:
	.cfi_restore_state
	movq	56(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	$1, %ecx
	movl	$1102500, %edx
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L23
	call	cudaGetErrorString@PLT
	leaq	.LC3(%rip), %r9
	pushq	%r13
	.cfi_remember_state
	.cfi_def_cfa_offset 168
	leaq	.LC9(%rip), %rcx
	pushq	$118
	.cfi_def_cfa_offset 176
	movq	%rax, %r8
	jmp	.L62
.L23:
	.cfi_restore_state
	movl	72(%rsp), %ecx
	movq	64(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	76(%rsp), %rdi
	movl	84(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	movq	56(%rsp), %rsi
	movq	48(%rsp), %rdi
	call	_Z49__device_stub__Z7cmp_winPA100_A100_iPA105_A105_KiPA100_A100_iPA105_A105_Ki
.L24:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L25
	call	cudaGetErrorString@PLT
	leaq	.LC3(%rip), %r9
	pushq	%r12
	.cfi_remember_state
	.cfi_def_cfa_offset 168
	leaq	.LC10(%rip), %rcx
	pushq	$121
	.cfi_def_cfa_offset 176
	movq	%rax, %r8
	jmp	.L62
.L25:
	.cfi_restore_state
	movq	(%rsp), %rdi
	movq	48(%rsp), %rsi
	movl	$2, %ecx
	movl	$800000, %edx
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L26
	call	cudaGetErrorString@PLT
	leaq	.LC3(%rip), %r9
	pushq	%rbp
	.cfi_remember_state
	.cfi_def_cfa_offset 168
	leaq	.LC11(%rip), %rcx
	pushq	$125
	.cfi_def_cfa_offset 176
	movq	%rax, %r8
	jmp	.L62
.L26:
	.cfi_restore_state
	call	clock@PLT
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%r14d, %r14d
	movq	%rax, %r15
	subq	%rbp, %rax
	movq	%rbx, %rbp
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC1(%rip), %xmm0
	call	__printf_chk@PLT
.L27:
	imulq	$44100, %r14, %r9
	movq	8(%rsp), %rax
	xorl	%edi, %edi
	xorl	%esi, %esi
	movq	%rbp, %r8
	addq	%r9, %rax
	movq	%rax, 24(%rsp)
.L36:
	leaq	0(,%rdi,4), %r11
	movq	%r8, %rax
	xorl	%r10d, %r10d
.L33:
	movq	24(%rsp), %rcx
	movl	(%rax), %edx
	movl	$6, 16(%rsp)
	leaq	(%r11,%rcx), %r13
.L28:
	movq	%r13, %r12
	movl	$6, %r9d
.L32:
	xorl	%ecx, %ecx
.L29:
	cmpl	(%r12,%rcx,4), %edx
	cmovg	(%r12,%rcx,4), %edx
	incq	%rcx
	cmpq	$6, %rcx
	jne	.L29
	addq	$420, %r12
	decl	%r9d
	jne	.L32
	addq	$44100, %r13
	decl	16(%rsp)
	jne	.L28
	incq	%r10
	movl	%edx, (%rax)
	addq	$4, %r11
	addq	$4, %rax
	cmpq	$100, %r10
	jne	.L33
	incl	%esi
	addq	$105, %rdi
	addq	$400, %r8
	cmpl	$100, %esi
	jne	.L36
	incq	%r14
	addq	$40000, %rbp
	cmpq	$20, %r14
	jne	.L27
	call	clock@PLT
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	subq	%r15, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC1(%rip), %xmm0
	call	__printf_chk@PLT
	xorl	%eax, %eax
	xorl	%edx, %edx
.L37:
	movq	(%rsp), %rcx
	leaq	(%rbx,%rax), %r11
	leaq	(%rcx,%rax), %r10
	xorl	%ecx, %ecx
.L42:
	imulq	$400, %rcx, %rsi
	xorl	%r8d, %r8d
.L39:
	movl	(%r11,%rsi), %r9d
	movl	(%r10,%rsi), %edi
	cmpl	%edi, %r9d
	je	.L38
	pushq	%r10
	.cfi_def_cfa_offset 168
	leaq	.LC14(%rip), %rsi
	xorl	%eax, %eax
	pushq	%rdi
	.cfi_def_cfa_offset 176
	movl	$2, %edi
	call	__printf_chk@PLT
	popq	%r11
	.cfi_def_cfa_offset 168
	popq	%rbx
	.cfi_def_cfa_offset 160
	jmp	.L10
.L38:
	incl	%r8d
	addq	$4, %rsi
	cmpl	$100, %r8d
	jne	.L39
	incq	%rcx
	cmpq	$100, %rcx
	jne	.L42
	incl	%edx
	addq	$40000, %rax
	cmpl	$20, %edx
	jne	.L37
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	free@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L43
	call	cudaGetErrorString@PLT
	movq	%rax, %r8
	pushq	%rsi
	.cfi_remember_state
	.cfi_def_cfa_offset 168
	pushq	$155
	.cfi_def_cfa_offset 176
	jmp	.L61
.L43:
	.cfi_restore_state
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	xorl	%eax, %eax
	testl	%edi, %edi
	je	.L8
	call	cudaGetErrorString@PLT
	pushq	%rcx
	.cfi_def_cfa_offset 168
	movq	%rax, %r8
	pushq	$157
	.cfi_def_cfa_offset 176
.L61:
	leaq	.LC3(%rip), %r9
	leaq	.LC16(%rip), %rcx
.L62:
	movq	stderr(%rip), %rdi
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
	leaq	.LC6(%rip), %rdx
.L60:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	jmp	.L59
.L8:
	movq	88(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L44
	call	__stack_chk_fail@PLT
.L44:
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC17:
	.string	"_Z7cmp_winPA100_A100_iPA105_A105_Ki"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.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	.LC17(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z7cmp_winPA100_A100_iPA105_A105_Ki(%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
.LFE2055:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1093567616
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
// these are just for timing measurments
#include <time.h>
// Computes minimum in a 3D volume, at each output point
// To compile it with nvcc execute: nvcc -O2 -o grid3d grid3d.cu
//define the window size (cubic volume) and the data set size
#define WSIZE 6
#define DATAXSIZE 100
#define DATAYSIZE 100
#define DATAZSIZE 20
//define the chunk sizes that each threadblock will work on
#define BLKXSIZE 8
#define BLKYSIZE 8
#define BLKZSIZE 8

// for cuda error checking
#define cudaCheckErrors(msg) \
    do { \
        hipError_t __err = hipGetLastError(); \
        if (__err != hipSuccess) { \
            fprintf(stderr, "Fatal error: %s (%s at %s:%d)\n", \
                msg, hipGetErrorString(__err), \
                __FILE__, __LINE__); \
            fprintf(stderr, "*** FAILED - ABORTING\n"); \
            return 1; \
        } \
    } while (0)
// device function to compute 3D volume minimum at each output point
__global__ void cmp_win(int knode[][DATAYSIZE][DATAXSIZE], const int kcell[][DATAYSIZE+(WSIZE-1)][DATAXSIZE+(WSIZE-1)])
{
    __shared__ int smem[(BLKZSIZE + (WSIZE-1))][(BLKYSIZE + (WSIZE-1))][(BLKXSIZE + (WSIZE-1))];
    int tempnode, i, j, k;
    int idx = blockIdx.x*blockDim.x + threadIdx.x;
    int idy = blockIdx.y*blockDim.y + threadIdx.y;
    int idz = blockIdx.z*blockDim.z + threadIdx.z;
    if ((idx < (DATAXSIZE+WSIZE-1)) && (idy < (DATAYSIZE+WSIZE-1)) && (idz < (DATAZSIZE+WSIZE-1))){
      smem[threadIdx.z][threadIdx.y][threadIdx.x]=kcell[idz][idy][idx];
      if ((threadIdx.z > (BLKZSIZE - WSIZE)) && (idz < DATAZSIZE))
        smem[threadIdx.z + (WSIZE-1)][threadIdx.y][threadIdx.x] = kcell[idz + (WSIZE-1)][idy][idx];
      if ((threadIdx.y > (BLKYSIZE - WSIZE)) && (idy < DATAYSIZE))
        smem[threadIdx.z][threadIdx.y + (WSIZE-1)][threadIdx.x] = kcell[idz][idy+(WSIZE-1)][idx];
      if ((threadIdx.x > (BLKXSIZE - WSIZE)) && (idx < DATAXSIZE))
        smem[threadIdx.z][threadIdx.y][threadIdx.x + (WSIZE-1)] = kcell[idz][idy][idx+(WSIZE-1)];
      if ((threadIdx.z > (BLKZSIZE - WSIZE)) && (threadIdx.y > (BLKYSIZE - WSIZE)) && (idz < DATAZSIZE) && (idy < DATAYSIZE))
        smem[threadIdx.z + (WSIZE-1)][threadIdx.y + (WSIZE-1)][threadIdx.x] = kcell[idz+(WSIZE-1)][idy+(WSIZE-1)][idx];
      if ((threadIdx.z > (BLKZSIZE - WSIZE)) && (threadIdx.x > (BLKXSIZE - WSIZE)) && (idz < DATAZSIZE) && (idx < DATAXSIZE))
        smem[threadIdx.z + (WSIZE-1)][threadIdx.y][threadIdx.x + (WSIZE-1)] = kcell[idz+(WSIZE-1)][idy][idx+(WSIZE-1)];
      if ((threadIdx.y > (BLKYSIZE - WSIZE)) && (threadIdx.x > (BLKXSIZE - WSIZE)) && (idy < DATAYSIZE) && (idx < DATAXSIZE))
        smem[threadIdx.z][threadIdx.y + (WSIZE-1)][threadIdx.x + (WSIZE-1)] = kcell[idz][idy+(WSIZE-1)][idx+(WSIZE-1)];
      if ((threadIdx.z > (BLKZSIZE - WSIZE)) && (threadIdx.y > (BLKYSIZE - WSIZE)) && (threadIdx.x > (BLKXSIZE - WSIZE)) && (idz < DATAZSIZE) && (idy < DATAYSIZE) && (idx < DATAXSIZE))
        smem[threadIdx.z+(WSIZE-1)][threadIdx.y+(WSIZE-1)][threadIdx.x+(WSIZE-1)] = kcell[idz+(WSIZE-1)][idy+(WSIZE-1)][idx+(WSIZE-1)];
      }
    __syncthreads();
    if ((idx < DATAXSIZE) && (idy < DATAYSIZE) && (idz < DATAZSIZE)){
      tempnode = knode[idz][idy][idx];
      for (i=0; i<WSIZE; i++)
        for (j=0; j<WSIZE; j++)
          for (k=0; k<WSIZE; k++)
          if (smem[threadIdx.z + i][threadIdx.y + j][threadIdx.x + k] < tempnode)
            tempnode = smem[threadIdx.z + i][threadIdx.y + j][threadIdx.x + k];
      knode[idz][idy][idx] = tempnode;
      }
}

int main(int argc, char *argv[])
{
    typedef int cRarray[DATAYSIZE+WSIZE-1][DATAXSIZE+WSIZE-1];
    typedef int nRarray[DATAYSIZE][DATAXSIZE];
    int i, j, k, u, v, w, temphnode;
    const dim3 blockSize(BLKXSIZE, BLKYSIZE, BLKZSIZE);
    const dim3 gridSize(((DATAXSIZE+BLKXSIZE-1)/BLKXSIZE), ((DATAYSIZE+BLKYSIZE-1)/BLKYSIZE), ((DATAZSIZE+BLKZSIZE-1)/BLKZSIZE));
// these are just for timing
    clock_t t0, t1, t2, t3;
    double t1sum=0.0f;
    double t2sum=0.0f;
    double t3sum=0.0f;
// overall data set sizes
    const int nx = DATAXSIZE;
    const int ny = DATAYSIZE;
    const int nz = DATAZSIZE;
// window (cubic minimization volume) dimensions
    const int wx = WSIZE;
    const int wy = WSIZE;
    const int wz = WSIZE;
// pointers for data set storage via malloc
    nRarray *hnode; // storage for result computed on host
    nRarray *node, *d_node;  // storage for result computed on device
    cRarray *cell, *d_cell;  // storage for input
// start timing
    t0 = clock();
// allocate storage for data set
    if ((cell = (cRarray *)malloc(((nx+(wx-1))*(ny+(wy-1))*(nz+(wz-1)))*sizeof(int))) == 0) {fprintf(stderr,"malloc Fail \n"); return 1;}
    if ((node = (nRarray *)malloc((nx*ny*nz)*sizeof(int))) == 0) {fprintf(stderr,"malloc Fail \n"); return 1; }
    if ((hnode = (nRarray *)malloc((nx*ny*nz)*sizeof(int))) == 0) {fprintf(stderr, "malloc Fail \n"); return 1; }
// synthesize data
    for(i=0; i<(nz+(wz-1)); i++)
      for(j=0; j<(ny+(wy-1)); j++)
        for (k=0; k<(nx+(wx-1)); k++){
          cell[i][j][k] = rand(); // unless we use a seed this will produce the same sequence all the time
          if ((i<nz) && (j<ny) && (k<nx)) {
            node[i][j][k]  = RAND_MAX;
            hnode[i][j][k] = RAND_MAX;
            }
          }
    t1 = clock();
    t1sum = ((double)(t1-t0))/CLOCKS_PER_SEC;
    printf("Init took %3.2f seconds.  Begin compute\n", t1sum);
// allocate GPU device buffers
    hipMalloc((void **) &d_cell, (((nx+(wx-1))*(ny+(wy-1))*(nz+(wz-1)))*sizeof(int)));
    cudaCheckErrors("Failed to allocate device buffer");
    hipMalloc((void **) &d_node, ((nx*ny*nz)*sizeof(int)));
    cudaCheckErrors("Failed to allocate device buffer2");
// copy data to GPU
    hipMemcpy(d_node, node, ((nx*ny*nz)*sizeof(int)), hipMemcpyHostToDevice);
    cudaCheckErrors("CUDA memcpy failure");
    hipMemcpy(d_cell, cell, (((nx+(wx-1))*(ny+(wy-1))*(nz+(wz-1)))*sizeof(int)), hipMemcpyHostToDevice);
    cudaCheckErrors("CUDA memcpy2 failure");

    cmp_win<<<gridSize,blockSize>>>(d_node, d_cell);
    cudaCheckErrors("Kernel launch failure");
// copy output data back to host

    hipMemcpy(node, d_node, ((nx*ny*nz)*sizeof(int)), hipMemcpyDeviceToHost);
    cudaCheckErrors("CUDA memcpy3 failure");
    t2 = clock();
    t2sum = ((double)(t2-t1))/CLOCKS_PER_SEC;
    printf(" Device compute took %3.2f seconds.  Beginning host compute.\n", t2sum);
// now compute the same result on the host
    for (u=0; u<nz; u++)
      for (v=0; v<ny; v++)
        for (w=0; w<nx; w++){
          temphnode = hnode[u][v][w];
          for (i=0; i<wz; i++)
            for (j=0; j<wy; j++)
              for (k=0; k<wx; k++)
                if (temphnode > cell[i+u][j+v][k+w]) temphnode = cell[i+u][j+v][k+w];
          hnode[u][v][w] = temphnode;
          }
    t3 = clock();
    t3sum = ((double)(t3-t2))/CLOCKS_PER_SEC;
    printf(" Host compute took %3.2f seconds.  Comparing results.\n", t3sum);
// and compare for accuracy
    for (i=0; i<nz; i++)
      for (j=0; j<ny; j++)
        for (k=0; k<nx; k++)
          if (hnode[i][j][k] != node[i][j][k]) {
            printf("Mismatch at x= %d, y= %d, z= %d  Host= %d, Device = %d\n", i, j, k, hnode[i][j][k], node[i][j][k]);
            return 1;
            }
    printf("Results match!\n");
    free(cell);
    free(node);
    hipFree(d_cell);
    cudaCheckErrors("hipFree fail");
    hipFree(d_node);
    cudaCheckErrors("hipFree fail");
    return 0;
}

	.text
	.file	"main.hip"
	.globl	_Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki # -- Begin function _Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki
	.type	_Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki,@function
_Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki: # @_Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z7cmp_winPA100_A100_iPA105_A105_Ki, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki, .Lfunc_end0-_Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI1_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.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
	callq	clock
	movq	%rax, %r15
	movl	$1102500, %edi                  # imm = 0x10D2A4
	callq	malloc
	testq	%rax, %rax
	je	.LBB1_1
# %bb.2:
	movq	%rax, %r14
	movl	$800000, %edi                   # imm = 0xC3500
	callq	malloc
	testq	%rax, %rax
	je	.LBB1_1
# %bb.3:
	movq	%rax, %r13
	movl	$800000, %edi                   # imm = 0xC3500
	callq	malloc
	testq	%rax, %rax
	je	.LBB1_1
# %bb.4:                                # %.preheader212.preheader
	movq	%r15, 56(%rsp)                  # 8-byte Spill
	xorl	%ecx, %ecx
	movq	%rcx, (%rsp)                    # 8-byte Spill
	movl	$2147483647, %ebp               # imm = 0x7FFFFFFF
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	movq	%rax, %r15
	movq	%r13, 40(%rsp)                  # 8-byte Spill
	movq	%r14, 32(%rsp)                  # 8-byte Spill
.LBB1_5:                                # %.preheader212
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_6 Depth 2
                                        #       Child Loop BB1_7 Depth 3
	movq	%r15, 80(%rsp)                  # 8-byte Spill
	movq	%r13, 72(%rsp)                  # 8-byte Spill
	movq	%r14, 64(%rsp)                  # 8-byte Spill
	xorl	%ecx, %ecx
.LBB1_6:                                # %.preheader211
                                        #   Parent Loop BB1_5 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_7 Depth 3
	cmpq	$20, (%rsp)                     # 8-byte Folded Reload
	setb	%al
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	cmpq	$100, %rcx
	setb	%r12b
	andb	%al, %r12b
	xorb	$1, %r12b
	xorl	%ebx, %ebx
.LBB1_7:                                #   Parent Loop BB1_5 Depth=1
                                        #     Parent Loop BB1_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	callq	rand
	movl	%eax, (%r14,%rbx,4)
	cmpq	$100, %rbx
	setae	%al
	orb	%r12b, %al
	jne	.LBB1_9
# %bb.8:                                #   in Loop: Header=BB1_7 Depth=3
	movl	%ebp, (%r13,%rbx,4)
	movl	%ebp, (%r15,%rbx,4)
.LBB1_9:                                #   in Loop: Header=BB1_7 Depth=3
	incq	%rbx
	cmpq	$105, %rbx
	jne	.LBB1_7
# %bb.10:                               #   in Loop: Header=BB1_6 Depth=2
	movq	16(%rsp), %rcx                  # 8-byte Reload
	incq	%rcx
	addq	$420, %r14                      # imm = 0x1A4
	movl	$400, %eax                      # imm = 0x190
	addq	%rax, %r13
	addq	%rax, %r15
	cmpq	$105, %rcx
	jne	.LBB1_6
# %bb.11:                               #   in Loop: Header=BB1_5 Depth=1
	movq	(%rsp), %rcx                    # 8-byte Reload
	incq	%rcx
	movq	64(%rsp), %r14                  # 8-byte Reload
	addq	$44100, %r14                    # imm = 0xAC44
	movl	$40000, %eax                    # imm = 0x9C40
	movq	72(%rsp), %r13                  # 8-byte Reload
	addq	%rax, %r13
	movq	80(%rsp), %r15                  # 8-byte Reload
	addq	%rax, %r15
	movq	%rcx, %rax
	movq	%rcx, (%rsp)                    # 8-byte Spill
	cmpq	$25, %rcx
	jne	.LBB1_5
# %bb.12:
	callq	clock
	movq	%rax, %r12
	subq	56(%rsp), %rax                  # 8-byte Folded Reload
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI1_0(%rip), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	leaq	24(%rsp), %rdi
	movl	$1102500, %esi                  # imm = 0x10D2A4
	callq	hipMalloc
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_13
# %bb.14:
	leaq	8(%rsp), %rdi
	movl	$800000, %esi                   # imm = 0xC3500
	callq	hipMalloc
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_15
# %bb.16:
	movq	8(%rsp), %rdi
	movl	$1, %ebp
	movl	$800000, %edx                   # imm = 0xC3500
	movq	40(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_17
# %bb.18:
	movq	24(%rsp), %rdi
	movl	$1102500, %edx                  # imm = 0x10D2A4
	movq	32(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_19
# %bb.20:
	movabsq	$55834574861, %rdi              # imm = 0xD0000000D
	movabsq	$34359738376, %rdx              # imm = 0x800000008
	movl	$3, %esi
	movl	$8, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_22
# %bb.21:
	movq	8(%rsp), %rdi
	movq	24(%rsp), %rsi
	callq	_Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki
.LBB1_22:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_23
# %bb.24:
	movq	8(%rsp), %rsi
	movl	$800000, %edx                   # imm = 0xC3500
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_25
# %bb.26:
	callq	clock
	movq	%rax, (%rsp)                    # 8-byte Spill
	subq	%r12, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI1_0(%rip), %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	movq	%rbx, %rsi
.LBB1_27:                               # %.preheader210
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_28 Depth 2
                                        #       Child Loop BB1_29 Depth 3
                                        #         Child Loop BB1_30 Depth 4
                                        #           Child Loop BB1_31 Depth 5
                                        #             Child Loop BB1_32 Depth 6
	imulq	$40000, %rax, %rdx              # imm = 0x9C40
	addq	48(%rsp), %rdx                  # 8-byte Folded Reload
	movq	%rsi, 16(%rsp)                  # 8-byte Spill
	xorl	%edi, %edi
.LBB1_28:                               # %.preheader209
                                        #   Parent Loop BB1_27 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_29 Depth 3
                                        #         Child Loop BB1_30 Depth 4
                                        #           Child Loop BB1_31 Depth 5
                                        #             Child Loop BB1_32 Depth 6
	imulq	$400, %rdi, %r8                 # imm = 0x190
	addq	%rdx, %r8
	movq	%rsi, %r9
	xorl	%r10d, %r10d
.LBB1_29:                               #   Parent Loop BB1_27 Depth=1
                                        #     Parent Loop BB1_28 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB1_30 Depth 4
                                        #           Child Loop BB1_31 Depth 5
                                        #             Child Loop BB1_32 Depth 6
	leaq	(%r8,%r10,4), %r11
	movl	(%r11), %ebp
	movq	%r9, %r14
	xorl	%r15d, %r15d
.LBB1_30:                               # %.preheader208
                                        #   Parent Loop BB1_27 Depth=1
                                        #     Parent Loop BB1_28 Depth=2
                                        #       Parent Loop BB1_29 Depth=3
                                        # =>      This Loop Header: Depth=4
                                        #           Child Loop BB1_31 Depth 5
                                        #             Child Loop BB1_32 Depth 6
	movq	%r14, %r12
	xorl	%r13d, %r13d
.LBB1_31:                               # %.preheader207
                                        #   Parent Loop BB1_27 Depth=1
                                        #     Parent Loop BB1_28 Depth=2
                                        #       Parent Loop BB1_29 Depth=3
                                        #         Parent Loop BB1_30 Depth=4
                                        # =>        This Loop Header: Depth=5
                                        #             Child Loop BB1_32 Depth 6
	xorl	%ebx, %ebx
.LBB1_32:                               #   Parent Loop BB1_27 Depth=1
                                        #     Parent Loop BB1_28 Depth=2
                                        #       Parent Loop BB1_29 Depth=3
                                        #         Parent Loop BB1_30 Depth=4
                                        #           Parent Loop BB1_31 Depth=5
                                        # =>          This Inner Loop Header: Depth=6
	movl	%ebp, %ecx
	movl	(%r12,%rbx,4), %ebp
	cmpl	%ebp, %ecx
	cmovll	%ecx, %ebp
	incq	%rbx
	cmpq	$6, %rbx
	jne	.LBB1_32
# %bb.33:                               #   in Loop: Header=BB1_31 Depth=5
	incq	%r13
	addq	$420, %r12                      # imm = 0x1A4
	cmpq	$6, %r13
	jne	.LBB1_31
# %bb.34:                               #   in Loop: Header=BB1_30 Depth=4
	incq	%r15
	addq	$44100, %r14                    # imm = 0xAC44
	cmpq	$6, %r15
	jne	.LBB1_30
# %bb.35:                               #   in Loop: Header=BB1_29 Depth=3
	movl	%ebp, (%r11)
	incq	%r10
	addq	$4, %r9
	cmpq	$100, %r10
	jne	.LBB1_29
# %bb.36:                               #   in Loop: Header=BB1_28 Depth=2
	incq	%rdi
	addq	$420, %rsi                      # imm = 0x1A4
	cmpq	$100, %rdi
	jne	.LBB1_28
# %bb.37:                               #   in Loop: Header=BB1_27 Depth=1
	incq	%rax
	movq	16(%rsp), %rsi                  # 8-byte Reload
	addq	$44100, %rsi                    # imm = 0xAC44
	cmpq	$20, %rax
	jne	.LBB1_27
# %bb.38:
	callq	clock
	subq	(%rsp), %rax                    # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI1_0(%rip), %xmm0
	movl	$.L.str.12, %edi
	movb	$1, %al
	callq	printf
	xorl	%esi, %esi
	movl	$400, %eax                      # imm = 0x190
	movl	$40000, %edi                    # imm = 0x9C40
	movq	40(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %r10
	movq	48(%rsp), %r15                  # 8-byte Reload
.LBB1_39:                               # %.preheader206
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_40 Depth 2
                                        #       Child Loop BB1_41 Depth 3
	movq	%r10, %r11
	movq	%r15, %rbx
	xorl	%edx, %edx
.LBB1_40:                               # %.preheader
                                        #   Parent Loop BB1_39 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_41 Depth 3
	xorl	%ecx, %ecx
.LBB1_41:                               #   Parent Loop BB1_39 Depth=1
                                        #     Parent Loop BB1_40 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	(%rbx,%rcx,4), %r8d
	movl	(%r11,%rcx,4), %r9d
	cmpl	%r9d, %r8d
	jne	.LBB1_42
# %bb.43:                               #   in Loop: Header=BB1_41 Depth=3
	incq	%rcx
	cmpq	$100, %rcx
	jne	.LBB1_41
# %bb.44:                               #   in Loop: Header=BB1_40 Depth=2
	incq	%rdx
	addq	%rax, %rbx
	addq	%rax, %r11
	cmpq	$100, %rdx
	jne	.LBB1_40
# %bb.45:                               #   in Loop: Header=BB1_39 Depth=1
	incq	%rsi
	addq	%rdi, %r15
	addq	%rdi, %r10
	cmpq	$20, %rsi
	jne	.LBB1_39
# %bb.46:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	24(%rsp), %rdi
	callq	hipFree
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_47
# %bb.48:
	movq	8(%rsp), %rdi
	callq	hipFree
	callq	hipGetLastError
	xorl	%ebp, %ebp
	testl	%eax, %eax
	je	.LBB1_53
# %bb.49:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.15, %edx
	movl	$.L.str.4, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rcx
	movl	$159, %r9d
	jmp	.LBB1_50
.LBB1_42:
	movl	$.L.str.13, %edi
                                        # kill: def $esi killed $esi killed $rsi
                                        # kill: def $edx killed $edx killed $rdx
                                        # kill: def $ecx killed $ecx killed $rcx
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_52
.LBB1_1:
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$13, %esi
	jmp	.LBB1_51
.LBB1_13:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %edx
	movl	$.L.str.4, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rcx
	movl	$113, %r9d
	jmp	.LBB1_50
.LBB1_15:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.6, %edx
	movl	$.L.str.4, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rcx
	movl	$115, %r9d
	jmp	.LBB1_50
.LBB1_17:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.7, %edx
	movl	$.L.str.4, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rcx
	movl	$118, %r9d
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rcx
	movl	$.L.str.5, %edi
	movl	$22, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB1_53
.LBB1_19:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.8, %edx
	movl	$.L.str.4, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rcx
	movl	$120, %r9d
	jmp	.LBB1_50
.LBB1_23:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.9, %edx
	movl	$.L.str.4, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rcx
	movl	$123, %r9d
	jmp	.LBB1_50
.LBB1_25:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.10, %edx
	movl	$.L.str.4, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rcx
	movl	$127, %r9d
.LBB1_50:
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rcx
	movl	$.L.str.5, %edi
	movl	$22, %esi
.LBB1_51:
	movl	$1, %edx
	callq	fwrite@PLT
.LBB1_52:
	movl	$1, %ebp
.LBB1_53:
	movl	%ebp, %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
.LBB1_47:
	.cfi_def_cfa_offset 144
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movl	$.L.str.15, %edx
	movl	$.L.str.4, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rcx
	movl	$157, %r9d
	jmp	.LBB1_50
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7cmp_winPA100_A100_iPA105_A105_Ki, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB3_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z7cmp_winPA100_A100_iPA105_A105_Ki,@object # @_Z7cmp_winPA100_A100_iPA105_A105_Ki
	.section	.rodata,"a",@progbits
	.globl	_Z7cmp_winPA100_A100_iPA105_A105_Ki
	.p2align	3, 0x0
_Z7cmp_winPA100_A100_iPA105_A105_Ki:
	.quad	_Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki
	.size	_Z7cmp_winPA100_A100_iPA105_A105_Ki, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"malloc Fail \n"
	.size	.L.str, 14

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Init took %3.2f seconds.  Begin compute\n"
	.size	.L.str.1, 41

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Fatal error: %s (%s at %s:%d)\n"
	.size	.L.str.2, 31

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Failed to allocate device buffer"
	.size	.L.str.3, 33

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/issamsaid/cuda-quickies/master/max_filter/main.hip"
	.size	.L.str.4, 113

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"*** FAILED - ABORTING\n"
	.size	.L.str.5, 23

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Failed to allocate device buffer2"
	.size	.L.str.6, 34

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"CUDA memcpy failure"
	.size	.L.str.7, 20

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"CUDA memcpy2 failure"
	.size	.L.str.8, 21

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Kernel launch failure"
	.size	.L.str.9, 22

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"CUDA memcpy3 failure"
	.size	.L.str.10, 21

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	" Device compute took %3.2f seconds.  Beginning host compute.\n"
	.size	.L.str.11, 62

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	" Host compute took %3.2f seconds.  Comparing results.\n"
	.size	.L.str.12, 55

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Mismatch at x= %d, y= %d, z= %d  Host= %d, Device = %d\n"
	.size	.L.str.13, 56

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"hipFree fail"
	.size	.L.str.15, 13

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7cmp_winPA100_A100_iPA105_A105_Ki"
	.size	.L__unnamed_1, 36

	.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	"Results match!"
	.size	.Lstr, 15

	.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 _Z22__device_stub__cmp_winPA100_A100_iPA105_A105_Ki
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z7cmp_winPA100_A100_iPA105_A105_Ki
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7cmp_winPA100_A100_iPA105_A105_Ki ; -- Begin function _Z7cmp_winPA100_A100_iPA105_A105_Ki
	.globl	_Z7cmp_winPA100_A100_iPA105_A105_Ki
	.p2align	8
	.type	_Z7cmp_winPA100_A100_iPA105_A105_Ki,@function
_Z7cmp_winPA100_A100_iPA105_A105_Ki:    ; @_Z7cmp_winPA100_A100_iPA105_A105_Ki
; %bb.0:
	s_clause 0x1
	s_load_b64 s[2:3], s[0:1], 0x1c
	s_load_b128 s[8:11], s[0:1], 0x0
	v_and_b32_e32 v6, 0x3ff, v0
	v_bfe_u32 v9, v0, 10, 10
	v_bfe_u32 v10, v0, 20, 10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_u32_u24_e32 v12, 52, v9
	v_mul_u32_u24_e32 v13, 0x2a4, v10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s0, s2, 16
	s_and_b32 s1, s2, 0xffff
	v_mad_u64_u32 v[2:3], null, s14, s0, v[9:10]
	v_mad_u64_u32 v[0:1], null, s13, s1, v[6:7]
	s_and_b32 s0, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mad_u64_u32 v[3:4], null, s15, s0, v[10:11]
	v_lshlrev_b32_e32 v11, 2, v6
	v_max_i32_e32 v14, v0, v2
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_gt_i32_e32 vcc_lo, 25, v3
	v_cmp_gt_i32_e64 s0, 0x69, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s0, vcc_lo
	s_and_saveexec_b32 s6, s0
	s_cbranch_execz .LBB0_17
; %bb.1:
	v_mad_i64_i32 v[4:5], null, 0xac44, v3, s[10:11]
	v_lshlrev_b64 v[7:8], 2, v[0:1]
	v_cmp_lt_u32_e64 s0, 2, v10
	v_add3_u32 v10, v13, v12, v11
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_i64_i32 v[15:16], null, 0x1a4, v2, v[4:5]
	v_add_co_u32 v4, vcc_lo, v15, v7
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, v16, v8, vcc_lo
	v_cmp_gt_i32_e32 vcc_lo, 20, v3
	global_load_b32 v15, v[4:5], off
	s_and_b32 s1, s0, vcc_lo
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v15
	s_and_saveexec_b32 s2, s1
	s_cbranch_execz .LBB0_3
; %bb.2:
	v_mad_i64_i32 v[15:16], null, 0xac44, v3, s[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_i64_i32 v[17:18], null, 0x1a4, v2, v[15:16]
	v_add_co_u32 v15, s1, v17, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e64 v16, s1, v18, v8, s1
	v_add_co_u32 v15, s1, 0x35000, v15
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v16, s1, 0, v16, s1
	global_load_b32 v15, v[15:16], off offset:3412
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v15 offset:3380
.LBB0_3:
	s_or_b32 exec_lo, exec_lo, s2
	v_cmp_lt_u32_e64 s2, 2, v9
	v_cmp_gt_i32_e64 s1, 0x64, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s4, s2, s1
	s_and_saveexec_b32 s3, s4
	s_cbranch_execz .LBB0_5
; %bb.4:
	global_load_b32 v9, v[4:5], off offset:2100
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v9 offset:260
.LBB0_5:
	s_or_b32 exec_lo, exec_lo, s3
	v_cmp_lt_u32_e64 s4, 2, v6
	v_cmp_gt_i32_e64 s3, 0x64, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s7, s4, s3
	s_and_saveexec_b32 s5, s7
	s_cbranch_execz .LBB0_7
; %bb.6:
	global_load_b32 v6, v[4:5], off offset:20
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v6 offset:20
.LBB0_7:
	s_or_b32 exec_lo, exec_lo, s5
	s_and_saveexec_b32 s7, s0
	s_cbranch_execz .LBB0_12
; %bb.8:
	s_and_b32 s5, s2, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s5, s1, s5
	s_and_saveexec_b32 s12, s5
	s_cbranch_execz .LBB0_10
; %bb.9:
	v_mad_i64_i32 v[15:16], null, 0xac44, v3, s[10:11]
	v_add_nc_u32_e32 v6, 5, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_i64_i32 v[17:18], null, 0x1a4, v6, v[15:16]
	v_add_co_u32 v6, s5, v17, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e64 v7, s5, v18, v8, s5
	v_add_co_u32 v6, s5, 0x35000, v6
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s5, 0, v7, s5
	global_load_b32 v6, v[6:7], off offset:3412
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v6 offset:3640
.LBB0_10:
	s_or_b32 exec_lo, exec_lo, s12
	s_and_b32 s5, s4, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s5, s3, s5
	s_and_b32 exec_lo, exec_lo, s5
	s_cbranch_execz .LBB0_12
; %bb.11:
	v_mad_i64_i32 v[6:7], null, 0xac44, v3, s[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_i64_i32 v[8:9], null, 0x1a4, v2, v[6:7]
	v_lshlrev_b64 v[6:7], 2, v[0:1]
	v_add_co_u32 v6, s5, v8, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e64 v7, s5, v9, v7, s5
	v_add_co_u32 v6, s5, 0x35000, v6
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s5, 0, v7, s5
	global_load_b32 v6, v[6:7], off offset:3432
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v6 offset:3400
.LBB0_12:                               ; %Flow142
	s_or_b32 exec_lo, exec_lo, s7
	s_and_b32 s5, s4, s1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s5, s3, s5
	s_and_b32 s7, s2, s5
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s5, s7
	s_cbranch_execz .LBB0_14
; %bb.13:
	global_load_b32 v4, v[4:5], off offset:2120
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v4 offset:280
.LBB0_14:
	s_or_b32 exec_lo, exec_lo, s5
	s_and_b32 s0, s0, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB0_17
; %bb.15:
	s_and_b32 s0, s4, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s1, s0
	s_and_b32 s0, s3, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB0_17
; %bb.16:
	v_mad_i64_i32 v[4:5], null, 0xac44, v3, s[10:11]
	v_add_nc_u32_e32 v8, 5, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_i64_i32 v[6:7], null, 0x1a4, v8, v[4:5]
	v_lshlrev_b64 v[4:5], 2, v[0:1]
	v_add_co_u32 v4, vcc_lo, v6, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, v7, v5, vcc_lo
	v_add_co_u32 v4, vcc_lo, 0x35000, v4
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
	global_load_b32 v4, v[4:5], off offset:3432
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v4 offset:3660
.LBB0_17:                               ; %Flow143
	s_or_b32 exec_lo, exec_lo, s6
	v_cmp_gt_i32_e32 vcc_lo, 0x64, v14
	v_cmp_gt_i32_e64 s0, 20, v3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_25
; %bb.18:
	v_mad_i64_i32 v[4:5], null, 0x9c40, v3, s[8:9]
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add3_u32 v3, v13, v12, v11
	s_mov_b32 s0, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_i64_i32 v[6:7], null, 0x190, v2, v[4:5]
	v_add_co_u32 v0, vcc_lo, v6, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, v7, v1, vcc_lo
	global_load_b32 v2, v[0:1], off
.LBB0_19:                               ; %.preheader117
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_20 Depth 2
                                        ;       Child Loop BB0_21 Depth 3
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v4, v3
	s_mov_b32 s1, 0
.LBB0_20:                               ; %.preheader
                                        ;   Parent Loop BB0_19 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_21 Depth 3
	s_mov_b32 s2, 0
.LBB0_21:                               ;   Parent Loop BB0_19 Depth=1
                                        ;     Parent Loop BB0_20 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v5, s2, v4
	s_add_i32 s2, s2, 4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lg_u32 s2, 24
	ds_load_b32 v5, v5
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_min_i32_e32 v2, v5, v2
	s_cbranch_scc1 .LBB0_21
; %bb.22:                               ;   in Loop: Header=BB0_20 Depth=2
	v_add_nc_u32_e32 v4, 52, v4
	s_add_i32 s1, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lg_u32 s1, 6
	s_cbranch_scc1 .LBB0_20
; %bb.23:                               ;   in Loop: Header=BB0_19 Depth=1
	v_add_nc_u32_e32 v3, 0x2a4, v3
	s_add_i32 s0, s0, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lg_u32 s0, 6
	s_cbranch_scc1 .LBB0_19
; %bb.24:
	global_store_b32 v[0:1], v2, off
.LBB0_25:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7cmp_winPA100_A100_iPA105_A105_Ki
		.amdhsa_group_segment_fixed_size 8788
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 13
		.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 1
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 2
		.amdhsa_next_free_vgpr 19
		.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	_Z7cmp_winPA100_A100_iPA105_A105_Ki, .Lfunc_end0-_Z7cmp_winPA100_A100_iPA105_A105_Ki
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1168
; NumSgprs: 18
; NumVgprs: 19
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 8788 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 19
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 13
; 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: 1
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 2
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 8788
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7cmp_winPA100_A100_iPA105_A105_Ki
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7cmp_winPA100_A100_iPA105_A105_Ki.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     19
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
