// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %rsi, -0x88(%rbp)
movq %rdx, -0x48(%rbp)
movl %edx, %r14d
imull %r14d, %r14d
movl 0x10(%rdi), %r12d
movq %r12, %rax
imulq %r14, %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
cmpl $0x0, 0xc(%rdi)
jle 0x7f40
movl $0x1, %eax
movq -0x48(%rbp), %rcx
subl %ecx, %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
leal -0x1(%rcx), %eax
shrl $0x1f, %eax
addl %ecx, %eax
decl %eax
sarl %eax
cmpl $0x1, %r14d
adcl $0x0, %r14d
movslq %edx, %rcx
cmpl %eax, %ecx
movl %eax, -0x54(%rbp)
cmovgl %edx, %eax
movl %eax, -0x58(%rbp)
movq %rcx, -0x98(%rbp)
subl %ecx, %eax
incl %eax
movq %rax, -0x90(%rbp)
leaq 0x8(%rbx), %rax
movq %rax, -0x78(%rbp)
leaq (,%r12,4), %rax
movq $0x0, -0x40(%rbp)
movl %edx, -0x2c(%rbp)
movl %edx, -0x30(%rbp)
movq %rbx, -0x80(%rbp)
movq %rdi, -0x68(%rbp)
movq %r14, -0x50(%rbp)
movq %r12, -0x70(%rbp)
movl 0x8(%rdi), %ecx
testl %ecx, %ecx
jle 0x7f2a
movl -0x2c(%rbp), %edx
movl %edx, -0x34(%rbp)
xorl %r10d, %r10d
movq %r14, %rdx
movq -0x78(%rbp), %rsi
cmpl $0x0, -0x48(%rbp)
je 0x7d15
movl $0x0, (%rsi)
movq $0x0, -0x8(%rsi)
addq %rax, %rsi
decq %rdx
jne 0x7cff
movl -0x54(%rbp), %edx
cmpl %edx, -0x2c(%rbp)
jg 0x7e10
movq -0x68(%rbp), %rdx
movl 0xc(%rdx), %esi
movl %esi, -0x60(%rbp)
movl 0x10(%rdx), %edi
movq 0x18(%rdx), %rdx
movq %rdx, -0xa8(%rbp)
movslq %ecx, %r9
movl -0x30(%rbp), %edx
imull %r9d, %edx
addl -0x34(%rbp), %edx
imull %edi, %edx
movl %r9d, %ecx
imull %edi, %ecx
movl %ecx, -0x5c(%rbp)
xorl %r14d, %r14d
movl -0x2c(%rbp), %ecx
movq %rcx, -0xa0(%rbp)
addl -0x40(%rbp), %ecx
setns %sil
cmpl -0x60(%rbp), %ecx
setl %cl
andb %sil, %cl
movslq %r14d, %r14
movq -0x90(%rbp), %rsi
leal (%rsi,%r14), %r13d
movq %rax, %r12
imulq %r14, %r12
addq %rbx, %r12
movl %edx, %r11d
movq -0x98(%rbp), %r8
testb %cl, %cl
je 0x7dcf
movq %r8, %rsi
addq %r10, %rsi
sets %r15b
cmpq %r9, %rsi
setge %sil
orb %r15b, %sil
jne 0x7dcf
testl %edi, %edi
jle 0x7de5
movslq %r11d, %rsi
addq -0xa8(%rbp), %rsi
xorl %r15d, %r15d
movzbl (%rsi,%r15), %ebx
movl %ebx, (%r12,%r15,4)
incq %r15
cmpq %r15, %rdi
jne 0x7dbc
jmp 0x7de5
testl %edi, %edi
jle 0x7de5
xorl %esi, %esi
movl $0x118, (%r12,%rsi,4)   # imm = 0x118
incq %rsi
cmpq %rsi, %rdi
jne 0x7dd5
incq %r14
incq %r8
addq %rax, %r12
addl %edi, %r11d
cmpl %r14d, %r13d
jne 0x7d91
movq -0xa0(%rbp), %rsi
leal 0x1(%rsi), %ecx
addl -0x5c(%rbp), %edx
cmpl -0x58(%rbp), %esi
movq -0x80(%rbp), %rbx
jne 0x7d58
xorl %edx, %edx
cmpl $0x0, -0x48(%rbp)
je 0x7ead
xorl %esi, %esi
xorl %edi, %edi
xorl %r15d, %r15d
xorl %r9d, %r9d
movq -0x50(%rbp), %r14
movq -0x70(%rbp), %r12
movq %rsi, %r11
imulq %r12, %r11
movl (%rbx,%r11,4), %ecx
cmpl $0x118, %ecx            # imm = 0x118
je 0x7e9f
movl 0x4(%rbx,%r11,4), %r8d
cmpl $0x118, %r8d            # imm = 0x118
je 0x7e9f
movl 0x8(%rbx,%r11,4), %r11d
cmpl $0x118, %r11d           # imm = 0x118
je 0x7e9f
xorl %ebx, %ebx
movq -0x78(%rbp), %r12
cmpl -0x8(%r12), %ecx
jne 0x7e7f
cmpl -0x4(%r12), %r8d
jne 0x7e7f
xorl %r13d, %r13d
cmpl (%r12), %r11d
sete %r13b
addl %r13d, %ebx
addq %rax, %r12
decq %r14
jne 0x7e63
cmpl %ebx, %r9d
movq -0x50(%rbp), %r14
movq -0x70(%rbp), %r12
jge 0x7e9f
movl %ecx, %edx
movl %r8d, %edi
movl %r11d, %r15d
movl %ebx, %r9d
incq %rsi
cmpq %r14, %rsi
movq -0x80(%rbp), %rbx
jne 0x7e2e
jmp 0x7eb6
xorl %edi, %edi
xorl %r15d, %r15d
movq -0x50(%rbp), %r14
movq -0x88(%rbp), %r8
movq 0x18(%r8), %rcx
movl 0x8(%r8), %esi
movq -0x40(%rbp), %r9
imull %r9d, %esi
addl %r10d, %esi
imull 0x10(%r8), %esi
movslq %esi, %rsi
movb %dl, (%rcx,%rsi)
movq 0x18(%r8), %rcx
movl 0x8(%r8), %edx
imull %r9d, %edx
addl %r10d, %edx
imull 0x10(%r8), %edx
movslq %edx, %rdx
movb %dil, 0x1(%rcx,%rdx)
movq 0x18(%r8), %rcx
movl 0x8(%r8), %edx
imull %r9d, %edx
addl %r10d, %edx
imull 0x10(%r8), %edx
movslq %edx, %rdx
movb %r15b, 0x2(%rcx,%rdx)
incq %r10
movq -0x68(%rbp), %rdi
movslq 0x8(%rdi), %rcx
incl -0x34(%rbp)
cmpq %rcx, %r10
jl 0x7cf2
movq -0x40(%rbp), %rcx
incl %ecx
incl -0x30(%rbp)
movq %rcx, -0x40(%rbp)
cmpl 0xc(%rdi), %ecx
jl 0x7cde
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop