// File: /workspace/github_cpp_makefile_star2_O1/rishabh-battulwar[P]imageprocessing/./include/ImageProc.h
// Function: ImageProc::apply_bilateral_filter(char const*, char const*, int, int, int, int, int, int)
void ImageProc::apply_bilateral_filter(const char *infile, const char *outfile, int width, int height, int window_size, int sigma, int sigma_simi, int iter)
{
	Image img_orig("color", width, height);
	Image img_modified("color", width, height);
	img_orig.read_image(infile, img_orig.cols, img_orig.rows);

	// Image img_red("bw", img_orig.cols, img_orig.rows);
	// Image img_blue("bw", img_orig.cols, img_orig.rows);
	// Image img_green("bw", img_orig.cols, img_orig.rows);
	// Image img_redOut("bw", img_orig.cols, img_orig.rows);
	// Image img_greenOut("bw", img_orig.cols, img_orig.rows);
	// Image img_blueOut("bw", img_orig.cols, img_orig.rows);

	// for(int i = 0; i < img_orig.rows; i++)
	// 	for(int j = 0; j < img_orig.cols; j++)
	// 	{
	// 		img_red.setvalue(i,j,0,img_orig.getvalue(i,j,0));
	// 		img_green.setvalue(i,j,0,img_orig.getvalue(i,j,1));
	// 		img_blue.setvalue(i,j,0,img_orig.getvalue(i,j,2));
	// 	}

	for(int i = 0; i < iter; i++)
	{
		// median_filter(img_orig, img_modified, window_size);
		// for(int i = 0; i < img_orig.rows; i++)
		// for(int j = 0; j < img_orig.cols; j++)
		// for(int k = 0; k < img_orig.channels; k++)
		// 	img_orig.setvalue(i,j,k,img_modified.getvalue(i,j,k));

		bilateral_filter(img_orig, img_modified, window_size, sigma, sigma_simi);
		for(int i = 0; i < img_orig.rows; i++)
		 	for(int j = 0; j < img_orig.cols; j++)
		 		for(int k = 0; k < img_orig.channels; k++)
			 	{
			 		img_orig.setvalue(i,j,k,img_modified.getvalue(i,j,k));
			 	}
	}

	img_modified.write_image(outfile, img_modified.cols, img_modified.rows);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, 0x4(%rsp)
movl %r8d, (%rsp)
movl %ecx, %r15d
movl %edx, %r12d
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
leaq 0x7b6a(%rip), %rbx      # 0x1165c
leaq 0x48(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4c6e
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x4c6e
movl 0x8(%r13), %ebx
movl 0xc(%r13), %eax
movq %rax, 0x10(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x4cde
cmpl $0x0, 0xa8(%rsp)
jle 0x9bfc
leaq 0x48(%rsp), %rax
movl 0x10(%rax), %r12d
leaq 0x28(%rsp), %rcx
movq 0x18(%rcx), %r13
movl 0x10(%rcx), %ebp
movq 0x18(%rax), %r14
movl %ebx, %eax
imull %r12d, %eax
movl %eax, 0xc(%rsp)
movl 0x8(%rcx), %eax
imull %ebp, %eax
movl %eax, 0x8(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movl (%rsp), %edx
movl 0x4(%rsp), %ecx
movl 0xa0(%rsp), %r8d
callq 0x9c1a
cmpl $0x0, 0x10(%rsp)
jle 0x9be8
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
testl %ebx, %ebx
jle 0x9bd6
movl %eax, %esi
movl %ecx, %edi
xorl %r8d, %r8d
testl %r12d, %r12d
jle 0x9bc9
movslq %edi, %r9
addq %r14, %r9
movslq %esi, %r10
addq %r13, %r10
xorl %r11d, %r11d
movb (%r10,%r11), %r15b
movb %r15b, (%r9,%r11)
incq %r11
cmpq %r11, %r12
jne 0x9bb9
incq %r8
addl %r12d, %edi
addl %ebp, %esi
cmpq %rbx, %r8
jne 0x9ba5
incq %rdx
addl 0xc(%rsp), %ecx
addl 0x8(%rsp), %eax
cmpq 0x10(%rsp), %rdx
jne 0x9b9a
movq 0x20(%rsp), %rax
incl %eax
cmpl 0xa8(%rsp), %eax
jne 0x9b6a
leaq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4e1a
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq