// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %r8d
movq %rsi, -0x88(%rbp)
movq %rdi, %r14
pushq $0x1
popq %rax
subl %edx, %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, %esi
leal -0x1(%r8), %eax
cltd
idivl %ecx
imull %r8d, %r8d
movl 0x10(%rdi), %r9d
movq %r9, %rcx
imulq %r8, %rcx
leaq 0xf(,%rcx,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
movq %rcx, %r10
subq %rdx, %r10
movq %r10, %rsp
movslq %esi, %r11
movq %r11, -0x90(%rbp)
movl %eax, -0x58(%rbp)
movslq %eax, %r11
negq %rdx
leaq (%rcx,%rdx), %rax
addq $0x8, %rax
movq %rax, -0x70(%rbp)
movq %r9, -0x98(%rbp)
leaq (,%r9,4), %r13
xorl %eax, %eax
movl %esi, -0x30(%rbp)
movl %esi, -0x2c(%rbp)
movq %r10, -0x78(%rbp)
movq %r8, -0x68(%rbp)
movq %rdi, -0x80(%rbp)
cmpl 0xc(%r14), %eax
jge 0x6e49
movq %rax, -0x48(%rbp)
movl -0x30(%rbp), %esi
xorl %edi, %edi
movslq 0x8(%r14), %r12
movq -0x70(%rbp), %rax
movq %r8, %rcx
cmpq %r12, %rdi
jl 0x6c4a
jmp 0x6e3b
andl $0x0, (%rax)
andq $0x0, -0x8(%rax)
addq %r13, %rax
subq $0x1, %rcx
jae 0x6c3f
movl 0xc(%r14), %eax
movl %eax, -0x54(%rbp)
movl 0x10(%r14), %ebx
movq 0x18(%r14), %rax
movq %rax, -0x40(%rbp)
testl %ebx, %ebx
movl $0x0, %edx
cmovgl %ebx, %edx
movl -0x2c(%rbp), %eax
imull %r12d, %eax
movl %esi, -0x4c(%rbp)
addl %esi, %eax
imull %ebx, %eax
movl %eax, -0x34(%rbp)
movl %r12d, %eax
imull %ebx, %eax
movl %eax, -0x50(%rbp)
xorl %eax, %eax
movl -0x30(%rbp), %esi
cmpl -0x58(%rbp), %esi
jg 0x6d32
movl %esi, -0x5c(%rbp)
movl %esi, %ecx
addl -0x48(%rbp), %ecx
setns %sil
cmpl -0x54(%rbp), %ecx
setl %r15b
andb %sil, %r15b
cltq
movq %r13, %r14
imulq %rax, %r14
addq %r10, %r14
movl -0x34(%rbp), %esi
movq -0x90(%rbp), %r10
cmpq %r11, %r10
jg 0x6d1e
testb %r15b, %r15b
je 0x6cfd
movq %r10, %rcx
addq %rdi, %rcx
sets %r9b
cmpq %r12, %rcx
setge %cl
orb %r9b, %cl
jne 0x6cfd
movslq %esi, %r9
addq -0x40(%rbp), %r9
xorl %ecx, %ecx
cmpq %rcx, %rdx
je 0x6d11
movzbl (%r9,%rcx), %r8d
movl %r8d, (%r14,%rcx,4)
incq %rcx
jmp 0x6cea
xorl %ecx, %ecx
cmpq %rcx, %rdx
je 0x6d11
movl $0x118, (%r14,%rcx,4)   # imm = 0x118
incq %rcx
jmp 0x6cff
incq %rax
incq %r10
addq %r13, %r14
addl %ebx, %esi
jmp 0x6cc2
movl -0x5c(%rbp), %esi
incl %esi
movl -0x50(%rbp), %ecx
addl %ecx, -0x34(%rbp)
movq -0x78(%rbp), %r10
jmp 0x6c8d
movq $0x0, -0x40(%rbp)
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %edx, %edx
xorl %esi, %esi
movq -0x68(%rbp), %r8
cmpq %r8, %rdx
je 0x6dd3
movq %rdx, %r9
imulq -0x98(%rbp), %r9
movl (%r10,%r9,4), %ecx
cmpl $0x118, %ecx            # imm = 0x118
je 0x6dc7
movl 0x4(%r10,%r9,4), %eax
cmpl $0x118, %eax            # imm = 0x118
je 0x6dc7
movl 0x8(%r10,%r9,4), %r9d
cmpl $0x118, %r9d            # imm = 0x118
je 0x6dc7
xorl %r10d, %r10d
movq -0x70(%rbp), %r14
movq %r8, %r15
subq $0x1, %r15
jb 0x6daf
cmpl -0x8(%r14), %ecx
jne 0x6daa
cmpl -0x4(%r14), %eax
jne 0x6daa
xorl %r8d, %r8d
cmpl (%r14), %r9d
sete %r8b
addl %r8d, %r10d
addq %r13, %r14
jmp 0x6d8b
cmpl %r10d, %esi
movq -0x68(%rbp), %r8
jge 0x6dc7
movl %r9d, %esi
movq %rsi, -0x40(%rbp)
movl %eax, %r12d
movl %ecx, %ebx
movl %r10d, %esi
incq %rdx
movq -0x78(%rbp), %r10
jmp 0x6d47
movq -0x88(%rbp), %rsi
movq 0x18(%rsi), %rcx
movl 0x8(%rsi), %edx
movq -0x48(%rbp), %r9
imull %r9d, %edx
addl %edi, %edx
imull 0x10(%rsi), %edx
movslq %edx, %rdx
movb %bl, (%rcx,%rdx)
movq 0x18(%rsi), %rcx
movl 0x8(%rsi), %edx
imull %r9d, %edx
addl %edi, %edx
imull 0x10(%rsi), %edx
movslq %edx, %rdx
movb %r12b, 0x1(%rcx,%rdx)
movq 0x18(%rsi), %rax
movl 0x8(%rsi), %ecx
imull %r9d, %ecx
addl %edi, %ecx
imull 0x10(%rsi), %ecx
movslq %ecx, %rcx
movq -0x40(%rbp), %rdx
movb %dl, 0x2(%rax,%rcx)
incq %rdi
movl -0x4c(%rbp), %esi
incl %esi
movq -0x80(%rbp), %r14
jmp 0x6c2a
movq -0x48(%rbp), %rax
incl %eax
incl -0x2c(%rbp)
jmp 0x6c17
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq