// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movl %r9d, 0x10(%rsp)
movl %r8d, 0xc(%rsp)
movl %ecx, %ebp
movl %edx, %r15d
movq %rsi, 0x28(%rsp)
movq %rdi, %r14
movl 0xb8(%rsp), %r13d
leaq 0x81ca(%rip), %r12      # 0x106c8
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3fd6
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
movl %r15d, %edx
movl %ebp, %ecx
callq 0x3fd6
movq %rbx, %rbp
movl 0x8(%rbx), %ebx
movl 0xc(%rbp), %r15d
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4032
movl 0x10(%rbp), %r12d
movq %rbp, %rsi
xorl %eax, %eax
testl %r12d, %r12d
movl $0x0, %r14d
cmovgl %r12d, %r14d
movl %ebx, %ecx
testl %ebx, %ebx
movl $0x0, %ebx
cmovgl %ecx, %ebx
movl %ecx, %edx
leaq 0x38(%rsp), %rcx
movq 0x18(%rcx), %rbp
testl %r15d, %r15d
cmovlel %eax, %r15d
movl %r15d, 0x20(%rsp)
movl 0x10(%rcx), %r15d
testl %r13d, %r13d
cmovlel %eax, %r13d
movl %r13d, 0x14(%rsp)
movq 0x18(%rsi), %r13
imull %r12d, %edx
movl %edx, 0x1c(%rsp)
movl 0x8(%rcx), %ecx
imull %r15d, %ecx
movl %ecx, 0x18(%rsp)
cmpl 0x14(%rsp), %eax
je 0x8625
movq %rax, 0x30(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl 0xc(%rsp), %edx
movl 0x10(%rsp), %ecx
movl 0xb0(%rsp), %r8d
callq 0x8644
xorl %esi, %esi
xorl %ecx, %ecx
xorl %edx, %edx
cmpl 0x20(%rsp), %edx
je 0x8619
movl %esi, 0x24(%rsp)
movl %ecx, %edi
xorl %r8d, %r8d
cmpq %rbx, %r8
je 0x8609
movslq %edi, %r9
addq %r13, %r9
movslq %esi, %r10
addq %rbp, %r10
xorl %r11d, %r11d
cmpq %r11, %r14
je 0x85fe
movb (%r10,%r11), %al
movb %al, (%r9,%r11)
incq %r11
jmp 0x85ec
incq %r8
addl %r12d, %edi
addl %r15d, %esi
jmp 0x85d8
incl %edx
addl 0x1c(%rsp), %ecx
movl 0x24(%rsp), %esi
addl 0x18(%rsp), %esi
jmp 0x85c9
movq 0x30(%rsp), %rax
incl %eax
jmp 0x8595
leaq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x411c
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop