#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <iomanip>
using namespace std;

#define iceil(num,den) (num+den-1)/den

//Kernel Function
__global__ void imgMulKernel(float* d_img_in, float* d_img_out, int w, int h, float *d_img_fin, int fw, int fh){
	
	//Access the pixel on the image
	int c = blockDim.x * blockIdx.x + threadIdx.x;
	int r = blockDim.y * blockIdx.y + threadIdx.y;
	
	//Ignore border elements
	if(r == 0 || r == h-1 || c == 0 || c == w-1)
		return;

	//Check if the index is in the image 
	if(c < w && r < h){
		int tl = d_img_in[(r-1)*w + (c-1)] * d_img_fin[0*fw + 0];
		int tc = d_img_in[(r-1)*w + (c)] * d_img_fin[0*fw + 1];
		int tr = d_img_in[(r-1)*w + (c+1)] * d_img_fin[0*fw + 2];

		int ml = d_img_in[r*w + (c-1)] * d_img_fin[1*fw + 0];
		int mc = d_img_in[r*w + c] * d_img_fin[1*fw + 1];
		int mr = d_img_in[r*w + (c+1)] * d_img_fin[1*fw + 2];
		
		int bl = d_img_in[(r+1)*w + (c-1)] * d_img_fin[2*fw + 0];
		int bc = d_img_in[(r+1)*w + (c)] * d_img_fin[2*fw + 1];
		int br = d_img_in[(r+1)*w + (c+1)] * d_img_fin[2*fw + 2];

		int sum = tl + tc + tr + ml + mc + mr + bl + bc + br;
		
		d_img_out[r*w + c] = sum/9;
		//d_img_out[row*w + col] = d_img_in[row*w + col] * 2;
	}
}

void imgMul(float*img_in, float* img_out, int w, int h, float *img_fin, int fw, int fh) {
	
	//This number of bytes are going be allocated and transferred
	int size = w * h * sizeof(float);
	int fsize = fw * fh * sizeof(float);

	float *d_img_in, *d_img_out, *d_img_fin;

	//Allocate memory from GPU for my input and output array
	cudaMalloc((void**)&d_img_in, size);
	cudaMalloc((void**)&d_img_out, size);
	cudaMalloc((void**)&d_img_fin, fsize);

	//Transfer data to the GPU
	cudaMemcpy(d_img_in, img_in, size, cudaMemcpyHostToDevice);
	cudaMemcpy(d_img_fin, img_fin, fsize, cudaMemcpyHostToDevice);

	dim3 myBlockDim(16, 16, 1);
	dim3 myGridDim(iceil(w, 16), iceil(h, 16), 1);
	//Kernel Launch
	imgMulKernel <<<myGridDim, myBlockDim >>> (d_img_in, d_img_out, w, h, d_img_fin, fw, fh);

	//Transfer results back to CPU
	cudaMemcpy(img_out, d_img_out, size, cudaMemcpyDeviceToHost);

	cudaFree(d_img_in);
	cudaFree(d_img_out);
}

std::string to_format(const int number) {
    std::stringstream ss;
    ss << std::setw(2) << std::setfill(' ') << number;
    return ss.str();
}

//Prints the image on screen
void printImage(float* img, int w, int h) {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << to_format(img[i*w + j]) << " ";
		}
		cout << endl;
	}
	cout << endl;
}

int main(int argc, char **argv){

	
	int w = atoi(argv[1]);
	int h = atoi(argv[2]);
	int fw = 3;
	int fh = 3;

	float *img_in = new float[w*h];
	float *img_out = new float[w*h];
	float *img_fin = new float[fw*fh];

	time_t t;
	srand((unsigned) time(&t));

	//Load value to the image
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			img_in[i*w + j] =rand() % 10 ;

	// Load value to filter
	for(int i = 0; i < fh; i++)
		for(int j = 0; j < fw; j++)
			img_fin[i*fw + j] = rand() % 10;
	
	cout << "Filter Array" << endl;
	printImage(img_fin, fw, fh);

	cout << "Input Array" << endl;
	printImage(img_in, w, h);

	imgMul(img_in, img_out, w, h, img_fin, fw, fh);
	
	cout << "Output Array" << endl;
	printImage(img_out, w, h);

	return 0;
}

	.file	"tmpxft_00287e8c_00000000-6_vecadd.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3921:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3921:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4685:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4685:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z40__device_stub__Z12imgMulKernelPfS_iiS_iiPfS_iiS_ii
	.type	_Z40__device_stub__Z12imgMulKernelPfS_iiS_iiPfS_iiS_ii, @function
_Z40__device_stub__Z12imgMulKernelPfS_iiS_iiPfS_iiS_ii:
.LFB3943:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movl	%edx, 28(%rsp)
	leaq	48(%rsp), %rdx
	movl	%ecx, 24(%rsp)
	leaq	56(%rsp), %rcx
	movq	%r8, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	192(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L3
	pushq	56(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z12imgMulKernelPfS_iiS_ii(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 208
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L3:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3943:
	.size	_Z40__device_stub__Z12imgMulKernelPfS_iiS_iiPfS_iiS_ii, .-_Z40__device_stub__Z12imgMulKernelPfS_iiS_iiPfS_iiS_ii
	.globl	_Z12imgMulKernelPfS_iiS_ii
	.type	_Z12imgMulKernelPfS_iiS_ii, @function
_Z12imgMulKernelPfS_iiS_ii:
.LFB3944:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z12imgMulKernelPfS_iiS_iiPfS_iiS_ii
	.cfi_endproc
.LFE3944:
	.size	_Z12imgMulKernelPfS_iiS_ii, .-_Z12imgMulKernelPfS_iiS_ii
	.globl	_Z6imgMulPfS_iiS_ii
	.type	_Z6imgMulPfS_iiS_ii, @function
_Z6imgMulPfS_iiS_ii:
.LFB3915:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r8, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%r9d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%ecx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%rsi, 8(%rsp)
	leaq	24(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	movl	%edx, %eax
	imull	%ecx, %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	32(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	144(%rsp), %ebx
	leaq	40(%rsp), %rdi
	imull	%r13d, %ebx
	sall	$2, %ebx
	movslq	%ebx, %rbx
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdx
	movq	24(%rsp), %rdi
	movq	%r15, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leal	15(%rbp), %eax
	movl	$16, %ecx
	xorl	%r9d, %r9d
	cltd
	xorl	%r8d, %r8d
	movl	$1, %esi
	idivl	%ecx
	movl	%eax, 60(%rsp)
	leal	15(%r12), %eax
	cltd
	idivl	%ecx
	movabsq	$68719476752, %rdx
	movl	$1, %ecx
	movl	%eax, 64(%rsp)
	movq	60(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L10
	pushq	%rax
	.cfi_def_cfa_offset 152
	movl	152(%rsp), %eax
	movl	%r12d, %ecx
	movl	%ebp, %edx
	movl	%r13d, %r9d
	pushq	%rax
	.cfi_def_cfa_offset 160
	movq	56(%rsp), %r8
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdi
	call	_Z40__device_stub__Z12imgMulKernelPfS_iiS_iiPfS_iiS_ii
	popq	%rdx
	.cfi_def_cfa_offset 152
	popq	%rcx
	.cfi_def_cfa_offset 144
.L10:
	movq	(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movq	8(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$88, %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
.LFE3915:
	.size	_Z6imgMulPfS_iiS_ii, .-_Z6imgMulPfS_iiS_ii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z12imgMulKernelPfS_iiS_ii"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3946:
	.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	.LC0(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12imgMulKernelPfS_iiS_ii(%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
.LFE3946:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.text
	.globl	_Z9to_formatB5cxx11i
	.type	_Z9to_formatB5cxx11i, @function
_Z9to_formatB5cxx11i:
.LFB3916:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3916
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	subq	$400, %rsp
	.cfi_def_cfa_offset 432
	movq	%fs:40, %rax
	movq	%rax, 392(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbp
	movq	%rbp, %rdi
.LEHB0:
	call	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEC1Ev@PLT
.LEHE0:
	movq	16(%rsp), %rax
	leaq	16(%rsp), %rdi
	movb	$32, %sil
	movq	-24(%rax), %rax
	movq	$2, 32(%rsp,%rax)
.LEHB1:
	call	_ZStlsIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_St8_SetfillIS3_E@PLT
	movq	%rax, %rdi
	movl	%r12d, %esi
	call	_ZNSolsEi@PLT
	leaq	24(%rsp), %rsi
	movq	%rbx, %rdi
	call	_ZNKSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEE3strEv@PLT
.LEHE1:
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev@PLT
	movq	392(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	jmp	.L20
.L19:
	endbr64
	movq	%rax, %rbx
.L16:
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev@PLT
	movq	392(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L20
	movq	%rbx, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L20:
	call	__stack_chk_fail@PLT
.L18:
	addq	$400, %rsp
	.cfi_def_cfa_offset 32
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3916:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3916:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3916-.LLSDACSB3916
.LLSDACSB3916:
	.uleb128 .LEHB0-.LFB3916
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3916
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L19-.LFB3916
	.uleb128 0
	.uleb128 .LEHB2-.LFB3916
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE3916:
	.text
	.size	_Z9to_formatB5cxx11i, .-_Z9to_formatB5cxx11i
	.section	.rodata.str1.1
.LC1:
	.string	" "
	.text
	.globl	_Z10printImagePfii
	.type	_Z10printImagePfii, @function
_Z10printImagePfii:
.LFB3917:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3917
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edx, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
.L23:
	cmpl	%r15d, %r14d
	jge	.L25
	movslq	%r13d, %rax
	xorl	%ebx, %ebx
	leaq	(%r12,%rax,4), %rax
	movq	%rax, 8(%rsp)
.L26:
	cmpl	%ebx, %ebp
	jle	.L34
	leaq	24(%rsp), %rax
	movq	%rax, (%rsp)
	movq	8(%rsp), %rax
	movq	(%rsp), %rdi
	cvttss2sil	(%rax,%rbx,4), %esi
.LEHB3:
	call	_Z9to_formatB5cxx11i
.LEHE3:
	movq	(%rsp), %rsi
	leaq	_ZSt4cout(%rip), %rdi
.LEHB4:
	call	_ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKNSt7__cxx1112basic_stringIS4_S5_T1_EE@PLT
	movq	%rax, %rdi
	leaq	.LC1(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.LEHE4:
	movq	(%rsp), %rdi
	incq	%rbx
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L26
.L34:
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	incl	%r14d
	addl	%ebp, %r13d
.LEHB5:
	call	_ZNSolsEPFRSoS_E.isra.0
	jmp	.L23
.L25:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L33
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	addq	$72, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	leaq	_ZSt4cout(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	_ZNSolsEPFRSoS_E.isra.0
.L31:
	.cfi_restore_state
	endbr64
	movq	%rax, %rbx
.L28:
	movq	(%rsp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
.L33:
	call	__stack_chk_fail@PLT
.L29:
	movq	%rbx, %rdi
	call	_Unwind_Resume@PLT
.LEHE5:
	.cfi_endproc
.LFE3917:
	.section	.gcc_except_table
.LLSDA3917:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3917-.LLSDACSB3917
.LLSDACSB3917:
	.uleb128 .LEHB3-.LFB3917
	.uleb128 .LEHE3-.LEHB3
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB4-.LFB3917
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L31-.LFB3917
	.uleb128 0
	.uleb128 .LEHB5-.LFB3917
	.uleb128 .LEHE5-.LEHB5
	.uleb128 0
	.uleb128 0
.LLSDACSE3917:
	.text
	.size	_Z10printImagePfii, .-_Z10printImagePfii
	.section	.rodata.str1.1
.LC2:
	.string	"Filter Array"
.LC3:
	.string	"Input Array"
.LC4:
	.string	"Output Array"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3918:
	.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
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movq	16(%rbp), %rdi
	movl	%eax, %ebx
	call	atoi@PLT
	movl	%ebx, %r13d
	imull	%eax, %r13d
	movl	%eax, %ebp
	movabsq	$2305843009213693950, %rax
	movslq	%r13d, %r13
	cmpq	%r13, %rax
	jb	.L36
	salq	$2, %r13
	movq	%r13, %rdi
	call	_Znam@PLT
	movq	%r13, %rdi
	movq	%rax, %r12
	call	_Znam@PLT
	movl	$36, %edi
	movq	%rax, 8(%rsp)
	call	_Znam@PLT
	leaq	32(%rsp), %rdi
	movq	%rax, %r13
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	xorl	%ecx, %ecx
	xorl	%esi, %esi
	jmp	.L37
.L36:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L48
	call	__cxa_throw_bad_array_new_length@PLT
.L49:
	incl	%esi
	addl	%ebx, %ecx
.L37:
	cmpl	%ebp, %esi
	jge	.L45
	movslq	%ecx, %rax
	xorl	%r15d, %r15d
	leaq	(%r12,%rax,4), %r14
.L41:
	cmpl	%r15d, %ebx
	jle	.L49
	movl	%ecx, 28(%rsp)
	movl	%esi, 16(%rsp)
	call	rand@PLT
	movl	$10, %ecx
	movl	16(%rsp), %esi
	cltd
	idivl	%ecx
	movl	28(%rsp), %ecx
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	jmp	.L41
.L45:
	xorl	%esi, %esi
.L40:
	imulq	$12, %rsi, %r14
	xorl	%r15d, %r15d
	addq	%r13, %r14
.L42:
	movq	%rsi, 16(%rsp)
	call	rand@PLT
	movl	$10, %ecx
	movq	16(%rsp), %rsi
	cltd
	idivl	%ecx
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	$3, %r15
	jne	.L42
	incq	%rsi
	cmpq	$3, %rsi
	jne	.L40
	leaq	_ZSt4cout(%rip), %r14
	leaq	.LC2(%rip), %rsi
	movq	%r14, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$3, %edx
	movl	$3, %esi
	movq	%r13, %rdi
	call	_Z10printImagePfii
	leaq	.LC3(%rip), %rsi
	movq	%r14, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	%ebp, %edx
	movl	%ebx, %esi
	movq	%r12, %rdi
	call	_Z10printImagePfii
	movl	$3, %r9d
	movq	%r13, %r8
	movl	%ebp, %ecx
	pushq	%rax
	.cfi_def_cfa_offset 120
	movl	%ebx, %edx
	movq	%r12, %rdi
	pushq	$3
	.cfi_def_cfa_offset 128
	movq	24(%rsp), %rsi
	call	_Z6imgMulPfS_iiS_ii
	popq	%rdx
	.cfi_def_cfa_offset 120
	leaq	.LC4(%rip), %rsi
	popq	%rcx
	.cfi_def_cfa_offset 112
	movq	%r14, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	8(%rsp), %rdi
	movl	%ebp, %edx
	movl	%ebx, %esi
	call	_Z10printImagePfii
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L44
.L48:
	call	__stack_chk_fail@PLT
.L44:
	addq	$56, %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
.LFE3918:
	.size	main, .-main
	.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
	.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 <iostream>
#include <stdlib.h>
#include <sstream>
#include <iomanip>
using namespace std;

#define iceil(num,den) (num+den-1)/den

//Kernel Function
__global__ void imgMulKernel(float* d_img_in, float* d_img_out, int w, int h, float *d_img_fin, int fw, int fh){
	
	//Access the pixel on the image
	int c = blockDim.x * blockIdx.x + threadIdx.x;
	int r = blockDim.y * blockIdx.y + threadIdx.y;
	
	//Ignore border elements
	if(r == 0 || r == h-1 || c == 0 || c == w-1)
		return;

	//Check if the index is in the image 
	if(c < w && r < h){
		int tl = d_img_in[(r-1)*w + (c-1)] * d_img_fin[0*fw + 0];
		int tc = d_img_in[(r-1)*w + (c)] * d_img_fin[0*fw + 1];
		int tr = d_img_in[(r-1)*w + (c+1)] * d_img_fin[0*fw + 2];

		int ml = d_img_in[r*w + (c-1)] * d_img_fin[1*fw + 0];
		int mc = d_img_in[r*w + c] * d_img_fin[1*fw + 1];
		int mr = d_img_in[r*w + (c+1)] * d_img_fin[1*fw + 2];
		
		int bl = d_img_in[(r+1)*w + (c-1)] * d_img_fin[2*fw + 0];
		int bc = d_img_in[(r+1)*w + (c)] * d_img_fin[2*fw + 1];
		int br = d_img_in[(r+1)*w + (c+1)] * d_img_fin[2*fw + 2];

		int sum = tl + tc + tr + ml + mc + mr + bl + bc + br;
		
		d_img_out[r*w + c] = sum/9;
		//d_img_out[row*w + col] = d_img_in[row*w + col] * 2;
	}
}

void imgMul(float*img_in, float* img_out, int w, int h, float *img_fin, int fw, int fh) {
	
	//This number of bytes are going be allocated and transferred
	int size = w * h * sizeof(float);
	int fsize = fw * fh * sizeof(float);

	float *d_img_in, *d_img_out, *d_img_fin;

	//Allocate memory from GPU for my input and output array
	hipMalloc((void**)&d_img_in, size);
	hipMalloc((void**)&d_img_out, size);
	hipMalloc((void**)&d_img_fin, fsize);

	//Transfer data to the GPU
	hipMemcpy(d_img_in, img_in, size, hipMemcpyHostToDevice);
	hipMemcpy(d_img_fin, img_fin, fsize, hipMemcpyHostToDevice);

	dim3 myBlockDim(16, 16, 1);
	dim3 myGridDim(iceil(w, 16), iceil(h, 16), 1);
	//Kernel Launch
	imgMulKernel <<<myGridDim, myBlockDim >>> (d_img_in, d_img_out, w, h, d_img_fin, fw, fh);

	//Transfer results back to CPU
	hipMemcpy(img_out, d_img_out, size, hipMemcpyDeviceToHost);

	hipFree(d_img_in);
	hipFree(d_img_out);
}

std::string to_format(const int number) {
    std::stringstream ss;
    ss << std::setw(2) << std::setfill(' ') << number;
    return ss.str();
}

//Prints the image on screen
void printImage(float* img, int w, int h) {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << to_format(img[i*w + j]) << " ";
		}
		cout << endl;
	}
	cout << endl;
}

int main(int argc, char **argv){

	
	int w = atoi(argv[1]);
	int h = atoi(argv[2]);
	int fw = 3;
	int fh = 3;

	float *img_in = new float[w*h];
	float *img_out = new float[w*h];
	float *img_fin = new float[fw*fh];

	time_t t;
	srand((unsigned) time(&t));

	//Load value to the image
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			img_in[i*w + j] =rand() % 10 ;

	// Load value to filter
	for(int i = 0; i < fh; i++)
		for(int j = 0; j < fw; j++)
			img_fin[i*fw + j] = rand() % 10;
	
	cout << "Filter Array" << endl;
	printImage(img_fin, fw, fh);

	cout << "Input Array" << endl;
	printImage(img_in, w, h);

	imgMul(img_in, img_out, w, h, img_fin, fw, fh);
	
	cout << "Output Array" << endl;
	printImage(img_out, w, h);

	return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z27__device_stub__imgMulKernelPfS_iiS_ii # -- Begin function _Z27__device_stub__imgMulKernelPfS_iiS_ii
	.type	_Z27__device_stub__imgMulKernelPfS_iiS_ii,@function
_Z27__device_stub__imgMulKernelPfS_iiS_ii: # @_Z27__device_stub__imgMulKernelPfS_iiS_ii
	.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	$160, %rsp
	.cfi_def_cfa_offset 208
	.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	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	20(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	16(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%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	208(%rsp), %rax
	movq	%rax, 48(%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	$_Z12imgMulKernelPfS_iiS_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z27__device_stub__imgMulKernelPfS_iiS_ii, .Lfunc_end0-_Z27__device_stub__imgMulKernelPfS_iiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z6imgMulPfS_iiS_ii             # -- Begin function _Z6imgMulPfS_iiS_ii
	.type	_Z6imgMulPfS_iiS_ii,@function
_Z6imgMulPfS_iiS_ii:                    # @_Z6imgMulPfS_iiS_ii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%r8, 48(%rsp)                   # 8-byte Spill
	movl	%ecx, %r14d
	movl	%edx, %r15d
	movq	%rsi, 56(%rsp)                  # 8-byte Spill
	movq	%rdi, 40(%rsp)                  # 8-byte Spill
	movl	%edx, %eax
	imull	%ecx, %eax
	shll	$2, %eax
	movl	%r9d, 28(%rsp)                  # 4-byte Spill
	movl	%r9d, %ebx
	imull	128(%rsp), %ebx
	shll	$2, %ebx
	movslq	%eax, %r12
	leaq	32(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movslq	%ebx, %r13
	leaq	64(%rsp), %rbx
	movq	%rbx, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%rbp), %rdi
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbx), %rdi
	movq	48(%rsp), %rsi                  # 8-byte Reload
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leal	15(%r15), %eax
	leal	30(%r15), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	sarl	$4, %ecx
	leal	15(%r14), %eax
	leal	30(%r14), %edi
	testl	%eax, %eax
	cmovnsl	%eax, %edi
	sarl	$4, %edi
	shlq	$32, %rdi
	orq	%rcx, %rdi
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movq	32(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	64(%rsp), %r8
	movl	128(%rsp), %eax
	movl	%eax, (%rsp)
	movl	%r15d, %edx
	movl	%r14d, %ecx
	movl	28(%rsp), %r9d                  # 4-byte Reload
	callq	_Z27__device_stub__imgMulKernelPfS_iiS_ii
.LBB1_2:
	movq	16(%rsp), %rsi
	movq	56(%rsp), %rdi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	addq	$72, %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_end1:
	.size	_Z6imgMulPfS_iiS_ii, .Lfunc_end1-_Z6imgMulPfS_iiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z9to_formatB5cxx11i            # -- Begin function _Z9to_formatB5cxx11i
	.type	_Z9to_formatB5cxx11i,@function
_Z9to_formatB5cxx11i:                   # @_Z9to_formatB5cxx11i
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$400, %rsp                      # imm = 0x190
	.cfi_def_cfa_offset 432
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movq	%rdi, %rbx
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	callq	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEC1Ev
	movq	16(%r14), %rax
	movq	-24(%rax), %rcx
	movq	$2, 40(%rsp,%rcx)
	movq	-24(%rax), %rax
	leaq	(%rsp,%rax), %r14
	addq	$24, %r14
	cmpb	$0, 225(%r14)
	jne	.LBB2_3
# %bb.1:
.Ltmp0:
	movq	%r14, %rdi
	movl	$32, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp1:
# %bb.2:                                # %.noexc
	movb	$1, 225(%r14)
.LBB2_3:
	leaq	24(%rsp), %rdi
	movb	$32, 224(%r14)
.Ltmp2:
	movl	%ebp, %esi
	callq	_ZNSolsEi
.Ltmp3:
# %bb.4:
	leaq	32(%rsp), %rsi
.Ltmp4:
	movq	%rbx, %rdi
	callq	_ZNKSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEE3strEv
.Ltmp5:
# %bb.5:                                # %_ZNKSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEE3strEv.exit
	leaq	8(%rsp), %rdi
	movl	$_ZTTNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE, %esi
	callq	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED2Ev
	leaq	136(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	movq	%rbx, %rax
	addq	$400, %rsp                      # imm = 0x190
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB2_6:
	.cfi_def_cfa_offset 432
.Ltmp6:
	movq	%rax, %rbx
	leaq	8(%rsp), %rdi
	movl	$_ZTTNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE, %esi
	callq	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED2Ev
	leaq	136(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	_Z9to_formatB5cxx11i, .Lfunc_end2-_Z9to_formatB5cxx11i
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table2:
.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 .Ltmp5-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp5
	.uleb128 .Ltmp6-.Lfunc_begin0           #     jumps to .Ltmp6
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp5-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Lfunc_end2-.Ltmp5             #   Call between .Ltmp5 and .Lfunc_end2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.globl	_Z10printImagePfii              # -- Begin function _Z10printImagePfii
	.type	_Z10printImagePfii,@function
_Z10printImagePfii:                     # @_Z10printImagePfii
.Lfunc_begin1:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception1
# %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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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	%rdi, 24(%rsp)                  # 8-byte Spill
	testl	%edx, %edx
	jle	.LBB3_10
# %bb.1:                                # %.preheader.lr.ph
	leaq	56(%rsp), %r12
	movl	%edx, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	%esi, %ebp
	xorl	%eax, %eax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	leaq	40(%rsp), %r15
	xorl	%r13d, %r13d
	movl	%esi, 20(%rsp)                  # 4-byte Spill
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
	testl	%esi, %esi
	jle	.LBB3_9
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	8(%rsp), %eax                   # 4-byte Reload
	movq	24(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,4), %rbx
	xorl	%r14d, %r14d
.LBB3_4:                                #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cvttss2si	(%rbx,%r14,4), %esi
	movq	%r15, %rdi
	callq	_Z9to_formatB5cxx11i
	movq	40(%rsp), %rsi
	movq	48(%rsp), %rdx
.Ltmp7:
	movl	$_ZSt4cout, %edi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp8:
# %bb.5:                                # %_ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKNSt7__cxx1112basic_stringIS4_S5_T1_EE.exit
                                        #   in Loop: Header=BB3_4 Depth=2
.Ltmp9:
	movl	$.L.str, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp10:
# %bb.6:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
                                        #   in Loop: Header=BB3_4 Depth=2
	movq	40(%rsp), %rdi
	cmpq	%r12, %rdi
	je	.LBB3_8
# %bb.7:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
                                        #   in Loop: Header=BB3_4 Depth=2
	callq	_ZdlPv
.LBB3_8:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
                                        #   in Loop: Header=BB3_4 Depth=2
	incq	%r14
	cmpq	%r14, %rbp
	jne	.LBB3_4
.LBB3_9:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	movl	$_ZSt4cout, %eax
	addq	%rax, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	incq	%r13
	movl	20(%rsp), %esi                  # 4-byte Reload
	movq	8(%rsp), %rax                   # 8-byte Reload
	addl	%esi, %eax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	cmpq	32(%rsp), %r13                  # 8-byte Folded Reload
	jne	.LBB3_2
.LBB3_10:                               # %._crit_edge18
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %ecx
	movq	-24(%rax), %rdi
	addq	%rcx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	addq	$72, %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
.LBB3_11:
	.cfi_def_cfa_offset 128
.Ltmp11:
	movq	%rax, %rbx
	movq	40(%rsp), %rdi
	cmpq	%r12, %rdi
	je	.LBB3_13
# %bb.12:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i13
	callq	_ZdlPv
.LBB3_13:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit15
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end3:
	.size	_Z10printImagePfii, .Lfunc_end3-_Z10printImagePfii
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table3:
.Lexception1:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end1-.Lcst_begin1
.Lcst_begin1:
	.uleb128 .Lfunc_begin1-.Lfunc_begin1    # >> Call Site 1 <<
	.uleb128 .Ltmp7-.Lfunc_begin1           #   Call between .Lfunc_begin1 and .Ltmp7
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp7-.Lfunc_begin1           # >> Call Site 2 <<
	.uleb128 .Ltmp10-.Ltmp7                 #   Call between .Ltmp7 and .Ltmp10
	.uleb128 .Ltmp11-.Lfunc_begin1          #     jumps to .Ltmp11
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp10-.Lfunc_begin1          # >> Call Site 3 <<
	.uleb128 .Lfunc_end3-.Ltmp10            #   Call between .Ltmp10 and .Lfunc_end3
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end1:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %r14
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r15d
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, %ebx
	imull	%r15d, %eax
	cltq
	leaq	(,%rax,4), %rcx
	testl	%eax, %eax
	movq	$-1, %r14
	cmovnsq	%rcx, %r14
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	$36, %edi
	callq	_Znam
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	leaq	48(%rsp), %rdi
	callq	time
	movl	%eax, %edi
	callq	srand
	movl	%ebx, 12(%rsp)                  # 4-byte Spill
	testl	%ebx, %ebx
	jle	.LBB4_1
# %bb.6:                                # %.preheader50.lr.ph
	movl	12(%rsp), %eax                  # 4-byte Reload
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	movl	%r15d, %r14d
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
.LBB4_7:                                # %.preheader50
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_9 Depth 2
	movl	%r15d, %r13d
	testl	%r15d, %r15d
	jle	.LBB4_10
# %bb.8:                                # %.lr.ph
                                        #   in Loop: Header=BB4_7 Depth=1
	movl	%r12d, %eax
	movq	16(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,4), %r15
	xorl	%ebx, %ebx
.LBB4_9:                                #   Parent Loop BB4_7 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r15,%rbx,4)
	incq	%rbx
	cmpq	%rbx, %r14
	jne	.LBB4_9
.LBB4_10:                               # %._crit_edge
                                        #   in Loop: Header=BB4_7 Depth=1
	incq	%rbp
	movl	%r13d, %r15d
	addl	%r13d, %r12d
	cmpq	40(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB4_7
.LBB4_1:                                # %.preheader.preheader
	xorl	%r14d, %r14d
	movq	24(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %r12
.LBB4_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_3 Depth 2
	xorl	%ebx, %ebx
.LBB4_3:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	cmpq	$3, %rbx
	jne	.LBB4_3
# %bb.4:                                #   in Loop: Header=BB4_2 Depth=1
	incq	%r14
	addq	$12, %r12
	cmpq	$3, %r14
	jne	.LBB4_2
# %bb.5:
	movl	$_ZSt4cout, %r13d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r13, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rbp, %rdi
	movl	$3, %esi
	movl	$3, %edx
	callq	_Z10printImagePfii
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$11, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r13, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	16(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	movl	%r15d, %esi
	movl	12(%rsp), %ebx                  # 4-byte Reload
	movl	%ebx, %edx
	callq	_Z10printImagePfii
	movl	$3, (%rsp)
	movq	%r14, %rdi
	movq	32(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rsi
	movl	%r15d, %edx
	movl	%ebx, %ecx
	movq	%rbp, %r8
	movl	$3, %r9d
	callq	_Z6imgMulPfS_iiS_ii
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r13, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%r14, %rdi
	movl	%r15d, %esi
	movl	%ebx, %edx
	callq	_Z10printImagePfii
	xorl	%eax, %eax
	addq	$56, %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_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12imgMulKernelPfS_iiS_ii, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z12imgMulKernelPfS_iiS_ii,@object # @_Z12imgMulKernelPfS_iiS_ii
	.section	.rodata,"a",@progbits
	.globl	_Z12imgMulKernelPfS_iiS_ii
	.p2align	3, 0x0
_Z12imgMulKernelPfS_iiS_ii:
	.quad	_Z27__device_stub__imgMulKernelPfS_iiS_ii
	.size	_Z12imgMulKernelPfS_iiS_ii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	" "
	.size	.L.str, 2

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Filter Array"
	.size	.L.str.1, 13

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Input Array"
	.size	.L.str.2, 12

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12imgMulKernelPfS_iiS_ii"
	.size	.L__unnamed_1, 27

	.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

	.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 _Z27__device_stub__imgMulKernelPfS_iiS_ii
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z12imgMulKernelPfS_iiS_ii
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12imgMulKernelPfS_iiS_ii ; -- Begin function _Z12imgMulKernelPfS_iiS_ii
	.globl	_Z12imgMulKernelPfS_iiS_ii
	.p2align	8
	.type	_Z12imgMulKernelPfS_iiS_ii,@function
_Z12imgMulKernelPfS_iiS_ii:             ; @_Z12imgMulKernelPfS_iiS_ii
; %bb.0:
	s_load_b32 s2, s[0:1], 0x34
	v_bfe_u32 v1, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[2:3], null, s15, s3, v[1:2]
	s_mov_b32 s3, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ne_u32_e32 0, v2
	s_cbranch_execz .LBB0_4
; %bb.1:
	s_load_b64 s[8:9], s[0:1], 0x10
	v_and_b32_e32 v3, 0x3ff, v0
	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[3:4]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, 0, v0
	s_waitcnt lgkmcnt(0)
	s_add_i32 s2, s9, -1
	s_add_i32 s3, s8, -1
	v_cmp_ne_u32_e64 s2, s2, v2
	v_cmp_ne_u32_e64 s3, s3, v0
	s_delay_alu instid0(VALU_DEP_2)
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s2
	s_cbranch_execz .LBB0_4
; %bb.2:
	v_cmp_gt_i32_e32 vcc_lo, s8, v0
	v_cmp_gt_i32_e64 s2, s9, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_b32 exec_lo, exec_lo, s2
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_add_nc_u32_e32 v1, -1, v2
	v_mul_lo_u32 v9, v2, s8
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x18
	v_ashrrev_i32_e32 v10, 31, v0
	v_mul_lo_u32 v2, v1, s8
	s_load_b32 s0, s[0:1], 0x20
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_4)
	v_ashrrev_i32_e32 v6, 31, v9
	v_add_nc_u32_e32 v7, v9, v0
	v_add_nc_u32_e32 v11, s8, v9
	v_ashrrev_i32_e32 v4, 31, v2
	v_add_nc_u32_e32 v1, v2, v0
	v_add_co_u32 v3, vcc_lo, v2, v0
	v_ashrrev_i32_e32 v8, 31, v7
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_ci_u32_e32 v4, vcc_lo, v4, v10, vcc_lo
	v_ashrrev_i32_e32 v2, 31, v1
	v_add_co_u32 v5, vcc_lo, v9, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	v_add_co_ci_u32_e32 v6, vcc_lo, v6, v10, vcc_lo
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_ashrrev_i32_e32 v12, 31, v11
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	s_delay_alu instid0(VALU_DEP_4)
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	v_add_co_u32 v1, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v2, vcc_lo
	v_add_co_u32 v5, vcc_lo, s4, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v6, vcc_lo
	v_add_co_u32 v9, vcc_lo, v11, v0
	v_add_nc_u32_e32 v11, v11, v0
	v_add_co_ci_u32_e32 v10, vcc_lo, v12, v10, vcc_lo
	v_add_co_u32 v13, vcc_lo, s4, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_ashrrev_i32_e32 v12, 31, v11
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	v_add_co_ci_u32_e32 v14, vcc_lo, s5, v8, vcc_lo
	s_clause 0x3
	global_load_b32 v15, v[3:4], off offset:-4
	global_load_b64 v[0:1], v[1:2], off
	global_load_b32 v6, v[5:6], off offset:-4
	global_load_b64 v[2:3], v[13:14], off
	v_lshlrev_b64 v[4:5], 2, v[11:12]
	s_ashr_i32 s1, s0, 31
	v_add_co_u32 v9, vcc_lo, s4, v9
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v4, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	s_clause 0x1
	global_load_b32 v9, v[9:10], off offset:-4
	global_load_b64 v[4:5], v[4:5], off
	s_lshl_b64 s[0:1], s[0:1], 2
	s_load_b64 s[8:9], s[2:3], 0x0
	s_add_u32 s4, s2, s0
	s_addc_u32 s5, s3, s1
	s_clause 0x1
	s_load_b32 s10, s[2:3], 0x8
	s_load_b64 s[2:3], s[4:5], 0x0
	s_add_u32 s0, s4, s0
	s_addc_u32 s1, s5, s1
	s_clause 0x2
	s_load_b32 s11, s[4:5], 0x8
	s_load_b64 s[4:5], s[0:1], 0x0
	s_load_b32 s0, s[0:1], 0x8
	s_waitcnt vmcnt(5) lgkmcnt(0)
	v_mul_f32_e32 v10, s8, v15
	s_waitcnt vmcnt(4)
	v_dual_mul_f32 v0, s9, v0 :: v_dual_mul_f32 v1, s10, v1
	s_waitcnt vmcnt(2)
	v_mul_f32_e32 v2, s3, v2
	v_mul_f32_e32 v6, s2, v6
	v_cvt_i32_f32_e32 v10, v10
	v_cvt_i32_f32_e32 v0, v0
	v_cvt_i32_f32_e32 v1, v1
	v_mul_f32_e32 v3, s11, v3
	v_cvt_i32_f32_e32 v2, v2
	v_cvt_i32_f32_e32 v6, v6
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add3_u32 v0, v0, v10, v1
	v_cvt_i32_f32_e32 v1, v3
	s_waitcnt vmcnt(1)
	v_mul_f32_e32 v9, s4, v9
	s_waitcnt vmcnt(0)
	v_dual_mul_f32 v3, s5, v4 :: v_dual_mul_f32 v4, s0, v5
	v_add3_u32 v0, v0, v6, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_i32_f32_e32 v5, v9
	v_cvt_i32_f32_e32 v2, v3
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_i32_f32_e32 v3, v4
	v_add3_u32 v0, v0, v1, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v0, v0, v2, v3
	v_mul_hi_i32 v0, 0x38e38e39, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v1, 31, v0
	v_ashrrev_i32_e32 v0, 1, v0
	v_add_nc_u32_e32 v0, v0, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_f32_i32_e32 v2, v0
	v_add_co_u32 v0, vcc_lo, s6, v7
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v8, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB0_4:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12imgMulKernelPfS_iiS_ii
		.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 16
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z12imgMulKernelPfS_iiS_ii, .Lfunc_end0-_Z12imgMulKernelPfS_iiS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 800
; NumSgprs: 18
; NumVgprs: 16
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 16
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .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:           _Z12imgMulKernelPfS_iiS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12imgMulKernelPfS_iiS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     16
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
