// File: /workspace/github_cpp_makefile_star2_O3/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 $0x98, %rsp
movq %rsi, -0x98(%rbp)
movl %edx, %r14d
imull %r14d, %r14d
movl 0x10(%rdi), %r15d
movq %r15, %rax
imulq %r14, %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %rdi, -0x40(%rbp)
movl 0xc(%rdi), %esi
testl %esi, %esi
jle 0x8009
movl $0x1, %eax
subl %edx, %eax
movl %eax, %edi
shrl $0x1f, %edi
addl %eax, %edi
sarl %edi
leal -0x1(%rdx), %eax
shrl $0x1f, %eax
addl %edx, %eax
decl %eax
sarl %eax
cmpl $0x1, %r14d
adcl $0x0, %r14d
movslq %edi, %rcx
cmpl %eax, %ecx
movl %eax, -0x64(%rbp)
cmovgl %edi, %eax
movl %eax, -0x68(%rbp)
movq %rcx, -0xb0(%rbp)
subl %ecx, %eax
incl %eax
movq %rax, -0xa8(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %ecx
leaq 0x8(%r12), %rax
movq %rax, -0x88(%rbp)
leaq (,%r15,4), %rax
leaq 0xc(%r12), %r8
movq %r8, -0xa0(%rbp)
movq $0x0, -0x48(%rbp)
movdqa 0x9948(%rip), %xmm0     # 0x11590
movdqa 0x9950(%rip), %xmm1     # 0x115a0
movdqa 0x9958(%rip), %xmm2     # 0x115b0
pcmpeqd %xmm3, %xmm3
movdqa 0x995c(%rip), %xmm4     # 0x115c0
movl %edi, -0x2c(%rbp)
movl %edi, -0x30(%rbp)
movq %rdx, -0x90(%rbp)
movq %r14, -0x50(%rbp)
movq %r15, -0x80(%rbp)
movq %r12, -0x58(%rbp)
testl %ecx, %ecx
jle 0x7ff4
movl -0x2c(%rbp), %esi
movl %esi, -0x34(%rbp)
movq $0x0, -0x60(%rbp)
movq %r14, %rdi
movq -0x88(%rbp), %rsi
testl %edx, %edx
je 0x7cb7
movl $0x0, (%rsi)
movq $0x0, -0x8(%rsi)
addq %rax, %rsi
decq %rdi
jne 0x7ca1
movl -0x64(%rbp), %edx
cmpl %edx, -0x2c(%rbp)
jg 0x7eba
movq -0x40(%rbp), %rdx
movl 0xc(%rdx), %esi
movl %esi, -0x70(%rbp)
movl 0x10(%rdx), %edi
movq 0x18(%rdx), %rdx
movq %rdx, -0xc0(%rbp)
movslq %ecx, %r11
leal 0x3(%rdi), %esi
andl $-0x4, %esi
leaq -0x1(%rdi), %rcx
movq %rcx, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movl -0x30(%rbp), %r14d
imull %r11d, %r14d
addl -0x34(%rbp), %r14d
imull %edi, %r14d
movl %r11d, %ecx
imull %edi, %ecx
movl %ecx, -0x6c(%rbp)
xorl %ecx, %ecx
pxor %xmm2, %xmm5
movl -0x2c(%rbp), %edx
movl %edx, %r8d
movslq %ecx, %r10
movq %rax, %r12
imulq %r10, %r12
movq -0x58(%rbp), %rcx
leaq (%rcx,%r12), %rdx
addq -0xa0(%rbp), %r12
movq %r8, -0xb8(%rbp)
movl %r8d, %ecx
addl -0x48(%rbp), %ecx
setns %r8b
cmpl -0x70(%rbp), %ecx
setl %bl
andb %r8b, %bl
movq -0xa8(%rbp), %rcx
addl %r10d, %ecx
movl %r14d, -0x74(%rbp)
movq -0xb0(%rbp), %r9
testb %bl, %bl
je 0x7d9d
movq %r9, %r8
addq -0x60(%rbp), %r8
js 0x7d9d
cmpq %r11, %r8
jge 0x7d9d
testl %edi, %edi
jle 0x7e82
movslq %r14d, %r13
addq -0xc0(%rbp), %r13
xorl %r8d, %r8d
movzbl (%r13,%r8), %r15d
movl %r15d, (%rdx,%r8,4)
incq %r8
cmpq %r8, %rdi
jne 0x7d86
jmp 0x7e82
testl %edi, %edi
jle 0x7e82
xorl %r13d, %r13d
movdqa %xmm1, %xmm6
movdqa %xmm0, %xmm7
movdqa %xmm6, %xmm8
pxor %xmm2, %xmm8
movdqa %xmm8, %xmm9
pcmpgtd %xmm5, %xmm9
pcmpeqd %xmm5, %xmm8
pshufd $0xf5, %xmm8, %xmm10    # xmm10 = xmm8[1,1,3,3]
pand %xmm9, %xmm10
pshufd $0xf5, %xmm9, %xmm8     # xmm8 = xmm9[1,1,3,3]
por %xmm10, %xmm8
movd %xmm8, %r8d
notl %r8d
testb $0x1, %r8b
je 0x7df6
movl $0x118, -0xc(%r12,%r13,4) # imm = 0x118
pxor %xmm3, %xmm8
pextrw $0x4, %xmm8, %r8d
testb $0x1, %r8b
je 0x7e10
movl $0x118, -0x8(%r12,%r13,4) # imm = 0x118
movdqa %xmm7, %xmm8
pxor %xmm2, %xmm8
movdqa %xmm8, %xmm9
pcmpgtd %xmm5, %xmm9
pcmpeqd %xmm5, %xmm8
pshufd $0xf5, %xmm8, %xmm10    # xmm10 = xmm8[1,1,3,3]
pand %xmm9, %xmm10
pshufd $0xf5, %xmm9, %xmm8     # xmm8 = xmm9[1,1,3,3]
por %xmm10, %xmm8
pxor %xmm3, %xmm8
pextrw $0x0, %xmm8, %r8d
testb $0x1, %r8b
je 0x7e59
movl $0x118, -0x4(%r12,%r13,4) # imm = 0x118
pextrw $0x4, %xmm8, %r8d
testb $0x1, %r8b
je 0x7e6d
movl $0x118, (%r12,%r13,4)   # imm = 0x118
addq $0x4, %r13
paddq %xmm4, %xmm6
paddq %xmm4, %xmm7
cmpq %r13, %rsi
jne 0x7db0
incq %r10
incq %r9
addq %rax, %r12
addl %edi, %r14d
addq %rax, %rdx
cmpl %r10d, %ecx
jne 0x7d5f
movq -0xb8(%rbp), %r8
leal 0x1(%r8), %edx
movl -0x74(%rbp), %r14d
addl -0x6c(%rbp), %r14d
cmpl -0x68(%rbp), %r8d
movl %edx, %r8d
jne 0x7d17
xorl %r13d, %r13d
movq -0x90(%rbp), %rdx
testl %edx, %edx
je 0x7f69
xorl %edi, %edi
xorl %esi, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq -0x50(%rbp), %r14
movq -0x80(%rbp), %r15
movq -0x58(%rbp), %r12
movq %rdi, %r11
imulq %r15, %r11
movl (%r12,%r11,4), %r9d
cmpl $0x118, %r9d            # imm = 0x118
je 0x7f5b
movl 0x4(%r12,%r11,4), %r10d
cmpl $0x118, %r10d           # imm = 0x118
je 0x7f5b
movl 0x8(%r12,%r11,4), %r11d
cmpl $0x118, %r11d           # imm = 0x118
je 0x7f5b
xorl %ebx, %ebx
movq -0x88(%rbp), %r12
cmpl -0x8(%r12), %r9d
jne 0x7f36
cmpl -0x4(%r12), %r10d
jne 0x7f36
xorl %r15d, %r15d
cmpl (%r12), %r11d
sete %r15b
addl %r15d, %ebx
addq %rax, %r12
decq %r14
jne 0x7f1a
cmpl %ebx, %r8d
movq -0x50(%rbp), %r14
movq -0x80(%rbp), %r15
movq -0x58(%rbp), %r12
jge 0x7f5b
movl %r9d, %r13d
movl %r10d, %esi
movl %r11d, %ecx
movl %ebx, %r8d
incq %rdi
cmpq %r14, %rdi
jne 0x7ee1
jmp 0x7f71
xorl %esi, %esi
xorl %ecx, %ecx
movq -0x50(%rbp), %r14
movq -0x98(%rbp), %r9
movq 0x18(%r9), %rdi
movl 0x8(%r9), %r8d
movq -0x48(%rbp), %r10
imull %r10d, %r8d
movq -0x60(%rbp), %r11
addl %r11d, %r8d
imull 0x10(%r9), %r8d
movslq %r8d, %r8
movb %r13b, (%rdi,%r8)
movq 0x18(%r9), %r8
movl 0x8(%r9), %edi
imull %r10d, %edi
addl %r11d, %edi
imull 0x10(%r9), %edi
movslq %edi, %rdi
movb %sil, 0x1(%r8,%rdi)
movq 0x18(%r9), %rdi
movl 0x8(%r9), %esi
imull %r10d, %esi
addl %r11d, %esi
imull 0x10(%r9), %esi
movslq %esi, %rsi
movb %cl, 0x2(%rdi,%rsi)
incq %r11
movq -0x40(%rbp), %rcx
movslq 0x8(%rcx), %rcx
incl -0x34(%rbp)
movq %r11, -0x60(%rbp)
cmpq %rcx, %r11
jl 0x7c93
movq -0x40(%rbp), %rsi
movl 0xc(%rsi), %esi
movq -0x48(%rbp), %rdi
incl %edi
incl -0x30(%rbp)
movq %rdi, -0x48(%rbp)
cmpl %esi, %edi
jl 0x7c7d
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq