#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <ctime>
#include <algorithm>

#define Color uchar4

float4 Sum(float4 a, Color b, float coef)
{
	return { a.x + (float)b.x * coef,
		a.y + (float)b.y * coef,
		a.z + (float)b.z * coef,
		a.w + (float)b.w * coef };
}

Color ToColor(float4 a, float normalizeValue)
{
	return { (unsigned char)(a.x / normalizeValue),
		(unsigned char)(a.y / normalizeValue),
		(unsigned char)(a.z / normalizeValue),
		(unsigned char)(a.w / normalizeValue) };
}

int GetCoordinate(int x, int y, int w, int h)
{
	int x_n = std::max(0, std::min(w - 1, x));
	int y_n = std::max(0, std::min(h - 1, y));

	return y_n * w + x_n;
}

void Kernel(Color* out, int w, int h, int radius, bool isX)
{
	float PI = 3.14159265359;

	Color c;
	float4 newColor;

	float r = radius != 0
		? radius
		: 1;
	float sum = 0;
	float coef = 0;

	int i, j, k;

	for (i = 0; i < h; i++)
	{
		for (j = 0; j < w; j++)
		{
			newColor = { 0,0,0,0 };
			sum = 0;

			for (k = -radius; k <= radius; k++)
			{
				int x = std::max(0, std::min(w - 1, j));
				int y = std::max(0, std::min(h - 1, i));

				c = isX
					? out[GetCoordinate(j + k, i, w, h)]
					: out[GetCoordinate(j, i + k, w, h)];
				coef = exp(-(float)(k * k) / (2 * r * r)) / (r * sqrt(2 * PI));

				newColor = Sum(newColor,
					c,
					coef);
				sum += coef;
			}

			out[i * w + j] = ToColor(newColor, sum);
		}
	}
}

void GetFilteredImage(Color* result, int width, int height, int radius)
{
	//Y
	Kernel(result, width, height, radius, false);

	//X
	Kernel(result, width, height, radius, true);
}

int main()
{
	std::string inFile;
	std::string outFile;
	int radius;

	std::cin >> inFile >> outFile >> radius;
	radius /= 10000.0;
	auto* file = fopen(inFile.c_str(), "rb");

	int width, height;
	fread(&width, sizeof(int), 1, file);
	fread(&height, sizeof(int), 1, file);

	auto hostMap = (Color*)malloc(sizeof(Color) * width * height);
	fread(hostMap, sizeof(Color), width * height, file);

	fclose(file);

	clock_t begin = clock();
	GetFilteredImage(hostMap, width, height, radius);
	clock_t end = clock();

	std::cout << double(end - begin) / CLOCKS_PER_SEC << std::endl;

	file = fopen(outFile.c_str(), "wb");

	fwrite(&width, sizeof(int), 1, file);
	fwrite(&height, sizeof(int), 1, file);
	fwrite(hostMap, sizeof(Color), width * height, file);

	fclose(file);

	free(hostMap);
}

	.file	"tmpxft_0032a988_00000000-6_kernelCPU.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3898:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3898:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z3Sum6float46uchar4f
	.type	_Z3Sum6float46uchar4f, @function
_Z3Sum6float46uchar4f:
.LFB3889:
	.cfi_startproc
	endbr64
	movzbl	%dil, %edx
	movq	%xmm0, %rax
	movq	%xmm1, %rsi
	movl	%edi, %ecx
	cvtsi2ssl	%edx, %xmm0
	movd	%eax, %xmm1
	movzbl	%ch, %edx
	shrq	$32, %rax
	movd	%eax, %xmm4
	shrl	$24, %ecx
	movaps	%xmm2, %xmm3
	mulss	%xmm2, %xmm0
	addss	%xmm1, %xmm0
	cvtsi2ssl	%edx, %xmm1
	movd	%xmm0, %eax
	mulss	%xmm2, %xmm1
	addss	%xmm4, %xmm1
	movq	%xmm1, %rdx
	movd	%esi, %xmm1
	shrq	$32, %rsi
	salq	$32, %rdx
	movd	%esi, %xmm5
	orq	%rax, %rdx
	movl	%edi, %eax
	shrl	$16, %eax
	movzbl	%al, %eax
	cvtsi2ssl	%eax, %xmm0
	mulss	%xmm2, %xmm0
	cvtsi2ssl	%ecx, %xmm2
	mulss	%xmm3, %xmm2
	addss	%xmm1, %xmm0
	movd	%xmm0, %eax
	movq	%rdx, %xmm0
	addss	%xmm5, %xmm2
	movq	%xmm2, %rcx
	salq	$32, %rcx
	orq	%rcx, %rax
	movq	%rax, %xmm1
	ret
	.cfi_endproc
.LFE3889:
	.size	_Z3Sum6float46uchar4f, .-_Z3Sum6float46uchar4f
	.globl	_Z7ToColor6float4f
	.type	_Z7ToColor6float4f, @function
_Z7ToColor6float4f:
.LFB3890:
	.cfi_startproc
	endbr64
	movq	%xmm0, %rax
	movq	%xmm1, %rcx
	divss	%xmm2, %xmm0
	shrq	$32, %rax
	shrq	$32, %rcx
	cvttss2sil	%xmm0, %esi
	movd	%eax, %xmm0
	divss	%xmm2, %xmm0
	movzbl	%sil, %edx
	cvttss2sil	%xmm0, %eax
	movaps	%xmm1, %xmm0
	divss	%xmm2, %xmm0
	movb	%al, %dh
	movzwl	%dx, %eax
	cvttss2sil	%xmm0, %esi
	movd	%ecx, %xmm0
	divss	%xmm2, %xmm0
	movzbl	%sil, %esi
	sall	$16, %esi
	orl	%esi, %eax
	cvttss2sil	%xmm0, %edx
	sall	$24, %edx
	orl	%edx, %eax
	ret
	.cfi_endproc
.LFE3890:
	.size	_Z7ToColor6float4f, .-_Z7ToColor6float4f
	.globl	_Z13GetCoordinateiiii
	.type	_Z13GetCoordinateiiii, @function
_Z13GetCoordinateiiii:
.LFB3891:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movl	%esi, 8(%rsp)
	leal	-1(%rdx), %esi
	movl	%edi, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	movl	%esi, 16(%rsp)
	leaq	16(%rsp), %rax
	cmpl	%edi, %esi
	jle	.L5
	leaq	12(%rsp), %rax
.L5:
	xorl	%esi, %esi
	cmpl	$0, (%rax)
	movl	%esi, 20(%rsp)
	jg	.L6
	leaq	20(%rsp), %rax
.L6:
	decl	%ecx
	movl	(%rax), %esi
	leaq	8(%rsp), %rax
	movl	%ecx, 16(%rsp)
	cmpl	8(%rsp), %ecx
	jg	.L7
	leaq	16(%rsp), %rax
.L7:
	xorl	%ecx, %ecx
	cmpl	$0, (%rax)
	movl	%ecx, 20(%rsp)
	jg	.L8
	leaq	20(%rsp), %rax
.L8:
	imull	(%rax), %edx
	leal	(%rdx,%rsi), %eax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3891:
	.size	_Z13GetCoordinateiiii, .-_Z13GetCoordinateiiii
	.globl	_Z6KernelP6uchar4iiib
	.type	_Z6KernelP6uchar4iiib, @function
_Z6KernelP6uchar4iiib:
.LFB3892:
	.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
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movss	.LC0(%rip), %xmm3
	movl	%esi, 8(%rsp)
	movl	%edx, 32(%rsp)
	movb	%r8b, 43(%rsp)
	movss	%xmm3, 4(%rsp)
	testl	%ecx, %ecx
	je	.L16
	cvtsi2ssl	%ecx, %xmm4
	movss	%xmm4, 4(%rsp)
.L16:
	xorl	%edx, %edx
	xorl	%r14d, %r14d
	movl	%edx, 36(%rsp)
.L17:
	cmpl	%r14d, 32(%rsp)
	jle	.L23
	movslq	36(%rsp), %rax
	xorl	%r12d, %r12d
	leaq	0(%r13,%rax,4), %r15
.L24:
	cmpl	%r12d, 8(%rsp)
	jle	.L28
	xorl	%eax, %eax
	movl	$0x00000000, 12(%rsp)
	movl	%ebp, %ebx
	movq	%rax, 16(%rsp)
	negl	%ebx
	movq	%rax, 24(%rsp)
.L18:
	cmpl	%ebp, %ebx
	jg	.L29
	cmpb	$0, 43(%rsp)
	je	.L19
	movl	32(%rsp), %ecx
	movl	8(%rsp), %edx
	leal	(%r12,%rbx), %edi
	movl	%r14d, %esi
	jmp	.L27
.L19:
	movl	32(%rsp), %ecx
	movl	8(%rsp), %edx
	leal	(%rbx,%r14), %esi
	movl	%r12d, %edi
.L27:
	call	_Z13GetCoordinateiiii
	movss	4(%rsp), %xmm1
	cltq
	leaq	0(%r13,%rax,4), %rax
	addss	%xmm1, %xmm1
	mulss	4(%rsp), %xmm1
	movl	(%rax), %edi
	movl	%ebx, %eax
	imull	%ebx, %eax
	incl	%ebx
	movl	%edi, 44(%rsp)
	cvtsi2ssl	%eax, %xmm0
	xorps	.LC2(%rip), %xmm0
	divss	%xmm1, %xmm0
	call	expf@PLT
	movq	24(%rsp), %xmm1
	movl	44(%rsp), %edi
	movaps	%xmm0, %xmm6
	movss	4(%rsp), %xmm0
	mulss	.LC3(%rip), %xmm0
	divss	%xmm0, %xmm6
	movq	16(%rsp), %xmm0
	movaps	%xmm6, %xmm2
	call	_Z3Sum6float46uchar4f
	addss	12(%rsp), %xmm6
	movq	%xmm0, 16(%rsp)
	movq	%xmm1, 24(%rsp)
	movss	%xmm6, 12(%rsp)
	jmp	.L18
.L29:
	movss	12(%rsp), %xmm2
	movq	16(%rsp), %xmm0
	incl	%r12d
	addq	$4, %r15
	movq	24(%rsp), %xmm1
	call	_Z7ToColor6float4f
	movl	%eax, -4(%r15)
	jmp	.L24
.L28:
	movl	8(%rsp), %edx
	incl	%r14d
	addl	%edx, 36(%rsp)
	jmp	.L17
.L23:
	addq	$56, %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
.LFE3892:
	.size	_Z6KernelP6uchar4iiib, .-_Z6KernelP6uchar4iiib
	.globl	_Z16GetFilteredImageP6uchar4iii
	.type	_Z16GetFilteredImageP6uchar4iii, @function
_Z16GetFilteredImageP6uchar4iii:
.LFB3893:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%r8d, %r8d
	movl	%ecx, 28(%rsp)
	movl	%edx, 24(%rsp)
	movl	%esi, 20(%rsp)
	movq	%rdi, 8(%rsp)
	call	_Z6KernelP6uchar4iiib
	movl	28(%rsp), %ecx
	movl	24(%rsp), %edx
	movl	$1, %r8d
	movl	20(%rsp), %esi
	movq	8(%rsp), %rdi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	_Z6KernelP6uchar4iiib
	.cfi_endproc
.LFE3893:
	.size	_Z16GetFilteredImageP6uchar4iii, .-_Z16GetFilteredImageP6uchar4iii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC5:
	.string	"rb"
.LC7:
	.string	"wb"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3894:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3894
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%edx, %edx
	leaq	_ZSt3cin(%rip), %rdi
	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	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	leaq	40(%rsp), %r12
	movb	$0, 56(%rsp)
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	movq	%r12, %rsi
	leaq	72(%rsp), %r13
	movq	%rax, 48(%rsp)
	leaq	88(%rsp), %rax
	movq	%rax, 72(%rsp)
	movq	%rdx, 80(%rsp)
	movb	$0, 88(%rsp)
.LEHB0:
	call	_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE@PLT
	movq	%rax, %rdi
	movq	%r13, %rsi
	call	_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE@PLT
	movq	%rax, %rdi
	leaq	28(%rsp), %rsi
	call	_ZNSirsERi@PLT
	cvtsi2sdl	28(%rsp), %xmm0
	divsd	.LC4(%rip), %xmm0
	movq	40(%rsp), %rdi
	leaq	.LC5(%rip), %rsi
	cvttsd2sil	%xmm0, %eax
	movl	%eax, 28(%rsp)
	call	fopen@PLT
	leaq	32(%rsp), %r15
	movq	%rax, %r8
	movl	$1, %ecx
	movq	%rax, %rbp
	movl	$4, %edx
	movl	$4, %esi
	movq	%r15, %rdi
	call	__fread_chk@PLT
	leaq	36(%rsp), %r14
	movq	%rbp, %r8
	movl	$1, %ecx
	movl	$4, %edx
	movl	$4, %esi
	movq	%r14, %rdi
	call	__fread_chk@PLT
	movslq	32(%rsp), %rcx
	movslq	36(%rsp), %rax
	imulq	%rax, %rcx
	leaq	0(,%rcx,4), %rsi
	movq	%rcx, 8(%rsp)
	movq	%rsi, %rdi
	movq	%rsi, (%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rcx
	movq	(%rsp), %rsi
	movq	%rbp, %r8
	movl	$4, %edx
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	__fread_chk@PLT
	movq	%rbp, %rdi
	call	fclose@PLT
	call	clock@PLT
	movl	28(%rsp), %ecx
	movl	36(%rsp), %edx
	movq	%rbx, %rdi
	movl	32(%rsp), %esi
	movq	%rax, %rbp
	call	_Z16GetFilteredImageP6uchar4iii
	call	clock@PLT
	leaq	_ZSt4cout(%rip), %rdi
	subq	%rbp, %rax
	cvtsi2sdq	%rax, %xmm0
	divsd	.LC6(%rip), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	72(%rsp), %rdi
	leaq	.LC7(%rip), %rsi
	call	fopen@PLT
	movq	%rax, %rcx
	movl	$1, %edx
	movl	$4, %esi
	movq	%r15, %rdi
	movq	%rax, %rbp
	call	fwrite@PLT
	movq	%rbp, %rcx
	movl	$1, %edx
	movl	$4, %esi
	movq	%r14, %rdi
	call	fwrite@PLT
	movl	32(%rsp), %edx
	imull	36(%rsp), %edx
	movq	%rbp, %rcx
	movq	%rbx, %rdi
	movl	$4, %esi
	movslq	%edx, %rdx
	call	fwrite@PLT
	movq	%rbp, %rdi
	call	fclose@PLT
.LEHE0:
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	%r12, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	jmp	.L37
.L36:
	endbr64
	movq	%rax, %rbx
.L33:
	movq	%r13, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	%r12, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L37
	movq	%rbx, %rdi
.LEHB1:
	call	_Unwind_Resume@PLT
.LEHE1:
.L37:
	call	__stack_chk_fail@PLT
.L35:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3894:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3894:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3894-.LLSDACSB3894
.LLSDACSB3894:
	.uleb128 .LEHB0-.LFB3894
	.uleb128 .LEHE0-.LEHB0
	.uleb128 .L36-.LFB3894
	.uleb128 0
	.uleb128 .LEHB1-.LFB3894
	.uleb128 .LEHE1-.LEHB1
	.uleb128 0
	.uleb128 0
.LLSDACSE3894:
	.section	.text.startup
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3921:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3921:
	.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
.LC0:
	.long	1065353216
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4
	.align 4
.LC3:
	.long	1075866777
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	0
	.long	1086556160
	.align 8
.LC6:
	.long	0
	.long	1093567616
	.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 <stdlib.h>
#include <iostream>
#include <ctime>
#include <algorithm>

#define Color uchar4

float4 Sum(float4 a, Color b, float coef)
{
	return { a.x + (float)b.x * coef,
		a.y + (float)b.y * coef,
		a.z + (float)b.z * coef,
		a.w + (float)b.w * coef };
}

Color ToColor(float4 a, float normalizeValue)
{
	return { (unsigned char)(a.x / normalizeValue),
		(unsigned char)(a.y / normalizeValue),
		(unsigned char)(a.z / normalizeValue),
		(unsigned char)(a.w / normalizeValue) };
}

int GetCoordinate(int x, int y, int w, int h)
{
	int x_n = std::max(0, std::min(w - 1, x));
	int y_n = std::max(0, std::min(h - 1, y));

	return y_n * w + x_n;
}

void Kernel(Color* out, int w, int h, int radius, bool isX)
{
	float PI = 3.14159265359;

	Color c;
	float4 newColor;

	float r = radius != 0
		? radius
		: 1;
	float sum = 0;
	float coef = 0;

	int i, j, k;

	for (i = 0; i < h; i++)
	{
		for (j = 0; j < w; j++)
		{
			newColor = { 0,0,0,0 };
			sum = 0;

			for (k = -radius; k <= radius; k++)
			{
				int x = std::max(0, std::min(w - 1, j));
				int y = std::max(0, std::min(h - 1, i));

				c = isX
					? out[GetCoordinate(j + k, i, w, h)]
					: out[GetCoordinate(j, i + k, w, h)];
				coef = exp(-(float)(k * k) / (2 * r * r)) / (r * sqrt(2 * PI));

				newColor = Sum(newColor,
					c,
					coef);
				sum += coef;
			}

			out[i * w + j] = ToColor(newColor, sum);
		}
	}
}

void GetFilteredImage(Color* result, int width, int height, int radius)
{
	//Y
	Kernel(result, width, height, radius, false);

	//X
	Kernel(result, width, height, radius, true);
}

int main()
{
	std::string inFile;
	std::string outFile;
	int radius;

	std::cin >> inFile >> outFile >> radius;
	radius /= 10000.0;
	auto* file = fopen(inFile.c_str(), "rb");

	int width, height;
	fread(&width, sizeof(int), 1, file);
	fread(&height, sizeof(int), 1, file);

	auto hostMap = (Color*)malloc(sizeof(Color) * width * height);
	fread(hostMap, sizeof(Color), width * height, file);

	fclose(file);

	clock_t begin = clock();
	GetFilteredImage(hostMap, width, height, radius);
	clock_t end = clock();

	std::cout << double(end - begin) / CLOCKS_PER_SEC << std::endl;

	file = fopen(outFile.c_str(), "wb");

	fwrite(&width, sizeof(int), 1, file);
	fwrite(&height, sizeof(int), 1, file);
	fwrite(hostMap, sizeof(Color), width * height, file);

	fclose(file);

	free(hostMap);
}

	.text
	.file	"kernelCPU.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z3Sum15HIP_vector_typeIfLj4EES_IhLj4EEf # -- Begin function _Z3Sum15HIP_vector_typeIfLj4EES_IhLj4EEf
	.type	_Z3Sum15HIP_vector_typeIfLj4EES_IhLj4EEf,@function
_Z3Sum15HIP_vector_typeIfLj4EES_IhLj4EEf: # @_Z3Sum15HIP_vector_typeIfLj4EES_IhLj4EEf
	.cfi_startproc
# %bb.0:
	movl	%edi, %edx
	shrl	$8, %edx
	movl	%edi, %ecx
	shrl	$16, %ecx
	movl	%edi, %eax
	shrl	$24, %eax
	movq	%xmm0, %rsi
	movd	%esi, %xmm3
	movl	$255, %r8d
	andl	%r8d, %edi
	xorps	%xmm0, %xmm0
	cvtsi2ss	%edi, %xmm0
	mulss	%xmm2, %xmm0
	addss	%xmm3, %xmm0
	shrq	$32, %rsi
	movd	%esi, %xmm3
	andl	%r8d, %edx
	cvtsi2ss	%edx, %xmm4
	mulss	%xmm2, %xmm4
	addss	%xmm3, %xmm4
	unpcklps	%xmm4, %xmm0                    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
	movq	%xmm1, %rdx
	movd	%edx, %xmm3
	andl	%r8d, %ecx
	xorps	%xmm1, %xmm1
	cvtsi2ss	%ecx, %xmm1
	mulss	%xmm2, %xmm1
	addss	%xmm3, %xmm1
	shrq	$32, %rdx
	movd	%edx, %xmm3
	xorps	%xmm4, %xmm4
	cvtsi2ss	%eax, %xmm4
	mulss	%xmm2, %xmm4
	addss	%xmm3, %xmm4
	unpcklps	%xmm4, %xmm1                    # xmm1 = xmm1[0],xmm4[0],xmm1[1],xmm4[1]
	retq
.Lfunc_end0:
	.size	_Z3Sum15HIP_vector_typeIfLj4EES_IhLj4EEf, .Lfunc_end0-_Z3Sum15HIP_vector_typeIfLj4EES_IhLj4EEf
	.cfi_endproc
                                        # -- End function
	.globl	_Z7ToColor15HIP_vector_typeIfLj4EEf # -- Begin function _Z7ToColor15HIP_vector_typeIfLj4EEf
	.type	_Z7ToColor15HIP_vector_typeIfLj4EEf,@function
_Z7ToColor15HIP_vector_typeIfLj4EEf:    # @_Z7ToColor15HIP_vector_typeIfLj4EEf
	.cfi_startproc
# %bb.0:
	movq	%xmm0, %rax
	movd	%eax, %xmm0
	divss	%xmm2, %xmm0
	cvttss2si	%xmm0, %ecx
	shrq	$32, %rax
	movd	%eax, %xmm0
	divss	%xmm2, %xmm0
	cvttss2si	%xmm0, %edx
	movq	%xmm1, %rax
	movd	%eax, %xmm0
	divss	%xmm2, %xmm0
	cvttss2si	%xmm0, %esi
	shrq	$32, %rax
	movd	%eax, %xmm0
	divss	%xmm2, %xmm0
	cvttss2si	%xmm0, %eax
	movl	$255, %edi
	andl	%edi, %ecx
	andl	%edi, %edx
	shll	$8, %edx
	orl	%ecx, %edx
	andl	%edi, %esi
	shll	$16, %esi
	orl	%edx, %esi
	shll	$24, %eax
	orl	%esi, %eax
	retq
.Lfunc_end1:
	.size	_Z7ToColor15HIP_vector_typeIfLj4EEf, .Lfunc_end1-_Z7ToColor15HIP_vector_typeIfLj4EEf
	.cfi_endproc
                                        # -- End function
	.globl	_Z13GetCoordinateiiii           # -- Begin function _Z13GetCoordinateiiii
	.type	_Z13GetCoordinateiiii,@function
_Z13GetCoordinateiiii:                  # @_Z13GetCoordinateiiii
	.cfi_startproc
# %bb.0:
                                        # kill: def $ecx killed $ecx def $rcx
                                        # kill: def $edx killed $edx def $rdx
	leal	-1(%rdx), %r8d
	cmpl	%edi, %r8d
	cmovgel	%edi, %r8d
	xorl	%edi, %edi
	testl	%r8d, %r8d
	cmovlel	%edi, %r8d
	leal	-1(%rcx), %eax
	cmpl	%esi, %eax
	cmovgel	%esi, %eax
	testl	%eax, %eax
	cmovlel	%edi, %eax
	imull	%edx, %eax
	addl	%r8d, %eax
	retq
.Lfunc_end2:
	.size	_Z13GetCoordinateiiii, .Lfunc_end2-_Z13GetCoordinateiiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z6KernelP15HIP_vector_typeIhLj4EEiiib
.LCPI3_0:
	.quad	0x40040d9324a48138              # double 2.5066283095076436
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI3_1:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.text
	.globl	_Z6KernelP15HIP_vector_typeIhLj4EEiiib
	.type	_Z6KernelP15HIP_vector_typeIhLj4EEiiib,@function
_Z6KernelP15HIP_vector_typeIhLj4EEiiib: # @_Z6KernelP15HIP_vector_typeIhLj4EEiiib
	.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	$136, %rsp
	.cfi_def_cfa_offset 192
	.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	%r8d, 56(%rsp)                  # 4-byte Spill
                                        # kill: def $ecx killed $ecx def $rcx
	movq	%rcx, 64(%rsp)                  # 8-byte Spill
                                        # kill: def $esi killed $esi def $rsi
	movq	%rsi, 16(%rsp)                  # 8-byte Spill
	movq	%rdi, 72(%rsp)                  # 8-byte Spill
	testl	%edx, %edx
	jle	.LBB3_13
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %esi
	movq	64(%rsp), %rcx                  # 8-byte Reload
	cmpl	$1, %ecx
	movl	%ecx, %eax
	adcl	$0, %eax
	cvtsi2ss	%eax, %xmm0
	movl	%ecx, %eax
	negl	%eax
	movl	%eax, 44(%rsp)                  # 4-byte Spill
	movq	16(%rsp), %rax                  # 8-byte Reload
	leal	-1(%rax), %edx
	movl	%edx, 12(%rsp)                  # 4-byte Spill
	movaps	%xmm0, %xmm1
	addss	%xmm0, %xmm1
	mulss	%xmm0, %xmm1
	movss	%xmm1, 52(%rsp)                 # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI3_0(%rip), %xmm0
	movsd	%xmm0, 104(%rsp)                # 8-byte Spill
	movl	%esi, %edx
	movq	%rdx, 80(%rsp)                  # 8-byte Spill
	decl	%esi
	movl	%esi, 8(%rsp)                   # 4-byte Spill
	movl	%eax, %eax
	movq	%rax, 88(%rsp)                  # 8-byte Spill
	leal	1(,%rcx,2), %eax
	movl	%eax, 40(%rsp)                  # 4-byte Spill
	movl	$255, %r15d
	xorl	%eax, %eax
	movq	%rax, 24(%rsp)                  # 8-byte Spill
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
                                        #       Child Loop BB3_7 Depth 3
	cmpl	$0, 16(%rsp)                    # 4-byte Folded Reload
	jle	.LBB3_12
# %bb.3:                                # %.lr.ph59
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	8(%rsp), %eax                   # 4-byte Reload
	movq	24(%rsp), %rdx                  # 8-byte Reload
	cmpl	%edx, %eax
	movl	%edx, %esi
	cmovll	%eax, %esi
	testl	%esi, %esi
	movl	$0, %eax
	cmovlel	%eax, %esi
	movq	16(%rsp), %rcx                  # 8-byte Reload
	imull	%ecx, %esi
	movl	%esi, 48(%rsp)                  # 4-byte Spill
	movl	%edx, %eax
	imull	%ecx, %eax
	movq	72(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,4), %rax
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	xorl	%eax, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
.LBB3_4:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_7 Depth 3
	cmpl	$0, 64(%rsp)                    # 4-byte Folded Reload
	js	.LBB3_5
# %bb.6:                                # %.lr.ph
                                        #   in Loop: Header=BB3_4 Depth=2
	movl	12(%rsp), %eax                  # 4-byte Reload
	movq	32(%rsp), %rcx                  # 8-byte Reload
	cmpl	%ecx, %eax
	movl	%ecx, %ebx
	cmovll	%eax, %ebx
	testl	%ebx, %ebx
	movl	$0, %eax
	cmovlel	%eax, %ebx
	xorps	%xmm1, %xmm1
	xorps	%xmm4, %xmm4
	movl	40(%rsp), %ebp                  # 4-byte Reload
	xorl	%r13d, %r13d
	movl	44(%rsp), %eax                  # 4-byte Reload
	movl	%eax, %r12d
.LBB3_7:                                #   Parent Loop BB3_2 Depth=1
                                        #     Parent Loop BB3_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	cmpb	$0, 56(%rsp)                    # 1-byte Folded Reload
	movss	%xmm1, 60(%rsp)                 # 4-byte Spill
	movaps	%xmm4, 112(%rsp)                # 16-byte Spill
	je	.LBB3_9
# %bb.8:                                #   in Loop: Header=BB3_7 Depth=3
	movq	32(%rsp), %rax                  # 8-byte Reload
	addl	%r12d, %eax
	movl	12(%rsp), %ecx                  # 4-byte Reload
	cmpl	%eax, %ecx
	cmovll	%ecx, %eax
	testl	%eax, %eax
	movl	$0, %ecx
	cmovlel	%ecx, %eax
	addl	48(%rsp), %eax                  # 4-byte Folded Reload
	jmp	.LBB3_10
.LBB3_9:                                #   in Loop: Header=BB3_7 Depth=3
	movq	24(%rsp), %rax                  # 8-byte Reload
	addl	%r12d, %eax
	movl	8(%rsp), %ecx                   # 4-byte Reload
	cmpl	%eax, %ecx
	cmovll	%ecx, %eax
	testl	%eax, %eax
	movl	$0, %ecx
	cmovlel	%ecx, %eax
	imull	16(%rsp), %eax                  # 4-byte Folded Reload
	addl	%ebx, %eax
.LBB3_10:                               #   in Loop: Header=BB3_7 Depth=3
	cltq
	movl	%r12d, %ecx
	imull	%r12d, %ecx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ecx, %xmm0
	movq	72(%rsp), %rcx                  # 8-byte Reload
	movl	(%rcx,%rax,4), %r14d
	xorps	.LCPI3_1(%rip), %xmm0
	divss	52(%rsp), %xmm0                 # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	callq	exp
	divsd	104(%rsp), %xmm0                # 8-byte Folded Reload
	cvtsd2ss	%xmm0, %xmm0
	movl	%r14d, %edx
	shrl	$8, %edx
	movl	%r14d, %ecx
	shrl	$16, %ecx
	movl	%r14d, %eax
	shrl	$24, %eax
	andl	%r15d, %r14d
	xorps	%xmm1, %xmm1
	cvtsi2ss	%r14d, %xmm1
	movd	%r13d, %xmm2
	mulss	%xmm0, %xmm1
	addss	%xmm2, %xmm1
	shrq	$32, %r13
	andl	%r15d, %edx
	xorps	%xmm2, %xmm2
	cvtsi2ss	%edx, %xmm2
	movd	%r13d, %xmm3
	mulss	%xmm0, %xmm2
	addss	%xmm3, %xmm2
	movdqa	112(%rsp), %xmm3                # 16-byte Reload
	movq	%xmm3, %rdx
	andl	%r15d, %ecx
	xorps	%xmm4, %xmm4
	cvtsi2ss	%ecx, %xmm4
	unpcklps	%xmm2, %xmm1                    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
	movd	%edx, %xmm2
	mulss	%xmm0, %xmm4
	addss	%xmm2, %xmm4
	shrq	$32, %rdx
	xorps	%xmm2, %xmm2
	cvtsi2ss	%eax, %xmm2
	movd	%edx, %xmm3
	mulss	%xmm0, %xmm2
	addss	%xmm3, %xmm2
	unpcklps	%xmm2, %xmm4                    # xmm4 = xmm4[0],xmm2[0],xmm4[1],xmm2[1]
	movq	%xmm1, %r13
	movss	60(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm1
	incl	%r12d
	decl	%ebp
	jne	.LBB3_7
	jmp	.LBB3_11
.LBB3_5:                                #   in Loop: Header=BB3_4 Depth=2
	xorps	%xmm4, %xmm4
	xorps	%xmm1, %xmm1
	xorl	%r13d, %r13d
.LBB3_11:                               # %._crit_edge
                                        #   in Loop: Header=BB3_4 Depth=2
	movd	%r13d, %xmm0
	divss	%xmm1, %xmm0
	cvttss2si	%xmm0, %eax
	shrq	$32, %r13
	movd	%r13d, %xmm0
	divss	%xmm1, %xmm0
	cvttss2si	%xmm0, %ecx
	movq	%xmm4, %rdx
	movd	%edx, %xmm0
	divss	%xmm1, %xmm0
	cvttss2si	%xmm0, %esi
	shrq	$32, %rdx
	movd	%edx, %xmm0
	divss	%xmm1, %xmm0
	cvttss2si	%xmm0, %edx
	andl	%r15d, %eax
	andl	%r15d, %ecx
	shll	$8, %ecx
	orl	%eax, %ecx
	andl	%r15d, %esi
	shll	$16, %esi
	orl	%ecx, %esi
	shll	$24, %edx
	orl	%esi, %edx
	movq	96(%rsp), %rax                  # 8-byte Reload
	movq	32(%rsp), %rcx                  # 8-byte Reload
	movl	%edx, (%rax,%rcx,4)
	incq	%rcx
	movq	%rcx, 32(%rsp)                  # 8-byte Spill
	cmpq	88(%rsp), %rcx                  # 8-byte Folded Reload
	jne	.LBB3_4
.LBB3_12:                               # %._crit_edge60
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	24(%rsp), %rcx                  # 8-byte Reload
	incq	%rcx
	movq	%rcx, %rax
	movq	%rcx, 24(%rsp)                  # 8-byte Spill
	cmpq	80(%rsp), %rcx                  # 8-byte Folded Reload
	jne	.LBB3_2
.LBB3_13:                               # %._crit_edge62
	addq	$136, %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_end3:
	.size	_Z6KernelP15HIP_vector_typeIhLj4EEiiib, .Lfunc_end3-_Z6KernelP15HIP_vector_typeIhLj4EEiiib
	.cfi_endproc
                                        # -- End function
	.globl	_Z16GetFilteredImageP15HIP_vector_typeIhLj4EEiii # -- Begin function _Z16GetFilteredImageP15HIP_vector_typeIhLj4EEiii
	.type	_Z16GetFilteredImageP15HIP_vector_typeIhLj4EEiii,@function
_Z16GetFilteredImageP15HIP_vector_typeIhLj4EEiii: # @_Z16GetFilteredImageP15HIP_vector_typeIhLj4EEiii
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %ebx
	movl	%edx, %ebp
	movl	%esi, %r14d
	movq	%rdi, %r15
	xorl	%r8d, %r8d
	callq	_Z6KernelP15HIP_vector_typeIhLj4EEiiib
	movq	%r15, %rdi
	movl	%r14d, %esi
	movl	%ebp, %edx
	movl	%ebx, %ecx
	movl	$1, %r8d
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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	_Z6KernelP15HIP_vector_typeIhLj4EEiiib # TAILCALL
.Lfunc_end4:
	.size	_Z16GetFilteredImageP15HIP_vector_typeIhLj4EEiii, .Lfunc_end4-_Z16GetFilteredImageP15HIP_vector_typeIhLj4EEiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI5_0:
	.quad	0x40c3880000000000              # double 1.0E+4
.LCPI5_1:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
.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	$88, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	40(%rsp), %rcx
	movq	%rcx, -16(%rcx)
	xorl	%eax, %eax
	movq	%rax, -8(%rcx)
	movb	%al, (%rcx)
	leaq	72(%rsp), %r13
	movq	%r13, -16(%r13)
	movq	%rax, -8(%r13)
	movb	%al, (%r13)
.Ltmp0:
	leaq	24(%rsp), %rsi
	movl	$_ZSt3cin, %edi
	callq	_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE
.Ltmp1:
# %bb.1:
.Ltmp2:
	leaq	56(%rsp), %rsi
	movq	%rax, %rdi
	callq	_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE
.Ltmp3:
# %bb.2:
.Ltmp4:
	leaq	12(%rsp), %rsi
	movq	%rax, %rdi
	callq	_ZNSirsERi
.Ltmp5:
# %bb.3:
	cvtsi2sdl	12(%rsp), %xmm0
	divsd	.LCPI5_0(%rip), %xmm0
	cvttsd2si	%xmm0, %eax
	movl	%eax, 12(%rsp)
	movq	24(%rsp), %rdi
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %r14
	leaq	20(%rsp), %rbx
	movl	$4, %esi
	movl	$1, %edx
	movq	%rbx, %rdi
	movq	%rax, %rcx
	callq	fread
	leaq	16(%rsp), %r12
	movl	$4, %esi
	movl	$1, %edx
	movq	%r12, %rdi
	movq	%r14, %rcx
	callq	fread
	movslq	(%rbx), %r15
	movslq	(%r12), %r12
	movq	%r15, %rdi
	imulq	%r12, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %rbx
	movl	%r12d, %eax
	imull	%r15d, %eax
	movslq	%eax, %rdx
	movl	$4, %esi
	movq	%rbx, %rdi
	movq	%r14, %rcx
	callq	fread
	movq	%r14, %rdi
	callq	fclose
	callq	clock
	movq	%rax, %r14
	movl	12(%rsp), %ebp
	movq	%rbx, %rdi
	movl	%r15d, %esi
	movl	%r12d, %edx
	movl	%ebp, %ecx
	xorl	%r8d, %r8d
	callq	_Z6KernelP15HIP_vector_typeIhLj4EEiiib
	movq	%rbx, %rdi
	movl	%r15d, %esi
	movl	%r12d, %edx
	movl	%ebp, %ecx
	movl	$1, %r8d
	callq	_Z6KernelP15HIP_vector_typeIhLj4EEiiib
	callq	clock
	subq	%r14, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI5_1(%rip), %xmm0
.Ltmp7:
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp8:
# %bb.4:                                # %_ZNSolsEd.exit
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
.Ltmp9:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp10:
# %bb.5:                                # %.noexc
.Ltmp11:
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
.Ltmp12:
# %bb.6:                                # %.noexc28
.Ltmp13:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp14:
# %bb.7:                                # %_ZNSolsEPFRSoS_E.exit
	movq	56(%rsp), %rdi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %r14
	leaq	20(%rsp), %r15
	movl	$4, %esi
	movl	$1, %edx
	movq	%r15, %rdi
	movq	%rax, %rcx
	callq	fwrite
	leaq	16(%rsp), %r12
	movl	$4, %esi
	movl	$1, %edx
	movq	%r12, %rdi
	movq	%r14, %rcx
	callq	fwrite
	movslq	(%r15), %rax
	movslq	(%r12), %rdx
	imulq	%rax, %rdx
	movl	$4, %esi
	movq	%rbx, %rdi
	movq	%r14, %rcx
	callq	fwrite
	movq	%r14, %rdi
	callq	fclose
	movq	%rbx, %rdi
	callq	free
	movq	56(%rsp), %rdi
	cmpq	%r13, %rdi
	je	.LBB5_9
# %bb.8:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	callq	_ZdlPv
.LBB5_9:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
	movq	24(%rsp), %rdi
	leaq	40(%rsp), %rax
	cmpq	%rax, %rdi
	je	.LBB5_11
# %bb.10:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i19
	callq	_ZdlPv
.LBB5_11:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit21
	xorl	%eax, %eax
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB5_12:
	.cfi_def_cfa_offset 144
.Ltmp6:
	jmp	.LBB5_14
.LBB5_13:
.Ltmp15:
.LBB5_14:
	movq	%rax, %rbx
	movq	56(%rsp), %rdi
	cmpq	%r13, %rdi
	je	.LBB5_16
# %bb.15:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i22
	callq	_ZdlPv
.LBB5_16:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit24
	movq	24(%rsp), %rdi
	leaq	40(%rsp), %rax
	cmpq	%rax, %rdi
	je	.LBB5_18
# %bb.17:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i25
	callq	_ZdlPv
.LBB5_18:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit27
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table5:
.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 .Ltmp0-.Lfunc_begin0           # >> Call Site 1 <<
	.uleb128 .Ltmp5-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp5
	.uleb128 .Ltmp6-.Lfunc_begin0           #     jumps to .Ltmp6
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp7-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp14-.Ltmp7                 #   Call between .Ltmp7 and .Ltmp14
	.uleb128 .Ltmp15-.Lfunc_begin0          #     jumps to .Ltmp15
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp14-.Lfunc_begin0          # >> Call Site 3 <<
	.uleb128 .Lfunc_end5-.Ltmp14            #   Call between .Ltmp14 and .Lfunc_end5
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"rb"
	.size	.L.str, 3

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

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.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 __gxx_personality_v0
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _ZSt3cin
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
