// File: rishabh-battulwar[P]imageprocessing/./include/ImageProc.h
// Function: ImageProc::oil_paint_filter(Image&, Image&, int)
void ImageProc::oil_paint_filter(Image &img_orig, Image &img_modified, int window_size)
{
	int ws = window_size; //window_size
	int wleft = ((-1*ws) + 1) / 2;
	int wright = (( 1*ws) - 1) / 2;
	int values[ws*ws][img_orig.channels];
	int max_occur_val[img_orig.channels], max_occurrence = 0, occurrence = 0;;
	int index;

	for(int i = 0; i < img_orig.rows; i++)
	 	for(int j = 0; j < img_orig.cols; j++)
	 	{
			max_occur_val[0] = max_occur_val[1] = max_occur_val[2] = 0;
			max_occurrence = 0;
			for(index = 0; index < ws*ws; index++)
				values[index][0] = values[index][1] = values[index][2] = 0;
			index = 0;

			for(int m = wleft; m <= wright; m++)
				for(int n = wleft; n <= wright; n++)
				{
					if((i+m >= 0) && (i+m < img_orig.rows) && (j+n >= 0) && (j+n < img_orig.cols))
						for(int k = 0; k < img_orig.channels; k++)
						{
							values[index][k] = img_orig.getvalue(i+m, j+n, k);
						}
					else
						for(int k = 0; k < img_orig.channels; k++)
							values[index][k] = 280;

					index++;

				}


//############ FIXXX for img_orig.channels
			for(index = 0; index < ws*ws; index++)
			{
				if(!(values[index][0] == 280) && !(values[index][1] == 280) && !(values[index][2] == 280))
				{
					occurrence = 0;
					for(int r = 0; r < ws*ws; r++)
					{
						if(values[index][0] == values[r][0] &&
						   values[index][1] == values[r][1] &&
						   values[index][2] == values[r][2])
							occurrence++;

					}

					if(max_occurrence < occurrence)
					{
						max_occurrence = occurrence;
						max_occur_val[0] = values[index][0];
						max_occur_val[1] = values[index][1];
						max_occur_val[2] = values[index][2];
					}
				}
			}
//#############

			img_modified.setvalue(i,j,0,max_occur_val[0]);
			img_modified.setvalue(i,j,1,max_occur_val[1]);
			img_modified.setvalue(i,j,2,max_occur_val[2]);


	 	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movl $0x1, %eax
subl %ecx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %ecx, %eax
sarl %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %ecx
movl %ecx, %edx
decl %edx
movl %ecx, %eax
shrl $0x1f, %edx
movl %edx, %ecx
leal -0x1(%rax,%rcx), %eax
sarl %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
imull %eax, %eax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x80(%rbp)
movq %rsp, %rdx
movq %rdx, -0x28(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x78(%rbp)
movq %rdx, %rsp
movq %rcx, -0x30(%rbp)
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x70(%rbp)
movq %rcx, %rsp
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0xced5
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xcec5
movq -0x70(%rbp), %rax
movl $0x0, 0x8(%rax)
movl $0x0, 0x4(%rax)
movl $0x0, (%rax)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl -0x18(%rbp), %ecx
imull -0x18(%rbp), %ecx
cmpl %ecx, %eax
jge 0xcbe1
movq -0x78(%rbp), %rax
movq -0x80(%rbp), %rdx
movslq -0x4c(%rbp), %rcx
imulq %rdx, %rcx
movl $0x0, 0x8(%rax,%rcx,4)
movslq -0x4c(%rbp), %rcx
imulq %rdx, %rcx
movl $0x0, 0x4(%rax,%rcx,4)
movslq -0x4c(%rbp), %rcx
imulq %rdx, %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xcb91
movl $0x0, -0x4c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xcd05
movl -0x1c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xccf5
movl -0x50(%rbp), %eax
addl -0x58(%rbp), %eax
cmpl $0x0, %eax
jl 0xcc9c
movl -0x50(%rbp), %eax
addl -0x58(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0xcc9c
movl -0x54(%rbp), %eax
addl -0x5c(%rbp), %eax
cmpl $0x0, %eax
jl 0xcc9c
movl -0x54(%rbp), %eax
addl -0x5c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xcc9c
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0xcc9a
movq -0x8(%rbp), %rdi
movl -0x50(%rbp), %esi
addl -0x58(%rbp), %esi
movl -0x54(%rbp), %edx
addl -0x5c(%rbp), %edx
movl -0x60(%rbp), %ecx
callq 0x83b0
movq -0x80(%rbp), %rsi
movl %eax, %edx
movq -0x78(%rbp), %rax
movslq -0x4c(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x60(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0xcc4b
jmp 0xccde
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0xccdc
movq -0x78(%rbp), %rax
movq -0x80(%rbp), %rdx
movslq -0x4c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x64(%rbp), %rcx
movl $0x118, (%rax,%rcx,4)   # imm = 0x118
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xcca3
jmp 0xccde
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xcc00
jmp 0xccf7
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0xcbee
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl -0x18(%rbp), %ecx
imull -0x18(%rbp), %ecx
cmpl %ecx, %eax
jge 0xce67
movq -0x78(%rbp), %rax
movq -0x80(%rbp), %rdx
movslq -0x4c(%rbp), %rcx
imulq %rdx, %rcx
cmpl $0x118, (%rax,%rcx,4)   # imm = 0x118
je 0xce57
movq -0x78(%rbp), %rax
movq -0x80(%rbp), %rdx
movslq -0x4c(%rbp), %rcx
imulq %rdx, %rcx
cmpl $0x118, 0x4(%rax,%rcx,4) # imm = 0x118
je 0xce57
movq -0x78(%rbp), %rax
movq -0x80(%rbp), %rdx
movslq -0x4c(%rbp), %rcx
imulq %rdx, %rcx
cmpl $0x118, 0x8(%rax,%rcx,4) # imm = 0x118
je 0xce57
movl $0x0, -0x48(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl -0x18(%rbp), %ecx
imull -0x18(%rbp), %ecx
cmpl %ecx, %eax
jge 0xce10
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %rsi
movslq -0x4c(%rbp), %rax
imulq %rsi, %rax
movl (%rcx,%rax,4), %eax
movslq -0x68(%rbp), %rdx
imulq %rsi, %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0xce00
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %rsi
movslq -0x4c(%rbp), %rax
imulq %rsi, %rax
movl 0x4(%rcx,%rax,4), %eax
movslq -0x68(%rbp), %rdx
imulq %rsi, %rdx
cmpl 0x4(%rcx,%rdx,4), %eax
jne 0xce00
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %rsi
movslq -0x4c(%rbp), %rax
imulq %rsi, %rax
movl 0x8(%rcx,%rax,4), %eax
movslq -0x68(%rbp), %rdx
imulq %rsi, %rdx
cmpl 0x8(%rcx,%rdx,4), %eax
jne 0xce00
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xce02
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0xcd85
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0xce55
movq -0x70(%rbp), %rax
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %rsi
movl -0x48(%rbp), %edx
movl %edx, -0x44(%rbp)
movslq -0x4c(%rbp), %rdx
imulq %rsi, %rdx
movl (%rcx,%rdx,4), %edx
movl %edx, (%rax)
movslq -0x4c(%rbp), %rdx
imulq %rsi, %rdx
movl 0x4(%rcx,%rdx,4), %edx
movl %edx, 0x4(%rax)
movslq -0x4c(%rbp), %rdx
imulq %rsi, %rdx
movl 0x8(%rcx,%rdx,4), %ecx
movl %ecx, 0x8(%rax)
jmp 0xce57
jmp 0xce59
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xcd0c
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
movl -0x54(%rbp), %edx
movl (%rax), %r8d
xorl %ecx, %ecx
callq 0x83f0
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
movl -0x54(%rbp), %edx
movl 0x4(%rax), %r8d
movl $0x1, %ecx
callq 0x83f0
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
movl -0x54(%rbp), %edx
movl 0x8(%rax), %r8d
movl $0x2, %ecx
callq 0x83f0
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0xcb5b
jmp 0xcec7
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xcb44
movq -0x28(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)