#include <stdio.h>
#include <stdint.h>

#define CHECK(call)                                                            \
{                                                                              \
    const cudaError_t error = call;                                            \
    if (error != cudaSuccess)                                                  \
    {                                                                          \
        fprintf(stderr, "Error: %s:%d, ", __FILE__, __LINE__);                 \
        fprintf(stderr, "code: %d, reason: %s\n", error,                       \
                cudaGetErrorString(error));                                    \
        exit(EXIT_FAILURE);                                                    \
    }                                                                          \
}

struct GpuTimer
{
    cudaEvent_t start;
    cudaEvent_t stop;

    GpuTimer()
    {
        cudaEventCreate(&start);
        cudaEventCreate(&stop);
    }

    ~GpuTimer()
    {
        cudaEventDestroy(start);
        cudaEventDestroy(stop);
    }

    void Start()
    {
        cudaEventRecord(start, 0);
    }

    void Stop()
    {
        cudaEventRecord(stop, 0);
    }

    float Elapsed()
    {
        float elapsed;
        cudaEventSynchronize(stop);
        cudaEventElapsedTime(&elapsed, start, stop);
        return elapsed;
    }
};

void readPnm(char * fileName, 
		int &width, int &height, uchar3 * &pixels)
{
	FILE * f = fopen(fileName, "r");
	if (f == NULL)
	{
		printf("Cannot read %s\n", fileName);
		exit(EXIT_FAILURE);
	}

	char type[3];
	fscanf(f, "%s", type);
	
	if (strcmp(type, "P3") != 0) // In this exercise, we don't touch other types
	{
		fclose(f);
		printf("Cannot read %s\n", fileName); 
		exit(EXIT_FAILURE); 
	}

	fscanf(f, "%i", &width);
	fscanf(f, "%i", &height);
	
	int max_val;
	fscanf(f, "%i", &max_val);
	if (max_val > 255) // In this exercise, we assume 1 byte per value
	{
		fclose(f);
		printf("Cannot read %s\n", fileName); 
		exit(EXIT_FAILURE); 
	}

	pixels = (uchar3 *)malloc(width * height * sizeof(uchar3));
	for (int i = 0; i < width * height; i++)
		fscanf(f, "%hhu%hhu%hhu", &pixels[i].x, &pixels[i].y, &pixels[i].z);

	fclose(f);
}

void writePnm(uchar3 * pixels, int width, int height, 
		char * fileName)
{
	FILE * f = fopen(fileName, "w");
	if (f == NULL)
	{
		printf("Cannot write %s\n", fileName);
		exit(EXIT_FAILURE);
	}	

	fprintf(f, "P3\n%i\n%i\n255\n", width, height); 

	for (int i = 0; i < width * height; i++)
		fprintf(f, "%hhu\n%hhu\n%hhu\n", pixels[i].x, pixels[i].y, pixels[i].z);
	
	fclose(f);
}

__global__ void blurImgKernel(uchar3 * inPixels, int width, int height, 
		float * filter, int filterWidth, 
		uchar3 * outPixels)
{
	// TODO
	int ix = blockIdx.x * blockDim.x + threadIdx.x;
	int iy = blockIdx.y * blockDim.y + threadIdx.y;
	if (ix < width && iy < height)
	{
		int i = iy * width + ix;
		int half = filterWidth / 2;
		float3 G;
		int idx = 0, dy = 0;
		G.x = G.y = G.z = 0.0f;
		for (int filterR = 0; filterR < filterWidth; filterR++)
		{
			for (int filterC = 0; filterC < filterWidth; filterC++)
			{ 
				idx = iy + filterR - half;
				dy = ix + filterC - half;
				if (idx < 0)
					idx = 0;
				if (idx >= height)
					idx = height - 1;
				idx *= width;
				if (dy < 0)
					dy = 0;
				if (dy >= width)
					dy = width - 1;
				idx += dy;
				G.x += filter[filterR * filterWidth + filterC] * inPixels[idx].x; 
				G.y += filter[filterR * filterWidth + filterC] * inPixels[idx].y;
				G.z += filter[filterR * filterWidth + filterC] * inPixels[idx].z;
			}
		}
		outPixels[i].x = G.x;
		outPixels[i].y = G.y;
		outPixels[i].z = G.z;
	}
}

void blurImg(uchar3 * inPixels, int width, int height, float * filter, int filterWidth, 
		uchar3 * outPixels,
		bool useDevice=false, dim3 blockSize=dim3(1, 1))
{
	GpuTimer timer;
	timer.Start();
	if (useDevice == false)
	{
		// TODO
		int half = filterWidth / 2;
		float Gx, Gy, Gz;
		for (int r = 0; r < height; r++)
		{
			for (int c = 0; c < width; c++)
			{
				int i = r * width + c;
				int idx = 0, dy = 0;
				Gx = Gy = Gz = 0.0f;
				for (int filterR = 0; filterR < filterWidth; filterR++)
				{
					for (int filterC = 0; filterC < filterWidth; filterC++)
					{ 
						idx = r + filterR - half;
						dy = c + filterC - half;
						if (idx < 0)
							idx = 0;
						if (idx >= height)
							idx = height - 1;
						idx *= width;
						if (dy < 0)
							dy = 0;
						if (dy >= width)
							dy = width - 1;
						idx += dy;
						Gx += filter[filterR * filterWidth + filterC] * inPixels[idx].x; 
						Gy += filter[filterR * filterWidth + filterC] * inPixels[idx].y;
						Gz += filter[filterR * filterWidth + filterC] * inPixels[idx].z;
					}
				}
				outPixels[i].x = Gx;
				outPixels[i].y = Gy;
				outPixels[i].z = Gz;
			}
		}
	}
	else // Use device
	{
		cudaDeviceProp devProp;
		cudaGetDeviceProperties(&devProp, 0);
		printf("GPU name: %s\n", devProp.name);
		printf("GPU compute capability: %d.%d\n", devProp.major, devProp.minor);

		// TODO
		// Allocate device memories
		uchar3 *d_inPixels, * d_outPixels;
		float * d_filter;
		CHECK(cudaMalloc(&d_inPixels, height * width * sizeof(uchar3)));
		CHECK(cudaMalloc(&d_outPixels, height * width * sizeof(uchar3)));
		CHECK(cudaMalloc(&d_filter, filterWidth * filterWidth * sizeof(float)));

		// Copy data to device memories
		CHECK(cudaMemcpy(d_inPixels, inPixels, height * width * sizeof(uchar3), cudaMemcpyHostToDevice));
		CHECK(cudaMemcpy(d_filter, filter, filterWidth * filterWidth * sizeof(float), cudaMemcpyHostToDevice));

		// Set grid size and call kernel (remember to check kernel error)
		dim3 gridSize((width - 1)/blockSize.x + 1, (height - 1)/blockSize.y + 1);
		blurImgKernel<<<gridSize, blockSize>>>(d_inPixels, width, height, d_filter, filterWidth, d_outPixels);
		cudaError_t errSync  = cudaGetLastError();
		cudaError_t errAsync = cudaDeviceSynchronize();
		if (errSync != cudaSuccess)
			printf("Sync kernel error: %s\n", cudaGetErrorString(errSync));
		if (errAsync != cudaSuccess)
			printf("Async kernel error: %s\n", cudaGetErrorString(errAsync));

		// Copy result from device memories
		CHECK(cudaMemcpy(outPixels, d_outPixels, height * width * sizeof(uchar3), cudaMemcpyDeviceToHost));

		// Free device memories
		CHECK(cudaFree(d_inPixels));
		CHECK(cudaFree(d_filter));
		CHECK(cudaFree(d_outPixels));
	}
	timer.Stop();
	float time = timer.Elapsed();
	printf("Processing time (%s): %f ms\n", 
    		useDevice == true? "use device" : "use host", time);
}

float computeError(uchar3 * a1, uchar3 * a2, int n)
{
	float err = 0;
	for (int i = 0; i < n; i++)
	{
		err += abs((int)a1[i].x - (int)a2[i].x);
		err += abs((int)a1[i].y - (int)a2[i].y);
		err += abs((int)a1[i].z - (int)a2[i].z);
	}
	err /= (n * 3);
	return err;
}

char * concatStr(const char * s1, const char * s2)
{
    char * result = (char *)malloc(strlen(s1) + strlen(s2) + 1);
    strcpy(result, s1);
    strcat(result, s2);
    return result;
}

int main(int argc, char ** argv)
{
	if (argc != 4 && argc != 6)
	{
		printf("The number of arguments is invalid\n");
		return EXIT_FAILURE;
	}

	// Read input image file
	int width, height;
	uchar3 * inPixels;
	readPnm(argv[1], width, height, inPixels);
	printf("Image size (width x height): %i x %i\n\n", width, height);

	// Read correct output image file
	int correctWidth, correctHeight;
	uchar3 * correctOutPixels;
	readPnm(argv[3], correctWidth, correctHeight, correctOutPixels);
	if (correctWidth != width || correctHeight != height)
	{
		printf("The shape of the correct output image is invalid\n");
		return EXIT_FAILURE;
	}

	// Set up a simple filter with blurring effect 
	int filterWidth = 9;
	float * filter = (float *)malloc(filterWidth * filterWidth * sizeof(float));
	for (int filterR = 0; filterR < filterWidth; filterR++)
	{
		for (int filterC = 0; filterC < filterWidth; filterC++)
		{
			filter[filterR * filterWidth + filterC] = 1. / (filterWidth * filterWidth);
		}
	}

	// Blur input image using host
	uchar3 * hostOutPixels = (uchar3 *)malloc(width * height * sizeof(uchar3)); 
	blurImg(inPixels, width, height, filter, filterWidth, hostOutPixels);
	
	// Compute mean absolute error between host result and correct result
	float hostErr = computeError(hostOutPixels, correctOutPixels, width * height);
	printf("Error: %f\n\n", hostErr);

	// Blur input image using device
	uchar3 * deviceOutPixels = (uchar3 *)malloc(width * height * sizeof(uchar3));
	dim3 blockSize(32, 32); // Default
	if (argc == 6)
	{
		blockSize.x = atoi(argv[4]);
		blockSize.y = atoi(argv[5]);
	}  
	blurImg(inPixels, width, height, filter, filterWidth, deviceOutPixels, true, blockSize);

	// Compute mean absolute error between device result and correct result
	float deviceErr = computeError(deviceOutPixels, correctOutPixels, width * height);
	printf("Error: %f\n\n", deviceErr);

	// Write results to files
	char * outFileNameBase = strtok(argv[2], "."); // Get rid of extension
	writePnm(hostOutPixels, width, height, concatStr(outFileNameBase, "_host.pnm"));
	writePnm(deviceOutPixels, width, height, concatStr(outFileNameBase, "_device.pnm"));

	// Free memories
	free(inPixels);
	free(correctOutPixels);
	free(hostOutPixels);
	free(deviceOutPixels);
	free(filter);
}

	.file	"tmpxft_00258a38_00000000-6_bt01_p2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2044:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2044:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"Cannot read %s\n"
.LC2:
	.string	"%s"
.LC3:
	.string	"P3"
.LC4:
	.string	"%i"
.LC5:
	.string	"%hhu%hhu%hhu"
	.text
	.globl	_Z7readPnmPcRiS0_RP6uchar3
	.type	_Z7readPnmPcRiS0_RP6uchar3, @function
_Z7readPnmPcRiS0_RP6uchar3:
.LFB2036:
	.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
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rcx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	leaq	.LC0(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	testq	%rax, %rax
	je	.L10
	leaq	5(%rsp), %r15
	movq	%rax, %rdi
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rbx
	movq	%r15, %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	leaq	.LC3(%rip), %rsi
	movq	%r15, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L4
.L11:
	movq	%rbx, %rdi
	call	fclose@PLT
.L10:
	movl	$2, %edi
	movq	%r14, %rdx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L4:
	leaq	.LC4(%rip), %r15
	movq	%r12, %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movq	%r15, %rsi
	call	__isoc23_fscanf@PLT
	movq	%rbp, %rdx
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	xorl	%eax, %eax
	movq	%rsp, %rdx
	movq	%r15, %rsi
	movq	%rbx, %rdi
	call	__isoc23_fscanf@PLT
	cmpl	$255, (%rsp)
	jg	.L11
	movl	(%r12), %edi
	imull	0(%rbp), %edi
	xorl	%r15d, %r15d
	leaq	.LC5(%rip), %r14
	movslq	%edi, %rdi
	leaq	(%rdi,%rdi,2), %rdi
	call	malloc@PLT
	movq	%rax, 0(%r13)
.L6:
	movl	(%r12), %eax
	imull	0(%rbp), %eax
	cmpl	%r15d, %eax
	jle	.L13
	leaq	(%r15,%r15,2), %rdx
	addq	0(%r13), %rdx
	movq	%r14, %rsi
	movq	%rbx, %rdi
	leaq	1(%rdx), %rcx
	leaq	2(%rdx), %r8
	xorl	%eax, %eax
	incq	%r15
	call	__isoc23_fscanf@PLT
	jmp	.L6
.L13:
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$24, %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
.LFE2036:
	.size	_Z7readPnmPcRiS0_RP6uchar3, .-_Z7readPnmPcRiS0_RP6uchar3
	.section	.rodata.str1.1
.LC6:
	.string	"w"
.LC7:
	.string	"Cannot write %s\n"
.LC8:
	.string	"P3\n%i\n%i\n255\n"
.LC9:
	.string	"%hhu\n%hhu\n%hhu\n"
	.text
	.globl	_Z8writePnmP6uchar3iiPc
	.type	_Z8writePnmP6uchar3iiPc, @function
_Z8writePnmP6uchar3iiPc:
.LFB2037:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rcx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%esi, %r13d
	leaq	.LC6(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdi, %rbx
	movq	%rcx, %rdi
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L15
	movl	$2, %edi
	movq	%r14, %rdx
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L15:
	movl	%r12d, %r8d
	movl	%r13d, %ecx
	movq	%rax, %rdi
	movq	%rax, %rbp
	leaq	.LC8(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	imull	%r12d, %r13d
	leaq	.LC9(%rip), %r14
	xorl	%r12d, %r12d
.L16:
	cmpl	%r12d, %r13d
	jle	.L19
	movzbl	(%rbx), %ecx
	movzbl	2(%rbx), %r9d
	movq	%r14, %rdx
	movl	$2, %esi
	movzbl	1(%rbx), %r8d
	movq	%rbp, %rdi
	xorl	%eax, %eax
	incl	%r12d
	addq	$3, %rbx
	call	__fprintf_chk@PLT
	jmp	.L16
.L19:
	popq	%rbx
	.cfi_def_cfa_offset 40
	movq	%rbp, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE2037:
	.size	_Z8writePnmP6uchar3iiPc, .-_Z8writePnmP6uchar3iiPc
	.globl	_Z12computeErrorP6uchar3S0_i
	.type	_Z12computeErrorP6uchar3S0_i, @function
_Z12computeErrorP6uchar3S0_i:
.LFB2039:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	xorl	%r8d, %r8d
	xorps	%xmm0, %xmm0
.L21:
	cmpl	%edx, %r8d
	jge	.L23
	movzbl	(%rsi,%rax), %r9d
	movzbl	(%rdi,%rax), %ecx
	subl	%r9d, %ecx
	movl	%ecx, %r9d
	negl	%r9d
	cmovns	%r9d, %ecx
	movzbl	1(%rsi,%rax), %r9d
	cvtsi2ssl	%ecx, %xmm1
	movzbl	1(%rdi,%rax), %ecx
	subl	%r9d, %ecx
	movl	%ecx, %r9d
	negl	%r9d
	addss	%xmm1, %xmm0
	cmovns	%r9d, %ecx
	movzbl	2(%rsi,%rax), %r9d
	cvtsi2ssl	%ecx, %xmm1
	movzbl	2(%rdi,%rax), %ecx
	subl	%r9d, %ecx
	movl	%ecx, %r9d
	negl	%r9d
	addss	%xmm0, %xmm1
	cmovns	%r9d, %ecx
	incl	%r8d
	addq	$3, %rax
	cvtsi2ssl	%ecx, %xmm0
	addss	%xmm1, %xmm0
	jmp	.L21
.L23:
	leal	(%rdx,%rdx,2), %edx
	cvtsi2ssl	%edx, %xmm1
	divss	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE2039:
	.size	_Z12computeErrorP6uchar3S0_i, .-_Z12computeErrorP6uchar3S0_i
	.globl	_Z9concatStrPKcS0_
	.type	_Z9concatStrPKcS0_, @function
_Z9concatStrPKcS0_:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rsi, %rbx
	call	strlen@PLT
	movq	%rbx, %rdi
	movq	%rax, %r12
	call	strlen@PLT
	leaq	1(%r12,%rax), %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movq	%rax, %rdi
	call	__strcpy_chk@PLT
	movq	%r12, %rdx
	movq	%rbx, %rsi
	movq	%rax, %rdi
	call	__strcat_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z9concatStrPKcS0_, .-_Z9concatStrPKcS0_
	.globl	_Z47__device_stub__Z13blurImgKernelP6uchar3iiPfiS0_P6uchar3iiPfiS0_
	.type	_Z47__device_stub__Z13blurImgKernelP6uchar3iiPfiS0_P6uchar3iiPfiS0_, @function
_Z47__device_stub__Z13blurImgKernelP6uchar3iiPfiS0_P6uchar3iiPfiS0_:
.LFB2066:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movl	%esi, 36(%rsp)
	leaq	84(%rsp), %rsi
	movl	%edx, 32(%rsp)
	leaq	56(%rsp), %rdx
	movq	%rcx, 24(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 20(%rsp)
	movq	%r9, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	36(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z13blurImgKernelP6uchar3iiPfiS0_(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L26:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2066:
	.size	_Z47__device_stub__Z13blurImgKernelP6uchar3iiPfiS0_P6uchar3iiPfiS0_, .-_Z47__device_stub__Z13blurImgKernelP6uchar3iiPfiS0_P6uchar3iiPfiS0_
	.globl	_Z13blurImgKernelP6uchar3iiPfiS0_
	.type	_Z13blurImgKernelP6uchar3iiPfiS0_, @function
_Z13blurImgKernelP6uchar3iiPfiS0_:
.LFB2067:
	.cfi_startproc
	endbr64
	jmp	_Z47__device_stub__Z13blurImgKernelP6uchar3iiPfiS0_P6uchar3iiPfiS0_
	.cfi_endproc
.LFE2067:
	.size	_Z13blurImgKernelP6uchar3iiPfiS0_, .-_Z13blurImgKernelP6uchar3iiPfiS0_
	.section	.rodata.str1.1
.LC11:
	.string	"use device"
.LC12:
	.string	"use host"
.LC13:
	.string	"GPU name: %s\n"
.LC14:
	.string	"GPU compute capability: %d.%d\n"
.LC15:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/hmhuan/PG_GPU/master/assignment/BT01/1612858/bt01_p2.cu"
.LC16:
	.string	"Error: %s:%d, "
.LC17:
	.string	"code: %d, reason: %s\n"
.LC18:
	.string	"Sync kernel error: %s\n"
.LC19:
	.string	"Async kernel error: %s\n"
.LC20:
	.string	"Processing time (%s): %f ms\n"
	.text
	.globl	_Z7blurImgP6uchar3iiPfiS0_b4dim3
	.type	_Z7blurImgP6uchar3iiPfiS0_b4dim3, @function
_Z7blurImgP6uchar3iiPfiS0_b4dim3:
.LFB2038:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA2038
	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	%edx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%r8d, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	subq	$1160, %rsp
	.cfi_def_cfa_offset 1216
	movl	1216(%rsp), %eax
	movq	%rdi, (%rsp)
	leaq	96(%rsp), %rdi
	movq	%rcx, 8(%rsp)
	movq	%r9, 16(%rsp)
	movl	%eax, 28(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 1144(%rsp)
	xorl	%eax, %eax
.LEHB0:
	call	cudaEventCreate@PLT
	leaq	104(%rsp), %rdi
	call	cudaEventCreate@PLT
.LEHE0:
	movq	96(%rsp), %rdi
	xorl	%esi, %esi
.LEHB1:
	call	cudaEventRecord@PLT
	cmpb	$0, 28(%rsp)
	jne	.L32
	movl	%ebp, %eax
	movl	$2, %ecx
	leal	-1(%r13), %esi
	xorl	%r11d, %r11d
	cltd
	movl	%esi, 44(%rsp)
	xorl	%r8d, %r8d
	idivl	%ecx
	movslq	%ebp, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	%rcx, 32(%rsp)
.L33:
	cmpl	%r13d, %r8d
	jge	.L39
	movq	16(%rsp), %rsi
	movslq	%r11d, %rcx
	xorl	%r9d, %r9d
	leaq	(%rcx,%rcx,2), %rcx
	addq	%rsi, %rcx
	movl	%r8d, %esi
	subl	%eax, %esi
	movl	%esi, 40(%rsp)
.L40:
	cmpl	%ebx, %r9d
	jge	.L103
	xorps	%xmm0, %xmm0
	movl	%r9d, %r15d
	movq	8(%rsp), %r12
	xorl	%r10d, %r10d
	movaps	%xmm0, %xmm1
	movaps	%xmm0, %xmm2
	subl	%eax, %r15d
.L34:
	cmpl	%ebp, %r10d
	jge	.L37
	movl	40(%rsp), %esi
	movl	$0, %edx
	addl	%r10d, %esi
	cmovs	%edx, %esi
	cmpl	%esi, %r13d
	cmovle	44(%rsp), %esi
	xorl	%edi, %edi
	imull	%ebx, %esi
.L36:
	leal	(%r15,%rdi), %edx
	xorl	%r14d, %r14d
	testl	%edx, %edx
	cmovs	%r14d, %edx
	cmpl	%edx, %ebx
	jg	.L35
	leal	-1(%rbx), %edx
.L35:
	addl	%esi, %edx
	movq	(%rsp), %r14
	movss	(%r12,%rdi,4), %xmm4
	incq	%rdi
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,2), %rdx
	addq	%r14, %rdx
	movzbl	(%rdx), %r14d
	cvtsi2ssl	%r14d, %xmm3
	movzbl	1(%rdx), %r14d
	movzbl	2(%rdx), %edx
	mulss	%xmm4, %xmm3
	addss	%xmm3, %xmm2
	cvtsi2ssl	%r14d, %xmm3
	mulss	%xmm4, %xmm3
	addss	%xmm3, %xmm1
	cvtsi2ssl	%edx, %xmm3
	mulss	%xmm4, %xmm3
	addss	%xmm3, %xmm0
	cmpl	%edi, %ebp
	jg	.L36
	movq	32(%rsp), %rsi
	incl	%r10d
	addq	%rsi, %r12
	jmp	.L34
.L37:
	cvttss2sil	%xmm2, %edx
	incl	%r9d
	addq	$3, %rcx
	movb	%dl, -3(%rcx)
	cvttss2sil	%xmm1, %edx
	movb	%dl, -2(%rcx)
	cvttss2sil	%xmm0, %edx
	movb	%dl, -1(%rcx)
	jmp	.L40
.L103:
	incl	%r8d
	addl	%ebx, %r11d
	jmp	.L33
.L32:
	leaq	112(%rsp), %r12
	xorl	%esi, %esi
	movq	%r12, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movq	%r12, %rdx
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	476(%rsp), %ecx
	movl	472(%rsp), %edx
	leaq	.LC14(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	%r13d, %r12d
	leaq	56(%rsp), %rdi
	imull	%ebx, %r12d
	movslq	%r12d, %r12
	leaq	(%r12,%r12,2), %r12
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	je	.L41
	movl	$206, %r8d
.L95:
	movq	stderr(%rip), %rdi
	leaq	.LC15(%rip), %rcx
	leaq	.LC16(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	%r14d, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %r8
	movl	%r14d, %ecx
.L74:
	movq	stderr(%rip), %rdi
	leaq	.LC17(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L41:
	leaq	64(%rsp), %rdi
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %r14d
	movl	$207, %r8d
	testl	%eax, %eax
	jne	.L95
	movl	%ebp, %r14d
	leaq	72(%rsp), %rdi
	imull	%ebp, %r14d
	movslq	%r14d, %r14
	salq	$2, %r14
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %r15d
	movl	$208, %r8d
	testl	%eax, %eax
	jne	.L98
	movq	(%rsp), %rsi
	movq	56(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %r15d
	testl	%eax, %eax
	je	.L45
	movl	$211, %r8d
.L98:
	movq	stderr(%rip), %rdi
	leaq	.LC15(%rip), %rcx
	leaq	.LC16(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	%r15d, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %r8
	movl	%r15d, %ecx
	jmp	.L74
.L45:
	movq	8(%rsp), %rsi
	movq	72(%rsp), %rdi
	movl	$1, %ecx
	movq	%r14, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %r14d
	movl	$212, %r8d
	testl	%eax, %eax
	jne	.L95
	leal	-1(%r13), %eax
	xorl	%edx, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	divl	1228(%rsp)
	movl	$1, 92(%rsp)
	xorl	%edx, %edx
	movl	$1, %esi
	leal	1(%rax), %ecx
	leal	-1(%rbx), %eax
	divl	1224(%rsp)
	movl	%ecx, 88(%rsp)
	movq	1224(%rsp), %rdx
	movl	1232(%rsp), %ecx
	incl	%eax
	movl	%eax, 84(%rsp)
	movq	84(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	je	.L47
.L49:
	call	cudaGetLastError@PLT
	movl	%eax, %ebp
	call	cudaDeviceSynchronize@PLT
	jmp	.L104
.L47:
	movq	64(%rsp), %r9
	movq	72(%rsp), %rcx
	movl	%ebp, %r8d
	movl	%r13d, %edx
	movq	56(%rsp), %rdi
	movl	%ebx, %esi
	call	_Z47__device_stub__Z13blurImgKernelP6uchar3iiPfiS0_P6uchar3iiPfiS0_
	jmp	.L49
.L104:
	movl	%eax, %ebx
	testl	%ebp, %ebp
	jne	.L50
.L53:
	testl	%ebx, %ebx
	jne	.L51
	jmp	.L52
.L50:
	movl	%ebp, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rdx
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L53
.L51:
	movl	%ebx, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %rdx
	leaq	.LC19(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L52:
	movq	64(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	$2, %ecx
	movq	%r12, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L55
	movl	$225, %r8d
	jmp	.L100
.L55:
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %ebx
	movl	$228, %r8d
	testl	%eax, %eax
	jne	.L100
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %ebx
	movl	$229, %r8d
	testl	%eax, %eax
	jne	.L100
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L39
	movl	$230, %r8d
.L100:
	movq	stderr(%rip), %rdi
	leaq	.LC15(%rip), %rcx
	leaq	.LC16(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	%ebx, %edi
	call	cudaGetErrorString@PLT
	movq	%rax, %r8
	movl	%ebx, %ecx
	jmp	.L74
.L39:
	movq	104(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	104(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	104(%rsp), %rdx
	movq	96(%rsp), %rsi
	leaq	84(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	cmpb	$0, 28(%rsp)
	leaq	.LC11(%rip), %rax
	leaq	.LC12(%rip), %rdx
	movl	$2, %edi
	cmovne	%rax, %rdx
	leaq	.LC20(%rip), %rsi
	movb	$1, %al
	cvtss2sd	84(%rsp), %xmm0
	call	__printf_chk@PLT
.LEHE1:
	movq	96(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	104(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	1144(%rsp), %rax
	subq	%fs:40, %rax
	je	.L62
	jmp	.L71
.L64:
	endbr64
	movq	%rax, %rbx
.L60:
	movq	96(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	104(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	1144(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L71
	movq	%rbx, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L71:
	call	__stack_chk_fail@PLT
.L62:
	addq	$1160, %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
.LFE2038:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA2038:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE2038-.LLSDACSB2038
.LLSDACSB2038:
	.uleb128 .LEHB0-.LFB2038
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB2038
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L64-.LFB2038
	.uleb128 0
	.uleb128 .LEHB2-.LFB2038
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE2038:
	.text
	.size	_Z7blurImgP6uchar3iiPfiS0_b4dim3, .-_Z7blurImgP6uchar3iiPfiS0_b4dim3
	.section	.rodata.str1.1
.LC21:
	.string	"The number of arguments is invalid\n"
.LC22:
	.string	"Image size (width x height): %i x %i\n\n"
.LC23:
	.string	"The shape of the correct output image is invalid\n"
.LC25:
	.string	"Error: %f\n\n"
.LC26:
	.string	"."
.LC27:
	.string	"_host.pnm"
.LC28:
	.string	"_device.pnm"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2041:
	.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)
	movl	%edi, %eax
	andl	$-3, %eax
	cmpl	$4, %eax
	je	.L106
	leaq	.LC21(%rip), %rsi
	jmp	.L118
.L106:
	movq	%rsi, %rbx
	leaq	56(%rsp), %rcx
	leaq	44(%rsp), %rdx
	movl	%edi, %r12d
	movq	8(%rbx), %rdi
	leaq	40(%rsp), %rsi
	call	_Z7readPnmPcRiS0_RP6uchar3
	movl	44(%rsp), %ecx
	movl	40(%rsp), %edx
	xorl	%eax, %eax
	leaq	.LC22(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	24(%rbx), %rdi
	leaq	64(%rsp), %rcx
	leaq	52(%rsp), %rdx
	leaq	48(%rsp), %rsi
	call	_Z7readPnmPcRiS0_RP6uchar3
	movl	40(%rsp), %r13d
	cmpl	%r13d, 48(%rsp)
	jne	.L108
	movl	44(%rsp), %r14d
	cmpl	%r14d, 52(%rsp)
	je	.L109
.L108:
	leaq	.LC23(%rip), %rsi
.L118:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L105
.L109:
	movl	$324, %edi
	call	malloc@PLT
	movss	.LC24(%rip), %xmm0
	xorl	%edx, %edx
	movq	%rax, %rbp
	movq	%rax, %rcx
.L111:
	xorl	%eax, %eax
.L112:
	movss	%xmm0, (%rcx,%rax,4)
	incq	%rax
	cmpq	$9, %rax
	jne	.L112
	addl	$9, %edx
	addq	$36, %rcx
	cmpl	$81, %edx
	jne	.L111
	movl	%r13d, %edi
	imull	%r14d, %edi
	movslq	%edi, %rdi
	leaq	(%rdi,%rdi,2), %rdi
	call	malloc@PLT
	movq	56(%rsp), %rcx
	movl	%r14d, %edx
	movl	%r13d, %esi
	movq	%rax, (%rsp)
	subq	$24, %rsp
	.cfi_def_cfa_offset 184
	movabsq	$4294967297, %rax
	movl	$9, %r8d
	movq	%rcx, 40(%rsp)
	movq	%rbp, %rcx
	leaq	.LC25(%rip), %r13
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	movq	%rax, (%rsp)
	movl	$1, 8(%rsp)
	pushq	$0
	.cfi_def_cfa_offset 192
	movq	32(%rsp), %r9
	movq	48(%rsp), %rdi
	call	_Z7blurImgP6uchar3iiPfiS0_b4dim3
	movq	96(%rsp), %rax
	movq	%rax, 56(%rsp)
	movl	72(%rsp), %edx
	addq	$32, %rsp
	.cfi_def_cfa_offset 160
	movq	%rax, %rsi
	imull	44(%rsp), %edx
	movq	(%rsp), %rdi
	call	_Z12computeErrorP6uchar3S0_i
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	40(%rsp), %r14d
	movl	44(%rsp), %r15d
	movl	%r14d, %edi
	imull	%r15d, %edi
	movslq	%edi, %rdi
	leaq	(%rdi,%rdi,2), %rdi
	call	malloc@PLT
	movl	$1, 84(%rsp)
	movq	%rax, 8(%rsp)
	movabsq	$137438953504, %rax
	movq	%rax, 76(%rsp)
	cmpl	$6, %r12d
	jne	.L114
	movq	32(%rbx), %rdi
	call	atoi@PLT
	movq	40(%rbx), %rdi
	movl	%eax, 76(%rsp)
	call	atoi@PLT
	movl	%eax, 80(%rsp)
.L114:
	subq	$24, %rsp
	.cfi_def_cfa_offset 184
	movl	$9, %r8d
	movq	%rbp, %rcx
	movl	%r15d, %edx
	movq	100(%rsp), %rax
	movl	%r14d, %esi
	movq	%rax, (%rsp)
	movl	108(%rsp), %eax
	movl	%eax, 8(%rsp)
	pushq	$1
	.cfi_def_cfa_offset 192
	movq	40(%rsp), %r9
	movq	48(%rsp), %rdi
	call	_Z7blurImgP6uchar3iiPfiS0_b4dim3
	movl	72(%rsp), %edx
	imull	76(%rsp), %edx
	addq	$32, %rsp
	.cfi_def_cfa_offset 160
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	_Z12computeErrorP6uchar3S0_i
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	16(%rbx), %rdi
	leaq	.LC26(%rip), %rsi
	call	strtok@PLT
	leaq	.LC27(%rip), %rsi
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	_Z9concatStrPKcS0_
	movl	44(%rsp), %edx
	movl	40(%rsp), %esi
	movq	(%rsp), %rdi
	movq	%rax, %rcx
	call	_Z8writePnmP6uchar3iiPc
	leaq	.LC28(%rip), %rsi
	movq	%rbx, %rdi
	call	_Z9concatStrPKcS0_
	movl	44(%rsp), %edx
	movl	40(%rsp), %esi
	movq	8(%rsp), %rdi
	movq	%rax, %rcx
	call	_Z8writePnmP6uchar3iiPc
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L105:
	movq	88(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L115
	call	__stack_chk_fail@PLT
.L115:
	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
.LFE2041:
	.size	main, .-main
	.section	.rodata.str1.1
.LC29:
	.string	"_Z13blurImgKernelP6uchar3iiPfiS0_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2069:
	.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	.LC29(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z13blurImgKernelP6uchar3iiPfiS0_(%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
.LFE2069:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC24:
	.long	1011500424
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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 <stdint.h>

#define CHECK(call)                                                            \
{                                                                              \
    const hipError_t error = call;                                            \
    if (error != hipSuccess)                                                  \
    {                                                                          \
        fprintf(stderr, "Error: %s:%d, ", __FILE__, __LINE__);                 \
        fprintf(stderr, "code: %d, reason: %s\n", error,                       \
                hipGetErrorString(error));                                    \
        exit(EXIT_FAILURE);                                                    \
    }                                                                          \
}

struct GpuTimer
{
    hipEvent_t start;
    hipEvent_t stop;

    GpuTimer()
    {
        hipEventCreate(&start);
        hipEventCreate(&stop);
    }

    ~GpuTimer()
    {
        hipEventDestroy(start);
        hipEventDestroy(stop);
    }

    void Start()
    {
        hipEventRecord(start, 0);
    }

    void Stop()
    {
        hipEventRecord(stop, 0);
    }

    float Elapsed()
    {
        float elapsed;
        hipEventSynchronize(stop);
        hipEventElapsedTime(&elapsed, start, stop);
        return elapsed;
    }
};

void readPnm(char * fileName, 
		int &width, int &height, uchar3 * &pixels)
{
	FILE * f = fopen(fileName, "r");
	if (f == NULL)
	{
		printf("Cannot read %s\n", fileName);
		exit(EXIT_FAILURE);
	}

	char type[3];
	fscanf(f, "%s", type);
	
	if (strcmp(type, "P3") != 0) // In this exercise, we don't touch other types
	{
		fclose(f);
		printf("Cannot read %s\n", fileName); 
		exit(EXIT_FAILURE); 
	}

	fscanf(f, "%i", &width);
	fscanf(f, "%i", &height);
	
	int max_val;
	fscanf(f, "%i", &max_val);
	if (max_val > 255) // In this exercise, we assume 1 byte per value
	{
		fclose(f);
		printf("Cannot read %s\n", fileName); 
		exit(EXIT_FAILURE); 
	}

	pixels = (uchar3 *)malloc(width * height * sizeof(uchar3));
	for (int i = 0; i < width * height; i++)
		fscanf(f, "%hhu%hhu%hhu", &pixels[i].x, &pixels[i].y, &pixels[i].z);

	fclose(f);
}

void writePnm(uchar3 * pixels, int width, int height, 
		char * fileName)
{
	FILE * f = fopen(fileName, "w");
	if (f == NULL)
	{
		printf("Cannot write %s\n", fileName);
		exit(EXIT_FAILURE);
	}	

	fprintf(f, "P3\n%i\n%i\n255\n", width, height); 

	for (int i = 0; i < width * height; i++)
		fprintf(f, "%hhu\n%hhu\n%hhu\n", pixels[i].x, pixels[i].y, pixels[i].z);
	
	fclose(f);
}

__global__ void blurImgKernel(uchar3 * inPixels, int width, int height, 
		float * filter, int filterWidth, 
		uchar3 * outPixels)
{
	// TODO
	int ix = blockIdx.x * blockDim.x + threadIdx.x;
	int iy = blockIdx.y * blockDim.y + threadIdx.y;
	if (ix < width && iy < height)
	{
		int i = iy * width + ix;
		int half = filterWidth / 2;
		float3 G;
		int idx = 0, dy = 0;
		G.x = G.y = G.z = 0.0f;
		for (int filterR = 0; filterR < filterWidth; filterR++)
		{
			for (int filterC = 0; filterC < filterWidth; filterC++)
			{ 
				idx = iy + filterR - half;
				dy = ix + filterC - half;
				if (idx < 0)
					idx = 0;
				if (idx >= height)
					idx = height - 1;
				idx *= width;
				if (dy < 0)
					dy = 0;
				if (dy >= width)
					dy = width - 1;
				idx += dy;
				G.x += filter[filterR * filterWidth + filterC] * inPixels[idx].x; 
				G.y += filter[filterR * filterWidth + filterC] * inPixels[idx].y;
				G.z += filter[filterR * filterWidth + filterC] * inPixels[idx].z;
			}
		}
		outPixels[i].x = G.x;
		outPixels[i].y = G.y;
		outPixels[i].z = G.z;
	}
}

void blurImg(uchar3 * inPixels, int width, int height, float * filter, int filterWidth, 
		uchar3 * outPixels,
		bool useDevice=false, dim3 blockSize=dim3(1, 1))
{
	GpuTimer timer;
	timer.Start();
	if (useDevice == false)
	{
		// TODO
		int half = filterWidth / 2;
		float Gx, Gy, Gz;
		for (int r = 0; r < height; r++)
		{
			for (int c = 0; c < width; c++)
			{
				int i = r * width + c;
				int idx = 0, dy = 0;
				Gx = Gy = Gz = 0.0f;
				for (int filterR = 0; filterR < filterWidth; filterR++)
				{
					for (int filterC = 0; filterC < filterWidth; filterC++)
					{ 
						idx = r + filterR - half;
						dy = c + filterC - half;
						if (idx < 0)
							idx = 0;
						if (idx >= height)
							idx = height - 1;
						idx *= width;
						if (dy < 0)
							dy = 0;
						if (dy >= width)
							dy = width - 1;
						idx += dy;
						Gx += filter[filterR * filterWidth + filterC] * inPixels[idx].x; 
						Gy += filter[filterR * filterWidth + filterC] * inPixels[idx].y;
						Gz += filter[filterR * filterWidth + filterC] * inPixels[idx].z;
					}
				}
				outPixels[i].x = Gx;
				outPixels[i].y = Gy;
				outPixels[i].z = Gz;
			}
		}
	}
	else // Use device
	{
		hipDeviceProp_t devProp;
		hipGetDeviceProperties(&devProp, 0);
		printf("GPU name: %s\n", devProp.name);
		printf("GPU compute capability: %d.%d\n", devProp.major, devProp.minor);

		// TODO
		// Allocate device memories
		uchar3 *d_inPixels, * d_outPixels;
		float * d_filter;
		CHECK(hipMalloc(&d_inPixels, height * width * sizeof(uchar3)));
		CHECK(hipMalloc(&d_outPixels, height * width * sizeof(uchar3)));
		CHECK(hipMalloc(&d_filter, filterWidth * filterWidth * sizeof(float)));

		// Copy data to device memories
		CHECK(hipMemcpy(d_inPixels, inPixels, height * width * sizeof(uchar3), hipMemcpyHostToDevice));
		CHECK(hipMemcpy(d_filter, filter, filterWidth * filterWidth * sizeof(float), hipMemcpyHostToDevice));

		// Set grid size and call kernel (remember to check kernel error)
		dim3 gridSize((width - 1)/blockSize.x + 1, (height - 1)/blockSize.y + 1);
		blurImgKernel<<<gridSize, blockSize>>>(d_inPixels, width, height, d_filter, filterWidth, d_outPixels);
		hipError_t errSync  = hipGetLastError();
		hipError_t errAsync = hipDeviceSynchronize();
		if (errSync != hipSuccess)
			printf("Sync kernel error: %s\n", hipGetErrorString(errSync));
		if (errAsync != hipSuccess)
			printf("Async kernel error: %s\n", hipGetErrorString(errAsync));

		// Copy result from device memories
		CHECK(hipMemcpy(outPixels, d_outPixels, height * width * sizeof(uchar3), hipMemcpyDeviceToHost));

		// Free device memories
		CHECK(hipFree(d_inPixels));
		CHECK(hipFree(d_filter));
		CHECK(hipFree(d_outPixels));
	}
	timer.Stop();
	float time = timer.Elapsed();
	printf("Processing time (%s): %f ms\n", 
    		useDevice == true? "use device" : "use host", time);
}

float computeError(uchar3 * a1, uchar3 * a2, int n)
{
	float err = 0;
	for (int i = 0; i < n; i++)
	{
		err += abs((int)a1[i].x - (int)a2[i].x);
		err += abs((int)a1[i].y - (int)a2[i].y);
		err += abs((int)a1[i].z - (int)a2[i].z);
	}
	err /= (n * 3);
	return err;
}

char * concatStr(const char * s1, const char * s2)
{
    char * result = (char *)malloc(strlen(s1) + strlen(s2) + 1);
    strcpy(result, s1);
    strcat(result, s2);
    return result;
}

int main(int argc, char ** argv)
{
	if (argc != 4 && argc != 6)
	{
		printf("The number of arguments is invalid\n");
		return EXIT_FAILURE;
	}

	// Read input image file
	int width, height;
	uchar3 * inPixels;
	readPnm(argv[1], width, height, inPixels);
	printf("Image size (width x height): %i x %i\n\n", width, height);

	// Read correct output image file
	int correctWidth, correctHeight;
	uchar3 * correctOutPixels;
	readPnm(argv[3], correctWidth, correctHeight, correctOutPixels);
	if (correctWidth != width || correctHeight != height)
	{
		printf("The shape of the correct output image is invalid\n");
		return EXIT_FAILURE;
	}

	// Set up a simple filter with blurring effect 
	int filterWidth = 9;
	float * filter = (float *)malloc(filterWidth * filterWidth * sizeof(float));
	for (int filterR = 0; filterR < filterWidth; filterR++)
	{
		for (int filterC = 0; filterC < filterWidth; filterC++)
		{
			filter[filterR * filterWidth + filterC] = 1. / (filterWidth * filterWidth);
		}
	}

	// Blur input image using host
	uchar3 * hostOutPixels = (uchar3 *)malloc(width * height * sizeof(uchar3)); 
	blurImg(inPixels, width, height, filter, filterWidth, hostOutPixels);
	
	// Compute mean absolute error between host result and correct result
	float hostErr = computeError(hostOutPixels, correctOutPixels, width * height);
	printf("Error: %f\n\n", hostErr);

	// Blur input image using device
	uchar3 * deviceOutPixels = (uchar3 *)malloc(width * height * sizeof(uchar3));
	dim3 blockSize(32, 32); // Default
	if (argc == 6)
	{
		blockSize.x = atoi(argv[4]);
		blockSize.y = atoi(argv[5]);
	}  
	blurImg(inPixels, width, height, filter, filterWidth, deviceOutPixels, true, blockSize);

	// Compute mean absolute error between device result and correct result
	float deviceErr = computeError(deviceOutPixels, correctOutPixels, width * height);
	printf("Error: %f\n\n", deviceErr);

	// Write results to files
	char * outFileNameBase = strtok(argv[2], "."); // Get rid of extension
	writePnm(hostOutPixels, width, height, concatStr(outFileNameBase, "_host.pnm"));
	writePnm(deviceOutPixels, width, height, concatStr(outFileNameBase, "_device.pnm"));

	// Free memories
	free(inPixels);
	free(correctOutPixels);
	free(hostOutPixels);
	free(deviceOutPixels);
	free(filter);
}

	.text
	.file	"bt01_p2.hip"
	.globl	_Z7readPnmPcRiS0_RP15HIP_vector_typeIhLj3EE # -- Begin function _Z7readPnmPcRiS0_RP15HIP_vector_typeIhLj3EE
	.type	_Z7readPnmPcRiS0_RP15HIP_vector_typeIhLj3EE,@function
_Z7readPnmPcRiS0_RP15HIP_vector_typeIhLj3EE: # @_Z7readPnmPcRiS0_RP15HIP_vector_typeIhLj3EE
	.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	%rcx, %rbx
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %r13
	movl	$.L.str, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_3
# %bb.1:
	movq	%rax, %r12
	leaq	1(%rsp), %rbp
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movzwl	(%rbp), %eax
	xorl	$13136, %eax                    # imm = 0x3350
	movzbl	2(%rbp), %ecx
	orw	%ax, %cx
	jne	.LBB0_2
# %bb.4:
	movl	$.L.str.4, %esi
	movq	%r12, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	$.L.str.4, %esi
	movq	%r12, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	leaq	4(%rsp), %rbp
	movl	$.L.str.4, %esi
	movq	%r12, %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$256, (%rbp)                    # imm = 0x100
	jge	.LBB0_2
# %bb.5:
	movslq	(%r15), %rax
	movslq	(%r14), %r13
	imulq	%rax, %r13
	leaq	(,%r13,2), %rdi
	addq	%r13, %rdi
	callq	malloc
	movq	%rax, (%rbx)
	testl	%r13d, %r13d
	jle	.LBB0_8
# %bb.6:                                # %.lr.ph.preheader
	movl	$2, %r13d
	xorl	%ebp, %ebp
.LBB0_7:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx), %rax
	leaq	(%rax,%r13), %r8
	leaq	(%rax,%r13), %rdx
	addq	$-2, %rdx
	leaq	(%rax,%r13), %rcx
	decq	%rcx
	movl	$.L.str.5, %esi
	movq	%r12, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	incq	%rbp
	movslq	(%r15), %rax
	movslq	(%r14), %rcx
	imulq	%rax, %rcx
	addq	$3, %r13
	cmpq	%rcx, %rbp
	jl	.LBB0_7
.LBB0_8:                                # %._crit_edge
	movq	%r12, %rdi
	callq	fclose
	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
	retq
.LBB0_2:
	.cfi_def_cfa_offset 64
	movq	%r12, %rdi
	callq	fclose
.LBB0_3:
	movl	$.L.str.1, %edi
	movq	%r13, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z7readPnmPcRiS0_RP15HIP_vector_typeIhLj3EE, .Lfunc_end0-_Z7readPnmPcRiS0_RP15HIP_vector_typeIhLj3EE
	.cfi_endproc
                                        # -- End function
	.globl	_Z8writePnmP15HIP_vector_typeIhLj3EEiiPc # -- Begin function _Z8writePnmP15HIP_vector_typeIhLj3EEiiPc
	.type	_Z8writePnmP15HIP_vector_typeIhLj3EEiiPc,@function
_Z8writePnmP15HIP_vector_typeIhLj3EEiiPc: # @_Z8writePnmP15HIP_vector_typeIhLj3EEiiPc
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, %r12
	movl	%edx, %ebp
	movl	%esi, %r15d
	movq	%rdi, %rbx
	movl	$.L.str.6, %esi
	movq	%rcx, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_5
# %bb.1:
	movq	%rax, %r14
	movl	$.L.str.8, %esi
	movq	%rax, %rdi
	movl	%r15d, %edx
	movl	%ebp, %ecx
	xorl	%eax, %eax
	callq	fprintf
	imull	%r15d, %ebp
	testl	%ebp, %ebp
	jle	.LBB1_4
# %bb.2:                                # %.lr.ph.preheader
	movl	%ebp, %eax
	leaq	(%rax,%rax,2), %r15
	xorl	%r12d, %r12d
.LBB1_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movzbl	(%rbx,%r12), %edx
	movzbl	1(%rbx,%r12), %ecx
	movzbl	2(%rbx,%r12), %r8d
	movl	$.L.str.9, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	addq	$3, %r12
	cmpq	%r12, %r15
	jne	.LBB1_3
.LBB1_4:                                # %._crit_edge
	movq	%r14, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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
.LBB1_5:
	.cfi_def_cfa_offset 48
	movl	$.L.str.7, %edi
	movq	%r12, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z8writePnmP15HIP_vector_typeIhLj3EEiiPc, .Lfunc_end1-_Z8writePnmP15HIP_vector_typeIhLj3EEiiPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z28__device_stub__blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_ # -- Begin function _Z28__device_stub__blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
	.type	_Z28__device_stub__blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_,@function
_Z28__device_stub__blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_: # @_Z28__device_stub__blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	20(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	16(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	48(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	40(%rsp), %r8
	movq	%r9, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z28__device_stub__blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_, .Lfunc_end2-_Z28__device_stub__blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
	.cfi_endproc
                                        # -- End function
	.globl	_Z7blurImgP15HIP_vector_typeIhLj3EEiiPfiS1_b4dim3 # -- Begin function _Z7blurImgP15HIP_vector_typeIhLj3EEiiPfiS1_b4dim3
	.type	_Z7blurImgP15HIP_vector_typeIhLj3EEiiPfiS1_b4dim3,@function
_Z7blurImgP15HIP_vector_typeIhLj3EEiiPfiS1_b4dim3: # @_Z7blurImgP15HIP_vector_typeIhLj3EEiiPfiS1_b4dim3
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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	$1592, %rsp                     # imm = 0x638
	.cfi_def_cfa_offset 1648
	.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	%r9, 64(%rsp)                   # 8-byte Spill
	movl	%r8d, 4(%rsp)                   # 4-byte Spill
	movq	%rcx, %r12
                                        # kill: def $edx killed $edx def $rdx
	movq	%rdx, 8(%rsp)                   # 8-byte Spill
	movl	%esi, %r15d
	movq	%rdi, %r13
	leaq	48(%rsp), %rdi
	callq	hipEventCreate
	leaq	56(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	movq	-8(%rbx), %rdi
.Ltmp0:
	xorl	%esi, %esi
	callq	hipEventRecord
.Ltmp1:
# %bb.1:                                # %_ZN8GpuTimer5StartEv.exit
	cmpb	$0, 1648(%rsp)
	je	.LBB3_2
# %bb.19:
.Ltmp2:
	leaq	120(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
.Ltmp3:
# %bb.20:
	leaq	120(%rsp), %rbx
	movl	$.L.str.10, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	360(%rbx), %esi
	movl	364(%rbx), %edx
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	movq	8(%rsp), %rax                   # 8-byte Reload
                                        # kill: def $eax killed $eax killed $rax
	imull	%r15d, %eax
	cltq
	leaq	(%rax,%rax,2), %r14
.Ltmp5:
	leaq	40(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
.Ltmp6:
# %bb.21:                               # %_ZL9hipMallocI15HIP_vector_typeIhLj3EEE10hipError_tPPT_m.exit
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.LBB3_22
# %bb.27:
.Ltmp10:
	leaq	32(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
.Ltmp11:
# %bb.28:                               # %_ZL9hipMallocI15HIP_vector_typeIhLj3EEE10hipError_tPPT_m.exit179
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.LBB3_29
# %bb.31:
	movl	4(%rsp), %eax                   # 4-byte Reload
	movl	%eax, %ebx
	imull	%ebx, %ebx
	shlq	$2, %rbx
.Ltmp15:
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
.Ltmp16:
# %bb.32:                               # %_ZL9hipMallocIfE10hipError_tPPT_m.exit
	movl	%eax, %ebp
	testl	%eax, %eax
	jne	.LBB3_33
# %bb.36:
	movq	40(%rsp), %rdi
.Ltmp20:
	movq	%r13, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp21:
# %bb.37:
	movl	%eax, %r13d
	testl	%eax, %eax
	jne	.LBB3_38
# %bb.41:
	movq	24(%rsp), %rdi
.Ltmp25:
	movq	%r12, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp26:
# %bb.42:
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.LBB3_43
# %bb.45:
	leaq	1656(%rsp), %rcx
	leal	-1(%r15), %eax
	xorl	%edx, %edx
	divl	(%rcx)
                                        # kill: def $eax killed $eax def $rax
	leal	1(%rax), %edi
	movq	8(%rsp), %rax                   # 8-byte Reload
	decl	%eax
	xorl	%edx, %edx
	divl	4(%rcx)
                                        # kill: def $eax killed $eax def $rax
	incl	%eax
	shlq	$32, %rax
	orq	%rax, %rdi
	movq	(%rcx), %rdx
	movl	8(%rcx), %ecx
.Ltmp30:
	movl	$1, %esi
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp31:
# %bb.46:
	testl	%eax, %eax
	jne	.LBB3_48
# %bb.47:
	movq	40(%rsp), %rdi
	movq	24(%rsp), %rcx
	movq	32(%rsp), %r9
.Ltmp32:
	movl	%r15d, %esi
	movq	8(%rsp), %rdx                   # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	movl	4(%rsp), %r8d                   # 4-byte Reload
	callq	_Z28__device_stub__blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
.Ltmp33:
.LBB3_48:
.Ltmp35:
	callq	hipGetLastError
.Ltmp36:
# %bb.49:
.Ltmp38:
	movl	%eax, %ebp
	callq	hipDeviceSynchronize
.Ltmp39:
# %bb.50:
	movl	%eax, %ebx
	testl	%ebp, %ebp
	je	.LBB3_53
# %bb.51:
.Ltmp40:
	movl	%ebp, %edi
	callq	hipGetErrorString
.Ltmp41:
# %bb.52:
	movl	$.L.str.15, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB3_53:
	testl	%ebx, %ebx
	je	.LBB3_56
# %bb.54:
.Ltmp42:
	movl	%ebx, %edi
	callq	hipGetErrorString
.Ltmp43:
# %bb.55:
	movl	$.L.str.16, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB3_56:
	movq	32(%rsp), %rsi
.Ltmp45:
	movq	64(%rsp), %rdi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
.Ltmp46:
# %bb.57:
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.LBB3_58
# %bb.62:
	movq	40(%rsp), %rdi
.Ltmp50:
	callq	hipFree
.Ltmp51:
# %bb.63:
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.LBB3_64
# %bb.66:
	movq	24(%rsp), %rdi
.Ltmp55:
	callq	hipFree
.Ltmp56:
# %bb.67:
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.LBB3_68
# %bb.70:
	movq	32(%rsp), %rdi
.Ltmp60:
	callq	hipFree
.Ltmp61:
# %bb.71:
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.LBB3_10
# %bb.72:
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movl	$.L.str.13, %edx
	movl	$232, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %r14
.Ltmp62:
	movl	%ebx, %edi
	callq	hipGetErrorString
.Ltmp63:
	jmp	.LBB3_23
.LBB3_2:
	cmpl	$0, 8(%rsp)                     # 4-byte Folded Reload
	jle	.LBB3_10
# %bb.3:                                # %.preheader181.lr.ph
	movl	4(%rsp), %eax                   # 4-byte Reload
	movl	%eax, %edi
	shrl	$31, %edi
	addl	%eax, %edi
	sarl	%edi
	negl	%edi
	movq	8(%rsp), %rsi                   # 8-byte Reload
	leal	-1(%rsi), %ecx
	leal	-1(%r15), %edx
	movl	%esi, %esi
	movq	%rsi, 88(%rsp)                  # 8-byte Spill
	movl	%r15d, %esi
	movq	%rsi, 96(%rsp)                  # 8-byte Spill
	movl	%eax, %r8d
	movq	%rdi, 80(%rsp)                  # 8-byte Spill
	movl	%edi, %eax
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	xorl	%eax, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
.LBB3_4:                                # %.preheader181
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_6 Depth 2
                                        #       Child Loop BB3_16 Depth 3
                                        #         Child Loop BB3_17 Depth 4
	testl	%r15d, %r15d
	jle	.LBB3_9
# %bb.5:                                # %.lr.ph197
                                        #   in Loop: Header=BB3_4 Depth=1
	movq	80(%rsp), %rax                  # 8-byte Reload
	movq	16(%rsp), %rsi                  # 8-byte Reload
	leal	(%rax,%rsi), %r11d
	movl	%esi, %eax
	imull	%r15d, %eax
	leaq	(%rax,%rax,2), %rax
	addq	64(%rsp), %rax                  # 8-byte Folded Reload
	movq	%rax, 104(%rsp)                 # 8-byte Spill
	movq	72(%rsp), %r9                   # 8-byte Reload
	xorl	%ebx, %ebx
.LBB3_6:                                #   Parent Loop BB3_4 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_16 Depth 3
                                        #         Child Loop BB3_17 Depth 4
	movq	%rbx, 112(%rsp)                 # 8-byte Spill
	cmpl	$0, 4(%rsp)                     # 4-byte Folded Reload
	jle	.LBB3_7
# %bb.15:                               # %.preheader.lr.ph
                                        #   in Loop: Header=BB3_6 Depth=2
	xorps	%xmm1, %xmm1
	xorl	%esi, %esi
	xorl	%r10d, %r10d
	xorps	%xmm2, %xmm2
	xorps	%xmm0, %xmm0
.LBB3_16:                               # %.preheader
                                        #   Parent Loop BB3_4 Depth=1
                                        #     Parent Loop BB3_6 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB3_17 Depth 4
	movl	%esi, %edi
	leaq	(%r12,%rdi,4), %rdi
	leal	(%r11,%r10), %r14d
	testl	%r14d, %r14d
	movl	$0, %ebx
	cmovgl	%r14d, %ebx
	cmpl	8(%rsp), %r14d                  # 4-byte Folded Reload
	cmovgel	%ecx, %ebx
	imull	%r15d, %ebx
	xorl	%r14d, %r14d
.LBB3_17:                               #   Parent Loop BB3_4 Depth=1
                                        #     Parent Loop BB3_6 Depth=2
                                        #       Parent Loop BB3_16 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	leal	(%r9,%r14), %eax
	testl	%eax, %eax
	movl	$0, %ebp
	cmovgl	%eax, %ebp
	cmpl	%r15d, %eax
	cmovgel	%edx, %ebp
	addl	%ebx, %ebp
	movss	(%rdi,%r14,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	movslq	%ebp, %rax
	leaq	(%rax,%rax,2), %rax
	movzbl	(%r13,%rax), %ebp
	xorps	%xmm4, %xmm4
	cvtsi2ss	%ebp, %xmm4
	movzbl	1(%r13,%rax), %ebp
	xorps	%xmm5, %xmm5
	cvtsi2ss	%ebp, %xmm5
	mulss	%xmm3, %xmm4
	addss	%xmm4, %xmm1
	mulss	%xmm3, %xmm5
	addss	%xmm5, %xmm2
	movzbl	2(%r13,%rax), %eax
	xorps	%xmm4, %xmm4
	cvtsi2ss	%eax, %xmm4
	mulss	%xmm3, %xmm4
	addss	%xmm4, %xmm0
	incq	%r14
	cmpq	%r14, %r8
	jne	.LBB3_17
# %bb.18:                               # %._crit_edge
                                        #   in Loop: Header=BB3_16 Depth=3
	incq	%r10
	addl	4(%rsp), %esi                   # 4-byte Folded Reload
	cmpq	%r8, %r10
	jne	.LBB3_16
	jmp	.LBB3_8
.LBB3_7:                                #   in Loop: Header=BB3_6 Depth=2
	xorps	%xmm0, %xmm0
	xorps	%xmm2, %xmm2
	xorps	%xmm1, %xmm1
.LBB3_8:                                # %._crit_edge192
                                        #   in Loop: Header=BB3_6 Depth=2
	cvttss2si	%xmm1, %esi
	movq	112(%rsp), %rbx                 # 8-byte Reload
	leaq	(%rbx,%rbx,2), %rdi
	cvttss2si	%xmm2, %r10d
	movq	104(%rsp), %rax                 # 8-byte Reload
	movb	%sil, (%rax,%rdi)
	movb	%r10b, 1(%rax,%rdi)
	cvttss2si	%xmm0, %esi
	movb	%sil, 2(%rax,%rdi)
	incq	%rbx
	incq	%r9
	cmpq	96(%rsp), %rbx                  # 8-byte Folded Reload
	jne	.LBB3_6
.LBB3_9:                                # %._crit_edge198
                                        #   in Loop: Header=BB3_4 Depth=1
	movq	16(%rsp), %rsi                  # 8-byte Reload
	incq	%rsi
	movq	%rsi, %rax
	movq	%rsi, 16(%rsp)                  # 8-byte Spill
	cmpq	88(%rsp), %rsi                  # 8-byte Folded Reload
	jne	.LBB3_4
.LBB3_10:                               # %.loopexit
	movq	56(%rsp), %rdi
.Ltmp65:
	xorl	%esi, %esi
	callq	hipEventRecord
.Ltmp66:
# %bb.11:                               # %_ZN8GpuTimer4StopEv.exit
	movq	56(%rsp), %rdi
.Ltmp68:
	callq	hipEventSynchronize
.Ltmp69:
	movb	1648(%rsp), %bl
# %bb.12:                               # %.noexc
	movq	48(%rsp), %rsi
	movq	56(%rsp), %rdx
.Ltmp70:
	leaq	120(%rsp), %rdi
	callq	hipEventElapsedTime
.Ltmp71:
# %bb.13:
	xorps	%xmm0, %xmm0
	cvtss2sd	120(%rsp), %xmm0
	movl	$.L.str.18, %eax
	movl	$.L.str.19, %esi
	testb	%bl, %bl
	cmovneq	%rax, %rsi
	movl	$.L.str.17, %edi
	movb	$1, %al
	callq	printf
	leaq	48(%rsp), %rdi
	callq	_ZN8GpuTimerD2Ev
	addq	$1592, %rsp                     # imm = 0x638
	.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
.LBB3_22:
	.cfi_def_cfa_offset 1648
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movl	$.L.str.13, %edx
	movl	$208, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %r14
.Ltmp7:
	movl	%ebx, %edi
	callq	hipGetErrorString
.Ltmp8:
	jmp	.LBB3_23
.LBB3_29:
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movl	$.L.str.13, %edx
	movl	$209, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %r14
.Ltmp12:
	movl	%ebx, %edi
	callq	hipGetErrorString
.Ltmp13:
	jmp	.LBB3_23
.LBB3_33:
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movl	$.L.str.13, %edx
	movl	$210, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rbx
.Ltmp17:
	movl	%ebp, %edi
	callq	hipGetErrorString
.Ltmp18:
# %bb.34:
	movl	$.L.str.14, %esi
	movq	%rbx, %rdi
	movl	%ebp, %edx
	jmp	.LBB3_24
.LBB3_38:
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movl	$.L.str.13, %edx
	movl	$213, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rbx
.Ltmp22:
	movl	%r13d, %edi
	callq	hipGetErrorString
.Ltmp23:
# %bb.39:
	movl	$.L.str.14, %esi
	movq	%rbx, %rdi
	movl	%r13d, %edx
	jmp	.LBB3_24
.LBB3_43:
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movl	$.L.str.13, %edx
	movl	$214, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %r14
.Ltmp27:
	movl	%ebx, %edi
	callq	hipGetErrorString
.Ltmp28:
	jmp	.LBB3_23
.LBB3_58:
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movl	$.L.str.13, %edx
	movl	$227, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %r14
.Ltmp47:
	movl	%ebx, %edi
	callq	hipGetErrorString
.Ltmp48:
	jmp	.LBB3_23
.LBB3_64:
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movl	$.L.str.13, %edx
	movl	$230, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %r14
.Ltmp52:
	movl	%ebx, %edi
	callq	hipGetErrorString
.Ltmp53:
	jmp	.LBB3_23
.LBB3_68:
	movq	stderr(%rip), %rdi
	movl	$.L.str.12, %esi
	movl	$.L.str.13, %edx
	movl	$231, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %r14
.Ltmp57:
	movl	%ebx, %edi
	callq	hipGetErrorString
.Ltmp58:
.LBB3_23:
	movl	$.L.str.14, %esi
	movq	%r14, %rdi
	movl	%ebx, %edx
.LBB3_24:
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.LBB3_59:
.Ltmp37:
	jmp	.LBB3_75
.LBB3_25:
.Ltmp4:
	jmp	.LBB3_75
.LBB3_76:
.Ltmp34:
	jmp	.LBB3_75
.LBB3_60:
.Ltmp44:
	jmp	.LBB3_75
.LBB3_74:
.Ltmp72:
	jmp	.LBB3_75
.LBB3_14:
.Ltmp67:
	jmp	.LBB3_75
.LBB3_73:
.Ltmp64:
	jmp	.LBB3_75
.LBB3_69:
.Ltmp59:
	jmp	.LBB3_75
.LBB3_65:
.Ltmp54:
	jmp	.LBB3_75
.LBB3_61:
.Ltmp49:
	jmp	.LBB3_75
.LBB3_44:
.Ltmp29:
	jmp	.LBB3_75
.LBB3_40:
.Ltmp24:
	jmp	.LBB3_75
.LBB3_35:
.Ltmp19:
	jmp	.LBB3_75
.LBB3_30:
.Ltmp14:
	jmp	.LBB3_75
.LBB3_26:
.Ltmp9:
.LBB3_75:
	movq	%rax, %rbx
	leaq	48(%rsp), %rdi
	callq	_ZN8GpuTimerD2Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end3:
	.size	_Z7blurImgP15HIP_vector_typeIhLj3EEiiPfiS1_b4dim3, .Lfunc_end3-_Z7blurImgP15HIP_vector_typeIhLj3EEiiPfiS1_b4dim3
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table3:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp67-.Lfunc_begin0          #     jumps to .Ltmp67
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp2-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp3-.Ltmp2                  #   Call between .Ltmp2 and .Ltmp3
	.uleb128 .Ltmp4-.Lfunc_begin0           #     jumps to .Ltmp4
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp5-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp6-.Ltmp5                  #   Call between .Ltmp5 and .Ltmp6
	.uleb128 .Ltmp9-.Lfunc_begin0           #     jumps to .Ltmp9
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp10-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Ltmp11-.Ltmp10                #   Call between .Ltmp10 and .Ltmp11
	.uleb128 .Ltmp14-.Lfunc_begin0          #     jumps to .Ltmp14
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp15-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp16-.Ltmp15                #   Call between .Ltmp15 and .Ltmp16
	.uleb128 .Ltmp19-.Lfunc_begin0          #     jumps to .Ltmp19
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp20-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp21-.Ltmp20                #   Call between .Ltmp20 and .Ltmp21
	.uleb128 .Ltmp24-.Lfunc_begin0          #     jumps to .Ltmp24
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp25-.Lfunc_begin0          # >> Call Site 8 <<
	.uleb128 .Ltmp26-.Ltmp25                #   Call between .Ltmp25 and .Ltmp26
	.uleb128 .Ltmp29-.Lfunc_begin0          #     jumps to .Ltmp29
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp30-.Lfunc_begin0          # >> Call Site 9 <<
	.uleb128 .Ltmp33-.Ltmp30                #   Call between .Ltmp30 and .Ltmp33
	.uleb128 .Ltmp34-.Lfunc_begin0          #     jumps to .Ltmp34
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp35-.Lfunc_begin0          # >> Call Site 10 <<
	.uleb128 .Ltmp36-.Ltmp35                #   Call between .Ltmp35 and .Ltmp36
	.uleb128 .Ltmp37-.Lfunc_begin0          #     jumps to .Ltmp37
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp38-.Lfunc_begin0          # >> Call Site 11 <<
	.uleb128 .Ltmp43-.Ltmp38                #   Call between .Ltmp38 and .Ltmp43
	.uleb128 .Ltmp44-.Lfunc_begin0          #     jumps to .Ltmp44
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp45-.Lfunc_begin0          # >> Call Site 12 <<
	.uleb128 .Ltmp46-.Ltmp45                #   Call between .Ltmp45 and .Ltmp46
	.uleb128 .Ltmp49-.Lfunc_begin0          #     jumps to .Ltmp49
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp50-.Lfunc_begin0          # >> Call Site 13 <<
	.uleb128 .Ltmp51-.Ltmp50                #   Call between .Ltmp50 and .Ltmp51
	.uleb128 .Ltmp54-.Lfunc_begin0          #     jumps to .Ltmp54
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp55-.Lfunc_begin0          # >> Call Site 14 <<
	.uleb128 .Ltmp56-.Ltmp55                #   Call between .Ltmp55 and .Ltmp56
	.uleb128 .Ltmp59-.Lfunc_begin0          #     jumps to .Ltmp59
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp60-.Lfunc_begin0          # >> Call Site 15 <<
	.uleb128 .Ltmp63-.Ltmp60                #   Call between .Ltmp60 and .Ltmp63
	.uleb128 .Ltmp64-.Lfunc_begin0          #     jumps to .Ltmp64
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp65-.Lfunc_begin0          # >> Call Site 16 <<
	.uleb128 .Ltmp66-.Ltmp65                #   Call between .Ltmp65 and .Ltmp66
	.uleb128 .Ltmp67-.Lfunc_begin0          #     jumps to .Ltmp67
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp68-.Lfunc_begin0          # >> Call Site 17 <<
	.uleb128 .Ltmp71-.Ltmp68                #   Call between .Ltmp68 and .Ltmp71
	.uleb128 .Ltmp72-.Lfunc_begin0          #     jumps to .Ltmp72
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp7-.Lfunc_begin0           # >> Call Site 18 <<
	.uleb128 .Ltmp8-.Ltmp7                  #   Call between .Ltmp7 and .Ltmp8
	.uleb128 .Ltmp9-.Lfunc_begin0           #     jumps to .Ltmp9
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp12-.Lfunc_begin0          # >> Call Site 19 <<
	.uleb128 .Ltmp13-.Ltmp12                #   Call between .Ltmp12 and .Ltmp13
	.uleb128 .Ltmp14-.Lfunc_begin0          #     jumps to .Ltmp14
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp17-.Lfunc_begin0          # >> Call Site 20 <<
	.uleb128 .Ltmp18-.Ltmp17                #   Call between .Ltmp17 and .Ltmp18
	.uleb128 .Ltmp19-.Lfunc_begin0          #     jumps to .Ltmp19
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp22-.Lfunc_begin0          # >> Call Site 21 <<
	.uleb128 .Ltmp23-.Ltmp22                #   Call between .Ltmp22 and .Ltmp23
	.uleb128 .Ltmp24-.Lfunc_begin0          #     jumps to .Ltmp24
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp27-.Lfunc_begin0          # >> Call Site 22 <<
	.uleb128 .Ltmp28-.Ltmp27                #   Call between .Ltmp27 and .Ltmp28
	.uleb128 .Ltmp29-.Lfunc_begin0          #     jumps to .Ltmp29
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp47-.Lfunc_begin0          # >> Call Site 23 <<
	.uleb128 .Ltmp48-.Ltmp47                #   Call between .Ltmp47 and .Ltmp48
	.uleb128 .Ltmp49-.Lfunc_begin0          #     jumps to .Ltmp49
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp52-.Lfunc_begin0          # >> Call Site 24 <<
	.uleb128 .Ltmp53-.Ltmp52                #   Call between .Ltmp52 and .Ltmp53
	.uleb128 .Ltmp54-.Lfunc_begin0          #     jumps to .Ltmp54
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp57-.Lfunc_begin0          # >> Call Site 25 <<
	.uleb128 .Ltmp58-.Ltmp57                #   Call between .Ltmp57 and .Ltmp58
	.uleb128 .Ltmp59-.Lfunc_begin0          #     jumps to .Ltmp59
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp58-.Lfunc_begin0          # >> Call Site 26 <<
	.uleb128 .Lfunc_end3-.Ltmp58            #   Call between .Ltmp58 and .Lfunc_end3
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZN8GpuTimerD2Ev,"axG",@progbits,_ZN8GpuTimerD2Ev,comdat
	.weak	_ZN8GpuTimerD2Ev                # -- Begin function _ZN8GpuTimerD2Ev
	.p2align	1, 0x90
	.type	_ZN8GpuTimerD2Ev,@function
_ZN8GpuTimerD2Ev:                       # @_ZN8GpuTimerD2Ev
.Lfunc_begin1:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception1
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movq	(%rdi), %rdi
.Ltmp73:
	callq	hipEventDestroy
.Ltmp74:
# %bb.1:
	movq	8(%rbx), %rdi
.Ltmp75:
	callq	hipEventDestroy
.Ltmp76:
# %bb.2:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB4_3:
	.cfi_def_cfa_offset 16
.Ltmp77:
	movq	%rax, %rdi
	callq	__clang_call_terminate
.Lfunc_end4:
	.size	_ZN8GpuTimerD2Ev, .Lfunc_end4-_ZN8GpuTimerD2Ev
	.cfi_endproc
	.section	.gcc_except_table._ZN8GpuTimerD2Ev,"aG",@progbits,_ZN8GpuTimerD2Ev,comdat
	.p2align	2, 0x0
GCC_except_table4:
.Lexception1:
	.byte	255                             # @LPStart Encoding = omit
	.byte	3                               # @TType Encoding = udata4
	.uleb128 .Lttbase0-.Lttbaseref0
.Lttbaseref0:
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end1-.Lcst_begin1
.Lcst_begin1:
	.uleb128 .Ltmp73-.Lfunc_begin1          # >> Call Site 1 <<
	.uleb128 .Ltmp76-.Ltmp73                #   Call between .Ltmp73 and .Ltmp76
	.uleb128 .Ltmp77-.Lfunc_begin1          #     jumps to .Ltmp77
	.byte	1                               #   On action: 1
.Lcst_end1:
	.byte	1                               # >> Action Record 1 <<
                                        #   Catch TypeInfo 1
	.byte	0                               #   No further actions
	.p2align	2, 0x0
                                        # >> Catch TypeInfos <<
	.long	0                               # TypeInfo 1
.Lttbase0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.globl	_Z12computeErrorP15HIP_vector_typeIhLj3EES1_i # -- Begin function _Z12computeErrorP15HIP_vector_typeIhLj3EES1_i
	.type	_Z12computeErrorP15HIP_vector_typeIhLj3EES1_i,@function
_Z12computeErrorP15HIP_vector_typeIhLj3EES1_i: # @_Z12computeErrorP15HIP_vector_typeIhLj3EES1_i
	.cfi_startproc
# %bb.0:
                                        # kill: def $edx killed $edx def $rdx
	testl	%edx, %edx
	jle	.LBB5_1
# %bb.3:                                # %.lr.ph.preheader
	movl	%edx, %eax
	leaq	(%rax,%rax,2), %rax
	xorps	%xmm0, %xmm0
	xorl	%ecx, %ecx
	movl	$255, %r8d
.LBB5_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movzbl	(%rdi,%rcx), %r9d
	movzbl	(%rsi,%rcx), %r10d
	subl	%r10d, %r9d
	movl	%r9d, %r10d
	negl	%r10d
	cmovsl	%r9d, %r10d
	andl	%r8d, %r10d
	xorps	%xmm1, %xmm1
	cvtsi2ss	%r10d, %xmm1
	movzbl	1(%rdi,%rcx), %r9d
	movzbl	1(%rsi,%rcx), %r10d
	subl	%r10d, %r9d
	movl	%r9d, %r10d
	negl	%r10d
	cmovsl	%r9d, %r10d
	andl	%r8d, %r10d
	xorps	%xmm2, %xmm2
	cvtsi2ss	%r10d, %xmm2
	addss	%xmm0, %xmm1
	movzbl	2(%rdi,%rcx), %r9d
	movzbl	2(%rsi,%rcx), %r10d
	subl	%r10d, %r9d
	movl	%r9d, %r10d
	negl	%r10d
	cmovsl	%r9d, %r10d
	andl	%r8d, %r10d
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r10d, %xmm0
	addss	%xmm1, %xmm2
	addss	%xmm2, %xmm0
	addq	$3, %rcx
	cmpq	%rcx, %rax
	jne	.LBB5_4
	jmp	.LBB5_2
.LBB5_1:
	xorps	%xmm0, %xmm0
.LBB5_2:                                # %._crit_edge
	leal	(%rdx,%rdx,2), %eax
	xorps	%xmm1, %xmm1
	cvtsi2ss	%eax, %xmm1
	divss	%xmm1, %xmm0
	retq
.Lfunc_end5:
	.size	_Z12computeErrorP15HIP_vector_typeIhLj3EES1_i, .Lfunc_end5-_Z12computeErrorP15HIP_vector_typeIhLj3EES1_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z9concatStrPKcS0_              # -- Begin function _Z9concatStrPKcS0_
	.type	_Z9concatStrPKcS0_,@function
_Z9concatStrPKcS0_:                     # @_Z9concatStrPKcS0_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	callq	strlen
	movq	%rax, %r15
	movq	%rbx, %rdi
	callq	strlen
	leaq	(%r15,%rax), %rdi
	incq	%rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rax, %rdi
	movq	%r14, %rsi
	callq	strcpy
	movq	%r15, %rdi
	movq	%rbx, %rsi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	strcat                          # TAILCALL
.Lfunc_end6:
	.size	_Z9concatStrPKcS0_, .Lfunc_end6-_Z9concatStrPKcS0_
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function 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	$104, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edi, %eax
	andl	$-3, %eax
	cmpl	$4, %eax
	jne	.LBB7_1
# %bb.3:
	movq	%rsi, %r14
	movl	%edi, %ebp
	movq	8(%rsi), %rdi
	leaq	8(%rsp), %r15
	leaq	4(%rsp), %rbx
	leaq	88(%rsp), %rcx
	movq	%r15, %rsi
	movq	%rbx, %rdx
	callq	_Z7readPnmPcRiS0_RP15HIP_vector_typeIhLj3EE
	movl	(%r15), %esi
	movl	(%rbx), %edx
	movl	$.L.str.21, %edi
	xorl	%eax, %eax
	callq	printf
	movq	24(%r14), %rdi
	leaq	100(%rsp), %rbx
	leaq	12(%rsp), %rdx
	leaq	80(%rsp), %rcx
	movq	%rbx, %rsi
	callq	_Z7readPnmPcRiS0_RP15HIP_vector_typeIhLj3EE
	movl	(%rbx), %ebx
	cmpl	(%r15), %ebx
	jne	.LBB7_5
# %bb.4:
	movl	12(%rsp), %r13d
	cmpl	4(%rsp), %r13d
	jne	.LBB7_5
# %bb.6:
	movl	$324, %edi                      # imm = 0x144
	callq	malloc
	movq	%rax, %r15
	xorl	%eax, %eax
	movq	%r15, %rcx
.LBB7_7:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_8 Depth 2
	xorl	%edx, %edx
.LBB7_8:                                #   Parent Loop BB7_7 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$1011500424, (%rcx,%rdx,4)      # imm = 0x3C4A4588
	incq	%rdx
	cmpq	$9, %rdx
	jne	.LBB7_8
# %bb.9:                                #   in Loop: Header=BB7_7 Depth=1
	incq	%rax
	addq	$36, %rcx
	cmpq	$9, %rax
	jne	.LBB7_7
# %bb.10:
	movl	%r13d, %eax
	imull	%ebx, %eax
	cltq
	leaq	(%rax,%rax,2), %rdi
	callq	malloc
	movq	%rax, %r12
	movq	88(%rsp), %rdi
	movabsq	$4294967297, %rax               # imm = 0x100000001
	movq	%rax, 64(%rsp)
	movl	$1, %r10d
	movl	%r10d, 72(%rsp)
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movq	72(%rsp), %rax
	movq	%rdi, 24(%rsp)                  # 8-byte Spill
	movl	%ebx, %esi
	movl	%r13d, %edx
	movq	%r15, 32(%rsp)                  # 8-byte Spill
	movq	%r15, %rcx
	movl	$9, %r8d
	movq	%r12, %r9
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	$0
	.cfi_adjust_cfa_offset 8
	callq	_Z7blurImgP15HIP_vector_typeIhLj3EEiiPfiS1_b4dim3
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movq	80(%rsp), %rsi
	movl	4(%rsp), %edx
	imull	8(%rsp), %edx
	movq	%r12, 56(%rsp)                  # 8-byte Spill
	movq	%r12, %rdi
	movq	%rsi, 48(%rsp)                  # 8-byte Spill
	callq	_Z12computeErrorP15HIP_vector_typeIhLj3EES1_i
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.23, %edi
	movb	$1, %al
	callq	printf
	movl	8(%rsp), %r12d
	movl	4(%rsp), %r13d
	movl	%r13d, %eax
	imull	%r12d, %eax
	cltq
	leaq	(%rax,%rax,2), %rdi
	callq	malloc
	movq	%rax, %rbx
	movl	$32, %eax
	movl	$32, %r15d
	cmpl	$6, %ebp
	jne	.LBB7_12
# %bb.11:
	movq	32(%r14), %rdi
	callq	atoi
	movl	%eax, %r15d
	movq	40(%r14), %rdi
	callq	atoi
.LBB7_12:
	movl	%r15d, 32(%rsp)
	movl	%eax, 36(%rsp)
	movl	$1, %r10d
	movl	%r10d, 40(%rsp)
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movq	40(%rsp), %rax
	movq	24(%rsp), %rdi                  # 8-byte Reload
	movl	%r12d, %esi
	movl	%r13d, %edx
	movq	32(%rsp), %rcx                  # 8-byte Reload
	movl	$9, %r8d
	movq	%rbx, %r9
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	callq	_Z7blurImgP15HIP_vector_typeIhLj3EEiiPfiS1_b4dim3
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movl	4(%rsp), %edx
	imull	8(%rsp), %edx
	movq	%rbx, %rdi
	movq	48(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rsi
	callq	_Z12computeErrorP15HIP_vector_typeIhLj3EES1_i
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.23, %edi
	movb	$1, %al
	callq	printf
	movq	16(%r14), %rdi
	movl	$.L.str.24, %esi
	callq	strtok
	movq	%rax, %r14
	movl	8(%rsp), %ebp
	movl	4(%rsp), %r15d
	movl	$.L.str.25, %esi
	movq	%rax, %rdi
	callq	_Z9concatStrPKcS0_
	movq	56(%rsp), %r13                  # 8-byte Reload
	movq	%r13, %rdi
	movl	%ebp, %esi
	movl	%r15d, %edx
	movq	%rax, %rcx
	callq	_Z8writePnmP15HIP_vector_typeIhLj3EEiiPc
	movl	8(%rsp), %ebp
	movl	4(%rsp), %r15d
	movl	$.L.str.26, %esi
	movq	%r14, %rdi
	callq	_Z9concatStrPKcS0_
	movq	%rbx, %rdi
	movl	%ebp, %esi
	movl	%r15d, %edx
	movq	%rax, %rcx
	callq	_Z8writePnmP15HIP_vector_typeIhLj3EEiiPc
	movq	16(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	24(%rsp), %rdi                  # 8-byte Reload
	callq	free
	xorl	%eax, %eax
	jmp	.LBB7_13
.LBB7_1:
	movl	$.Lstr.1, %edi
	jmp	.LBB7_2
.LBB7_5:
	movl	$.Lstr, %edi
.LBB7_2:
	callq	puts@PLT
	movl	$1, %eax
.LBB7_13:
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	main, .Lfunc_end7-main
	.cfi_endproc
                                        # -- End function
	.section	.text.__clang_call_terminate,"axG",@progbits,__clang_call_terminate,comdat
	.hidden	__clang_call_terminate          # -- Begin function __clang_call_terminate
	.weak	__clang_call_terminate
	.type	__clang_call_terminate,@function
__clang_call_terminate:                 # @__clang_call_terminate
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__cxa_begin_catch
	callq	_ZSt9terminatev
.Lfunc_end8:
	.size	__clang_call_terminate, .Lfunc_end8-__clang_call_terminate
	.cfi_endproc
                                        # -- End function
	.text
	.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	.LBB9_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB9_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_, %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_end9:
	.size	__hip_module_ctor, .Lfunc_end9-__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	.LBB10_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
.LBB10_2:
	retq
.Lfunc_end10:
	.size	__hip_module_dtor, .Lfunc_end10-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"r"
	.size	.L.str, 2

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Cannot read %s\n"
	.size	.L.str.1, 16

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

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%hhu%hhu%hhu"
	.size	.L.str.5, 13

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Cannot write %s\n"
	.size	.L.str.7, 17

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"P3\n%i\n%i\n255\n"
	.size	.L.str.8, 14

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

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

	.type	.L.str.10,@object               # @.str.10
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.10:
	.asciz	"GPU name: %s\n"
	.size	.L.str.10, 14

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"GPU compute capability: %d.%d\n"
	.size	.L.str.11, 31

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Error: %s:%d, "
	.size	.L.str.12, 15

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/hmhuan/PG_GPU/master/assignment/BT01/1612858/bt01_p2.hip"
	.size	.L.str.13, 119

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"code: %d, reason: %s\n"
	.size	.L.str.14, 22

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Sync kernel error: %s\n"
	.size	.L.str.15, 23

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Async kernel error: %s\n"
	.size	.L.str.16, 24

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"Processing time (%s): %f ms\n"
	.size	.L.str.17, 29

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"use device"
	.size	.L.str.18, 11

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"use host"
	.size	.L.str.19, 9

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"Image size (width x height): %i x %i\n\n"
	.size	.L.str.21, 39

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"Error: %f\n\n"
	.size	.L.str.23, 12

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

	.type	.L.str.25,@object               # @.str.25
.L.str.25:
	.asciz	"_host.pnm"
	.size	.L.str.25, 10

	.type	.L.str.26,@object               # @.str.26
.L.str.26:
	.asciz	"_device.pnm"
	.size	.L.str.26, 12

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_"
	.size	.L__unnamed_1, 51

	.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	"The shape of the correct output image is invalid"
	.size	.Lstr, 49

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"The number of arguments is invalid"
	.size	.Lstr.1, 35

	.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 _Z28__device_stub__blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_ ; -- Begin function _Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
	.globl	_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
	.p2align	8
	.type	_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_,@function
_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_: ; @_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b64 s[4:5], s[0:1], 0x8
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s2, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s3, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s4, v0
	v_cmp_gt_i32_e64 s2, s5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_8
; %bb.1:
	s_load_b32 s12, s[0:1], 0x18
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v3, 0
	v_mov_b32_e32 v4, 0
	s_mov_b32 s3, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s12, 1
	s_cbranch_scc1 .LBB0_7
; %bb.2:                                ; %.preheader.lr.ph
	s_clause 0x1
	s_load_b64 s[6:7], s[0:1], 0x0
	s_load_b64 s[8:9], s[0:1], 0x10
	s_lshr_b32 s2, s12, 1
	v_dual_mov_b32 v3, 0 :: v_dual_mov_b32 v6, 0
	v_subrev_nc_u32_e32 v2, s2, v1
	v_subrev_nc_u32_e32 v4, s2, v0
	v_mov_b32_e32 v5, 0
	s_add_i32 s13, s5, -1
	s_add_i32 s14, s4, -1
	s_mov_b32 s2, s3
	s_mov_b32 s15, s3
.LBB0_3:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_nc_u32_e32 v7, s15, v2
	s_lshl_b64 s[10:11], s[2:3], 2
	s_mov_b32 s16, 0
	s_waitcnt lgkmcnt(0)
	s_add_u32 s10, s8, s10
	s_addc_u32 s11, s9, s11
	v_max_i32_e32 v7, 0, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e32 vcc_lo, s5, v7
	v_cndmask_b32_e32 v7, s13, v7, vcc_lo
	v_mul_lo_u32 v7, v7, s4
.LBB0_4:                                ;   Parent Loop BB0_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v8, s16, v4
	s_add_i32 s16, s16, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_max_i32_e32 v8, 0, v8
	v_cmp_gt_i32_e32 vcc_lo, s4, v8
	v_cndmask_b32_e32 v8, s14, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v10, v8, v7
	v_mad_i64_i32 v[8:9], null, v10, 3, s[6:7]
	s_clause 0x1
	global_load_u16 v10, v[8:9], off
	global_load_u8 v8, v[8:9], off offset:2
	s_load_b32 s17, s[10:11], 0x0
	s_add_u32 s10, s10, 4
	s_addc_u32 s11, s11, 0
	s_cmp_eq_u32 s12, s16
	s_waitcnt vmcnt(1)
	v_cvt_f32_ubyte0_e32 v9, v10
	v_cvt_f32_ubyte1_e32 v10, v10
	s_waitcnt vmcnt(0)
	v_cvt_f32_ubyte0_e32 v8, v8
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_fmac_f32 v3, s17, v9 :: v_dual_fmac_f32 v6, s17, v10
	v_fmac_f32_e32 v5, s17, v8
	s_cbranch_scc0 .LBB0_4
; %bb.5:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_add_i32 s15, s15, 1
	s_add_i32 s2, s2, s12
	s_cmp_eq_u32 s15, s12
	s_cbranch_scc0 .LBB0_3
; %bb.6:                                ; %._crit_edge82.loopexit
	v_cvt_i32_f32_e32 v2, v3
	v_cvt_i32_f32_e32 v3, v6
	v_cvt_i32_f32_e32 v4, v5
.LBB0_7:                                ; %._crit_edge82
	s_load_b64 s[0:1], s[0:1], 0x20
	v_mad_u64_u32 v[5:6], null, v1, s4, v[0:1]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b16 v3, 8, v3
	v_or_b32_e32 v2, v2, v3
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_3)
	v_mad_i64_i32 v[0:1], null, v5, 3, s[0:1]
	s_clause 0x1
	global_store_b8 v[0:1], v4, off offset:2
	global_store_b16 v[0:1], v2, off
.LBB0_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 11
		.amdhsa_next_free_sgpr 18
		.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	_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_, .Lfunc_end0-_Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 484
; NumSgprs: 20
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 11
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z13blurImgKernelP15HIP_vector_typeIhLj3EEiiPfiS1_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     11
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
