#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#ifndef __CUDACC__
#define __CUDACC__
#endif
#include "device_functions.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define DEFAULT_THRESHOLD  8000

#define DEFAULT_FILENAME "BWstop-sign.ppm"
#define MASK_WIDTH 3
#define HALF_MASK_WIDTH (MASK_WIDTH/2)
#define TILE_WIDTH 16
#define INPUT_TILE_WIDTH (TILE_WIDTH+(2*HALF_MASK_WIDTH))

__constant__ int Mx[MASK_WIDTH*MASK_WIDTH];
__constant__ int My[MASK_WIDTH*MASK_WIDTH];

__global__ void filter(int* output, const unsigned int* const input, const int xsize, const int ysize, const int thresh)
{
	__shared__ int S[INPUT_TILE_WIDTH*INPUT_TILE_WIDTH];

	int2 global = make_int2(blockIdx.x*blockDim.x + threadIdx.x, blockIdx.y*blockDim.y + threadIdx.y);
	unsigned int t = global.y*xsize + global.x;
	int2 tile = make_int2(threadIdx.x + HALF_MASK_WIDTH, threadIdx.y + HALF_MASK_WIDTH);


	if (global.x >= xsize || global.y >= ysize)
	{
		return;
	}

	// Offset by half tile width in shared memory becuase of halo, px(0,0) stored at s[1,1]
	S[(tile.y)*INPUT_TILE_WIDTH + tile.x] = input[t];

	// Border threads fetch the halo or ghost pixels
	// Left halo
	if (threadIdx.x < HALF_MASK_WIDTH)
	{
		S[(tile.y)*INPUT_TILE_WIDTH + threadIdx.x] = global.x < HALF_MASK_WIDTH ? 0 : input[t - HALF_MASK_WIDTH];
		// Top Left corner
		if (threadIdx.y < HALF_MASK_WIDTH)
		{
			S[(threadIdx.y)*INPUT_TILE_WIDTH + threadIdx.x] =
				(global.y < HALF_MASK_WIDTH || global.x < HALF_MASK_WIDTH) ? 0 : input[t - HALF_MASK_WIDTH - xsize];
		}
	}

	// Top Halo
	if (threadIdx.y < HALF_MASK_WIDTH)
	{
		S[(threadIdx.y)*INPUT_TILE_WIDTH + tile.x] = global.y < HALF_MASK_WIDTH ? 0 : input[t - xsize];
		// Top Right corner
		if (threadIdx.x >= blockDim.x - HALF_MASK_WIDTH)
		{
			S[(threadIdx.y)*INPUT_TILE_WIDTH + tile.x + HALF_MASK_WIDTH]
				= global.y < HALF_MASK_WIDTH || global.x >= xsize - HALF_MASK_WIDTH ? 0 : input[t - xsize + HALF_MASK_WIDTH];
		}
	}

	// Right Halo
	if (threadIdx.x >= blockDim.x - HALF_MASK_WIDTH)
	{
		S[(tile.y)*INPUT_TILE_WIDTH + tile.x + HALF_MASK_WIDTH]
			= global.x >= xsize - HALF_MASK_WIDTH ? 0 : input[t + HALF_MASK_WIDTH];
		// Bottom Right Corner
		if (threadIdx.y >= blockDim.y - HALF_MASK_WIDTH)
		{
			S[(tile.y + HALF_MASK_WIDTH)*INPUT_TILE_WIDTH + tile.x + HALF_MASK_WIDTH]
				= global.x >= xsize - HALF_MASK_WIDTH || global.y >= ysize - HALF_MASK_WIDTH ? 0 : input[t + HALF_MASK_WIDTH + xsize];
		}
	}

	// Bottom Halo
	if (threadIdx.y >= blockDim.y - HALF_MASK_WIDTH)
	{
		S[(tile.y + HALF_MASK_WIDTH)*INPUT_TILE_WIDTH + tile.x]
			= global.y >= ysize - HALF_MASK_WIDTH ? 0 : input[t + xsize];
		// Bottom Left corner
		if (threadIdx.x < HALF_MASK_WIDTH)
		{
			S[(tile.y + HALF_MASK_WIDTH)*INPUT_TILE_WIDTH + threadIdx.x]
				= global.x < HALF_MASK_WIDTH || global.y >= ysize - HALF_MASK_WIDTH ? 0 : input[t + xsize - HALF_MASK_WIDTH];
		}
	}

	__syncthreads();

	// HALF_MASK_WIDTH border
	if (global.x < HALF_MASK_WIDTH || global.x >= xsize - HALF_MASK_WIDTH || global.y <HALF_MASK_WIDTH || global.y >= ysize - HALF_MASK_WIDTH)
	{
		return;
	}

	int px = 0;
	int py = 0;
	int start_x = tile.x - HALF_MASK_WIDTH;
	int start_y = tile.y - HALF_MASK_WIDTH;
	for (int r = 0; r < MASK_WIDTH; r++)
	{
		int row = start_y + r;
		for (int c = 0; c < MASK_WIDTH; c++)
		{
			int col = start_x + c;
			px += S[row*INPUT_TILE_WIDTH + col] * Mx[r*MASK_WIDTH + c];
			py += S[row*INPUT_TILE_WIDTH + col] * My[r*MASK_WIDTH + c];
		}
	}

	if ((px*px + py*py) > thresh)
	{
		output[t] = 255;
	}
	else
	{
		output[t] = 0;
	}
}

unsigned int *read_ppm( char *filename, int * xsize, int * ysize, int *maxval ){
  
	if ( !filename || filename[0] == '\0') {
		fprintf(stderr, "read_ppm but no file name\n");
		return NULL;  // fail
	}

	FILE *fp;

	fprintf(stderr, "read_ppm( %s )\n", filename);
	fp = fopen( filename, "rb");
	if (!fp) 
	{
		fprintf(stderr, "read_ppm()    ERROR  file '%s' cannot be opened for reading\n", filename);
		return NULL; // fail 
	}

	char chars[1024];
	//int num = read(fd, chars, 1000);
	int num = fread(chars, sizeof(char), 1000, fp);

	if (chars[0] != 'P' || chars[1] != '6') 
	{
		fprintf(stderr, "Texture::Texture()    ERROR  file '%s' does not start with \"P6\"  I am expecting a binary PPM file\n", filename);
		return NULL;
	}

	unsigned int width, height, maxvalue;


	char *ptr = chars+3; // P 6 newline
	if (*ptr == '#') // comment line! 
	{
		ptr = 1 + strstr(ptr, "\n");
	}

	num = sscanf(ptr, "%d\n%d\n%d",  &width, &height, &maxvalue);
	fprintf(stderr, "read %d things   width %d  height %d  maxval %d\n", num, width, height, maxvalue);  
	*xsize = width;
	*ysize = height;
	*maxval = maxvalue;
  
	unsigned int *pic = (unsigned int *)malloc( width * height * sizeof(unsigned int));
	if (!pic) {
		fprintf(stderr, "read_ppm()  unable to allocate %d x %d unsigned ints for the picture\n", width, height);
		return NULL; // fail but return
	}

	// allocate buffer to read the rest of the file into
	int bufsize =  3 * width * height * sizeof(unsigned char);
	if ((*maxval) > 255) bufsize *= 2;
	unsigned char *buf = (unsigned char *)malloc( bufsize );
	if (!buf) {
		fprintf(stderr, "read_ppm()  unable to allocate %d bytes of read buffer\n", bufsize);
		return NULL; // fail but return
	}

	// really read
	char duh[80];
	char *line = chars;

	// find the start of the pixel data. 
	sprintf(duh, "%d\0", *xsize);
	line = strstr(line, duh);
	//fprintf(stderr, "%s found at offset %d\n", duh, line-chars);
	line += strlen(duh) + 1;

	sprintf(duh, "%d\0", *ysize);
	line = strstr(line, duh);
	//fprintf(stderr, "%s found at offset %d\n", duh, line-chars);
	line += strlen(duh) + 1;

	sprintf(duh, "%d\0", *maxval);
	line = strstr(line, duh);
	
	fprintf(stderr, "%s found at offset %d\n", duh, line - chars);
	line += strlen(duh) + 1;

	long offset = line - chars;
	//lseek(fd, offset, SEEK_SET); // move to the correct offset
	fseek(fp, offset, SEEK_SET); // move to the correct offset
	//long numread = read(fd, buf, bufsize);
	long numread = fread(buf, sizeof(char), bufsize, fp);
	fprintf(stderr, "Texture %s   read %ld of %ld bytes\n", filename, numread, bufsize); 

	fclose(fp);
	
	int pixels = (*xsize) * (*ysize);
	for (int i=0; i<pixels; i++) 
		pic[i] = (int) buf[3*i];  // red channel
	
	return pic; // success
}

void write_ppm( char *filename, int xsize, int ysize, int maxval, int *pic) 
{
	FILE *fp;
	int x,y;
  
	fp = fopen(filename, "wb");
	if (!fp) 
	{
		fprintf(stderr, "FAILED TO OPEN FILE '%s' for writing\n", filename);
		exit(-1); 
	}
  
	fprintf(fp, "P6\n"); 
	fprintf(fp,"%d %d\n%d\n", xsize, ysize, maxval);
  
	int numpix = xsize * ysize;
	for (int i=0; i<numpix; i++) {
		unsigned char uc = (unsigned char) pic[i];
		fprintf(fp, "%c%c%c", uc, uc, uc); 
	}

	fclose(fp);
}

void compareImages(int* expected, int* actual, int xsize, int ysize)
{
	char* result = "PASSED";
	for(int i=0;i<ysize;i++)
	{
		for(int j=0; j<xsize;j++)
		{
			if(expected[i*xsize + j] !=actual[i*xsize+j])
			{
				printf("Mismatch at (%d, %d): Expected/Actual = %d/%d\n", i, j, expected[i*xsize + j], actual[i*xsize + j]);
				result = "FAILED";
			}
		}
	}
	printf("Test %s\n", result);
}

int main(int argc, char **argv)
{
	int thresh = DEFAULT_THRESHOLD;
	char *filename;
	filename = strdup(DEFAULT_FILENAME);

	if (argc > 1) {
		if (argc == 3) { // filename AND threshold
			filename = strdup(argv[1]);
			thresh = atoi(argv[2]);
		}
		if (argc == 2) { // default file but specified threshhold
			thresh = atoi(argv[1]);
		}
		fprintf(stderr, "file %s    threshold %d\n", filename, thresh);
	}

	int xsize, ysize, maxval;
	unsigned int *pic = read_ppm(filename, &xsize, &ysize, &maxval);

	printf("Compute Gold start\n");
	int numbytes = xsize * ysize * sizeof(int);
	int *result = (int *)malloc(numbytes);
	if (!result) {
		fprintf(stderr, "sobel() unable to malloc %d bytes\n", numbytes);
		exit(-1); // fail
	}

	int i, j, magnitude, sum1, sum2;

	for (int row = 0; row < ysize; row++) {
		for (int col = 0; col < xsize; col++) {
			result[row*xsize + col] = 0;
		}
	}

	for (i = 1; i < ysize - 1; i++) {
		for (j = 1; j < xsize - 1; j++) {

			int offset = i*xsize + j;

			sum1 = pic[xsize * (i - 1) + j + 1] - pic[xsize*(i - 1) + j - 1]
				+ 2 * pic[xsize * (i)+j + 1] - 2 * pic[xsize*(i)+j - 1]
				+ pic[xsize * (i + 1) + j + 1] - pic[xsize*(i + 1) + j - 1];

			sum2 = pic[xsize * (i - 1) + j - 1] + 2 * pic[xsize * (i - 1) + j] + pic[xsize * (i - 1) + j + 1]
				- pic[xsize * (i + 1) + j - 1] - 2 * pic[xsize * (i + 1) + j] - pic[xsize * (i + 1) + j + 1];

			magnitude = sum1*sum1 + sum2*sum2;

			if (magnitude > thresh)
				result[offset] = 255;
			else
				result[offset] = 0;
		}
	}
	printf("Compute Gold Complete\n");
	write_ppm("result8000gold.ppm", xsize, ysize, 255, result);
	
	printf("Compute CUDA start\n");
	
	int h_Mx[MASK_WIDTH*MASK_WIDTH] =
	{	
		-1,  0,  1,
		-2,  0,  2,
		-1,  0,  1 
	};
	int h_My[MASK_WIDTH*MASK_WIDTH] =
	{ 
		-1, -2, -1,
		0,  0,  0,
		1,  2,  1
	};
	/*int h_Mx[MASK_WIDTH*MASK_WIDTH] =
	{
		-2,  -1,  0,  1,  2,
		-3,  -2,  0,  2,  3,
		-4,  -3,  0,  3,  4,
		-3,  -2,  0,  2,  3,
		-2,  -1,  0,  1,  2,
	};
	int h_My[MASK_WIDTH*MASK_WIDTH] =
	{
		-2, -3, -4, -3, -2,
		-1, -2, -3, -2, -1,
		 0,  0,  0,  0,  0,
		 1,  2,  3,  2,  1,
		 2,  3,  4,  3,  2
	};*/
	cudaMemcpyToSymbol(Mx, h_Mx, MASK_WIDTH*MASK_WIDTH * sizeof(int));
	cudaMemcpyToSymbol(My, h_My, MASK_WIDTH *MASK_WIDTH * sizeof(int));
	int channelBytes = xsize*ysize * sizeof(int);
	unsigned int *d_pic;
	int* h_result, *d_result;
	h_result = (int*)malloc(channelBytes);
	cudaMalloc(&d_pic, xsize*ysize * sizeof(unsigned int));
	cudaMalloc(&d_result, channelBytes);
	cudaMemcpy(d_pic, pic, xsize*ysize * sizeof(unsigned int), cudaMemcpyHostToDevice);
	dim3 blockSize(TILE_WIDTH, TILE_WIDTH);
	dim3 gridSize((int)ceil((float)xsize / blockSize.x), (int)ceil((float)ysize / blockSize.y), 1);
	filter<<<gridSize, blockSize>>>(d_result, d_pic, xsize, ysize, thresh);	
	cudaMemcpy(h_result, d_result, channelBytes, cudaMemcpyDeviceToHost);
	cudaDeviceSynchronize();	
	printf("Compute CUDA Complete\n");

	write_ppm("result_cuda.ppm", xsize, ysize, 255, h_result);
	compareImages(result, h_result, xsize, ysize);
	
	cudaFree(d_pic);
	cudaFree(d_result);
	free(pic);
	free(result);
	free(h_result);
	fprintf(stderr, "sobel done\n");
}


	.file	"tmpxft_0025fe38_00000000-6_sobel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"read_ppm but no file name\n"
.LC3:
	.string	"read_ppm( %s )\n"
.LC4:
	.string	"rb"
.LC5:
	.string	"read_ppm()    ERROR  file '%s' cannot be opened for reading\n"
.LC6:
	.string	"Texture::Texture()    ERROR  file '%s' does not start with \"P6\"  I am expecting a binary PPM file\n"
.LC7:
	.string	"%d\n%d\n%d"
.LC8:
	.string	"read %d things   width %d  height %d  maxval %d\n"
.LC9:
	.string	"read_ppm()  unable to allocate %d x %d unsigned ints for the picture\n"
.LC10:
	.string	"read_ppm()  unable to allocate %d bytes of read buffer\n"
	.section	.rodata
.LC11:
	.string	"%d"
	.string	""
	.section	.rodata.str1.1
.LC12:
	.string	"%s found at offset %d\n"
.LC13:
	.string	"Texture %s   read %ld of %ld bytes\n"
	.text
	.globl	_Z8read_ppmPcPiS0_S0_
	.type	_Z8read_ppmPcPiS0_S0_, @function
_Z8read_ppmPcPiS0_S0_:
.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	$1208, %rsp
	.cfi_def_cfa_offset 1264
	movq	%rdi, 16(%rsp)
	movq	stderr(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 1192(%rsp)
	xorl	%eax, %eax
	cmpq	$0, 16(%rsp)
	je	.L3
	movq	16(%rsp), %rax
	cmpb	$0, (%rax)
	jne	.L4
.L3:
	leaq	.LC2(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L5
.L4:
	movq	%rcx, %r14
	movq	16(%rsp), %rcx
	movq	%rsi, %r13
	movq	%rdx, %r12
	movl	$2, %esi
	leaq	.LC3(%rip), %rdx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	16(%rsp), %rdi
	leaq	.LC4(%rip), %rsi
	call	fopen@PLT
	movq	%rax, 24(%rsp)
	testq	%rax, %rax
	jne	.L6
	movq	16(%rsp), %rcx
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC5(%rip), %rdx
.L22:
	call	__fprintf_chk@PLT
.L5:
	xorl	%ebx, %ebx
	jmp	.L2
.L6:
	movq	24(%rsp), %r8
	movl	$1000, %ecx
	movl	$1, %edx
	leaq	168(%rsp), %rdi
	movl	$1024, %esi
	call	__fread_chk@PLT
	cmpb	$80, 168(%rsp)
	jne	.L8
	cmpb	$54, 169(%rsp)
	je	.L9
.L8:
	movq	16(%rsp), %rcx
	movq	stderr(%rip), %rdi
	leaq	.LC6(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	jmp	.L22
.L9:
	cmpb	$35, 171(%rsp)
	leaq	171(%rsp), %rdi
	jne	.L10
	movl	$10, %esi
	call	strchr@PLT
	leaq	1(%rax), %rdi
.L10:
	leaq	80(%rsp), %rcx
	leaq	76(%rsp), %rdx
	xorl	%eax, %eax
	leaq	84(%rsp), %r8
	leaq	.LC7(%rip), %rsi
	call	__isoc23_sscanf@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC8(%rip), %rdx
	movl	%eax, %ecx
	pushq	%rax
	.cfi_def_cfa_offset 1272
	movl	92(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 1280
	movl	96(%rsp), %r9d
	xorl	%eax, %eax
	movl	92(%rsp), %r8d
	call	__fprintf_chk@PLT
	movl	92(%rsp), %ebp
	movl	96(%rsp), %r8d
	movl	100(%rsp), %eax
	movl	%ebp, %r15d
	movl	%ebp, 0(%r13)
	imull	%r8d, %r15d
	movl	%r8d, (%r12)
	movl	%eax, (%r14)
	movl	%r8d, 24(%rsp)
	movl	%r15d, %edi
	salq	$2, %rdi
	call	malloc@PLT
	popq	%rdx
	.cfi_def_cfa_offset 1272
	popq	%rcx
	.cfi_def_cfa_offset 1264
	testq	%rax, %rax
	movl	8(%rsp), %r8d
	movq	%rax, %rbx
	jne	.L11
	movq	stderr(%rip), %rdi
	movl	%ebp, %ecx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC9(%rip), %rdx
	call	__fprintf_chk@PLT
	jmp	.L5
.L11:
	cmpl	$255, (%r14)
	leal	(%r15,%r15,2), %r9d
	jle	.L12
	addl	%r9d, %r9d
.L12:
	movslq	%r9d, %rax
	movl	%r9d, 8(%rsp)
	movq	%rax, %rdi
	movq	%rax, 32(%rsp)
	call	malloc@PLT
	movl	8(%rsp), %r9d
	testq	%rax, %rax
	movq	%rax, %rbp
	jne	.L13
	movq	stderr(%rip), %rdi
	movl	%r9d, %ecx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC10(%rip), %rdx
	call	__fprintf_chk@PLT
	jmp	.L5
.L13:
	movl	0(%r13), %r8d
	leaq	88(%rsp), %rax
	movl	$80, %edx
	leaq	.LC11(%rip), %rcx
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movl	$2, %esi
	movl	%r9d, 60(%rsp)
	leaq	168(%rsp), %r15
	call	__sprintf_chk@PLT
	movq	8(%rsp), %rsi
	movq	%r15, %rdi
	call	strstr@PLT
	movq	8(%rsp), %rdi
	movq	%rax, 48(%rsp)
	call	strlen@PLT
	movl	(%r12), %r8d
	movq	8(%rsp), %rdi
	leaq	.LC11(%rip), %rcx
	movl	$80, %edx
	movq	%rax, 40(%rsp)
	movl	$2, %esi
	xorl	%eax, %eax
	call	__sprintf_chk@PLT
	movq	40(%rsp), %r10
	movq	48(%rsp), %r11
	movq	8(%rsp), %rsi
	leaq	1(%r11,%r10), %rdi
	call	strstr@PLT
	movq	8(%rsp), %rdi
	movq	%rax, 48(%rsp)
	call	strlen@PLT
	movl	(%r14), %r8d
	movq	8(%rsp), %rdi
	leaq	.LC11(%rip), %rcx
	movl	$80, %edx
	movq	%rax, 40(%rsp)
	movl	$2, %esi
	xorl	%eax, %eax
	call	__sprintf_chk@PLT
	movq	40(%rsp), %r10
	movq	48(%rsp), %r11
	movq	8(%rsp), %rsi
	leaq	1(%r11,%r10), %rdi
	call	strstr@PLT
	movq	8(%rsp), %rcx
	movl	$2, %esi
	movq	stderr(%rip), %rdi
	movq	%rax, %r8
	leaq	.LC12(%rip), %rdx
	movq	%rax, %r14
	xorl	%eax, %eax
	subq	%r15, %r8
	call	__fprintf_chk@PLT
	movq	8(%rsp), %rdi
	call	strlen@PLT
	movq	24(%rsp), %rdi
	xorl	%edx, %edx
	leaq	1(%r14,%rax), %rsi
	subq	%r15, %rsi
	call	fseek@PLT
	movq	32(%rsp), %rcx
	movq	24(%rsp), %r8
	movq	%rbp, %rdi
	movl	$1, %edx
	movq	%rcx, %rsi
	call	__fread_chk@PLT
	movl	60(%rsp), %r9d
	movq	16(%rsp), %rcx
	leaq	.LC13(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %r8
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	24(%rsp), %rdi
	call	fclose@PLT
	movl	0(%r13), %edx
	imull	(%r12), %edx
	xorl	%eax, %eax
.L14:
	cmpl	%eax, %edx
	jle	.L2
	leaq	(%rax,%rax,2), %rcx
	movzbl	0(%rbp,%rcx), %ecx
	movl	%ecx, (%rbx,%rax,4)
	incq	%rax
	jmp	.L14
.L2:
	movq	1192(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$1208, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z8read_ppmPcPiS0_S0_, .-_Z8read_ppmPcPiS0_S0_
	.section	.rodata.str1.1
.LC14:
	.string	"wb"
.LC15:
	.string	"FAILED TO OPEN FILE '%s' for writing\n"
.LC16:
	.string	"P6\n"
.LC17:
	.string	"%d %d\n%d\n"
.LC18:
	.string	"%c%c%c"
	.text
	.globl	_Z9write_ppmPciiiPi
	.type	_Z9write_ppmPciiiPi, @function
_Z9write_ppmPciiiPi:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%ecx, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%r8, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	leaq	.LC14(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%r9
	.cfi_def_cfa_offset 64
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L25
	movq	stderr(%rip), %rdi
	movq	%r14, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC15(%rip), %rdx
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L25:
	movq	%rax, %rdi
	movq	%rax, %rbx
	xorl	%eax, %eax
	movl	$2, %esi
	leaq	.LC16(%rip), %rdx
	leaq	.LC18(%rip), %r14
	call	__fprintf_chk@PLT
	movl	%r12d, %r8d
	movl	%ebp, %ecx
	movl	%r15d, %r9d
	movl	$2, %esi
	imull	%r12d, %ebp
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	.LC17(%rip), %rdx
	xorl	%r12d, %r12d
	call	__fprintf_chk@PLT
.L26:
	cmpl	%r12d, %ebp
	jle	.L29
	movzbl	0(%r13,%r12,4), %ecx
	movq	%r14, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	movq	%rbx, %rdi
	incq	%r12
	movl	%ecx, %r9d
	movl	%ecx, %r8d
	call	__fprintf_chk@PLT
	jmp	.L26
.L29:
	popq	%rax
	.cfi_def_cfa_offset 56
	movq	%rbx, %rdi
	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
	jmp	fclose@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z9write_ppmPciiiPi, .-_Z9write_ppmPciiiPi
	.section	.rodata.str1.1
.LC19:
	.string	"FAILED"
.LC20:
	.string	"PASSED"
.LC21:
	.string	"Mismatch at (%d, %d): Expected/Actual = %d/%d\n"
.LC22:
	.string	"Test %s\n"
	.text
	.globl	_Z13compareImagesPiS_ii
	.type	_Z13compareImagesPiS_ii, @function
_Z13compareImagesPiS_ii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r10d, %r10d
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	leaq	.LC20(%rip), %rdx
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	%ecx, (%rsp)
.L31:
	movl	(%rsp), %eax
	cmpl	%eax, %r10d
	jge	.L34
	movslq	%r15d, %rbp
	xorl	%ebx, %ebx
	salq	$2, %rbp
	leaq	(%r14,%rbp), %r11
	addq	%r13, %rbp
.L35:
	cmpl	%ebx, %r12d
	jle	.L37
	movl	(%r11,%rbx,4), %r8d
	movl	0(%rbp,%rbx,4), %r9d
	cmpl	%r9d, %r8d
	je	.L32
	movl	%r10d, %edx
	movl	%ebx, %ecx
	leaq	.LC21(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	movq	%r11, 8(%rsp)
	movl	%r10d, 4(%rsp)
	call	__printf_chk@PLT
	movq	8(%rsp), %r11
	movl	4(%rsp), %r10d
	leaq	.LC19(%rip), %rdx
.L32:
	incq	%rbx
	jmp	.L35
.L37:
	incl	%r10d
	addl	%r12d, %r15d
	jmp	.L31
.L34:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	leaq	.LC22(%rip), %rsi
	movl	$2, %edi
	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
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z13compareImagesPiS_ii, .-_Z13compareImagesPiS_ii
	.globl	_Z31__device_stub__Z6filterPiPKjiiiPiPKjiii
	.type	_Z31__device_stub__Z6filterPiPKjiiiPiPKjiii, @function
_Z31__device_stub__Z6filterPiPKjiiiPiPKjiii:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%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	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L38
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z6filterPiPKjiii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	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 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L38:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z31__device_stub__Z6filterPiPKjiiiPiPKjiii, .-_Z31__device_stub__Z6filterPiPKjiiiPiPKjiii
	.globl	_Z6filterPiPKjiii
	.type	_Z6filterPiPKjiii, @function
_Z6filterPiPKjiii:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z6filterPiPKjiiiPiPKjiii
	.cfi_endproc
.LFE2056:
	.size	_Z6filterPiPKjiii, .-_Z6filterPiPKjiii
	.section	.rodata.str1.1
.LC23:
	.string	"BWstop-sign.ppm"
.LC24:
	.string	"file %s    threshold %d\n"
.LC25:
	.string	"Compute Gold start\n"
.LC26:
	.string	"sobel() unable to malloc %d bytes\n"
.LC27:
	.string	"Compute Gold Complete\n"
.LC28:
	.string	"result8000gold.ppm"
.LC29:
	.string	"Compute CUDA start\n"
.LC31:
	.string	"Compute CUDA Complete\n"
.LC32:
	.string	"result_cuda.ppm"
.LC33:
	.string	"sobel done\n"
	.section	.rodata
	.align 32
.LC0:
	.long	-1
	.long	0
	.long	1
	.long	-2
	.long	0
	.long	2
	.long	-1
	.long	0
	.long	1
	.align 32
.LC1:
	.long	-1
	.long	-2
	.long	-1
	.long	0
	.long	0
	.long	0
	.long	1
	.long	2
	.long	1
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.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
	movl	%edi, %r13d
	leaq	.LC23(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	$8000, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$200, %rsp
	.cfi_def_cfa_offset 256
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	call	strdup@PLT
	movq	%rax, %rbx
	cmpl	$1, %r13d
	jle	.L44
	cmpl	$3, %r13d
	jne	.L45
	movq	8(%r12), %rdi
	call	strdup@PLT
	movq	16(%r12), %rdi
	movq	%rax, %rbx
	jmp	.L63
.L45:
	cmpl	$2, %r13d
	jne	.L46
	movq	8(%r12), %rdi
.L63:
	call	atoi@PLT
	movl	%eax, %ebp
.L46:
	movq	stderr(%rip), %rdi
	movl	%ebp, %r8d
	movq	%rbx, %rcx
	xorl	%eax, %eax
	leaq	.LC24(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
.L44:
	leaq	68(%rsp), %rcx
	leaq	64(%rsp), %rdx
	movq	%rbx, %rdi
	leaq	60(%rsp), %rsi
	call	_Z8read_ppmPcPiS0_S0_
	leaq	.LC25(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %r14
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	60(%rsp), %ebx
	movl	64(%rsp), %r13d
	movl	%ebx, %r15d
	imull	%r13d, %r15d
	movslq	%r15d, %rax
	sall	$2, %r15d
	movq	%rax, 24(%rsp)
	movslq	%r15d, %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	%rax, %r12
	testq	%rax, %rax
	je	.L47
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	jmp	.L48
.L47:
	movq	stderr(%rip), %rdi
	movl	%r15d, %ecx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC26(%rip), %rdx
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L64:
	incl	%ecx
	addl	%ebx, %edx
.L48:
	cmpl	%ecx, %r13d
	jle	.L60
	movslq	%edx, %rax
	leaq	(%r12,%rax,4), %rsi
	xorl	%eax, %eax
.L51:
	cmpl	%eax, %ebx
	jle	.L64
	xorl	%edi, %edi
	movl	%edi, (%rsi,%rax,4)
	incq	%rax
	jmp	.L51
.L60:
	leal	-1(%r13), %eax
	movl	%ebx, %r8d
	xorl	%r10d, %r10d
	movl	$1, %r11d
	movl	%eax, 40(%rsp)
	leal	-1(%rbx), %eax
	movl	%eax, 44(%rsp)
.L50:
	cmpl	%r11d, 40(%rsp)
	jle	.L54
	movslq	%r8d, %rax
	movslq	%r10d, %rdx
	addl	%ebx, %r8d
	movl	$1, %edi
	salq	$2, %rax
	leaq	(%r14,%rdx,4), %rsi
	movslq	%r8d, %rdx
	leaq	(%r14,%rax), %r9
	addq	%r12, %rax
	leaq	(%r14,%rdx,4), %rcx
	movq	%rax, 32(%rsp)
.L55:
	cmpl	%edi, 44(%rsp)
	jle	.L65
	movl	8(%rcx), %r15d
	movl	8(%rsi), %eax
	movl	8(%r9), %edx
	addl	%r15d, %eax
	leal	(%rax,%rdx,2), %eax
	movl	(%r9), %edx
	subl	(%rsi), %eax
	subl	(%rcx), %eax
	addl	%edx, %edx
	subl	%edx, %eax
	movl	8(%rsi), %edx
	addl	(%rsi), %edx
	movl	%eax, 16(%rsp)
	movl	4(%rsi), %eax
	leal	(%rdx,%rax,2), %edx
	movl	4(%rcx), %eax
	subl	(%rcx), %edx
	subl	%r15d, %edx
	leal	(%rax,%rax), %r15d
	movl	16(%rsp), %eax
	subl	%r15d, %edx
	imull	%edx, %edx
	imull	%eax, %eax
	addl	%edx, %eax
	movl	$255, %edx
	cmpl	%eax, %ebp
	movl	$0, %eax
	cmovl	%edx, %eax
	movq	32(%rsp), %rdx
	addq	$4, %rsi
	addq	$4, %r9
	addq	$4, %rcx
	movl	%eax, (%rdx,%rdi,4)
	incq	%rdi
	jmp	.L55
.L65:
	incl	%r11d
	addl	%ebx, %r10d
	jmp	.L50
.L54:
	leaq	.LC27(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r12, %r8
	movl	$255, %ecx
	movl	%r13d, %edx
	movl	%ebx, %esi
	leaq	.LC28(%rip), %rdi
	call	_Z9write_ppmPciiiPi
	leaq	.LC29(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	112(%rsp), %rdi
	movl	$9, %ecx
	leaq	.LC0(%rip), %rsi
	rep movsl
	leaq	148(%rsp), %rdi
	leaq	.LC1(%rip), %rsi
	movl	$9, %ecx
	rep movsl
	movl	$1, %r8d
	leaq	112(%rsp), %rsi
	movl	$36, %edx
	leaq	_ZL2Mx(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %r8d
	xorl	%ecx, %ecx
	leaq	148(%rsp), %rsi
	movl	$36, %edx
	leaq	_ZL2My(%rip), %rdi
	call	cudaMemcpyToSymbol@PLT
	movq	8(%rsp), %rdi
	call	malloc@PLT
	movq	24(%rsp), %rdx
	leaq	72(%rsp), %rdi
	movq	%rax, %r15
	salq	$2, %rdx
	movq	%rdx, %rsi
	movq	%rdx, 16(%rsp)
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdx
	movq	72(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	cvtsi2ssl	%r13d, %xmm0
	mulss	.LC30(%rip), %xmm0
	call	ceilf@PLT
	movss	%xmm0, 16(%rsp)
	cvtsi2ssl	%ebx, %xmm0
	mulss	.LC30(%rip), %xmm0
	call	ceilf@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	cvttss2sil	%xmm0, %eax
	movss	16(%rsp), %xmm1
	movl	$1, %esi
	movabsq	$68719476752, %rdx
	movl	%eax, 100(%rsp)
	cvttss2sil	%xmm1, %eax
	movl	%eax, 104(%rsp)
	movq	100(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L56
	movq	72(%rsp), %rsi
	movq	80(%rsp), %rdi
	movl	%ebp, %r8d
	movl	%r13d, %ecx
	movl	%ebx, %edx
	call	_Z31__device_stub__Z6filterPiPKjiiiPiPKjiii
.L56:
	movq	8(%rsp), %rdx
	movq	80(%rsp), %rsi
	movl	$2, %ecx
	movq	%r15, %rdi
	call	cudaMemcpy@PLT
	call	cudaDeviceSynchronize@PLT
	leaq	.LC31(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r15, %r8
	movl	$255, %ecx
	movl	%r13d, %edx
	movl	%ebx, %esi
	leaq	.LC32(%rip), %rdi
	call	_Z9write_ppmPciiiPi
	movl	%ebx, %edx
	movq	%r15, %rsi
	movl	%r13d, %ecx
	movq	%r12, %rdi
	call	_Z13compareImagesPiS_ii
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%r15, %rdi
	call	free@PLT
	movq	stderr(%rip), %rdi
	xorl	%eax, %eax
	leaq	.LC33(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L57
	call	__stack_chk_fail@PLT
.L57:
	addq	$200, %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
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC36:
	.string	"_Z6filterPiPKjiii"
.LC37:
	.string	"Mx"
.LC38:
	.string	"My"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC36(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z6filterPiPKjiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC37(%rip), %rdx
	movl	$36, %r9d
	leaq	_ZL2Mx(%rip), %rsi
	pushq	$1
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC38(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$36, %r9d
	leaq	_ZL2My(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2058:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZL2My
	.comm	_ZL2My,36,32
	.local	_ZL2Mx
	.comm	_ZL2Mx,36,32
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC30:
	.long	1031798784
	.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"

#ifndef __HIPCC__
#define __HIPCC__
#endif
#include "hip/device_functions.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define DEFAULT_THRESHOLD  8000

#define DEFAULT_FILENAME "BWstop-sign.ppm"
#define MASK_WIDTH 3
#define HALF_MASK_WIDTH (MASK_WIDTH/2)
#define TILE_WIDTH 16
#define INPUT_TILE_WIDTH (TILE_WIDTH+(2*HALF_MASK_WIDTH))

__constant__ int Mx[MASK_WIDTH*MASK_WIDTH];
__constant__ int My[MASK_WIDTH*MASK_WIDTH];

__global__ void filter(int* output, const unsigned int* const input, const int xsize, const int ysize, const int thresh)
{
	__shared__ int S[INPUT_TILE_WIDTH*INPUT_TILE_WIDTH];

	int2 global = make_int2(blockIdx.x*blockDim.x + threadIdx.x, blockIdx.y*blockDim.y + threadIdx.y);
	unsigned int t = global.y*xsize + global.x;
	int2 tile = make_int2(threadIdx.x + HALF_MASK_WIDTH, threadIdx.y + HALF_MASK_WIDTH);


	if (global.x >= xsize || global.y >= ysize)
	{
		return;
	}

	// Offset by half tile width in shared memory becuase of halo, px(0,0) stored at s[1,1]
	S[(tile.y)*INPUT_TILE_WIDTH + tile.x] = input[t];

	// Border threads fetch the halo or ghost pixels
	// Left halo
	if (threadIdx.x < HALF_MASK_WIDTH)
	{
		S[(tile.y)*INPUT_TILE_WIDTH + threadIdx.x] = global.x < HALF_MASK_WIDTH ? 0 : input[t - HALF_MASK_WIDTH];
		// Top Left corner
		if (threadIdx.y < HALF_MASK_WIDTH)
		{
			S[(threadIdx.y)*INPUT_TILE_WIDTH + threadIdx.x] =
				(global.y < HALF_MASK_WIDTH || global.x < HALF_MASK_WIDTH) ? 0 : input[t - HALF_MASK_WIDTH - xsize];
		}
	}

	// Top Halo
	if (threadIdx.y < HALF_MASK_WIDTH)
	{
		S[(threadIdx.y)*INPUT_TILE_WIDTH + tile.x] = global.y < HALF_MASK_WIDTH ? 0 : input[t - xsize];
		// Top Right corner
		if (threadIdx.x >= blockDim.x - HALF_MASK_WIDTH)
		{
			S[(threadIdx.y)*INPUT_TILE_WIDTH + tile.x + HALF_MASK_WIDTH]
				= global.y < HALF_MASK_WIDTH || global.x >= xsize - HALF_MASK_WIDTH ? 0 : input[t - xsize + HALF_MASK_WIDTH];
		}
	}

	// Right Halo
	if (threadIdx.x >= blockDim.x - HALF_MASK_WIDTH)
	{
		S[(tile.y)*INPUT_TILE_WIDTH + tile.x + HALF_MASK_WIDTH]
			= global.x >= xsize - HALF_MASK_WIDTH ? 0 : input[t + HALF_MASK_WIDTH];
		// Bottom Right Corner
		if (threadIdx.y >= blockDim.y - HALF_MASK_WIDTH)
		{
			S[(tile.y + HALF_MASK_WIDTH)*INPUT_TILE_WIDTH + tile.x + HALF_MASK_WIDTH]
				= global.x >= xsize - HALF_MASK_WIDTH || global.y >= ysize - HALF_MASK_WIDTH ? 0 : input[t + HALF_MASK_WIDTH + xsize];
		}
	}

	// Bottom Halo
	if (threadIdx.y >= blockDim.y - HALF_MASK_WIDTH)
	{
		S[(tile.y + HALF_MASK_WIDTH)*INPUT_TILE_WIDTH + tile.x]
			= global.y >= ysize - HALF_MASK_WIDTH ? 0 : input[t + xsize];
		// Bottom Left corner
		if (threadIdx.x < HALF_MASK_WIDTH)
		{
			S[(tile.y + HALF_MASK_WIDTH)*INPUT_TILE_WIDTH + threadIdx.x]
				= global.x < HALF_MASK_WIDTH || global.y >= ysize - HALF_MASK_WIDTH ? 0 : input[t + xsize - HALF_MASK_WIDTH];
		}
	}

	__syncthreads();

	// HALF_MASK_WIDTH border
	if (global.x < HALF_MASK_WIDTH || global.x >= xsize - HALF_MASK_WIDTH || global.y <HALF_MASK_WIDTH || global.y >= ysize - HALF_MASK_WIDTH)
	{
		return;
	}

	int px = 0;
	int py = 0;
	int start_x = tile.x - HALF_MASK_WIDTH;
	int start_y = tile.y - HALF_MASK_WIDTH;
	for (int r = 0; r < MASK_WIDTH; r++)
	{
		int row = start_y + r;
		for (int c = 0; c < MASK_WIDTH; c++)
		{
			int col = start_x + c;
			px += S[row*INPUT_TILE_WIDTH + col] * Mx[r*MASK_WIDTH + c];
			py += S[row*INPUT_TILE_WIDTH + col] * My[r*MASK_WIDTH + c];
		}
	}

	if ((px*px + py*py) > thresh)
	{
		output[t] = 255;
	}
	else
	{
		output[t] = 0;
	}
}

unsigned int *read_ppm( char *filename, int * xsize, int * ysize, int *maxval ){
  
	if ( !filename || filename[0] == '\0') {
		fprintf(stderr, "read_ppm but no file name\n");
		return NULL;  // fail
	}

	FILE *fp;

	fprintf(stderr, "read_ppm( %s )\n", filename);
	fp = fopen( filename, "rb");
	if (!fp) 
	{
		fprintf(stderr, "read_ppm()    ERROR  file '%s' cannot be opened for reading\n", filename);
		return NULL; // fail 
	}

	char chars[1024];
	//int num = read(fd, chars, 1000);
	int num = fread(chars, sizeof(char), 1000, fp);

	if (chars[0] != 'P' || chars[1] != '6') 
	{
		fprintf(stderr, "Texture::Texture()    ERROR  file '%s' does not start with \"P6\"  I am expecting a binary PPM file\n", filename);
		return NULL;
	}

	unsigned int width, height, maxvalue;


	char *ptr = chars+3; // P 6 newline
	if (*ptr == '#') // comment line! 
	{
		ptr = 1 + strstr(ptr, "\n");
	}

	num = sscanf(ptr, "%d\n%d\n%d",  &width, &height, &maxvalue);
	fprintf(stderr, "read %d things   width %d  height %d  maxval %d\n", num, width, height, maxvalue);  
	*xsize = width;
	*ysize = height;
	*maxval = maxvalue;
  
	unsigned int *pic = (unsigned int *)malloc( width * height * sizeof(unsigned int));
	if (!pic) {
		fprintf(stderr, "read_ppm()  unable to allocate %d x %d unsigned ints for the picture\n", width, height);
		return NULL; // fail but return
	}

	// allocate buffer to read the rest of the file into
	int bufsize =  3 * width * height * sizeof(unsigned char);
	if ((*maxval) > 255) bufsize *= 2;
	unsigned char *buf = (unsigned char *)malloc( bufsize );
	if (!buf) {
		fprintf(stderr, "read_ppm()  unable to allocate %d bytes of read buffer\n", bufsize);
		return NULL; // fail but return
	}

	// really read
	char duh[80];
	char *line = chars;

	// find the start of the pixel data. 
	sprintf(duh, "%d\0", *xsize);
	line = strstr(line, duh);
	//fprintf(stderr, "%s found at offset %d\n", duh, line-chars);
	line += strlen(duh) + 1;

	sprintf(duh, "%d\0", *ysize);
	line = strstr(line, duh);
	//fprintf(stderr, "%s found at offset %d\n", duh, line-chars);
	line += strlen(duh) + 1;

	sprintf(duh, "%d\0", *maxval);
	line = strstr(line, duh);
	
	fprintf(stderr, "%s found at offset %d\n", duh, line - chars);
	line += strlen(duh) + 1;

	long offset = line - chars;
	//lseek(fd, offset, SEEK_SET); // move to the correct offset
	fseek(fp, offset, SEEK_SET); // move to the correct offset
	//long numread = read(fd, buf, bufsize);
	long numread = fread(buf, sizeof(char), bufsize, fp);
	fprintf(stderr, "Texture %s   read %ld of %ld bytes\n", filename, numread, bufsize); 

	fclose(fp);
	
	int pixels = (*xsize) * (*ysize);
	for (int i=0; i<pixels; i++) 
		pic[i] = (int) buf[3*i];  // red channel
	
	return pic; // success
}

void write_ppm( char *filename, int xsize, int ysize, int maxval, int *pic) 
{
	FILE *fp;
	int x,y;
  
	fp = fopen(filename, "wb");
	if (!fp) 
	{
		fprintf(stderr, "FAILED TO OPEN FILE '%s' for writing\n", filename);
		exit(-1); 
	}
  
	fprintf(fp, "P6\n"); 
	fprintf(fp,"%d %d\n%d\n", xsize, ysize, maxval);
  
	int numpix = xsize * ysize;
	for (int i=0; i<numpix; i++) {
		unsigned char uc = (unsigned char) pic[i];
		fprintf(fp, "%c%c%c", uc, uc, uc); 
	}

	fclose(fp);
}

void compareImages(int* expected, int* actual, int xsize, int ysize)
{
	char* result = "PASSED";
	for(int i=0;i<ysize;i++)
	{
		for(int j=0; j<xsize;j++)
		{
			if(expected[i*xsize + j] !=actual[i*xsize+j])
			{
				printf("Mismatch at (%d, %d): Expected/Actual = %d/%d\n", i, j, expected[i*xsize + j], actual[i*xsize + j]);
				result = "FAILED";
			}
		}
	}
	printf("Test %s\n", result);
}

int main(int argc, char **argv)
{
	int thresh = DEFAULT_THRESHOLD;
	char *filename;
	filename = strdup(DEFAULT_FILENAME);

	if (argc > 1) {
		if (argc == 3) { // filename AND threshold
			filename = strdup(argv[1]);
			thresh = atoi(argv[2]);
		}
		if (argc == 2) { // default file but specified threshhold
			thresh = atoi(argv[1]);
		}
		fprintf(stderr, "file %s    threshold %d\n", filename, thresh);
	}

	int xsize, ysize, maxval;
	unsigned int *pic = read_ppm(filename, &xsize, &ysize, &maxval);

	printf("Compute Gold start\n");
	int numbytes = xsize * ysize * sizeof(int);
	int *result = (int *)malloc(numbytes);
	if (!result) {
		fprintf(stderr, "sobel() unable to malloc %d bytes\n", numbytes);
		exit(-1); // fail
	}

	int i, j, magnitude, sum1, sum2;

	for (int row = 0; row < ysize; row++) {
		for (int col = 0; col < xsize; col++) {
			result[row*xsize + col] = 0;
		}
	}

	for (i = 1; i < ysize - 1; i++) {
		for (j = 1; j < xsize - 1; j++) {

			int offset = i*xsize + j;

			sum1 = pic[xsize * (i - 1) + j + 1] - pic[xsize*(i - 1) + j - 1]
				+ 2 * pic[xsize * (i)+j + 1] - 2 * pic[xsize*(i)+j - 1]
				+ pic[xsize * (i + 1) + j + 1] - pic[xsize*(i + 1) + j - 1];

			sum2 = pic[xsize * (i - 1) + j - 1] + 2 * pic[xsize * (i - 1) + j] + pic[xsize * (i - 1) + j + 1]
				- pic[xsize * (i + 1) + j - 1] - 2 * pic[xsize * (i + 1) + j] - pic[xsize * (i + 1) + j + 1];

			magnitude = sum1*sum1 + sum2*sum2;

			if (magnitude > thresh)
				result[offset] = 255;
			else
				result[offset] = 0;
		}
	}
	printf("Compute Gold Complete\n");
	write_ppm("result8000gold.ppm", xsize, ysize, 255, result);
	
	printf("Compute CUDA start\n");
	
	int h_Mx[MASK_WIDTH*MASK_WIDTH] =
	{	
		-1,  0,  1,
		-2,  0,  2,
		-1,  0,  1 
	};
	int h_My[MASK_WIDTH*MASK_WIDTH] =
	{ 
		-1, -2, -1,
		0,  0,  0,
		1,  2,  1
	};
	/*int h_Mx[MASK_WIDTH*MASK_WIDTH] =
	{
		-2,  -1,  0,  1,  2,
		-3,  -2,  0,  2,  3,
		-4,  -3,  0,  3,  4,
		-3,  -2,  0,  2,  3,
		-2,  -1,  0,  1,  2,
	};
	int h_My[MASK_WIDTH*MASK_WIDTH] =
	{
		-2, -3, -4, -3, -2,
		-1, -2, -3, -2, -1,
		 0,  0,  0,  0,  0,
		 1,  2,  3,  2,  1,
		 2,  3,  4,  3,  2
	};*/
	hipMemcpyToSymbol(HIP_SYMBOL(Mx), h_Mx, MASK_WIDTH*MASK_WIDTH * sizeof(int));
	hipMemcpyToSymbol(HIP_SYMBOL(My), h_My, MASK_WIDTH *MASK_WIDTH * sizeof(int));
	int channelBytes = xsize*ysize * sizeof(int);
	unsigned int *d_pic;
	int* h_result, *d_result;
	h_result = (int*)malloc(channelBytes);
	hipMalloc(&d_pic, xsize*ysize * sizeof(unsigned int));
	hipMalloc(&d_result, channelBytes);
	hipMemcpy(d_pic, pic, xsize*ysize * sizeof(unsigned int), hipMemcpyHostToDevice);
	dim3 blockSize(TILE_WIDTH, TILE_WIDTH);
	dim3 gridSize((int)ceil((float)xsize / blockSize.x), (int)ceil((float)ysize / blockSize.y), 1);
	filter<<<gridSize, blockSize>>>(d_result, d_pic, xsize, ysize, thresh);	
	hipMemcpy(h_result, d_result, channelBytes, hipMemcpyDeviceToHost);
	hipDeviceSynchronize();	
	printf("Compute CUDA Complete\n");

	write_ppm("result_cuda.ppm", xsize, ysize, 255, h_result);
	compareImages(result, h_result, xsize, ysize);
	
	hipFree(d_pic);
	hipFree(d_result);
	free(pic);
	free(result);
	free(h_result);
	fprintf(stderr, "sobel done\n");
}


	.text
	.file	"sobel.hip"
	.globl	_Z21__device_stub__filterPiPKjiii # -- Begin function _Z21__device_stub__filterPiPKjiii
	.type	_Z21__device_stub__filterPiPKjiii,@function
_Z21__device_stub__filterPiPKjiii:      # @_Z21__device_stub__filterPiPKjiii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z6filterPiPKjiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z21__device_stub__filterPiPKjiii, .Lfunc_end0-_Z21__device_stub__filterPiPKjiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8read_ppmPcPiS0_S0_           # -- Begin function _Z8read_ppmPcPiS0_S0_
	.type	_Z8read_ppmPcPiS0_S0_,@function
_Z8read_ppmPcPiS0_S0_:                  # @_Z8read_ppmPcPiS0_S0_
	.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	$1160, %rsp                     # imm = 0x488
	.cfi_def_cfa_offset 1216
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	testq	%rdi, %rdi
	je	.LBB1_2
# %bb.1:
	movq	%rdi, %rbx
	cmpb	$0, (%rdi)
	jne	.LBB1_3
.LBB1_2:
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$26, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	xorl	%r12d, %r12d
.LBB1_18:
	movq	%r12, %rax
	addq	$1160, %rsp                     # imm = 0x488
	.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_3:
	.cfi_def_cfa_offset 1216
	movq	%rcx, %rbp
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	stderr(%rip), %rdi
	movl	$.L.str.1, %esi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.2, %esi
	movq	%rbx, %rdi
	callq	fopen
	testq	%rax, %rax
	jne	.LBB1_6
# %bb.4:
	movq	stderr(%rip), %rdi
	xorl	%r12d, %r12d
	movl	$.L.str.3, %esi
	jmp	.LBB1_5
.LBB1_6:
	movq	%rax, %r12
	leaq	128(%rsp), %r13
	movl	$1, %esi
	movl	$1000, %edx                     # imm = 0x3E8
	movq	%r13, %rdi
	movq	%rax, %rcx
	callq	fread
	cmpb	$80, (%r13)
	jne	.LBB1_8
# %bb.7:
	cmpb	$54, 129(%rsp)
	jne	.LBB1_8
# %bb.9:
	leaq	131(%rsp), %rdi
	cmpb	$35, (%rdi)
	movq	%r14, 8(%rsp)                   # 8-byte Spill
	movq	%r12, 32(%rsp)                  # 8-byte Spill
	jne	.LBB1_11
# %bb.10:
	movl	$10, %esi
	callq	strchr@PLT
	movq	%rax, %rdi
	incq	%rdi
.LBB1_11:
	leaq	44(%rsp), %r14
	leaq	40(%rsp), %r12
	leaq	20(%rsp), %r13
	movl	$.L.str.6, %esi
	movq	%r14, %rdx
	movq	%r12, %rcx
	movq	%r13, %r8
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movq	stderr(%rip), %rdi
	movl	(%r14), %ecx
	movl	(%r12), %r8d
	movl	(%r13), %r9d
	movl	$.L.str.7, %esi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
	movl	(%r14), %r13d
	movq	%r15, 24(%rsp)                  # 8-byte Spill
	movl	%r13d, (%r15)
	movl	(%r12), %r14d
	movq	8(%rsp), %rax                   # 8-byte Reload
	movl	%r14d, (%rax)
	leaq	20(%rsp), %rax
	movl	(%rax), %eax
	movl	%eax, (%rsp)                    # 4-byte Spill
	movl	%eax, (%rbp)
	movl	%r14d, %r15d
	imull	%r13d, %r15d
	leaq	(,%r15,4), %rdi
	callq	malloc
	testq	%rax, %rax
	jne	.LBB1_13
# %bb.12:
	movq	stderr(%rip), %rdi
	xorl	%r12d, %r12d
	movl	$.L.str.8, %esi
	movl	%r13d, %edx
	movl	%r14d, %ecx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_18
.LBB1_8:
	movq	stderr(%rip), %rdi
	xorl	%r12d, %r12d
	movl	$.L.str.4, %esi
.LBB1_5:
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_18
.LBB1_13:
	movq	%rax, %r12
	leal	(%r15,%r15,2), %r14d
	cmpl	$256, (%rsp)                    # 4-byte Folded Reload
                                        # imm = 0x100
	setge	%cl
	shll	%cl, %r14d
	movslq	%r14d, %r15
	movq	%r15, %rdi
	callq	malloc
	testq	%rax, %rax
	jne	.LBB1_15
# %bb.14:
	movq	stderr(%rip), %rdi
	xorl	%r12d, %r12d
	movl	$.L.str.9, %esi
	movl	%r14d, %edx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_18
.LBB1_15:
	movq	%rax, %r13
	movq	24(%rsp), %rax                  # 8-byte Reload
	movl	(%rax), %edx
	leaq	48(%rsp), %r14
	movl	$.L.str.10, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	sprintf
	movq	%r15, (%rsp)                    # 8-byte Spill
	leaq	128(%rsp), %rdi
	movq	%r14, %rsi
	movq	%r14, %r15
	callq	strstr
	movq	%rax, %r14
	movq	%r15, %rdi
	callq	strlen
	addq	%rax, %r14
	incq	%r14
	movq	8(%rsp), %rax                   # 8-byte Reload
	movl	(%rax), %edx
	movl	$.L.str.10, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	sprintf
	movq	%r14, %rdi
	movq	%r15, %rsi
	callq	strstr
	movq	%rax, %r14
	movq	%r15, %rdi
	callq	strlen
	addq	%rax, %r14
	incq	%r14
	movl	(%rbp), %edx
	movl	$.L.str.10, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	sprintf
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r15, %rbp
	callq	strstr
	movq	%rax, %r14
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	leaq	128(%rsp), %r15
	subq	%r15, %rcx
	movl	$.L.str.11, %esi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	%rbp, %rdi
	callq	strlen
	addq	%rax, %r14
	subq	%r15, %r14
	incq	%r14
	movq	32(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rdi
	movq	%r14, %rsi
	xorl	%edx, %edx
	callq	fseek
	movl	$1, %esi
	movq	%r13, %rdi
	movq	(%rsp), %r14                    # 8-byte Reload
	movq	%r14, %rdx
	movq	%rbp, %rcx
	callq	fread
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movq	%rbx, %rdx
	movq	%rax, %rcx
	movl	%r14d, %r8d
	xorl	%eax, %eax
	callq	fprintf
	movq	%rbp, %rdi
	callq	fclose
	movq	8(%rsp), %rax                   # 8-byte Reload
	movl	(%rax), %eax
	movq	24(%rsp), %rcx                  # 8-byte Reload
	imull	(%rcx), %eax
	testl	%eax, %eax
	jle	.LBB1_18
# %bb.16:                               # %.lr.ph.preheader
	movl	%eax, %eax
	xorl	%ecx, %ecx
.LBB1_17:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movzbl	(%r13), %edx
	movl	%edx, (%r12,%rcx,4)
	incq	%rcx
	addq	$3, %r13
	cmpq	%rcx, %rax
	jne	.LBB1_17
	jmp	.LBB1_18
.Lfunc_end1:
	.size	_Z8read_ppmPcPiS0_S0_, .Lfunc_end1-_Z8read_ppmPcPiS0_S0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9write_ppmPciiiPi             # -- Begin function _Z9write_ppmPciiiPi
	.type	_Z9write_ppmPciiiPi,@function
_Z9write_ppmPciiiPi:                    # @_Z9write_ppmPciiiPi
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%r8, %rbx
	movl	%ecx, %r12d
	movl	%edx, %ebp
	movl	%esi, %r15d
	movq	%rdi, %r13
	movl	$.L.str.13, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB2_5
# %bb.1:
	movq	%rax, %r14
	movl	$.L.str.15, %edi
	movl	$3, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fwrite@PLT
	movl	$.L.str.16, %esi
	movq	%r14, %rdi
	movl	%r15d, %edx
	movl	%ebp, %ecx
	movl	%r12d, %r8d
	xorl	%eax, %eax
	callq	fprintf
	imull	%r15d, %ebp
	testl	%ebp, %ebp
	jle	.LBB2_4
# %bb.2:                                # %.lr.ph.preheader
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
.LBB2_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movzbl	(%rbx,%r12,4), %ecx
	movl	$.L.str.17, %esi
	movq	%r14, %rdi
	movl	%ecx, %edx
	movl	%ecx, %r8d
	xorl	%eax, %eax
	callq	fprintf
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB2_3
.LBB2_4:                                # %._crit_edge
	movq	%r14, %rdi
	addq	$8, %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
	jmp	fclose                          # TAILCALL
.LBB2_5:
	.cfi_def_cfa_offset 64
	movq	stderr(%rip), %rdi
	movl	$.L.str.14, %esi
	movq	%r13, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$-1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z9write_ppmPciiiPi, .Lfunc_end2-_Z9write_ppmPciiiPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z13compareImagesPiS_ii         # -- Begin function _Z13compareImagesPiS_ii
	.type	_Z13compareImagesPiS_ii,@function
_Z13compareImagesPiS_ii:                # @_Z13compareImagesPiS_ii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, 24(%rsp)                  # 8-byte Spill
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	testl	%ecx, %ecx
	jle	.LBB3_1
# %bb.2:                                # %.preheader.lr.ph
	movl	%ecx, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	%edx, %r14d
	movl	$.L.str.18, %esi
	xorl	%r15d, %r15d
	xorl	%r12d, %r12d
	movl	%edx, 12(%rsp)                  # 4-byte Spill
.LBB3_3:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_5 Depth 2
	testl	%edx, %edx
	jle	.LBB3_8
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB3_3 Depth=1
	movl	%r15d, %eax
	movq	24(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,4), %rbp
	movq	16(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,4), %rbx
	xorl	%r13d, %r13d
.LBB3_5:                                #   Parent Loop BB3_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rbx,%r13,4), %ecx
	movl	(%rbp,%r13,4), %r8d
	cmpl	%r8d, %ecx
	je	.LBB3_7
# %bb.6:                                #   in Loop: Header=BB3_5 Depth=2
	movl	$.L.str.19, %edi
	movl	%r12d, %esi
	movl	%r13d, %edx
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.20, %esi
.LBB3_7:                                #   in Loop: Header=BB3_5 Depth=2
	incq	%r13
	cmpq	%r13, %r14
	jne	.LBB3_5
.LBB3_8:                                # %._crit_edge
                                        #   in Loop: Header=BB3_3 Depth=1
	incq	%r12
	movl	12(%rsp), %edx                  # 4-byte Reload
	addl	%edx, %r15d
	cmpq	32(%rsp), %r12                  # 8-byte Folded Reload
	jne	.LBB3_3
	jmp	.LBB3_9
.LBB3_1:
	movl	$.L.str.18, %esi
.LBB3_9:                                # %._crit_edge33
	movl	$.L.str.21, %edi
	xorl	%eax, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.Lfunc_end3:
	.size	_Z13compareImagesPiS_ii, .Lfunc_end3-_Z13compareImagesPiS_ii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x3d800000                      # float 0.0625
	.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	$216, %rsp
	.cfi_def_cfa_offset 272
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r14
	movl	%edi, %r15d
	movl	$.L.str.22, %edi
	callq	strdup
	movq	%rax, %rbx
	movl	$8000, %ebp                     # imm = 0x1F40
	cmpl	$2, %r15d
	jl	.LBB4_7
# %bb.1:
	je	.LBB4_2
# %bb.3:
	cmpl	$3, %r15d
	jne	.LBB4_6
# %bb.4:                                # %.thread
	movq	8(%r14), %rdi
	callq	strdup
	movq	%rax, %rbx
	movl	$2, %eax
	jmp	.LBB4_5
.LBB4_2:
	movl	$1, %eax
.LBB4_5:                                # %.sink.split
	movq	(%r14,%rax,8), %rdi
	callq	atoi
	movl	%eax, %ebp
.LBB4_6:
	movq	stderr(%rip), %rdi
	movl	$.L.str.23, %esi
	movq	%rbx, %rdx
	movl	%ebp, %ecx
	xorl	%eax, %eax
	callq	fprintf
.LBB4_7:
	leaq	124(%rsp), %r14
	leaq	120(%rsp), %r12
	leaq	116(%rsp), %rcx
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%r12, %rdx
	callq	_Z8read_ppmPcPiS0_S0_
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	(%r14), %r13d
	movl	(%r12), %r14d
	movl	%r14d, %eax
	imull	%r13d, %eax
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	leal	(,%rax,4), %ebx
	movslq	%ebx, %rdi
	movq	%rdi, 32(%rsp)                  # 8-byte Spill
	callq	malloc
	testq	%rax, %rax
	je	.LBB4_24
# %bb.8:                                # %.preheader121
	movq	%rax, %r15
	movq	%r14, 8(%rsp)                   # 8-byte Spill
	testl	%r14d, %r14d
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	movq	%r13, 48(%rsp)                  # 8-byte Spill
	jle	.LBB4_21
# %bb.9:                                # %.preheader120.lr.ph
	movslq	%r13d, %rax
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	leaq	(,%r13,4), %rbx
	xorl	%r12d, %r12d
	movq	8(%rsp), %r14                   # 8-byte Reload
.LBB4_10:                               # %.preheader120
                                        # =>This Inner Loop Header: Depth=1
	testl	%r13d, %r13d
	jle	.LBB4_12
# %bb.11:                               # %.lr.ph
                                        #   in Loop: Header=BB4_10 Depth=1
	movl	%r12d, %eax
	leaq	(%r15,%rax,4), %rdi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	callq	memset@PLT
.LBB4_12:                               # %._crit_edge
                                        #   in Loop: Header=BB4_10 Depth=1
	addl	%r13d, %r12d
	decq	%r14
	jne	.LBB4_10
# %bb.13:                               # %.preheader119
	cmpl	$3, 8(%rsp)                     # 4-byte Folded Reload
	jl	.LBB4_21
# %bb.14:                               # %.preheader.lr.ph
	movq	8(%rsp), %rax                   # 8-byte Reload
	decl	%eax
	leal	-1(%r13), %esi
	movq	24(%rsp), %rcx                  # 8-byte Reload
	addq	$8, %rcx
	movq	%rcx, 88(%rsp)                  # 8-byte Spill
	shlq	$2, 40(%rsp)                    # 8-byte Folded Spill
	movq	%r15, %rcx
	addq	$4, %rcx
	movq	%rcx, 80(%rsp)                  # 8-byte Spill
	leaq	-4(,%rsi,4), %rsi
	movl	$1, %edi
	movl	$255, %r8d
	movq	%rax, 96(%rsp)                  # 8-byte Spill
.LBB4_15:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_18 Depth 2
	cmpl	$2, %r13d
	jle	.LBB4_16
# %bb.17:                               # %.lr.ph125
                                        #   in Loop: Header=BB4_15 Depth=1
	leaq	-1(%rdi), %r10
	leaq	1(%rdi), %rcx
	movq	40(%rsp), %rax                  # 8-byte Reload
	movq	%rax, %r11
	movq	%rcx, 104(%rsp)                 # 8-byte Spill
	imulq	%rcx, %r11
	movq	88(%rsp), %rcx                  # 8-byte Reload
	addq	%rcx, %r11
	imulq	%rax, %r10
	addq	%rcx, %r10
	imulq	%rax, %rdi
	movq	80(%rsp), %rax                  # 8-byte Reload
	leaq	(%rax,%rdi), %rbx
	addq	%rcx, %rdi
	xorl	%r12d, %r12d
.LBB4_18:                               #   Parent Loop BB4_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r10,%r12), %r14d
	movl	(%rdi,%r12), %edx
	movl	-8(%r11,%r12), %eax
	subl	-8(%rdi,%r12), %edx
	movl	(%r11,%r12), %r13d
	leal	(%r14,%r13), %ecx
	movl	-8(%r10,%r12), %r15d
	subl	%r15d, %ecx
	subl	%eax, %ecx
	leal	(%rcx,%rdx,2), %ecx
	addl	%r14d, %r15d
	addl	%eax, %r13d
	subl	%r13d, %r15d
	movl	-4(%r10,%r12), %eax
	subl	-4(%r11,%r12), %eax
	leal	(%r15,%rax,2), %eax
	imull	%ecx, %ecx
	imull	%eax, %eax
	addl	%ecx, %eax
	cmpl	%ebp, %eax
	movl	$0, %eax
	cmovgl	%r8d, %eax
	movl	%eax, (%rbx,%r12)
	addq	$4, %r12
	cmpq	%r12, %rsi
	jne	.LBB4_18
# %bb.19:                               #   in Loop: Header=BB4_15 Depth=1
	movq	104(%rsp), %rcx                 # 8-byte Reload
	movq	%rcx, %rdi
	movq	56(%rsp), %r15                  # 8-byte Reload
	movq	48(%rsp), %r13                  # 8-byte Reload
	movq	96(%rsp), %rax                  # 8-byte Reload
	jmp	.LBB4_20
.LBB4_16:                               # %.preheader.._crit_edge126_crit_edge
                                        #   in Loop: Header=BB4_15 Depth=1
	incq	%rdi
	movq	%rdi, %rcx
.LBB4_20:                               # %._crit_edge126
                                        #   in Loop: Header=BB4_15 Depth=1
	cmpq	%rax, %rcx
	jne	.LBB4_15
.LBB4_21:                               # %._crit_edge128
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.L.str.27, %edi
	movl	%r13d, %esi
	movq	8(%rsp), %r14                   # 8-byte Reload
	movl	%r14d, %edx
	movl	$255, %ecx
	movq	%r15, %r8
	callq	_Z9write_ppmPciiiPi
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	xorps	%xmm0, %xmm0
	leaq	176(%rsp), %rsi
	movaps	%xmm0, (%rsi)
	movaps	%xmm0, 16(%rsi)
	movl	$-1, %eax
	movl	%eax, (%rsi)
	movabsq	$-8589934591, %rcx              # imm = 0xFFFFFFFE00000001
	movq	%rcx, 8(%rsi)
	movabsq	$-4294967294, %rcx              # imm = 0xFFFFFFFF00000002
	movq	%rcx, 20(%rsi)
	movl	$1, %ecx
	movl	%ecx, 32(%rsi)
	leaq	128(%rsp), %rbx
	movaps	%xmm0, (%rbx)
	movaps	%xmm0, 16(%rbx)
	movabsq	$-4294967297, %rdx              # imm = 0xFFFFFFFEFFFFFFFF
	movq	%rdx, (%rbx)
	movl	%eax, 8(%rbx)
	movabsq	$8589934593, %rax               # imm = 0x200000001
	movq	%rax, 24(%rbx)
	movl	%ecx, 32(%rbx)
	movl	$Mx, %edi
	movl	$36, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	movl	$My, %edi
	movl	$36, %edx
	movq	%rbx, %rsi
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	movq	32(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %rbx
	movslq	72(%rsp), %r13                  # 4-byte Folded Reload
	shlq	$2, %r13
	leaq	64(%rsp), %r12
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%r12), %rdi
	movq	24(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rsi
	movq	%r13, %rdx
	movq	%r14, %r13
	movq	48(%rsp), %r12                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r12d, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r14d
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r13d, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %edi
	shlq	$32, %rdi
	orq	%r14, %rdi
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_23
# %bb.22:
	movq	16(%rsp), %rdi
	movq	64(%rsp), %rsi
	movl	%r12d, %edx
	movl	%r13d, %ecx
	movl	%ebp, %r8d
	callq	_Z21__device_stub__filterPiPKjiii
.LBB4_23:
	movq	16(%rsp), %rsi
	movq	%rbx, %rdi
	movq	32(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movl	$.L.str.30, %edi
	movl	%r12d, %esi
	movl	%r13d, %edx
	movl	$255, %ecx
	movq	%rbx, %r8
	callq	_Z9write_ppmPciiiPi
	movq	56(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	movq	%rbx, %rsi
	movl	%r12d, %edx
	movl	%r13d, %ecx
	callq	_Z13compareImagesPiS_ii
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	%r15, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	stderr(%rip), %rcx
	movl	$.L.str.31, %edi
	movl	$11, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	xorl	%eax, %eax
	addq	$216, %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
.LBB4_24:
	.cfi_def_cfa_offset 272
	movq	stderr(%rip), %rdi
	movl	$.L.str.25, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	fprintf
	movl	$-1, %edi
	callq	exit
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	subq	$32, %rsp
	.cfi_adjust_cfa_offset 32
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6filterPiPKjiii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movl	$Mx, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$36, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$My, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movl	$36, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$__hip_module_dtor, %edi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	Mx,@object                      # @Mx
	.local	Mx
	.comm	Mx,36,16
	.type	My,@object                      # @My
	.local	My
	.comm	My,36,16
	.type	_Z6filterPiPKjiii,@object       # @_Z6filterPiPKjiii
	.section	.rodata,"a",@progbits
	.globl	_Z6filterPiPKjiii
	.p2align	3, 0x0
_Z6filterPiPKjiii:
	.quad	_Z21__device_stub__filterPiPKjiii
	.size	_Z6filterPiPKjiii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"read_ppm but no file name\n"
	.size	.L.str, 27

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"read_ppm( %s )\n"
	.size	.L.str.1, 16

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"read_ppm()    ERROR  file '%s' cannot be opened for reading\n"
	.size	.L.str.3, 61

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Texture::Texture()    ERROR  file '%s' does not start with \"P6\"  I am expecting a binary PPM file\n"
	.size	.L.str.4, 99

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%d\n%d\n%d"
	.size	.L.str.6, 9

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"read %d things   width %d  height %d  maxval %d\n"
	.size	.L.str.7, 49

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"read_ppm()  unable to allocate %d x %d unsigned ints for the picture\n"
	.size	.L.str.8, 70

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"read_ppm()  unable to allocate %d bytes of read buffer\n"
	.size	.L.str.9, 56

	.type	.L.str.10,@object               # @.str.10
	.section	.rodata.cst4,"aM",@progbits,4
.L.str.10:
	.asciz	"%d\000"
	.size	.L.str.10, 4

	.type	.L.str.11,@object               # @.str.11
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.11:
	.asciz	"%s found at offset %d\n"
	.size	.L.str.11, 23

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Texture %s   read %ld of %ld bytes\n"
	.size	.L.str.12, 36

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

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"FAILED TO OPEN FILE '%s' for writing\n"
	.size	.L.str.14, 38

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"P6\n"
	.size	.L.str.15, 4

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

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"%c%c%c"
	.size	.L.str.17, 7

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"PASSED"
	.size	.L.str.18, 7

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"Mismatch at (%d, %d): Expected/Actual = %d/%d\n"
	.size	.L.str.19, 47

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"FAILED"
	.size	.L.str.20, 7

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"Test %s\n"
	.size	.L.str.21, 9

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"BWstop-sign.ppm"
	.size	.L.str.22, 16

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"file %s    threshold %d\n"
	.size	.L.str.23, 25

	.type	.L.str.25,@object               # @.str.25
.L.str.25:
	.asciz	"sobel() unable to malloc %d bytes\n"
	.size	.L.str.25, 35

	.type	.L.str.27,@object               # @.str.27
.L.str.27:
	.asciz	"result8000gold.ppm"
	.size	.L.str.27, 19

	.type	.L.str.30,@object               # @.str.30
.L.str.30:
	.asciz	"result_cuda.ppm"
	.size	.L.str.30, 16

	.type	.L.str.31,@object               # @.str.31
.L.str.31:
	.asciz	"sobel done\n"
	.size	.L.str.31, 12

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6filterPiPKjiii"
	.size	.L__unnamed_1, 18

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"Mx"
	.size	.L__unnamed_2, 3

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"My"
	.size	.L__unnamed_3, 3

	.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	"Compute Gold start"
	.size	.Lstr, 19

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Compute Gold Complete"
	.size	.Lstr.1, 22

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Compute CUDA start"
	.size	.Lstr.2, 19

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Compute CUDA Complete"
	.size	.Lstr.3, 22

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z21__device_stub__filterPiPKjiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym Mx
	.addrsig_sym My
	.addrsig_sym _Z6filterPiPKjiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6filterPiPKjiii       ; -- Begin function _Z6filterPiPKjiii
	.globl	_Z6filterPiPKjiii
	.p2align	8
	.type	_Z6filterPiPKjiii,@function
_Z6filterPiPKjiii:                      ; @_Z6filterPiPKjiii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b128 s[4:7], s[0:1], 0x10
	v_and_b32_e32 v3, 0x3ff, v0
	v_bfe_u32 v2, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s7, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[6:7], null, s14, s7, v[3:4]
	v_mad_u64_u32 v[4:5], null, s15, s3, v[2:3]
	v_cmp_gt_i32_e32 vcc_lo, s4, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s2, s5, v4
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s8, s2
	s_cbranch_execz .LBB0_41
; %bb.1:
	s_load_b128 s[8:11], s[0:1], 0x0
	v_mad_u64_u32 v[7:8], null, v4, s4, v[6:7]
	v_mov_b32_e32 v8, 0
	v_mul_u32_u24_e32 v5, 18, v2
	s_mov_b32 s0, -1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[7:8]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v9, vcc_lo, s10, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v10, vcc_lo, s11, v1, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, 0, v3
	global_load_b32 v10, v[9:10], off
	v_add_lshl_u32 v9, v3, v5, 2
	s_waitcnt vmcnt(0)
	ds_store_b32 v9, v10 offset:76
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_9
; %bb.2:
	v_cmp_gt_i32_e64 s0, 1, v6
	s_mov_b32 s12, exec_lo
	v_cmpx_lt_i32_e32 0, v6
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_dual_mov_b32 v11, 0 :: v_dual_add_nc_u32 v10, -1, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[10:11], 2, v[10:11]
	v_add_co_u32 v10, s1, s10, v10
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v11, s1, s11, v11, s1
	global_load_b32 v8, v[10:11], off
.LBB0_4:
	s_or_b32 exec_lo, exec_lo, s12
	v_lshlrev_b32_e32 v10, 2, v5
	s_mov_b32 s13, 0
	s_mov_b32 s12, exec_lo
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v8 offset:72
	v_cmpx_eq_u32_e32 0, v2
	s_cbranch_execz .LBB0_8
; %bb.5:
	v_cmp_lt_i32_e64 s1, 0, v4
	v_mov_b32_e32 v8, 0
	v_mov_b32_e32 v10, 0
	s_xor_b32 s0, s0, -1
	s_delay_alu instid0(VALU_DEP_3) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s0, s1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_7
; %bb.6:
	v_xad_u32 v10, s4, -1, v7
	v_mov_b32_e32 v11, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[10:11], 2, v[10:11]
	v_add_co_u32 v10, s0, s10, v10
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v11, s0, s11, v11, s0
	global_load_b32 v10, v[10:11], off
.LBB0_7:
	s_or_b32 exec_lo, exec_lo, s1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 s13, exec_lo
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v10
.LBB0_8:                                ; %Flow181
	s_or_b32 exec_lo, exec_lo, s12
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_not1_b32 s0, s13, exec_lo
.LBB0_9:                                ; %Flow180
	s_or_b32 exec_lo, exec_lo, s2
	s_and_saveexec_b32 s2, s0
	s_cbranch_execz .LBB0_17
; %bb.10:
	v_cmp_eq_u32_e64 s0, 0, v2
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB0_17
; %bb.11:
	v_cmp_lt_i32_e64 s0, 0, v4
	v_mov_b32_e32 v10, 0
	s_delay_alu instid0(VALU_DEP_2)
	s_and_saveexec_b32 s12, s0
	s_cbranch_execz .LBB0_13
; %bb.12:
	v_subrev_nc_u32_e32 v10, s4, v7
	v_mov_b32_e32 v11, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[10:11], 2, v[10:11]
	v_add_co_u32 v10, s1, s10, v10
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v11, s1, s11, v11, s1
	global_load_b32 v10, v[10:11], off
.LBB0_13:
	s_or_b32 exec_lo, exec_lo, s12
	s_add_i32 s1, s7, -1
	v_lshlrev_b32_e32 v8, 2, v3
	v_cmp_le_u32_e64 s1, s1, v3
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v10 offset:4
	s_and_b32 exec_lo, exec_lo, s1
	s_cbranch_execz .LBB0_17
; %bb.14:
	s_add_i32 s1, s4, -1
	v_mov_b32_e32 v10, 0
	v_cmp_gt_i32_e64 s1, s1, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s0, s1
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_16
; %bb.15:
	v_subrev_nc_u32_e32 v10, s4, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v11, 0 :: v_dual_add_nc_u32 v10, 1, v10
	v_lshlrev_b64 v[10:11], 2, v[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v10, s0, s10, v10
	v_add_co_ci_u32_e64 v11, s0, s11, v11, s0
	global_load_b32 v10, v[10:11], off
.LBB0_16:
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v10 offset:8
.LBB0_17:
	s_or_b32 exec_lo, exec_lo, s2
	s_add_i32 s7, s7, -1
	v_add_nc_u32_e32 v8, 4, v9
	v_cmp_le_u32_e64 s0, s7, v3
                                        ; implicit-def: $sgpr7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s1, s0
	s_xor_b32 s2, exec_lo, s1
	s_cbranch_execz .LBB0_25
; %bb.18:
	s_add_i32 s0, s4, -1
	v_mov_b32_e32 v9, 0
	v_cmp_gt_i32_e64 s0, s0, v6
	s_delay_alu instid0(VALU_DEP_1)
	s_and_saveexec_b32 s7, s0
	s_cbranch_execz .LBB0_20
; %bb.19:
	v_dual_mov_b32 v10, 0 :: v_dual_add_nc_u32 v9, 1, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	v_add_co_u32 v9, s1, s10, v9
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v10, s1, s11, v10, s1
	global_load_b32 v9, v[9:10], off
.LBB0_20:
	s_or_b32 exec_lo, exec_lo, s7
	s_add_i32 s7, s3, -1
	s_mov_b32 s12, exec_lo
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v9 offset:76
	v_cmpx_le_u32_e64 s7, v2
	s_cbranch_execz .LBB0_24
; %bb.21:
	s_add_i32 s1, s5, -1
	v_mov_b32_e32 v9, 0
	v_cmp_gt_i32_e64 s1, s1, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s0, s1
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_23
; %bb.22:
	v_add3_u32 v9, v7, s4, 1
	v_mov_b32_e32 v10, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	v_add_co_u32 v9, s0, s10, v9
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v10, s0, s11, v10, s0
	global_load_b32 v9, v[9:10], off
.LBB0_23:
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v9 offset:148
.LBB0_24:                               ; %Flow176
	s_or_b32 exec_lo, exec_lo, s12
.LBB0_25:                               ; %Flow177
	s_or_saveexec_b32 s0, s2
	v_mov_b32_e32 v9, s7
	s_xor_b32 exec_lo, exec_lo, s0
; %bb.26:                               ; %._crit_edge
	s_add_i32 s1, s3, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mov_b32_e32 v9, s1
; %bb.27:
	s_or_b32 exec_lo, exec_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_mov_b32 s2, exec_lo
	v_cmpx_ge_u32_e64 v2, v9
	s_cbranch_execz .LBB0_34
; %bb.28:
	s_add_i32 s1, s5, -1
	v_mov_b32_e32 v9, 0
	v_cmp_le_i32_e64 s0, s1, v4
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_i32_e64 s1, v4
	s_cbranch_execz .LBB0_30
; %bb.29:
	v_dual_mov_b32 v10, 0 :: v_dual_add_nc_u32 v9, s4, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	v_add_co_u32 v9, s1, s10, v9
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v10, s1, s11, v10, s1
	global_load_b32 v9, v[9:10], off
.LBB0_30:
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v9 offset:144
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_34
; %bb.31:
	v_cmp_lt_i32_e32 vcc_lo, 0, v6
	v_mov_b32_e32 v8, 0
	s_xor_b32 s0, s0, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s1, vcc_lo, s0
	s_and_saveexec_b32 s0, s1
	s_cbranch_execz .LBB0_33
; %bb.32:
	v_add3_u32 v7, s4, -1, v7
	v_mov_b32_e32 v8, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	v_add_co_u32 v7, vcc_lo, s10, v7
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v8, vcc_lo, s11, v8, vcc_lo
	global_load_b32 v8, v[7:8], off
.LBB0_33:
	s_or_b32 exec_lo, exec_lo, s0
	v_lshlrev_b32_e32 v5, 2, v5
	s_waitcnt vmcnt(0)
	ds_store_b32 v5, v8 offset:144
.LBB0_34:                               ; %Flow175
	s_or_b32 exec_lo, exec_lo, s2
	v_cmp_lt_i32_e32 vcc_lo, 0, v6
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_41
; %bb.35:
	s_add_i32 s0, s4, -1
	s_add_i32 s1, s5, -1
	v_cmp_gt_i32_e32 vcc_lo, s0, v6
	v_cmp_gt_i32_e64 s0, s1, v4
	v_cmp_lt_i32_e64 s1, 0, v4
	s_delay_alu instid0(VALU_DEP_2)
	s_and_b32 s0, vcc_lo, s0
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s0, s1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB0_41
; %bb.36:                               ; %.preheader.preheader
	v_dual_mov_b32 v3, 0 :: v_dual_lshlrev_b32 v4, 2, v3
	s_mov_b32 s7, 0
	s_getpc_b64 s[0:1]
	s_add_u32 s0, s0, Mx@rel32@lo+4
	s_addc_u32 s1, s1, Mx@rel32@hi+12
	s_getpc_b64 s[2:3]
	s_add_u32 s2, s2, My@rel32@lo+4
	s_addc_u32 s3, s3, My@rel32@hi+12
	v_mad_u32_u24 v2, 0x48, v2, v4
	v_mov_b32_e32 v4, 0
.LBB0_37:                               ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_38 Depth 2
	s_delay_alu instid0(VALU_DEP_2)
	v_mov_b32_e32 v6, v2
	s_mov_b64 s[4:5], 0
.LBB0_38:                               ;   Parent Loop BB0_37 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s10, s0, s4
	s_addc_u32 s11, s1, s5
	s_add_u32 s12, s2, s4
	ds_load_b32 v8, v6
	s_addc_u32 s13, s3, s5
	s_load_b32 s10, s[10:11], 0x0
	s_load_b32 s11, s[12:13], 0x0
	v_mov_b32_e32 v5, v3
	v_mov_b32_e32 v7, v4
	s_add_u32 s4, s4, 4
	s_addc_u32 s5, s5, 0
	s_cmp_eq_u32 s4, 12
	s_waitcnt lgkmcnt(0)
	v_mad_u64_u32 v[3:4], null, s10, v8, v[5:6]
	v_add_nc_u32_e32 v6, 4, v6
	v_mad_u64_u32 v[4:5], null, s11, v8, v[7:8]
	s_cbranch_scc0 .LBB0_38
; %bb.39:                               ;   in Loop: Header=BB0_37 Depth=1
	s_add_i32 s7, s7, 1
	s_add_u32 s0, s0, 12
	s_addc_u32 s1, s1, 0
	v_add_nc_u32_e32 v2, 0x48, v2
	s_add_u32 s2, s2, 12
	s_addc_u32 s3, s3, 0
	s_cmp_eq_u32 s7, 3
	s_cbranch_scc0 .LBB0_37
; %bb.40:                               ; %.sink.split
	v_mul_lo_u32 v2, v4, v4
	v_add_co_u32 v0, vcc_lo, s8, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s9, v1, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[4:5], null, v3, v3, v[2:3]
	v_cmp_lt_i32_e32 vcc_lo, s6, v4
	v_cndmask_b32_e64 v2, 0, 0xff, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB0_41:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6filterPiPKjiii
		.amdhsa_group_segment_fixed_size 1296
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 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	_Z6filterPiPKjiii, .Lfunc_end0-_Z6filterPiPKjiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1544
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 1296 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
	.protected	Mx                      ; @Mx
	.type	Mx,@object
	.section	.bss,"aw",@nobits
	.globl	Mx
	.p2align	4, 0x0
Mx:
	.zero	36
	.size	Mx, 36

	.protected	My                      ; @My
	.type	My,@object
	.globl	My
	.p2align	4, 0x0
My:
	.zero	36
	.size	My, 36

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.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 Mx
	.addrsig_sym My
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 1296
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6filterPiPKjiii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6filterPiPKjiii.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
