// File: /workspace/github_cpp_makefile_star2_O2/rishabh-battulwar[P]imageprocessing/./include/ImageProc.h
// Function: ImageProc::non_uniform_box_filter(Image&, Image&, int)
void ImageProc::non_uniform_box_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 wtop = wleft;
	int wbottom = wright;

	double filter_kernel[ws][ws], kernel_sum = 0, normalized_kernel[ws][ws];
	double row_exp = 0, col_exp;
	for(int i = wtop, row = 0; i <= wbottom; i++, row++)
	{
		col_exp = row_exp;

		for(int j = wleft, col = 0; j <= wright; j++, col++)
		{
			filter_kernel[row][col] = pow(2.0, col_exp);

			if(j < 0)
				col_exp++;
			if(j >= 0)
				col_exp--;
		}

		if(i < 0)
			row_exp++;

		if(i >= 0)
			row_exp--;
	}

	for(int row = 0; row < ws; row++)
		for(int col = 0; col < ws; col++)
			kernel_sum += filter_kernel[row][col];

	for(int row = 0; row < ws; row++)
		for(int col = 0; col < ws; col++)
			normalized_kernel[row][col] = filter_kernel[row][col] / kernel_sum;

	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++)
		 	{
				int values[ws][ws];
				for(int row = 0; row < ws; row++)
					for(int col = 0; col < ws; col++)
						values[row][col] = 0;
				int values_avg = 0;

				for(int m = wleft, row = 0; m <= wright; m++, row++)
					for(int n = wtop, col = 0; n <= wbottom; n++, col++)
					{
						if((i+m >= 0) && (i+m < img_orig.rows) && (j+n >= 0) && (j+n < img_orig.cols))
						{
							values[row][col] = img_orig.getvalue((i+m),(j+n),k) * normalized_kernel[row][col];
						}
						else
						{
							values[row][col] = img_orig.getvalue((i+m),(j-n),k) * normalized_kernel[row][col];
						}
					}

				for(int row = 0; row < ws; row++)
					for(int col = 0; col < ws; col++)
						values_avg += values[row][col];

				img_modified.setvalue(i,j,k,values_avg);
			}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %r8d
movq %rsi, -0xa8(%rbp)
movq %rdi, -0x98(%rbp)
pushq $0x1
popq %rax
subl %edx, %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
movl %eax, %r15d
leal -0x1(%r8), %eax
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movq %r8, -0x60(%rbp)
movl %r8d, %edx
movq %rdx, %rax
imulq %rdx, %rax
movq %rsp, %rsi
movq %rax, -0x68(%rbp)
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rsi
movq %rsi, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x90(%rbp)
movq %rcx, %rsp
movq %rdx, -0x88(%rbp)
leaq (,%rdx,8), %rax
movq %rax, -0x58(%rbp)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x8840(%rip), %rbx      # 0x105b0
movq %rsi, -0x70(%rbp)
movq %rsi, %r13
movl %r15d, -0x40(%rbp)
cmpl -0x2c(%rbp), %r15d
jg 0x7de2
movq %r13, %r12
movl -0x40(%rbp), %r14d
movsd -0x38(%rbp), %xmm0
cmpl -0x2c(%rbp), %r14d
jg 0x7dc1
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
callq 0x2130
movsd %xmm0, (%r13)
movsd -0x48(%rbp), %xmm0
movl %r14d, %eax
shrl $0x1f, %eax
addsd (%rbx,%rax,8), %xmm0
incl %r14d
addq $0x8, %r13
jmp 0x7d8d
movl %r15d, %eax
shrl $0x1f, %eax
movsd -0x38(%rbp), %xmm0
addsd (%rbx,%rax,8), %xmm0
movsd %xmm0, -0x38(%rbp)
incl %r15d
movq %r12, %r13
addq -0x58(%rbp), %r13
jmp 0x7d7b
xorl %eax, %eax
movq -0x60(%rbp), %rdi
testl %edi, %edi
cmovlel %eax, %edi
xorpd %xmm0, %xmm0
movq -0x70(%rbp), %rsi
movq %rsi, %rcx
movq -0x98(%rbp), %r8
movq -0x88(%rbp), %r9
cmpq %rdi, %rax
je 0x7e25
xorl %edx, %edx
cmpq %rdx, %r9
je 0x7e1c
addsd (%rcx,%rdx,8), %xmm0
incq %rdx
jmp 0x7e0d
incq %rax
addq -0x58(%rbp), %rcx
jmp 0x7e06
xorl %eax, %eax
movq -0x90(%rbp), %rcx
cmpq %rdi, %rax
je 0x7e5c
xorl %edx, %edx
cmpq %rdx, %r9
je 0x7e4d
movsd (%rsi,%rdx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rdx,8)
incq %rdx
jmp 0x7e35
incq %rax
movq -0x58(%rbp), %rdx
addq %rdx, %rcx
addq %rdx, %rsi
jmp 0x7e2e
movl -0x3c(%rbp), %eax
movslq %eax, %rcx
movq %rcx, -0xc0(%rbp)
movslq -0x2c(%rbp), %r11
leaq (,%r9,4), %r10
negl %eax
movl %eax, -0x3c(%rbp)
xorl %r14d, %r14d
movq -0x68(%rbp), %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rax, -0xa0(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq %rdi, -0x60(%rbp)
movq %r10, -0xb8(%rbp)
cmpl 0xc(%r8), %r14d
jge 0x8090
movl -0x3c(%rbp), %eax
movl %eax, -0x50(%rbp)
xorl %r12d, %r12d
movq %r14, -0xc8(%rbp)
movslq 0x8(%r8), %rax
cmpq %rax, %r12
jge 0x8085
xorl %esi, %esi
movl %esi, -0x38(%rbp)
cmpl 0x10(%r8), %esi
jge 0x807a
movq %rsp, -0xb0(%rbp)
movq %rsp, %rsi
subq -0xa0(%rbp), %rsi
movq %rsi, %rsp
movq %rsi, %rax
xorl %edx, %edx
cmpq %rdi, %rdx
je 0x7f11
xorl %ecx, %ecx
cmpq %rcx, %r9
je 0x7f09
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x7efb
incq %rdx
addq %r10, %rax
jmp 0x7ef4
movl 0xc(%r8), %eax
movl %eax, -0x78(%rbp)
movl 0x10(%r8), %edi
movslq 0x8(%r8), %rax
movq 0x18(%r8), %r13
movl -0x4c(%rbp), %r15d
imull %eax, %r15d
addl -0x50(%rbp), %r15d
imull %edi, %r15d
movq %rax, -0x48(%rbp)
imull %edi, %eax
movl %eax, -0x74(%rbp)
movq %rsi, %r8
movq -0x90(%rbp), %rbx
movl -0x40(%rbp), %eax
movl -0x38(%rbp), %r9d
cmpl -0x2c(%rbp), %eax
jg 0x8016
movl %eax, -0x7c(%rbp)
movl %eax, %ecx
addl %r14d, %ecx
setns %al
cmpl -0x78(%rbp), %ecx
setl %dl
andb %al, %dl
imull -0x48(%rbp), %ecx
movl %ecx, -0x70(%rbp)
movl %r15d, -0x68(%rbp)
xorl %eax, %eax
movq -0xc0(%rbp), %rcx
cmpq %r11, %rcx
jg 0x7fef
movl %r15d, %r14d
testb %dl, %dl
je 0x7fc4
movq %rcx, %r10
addq %r12, %r10
setns %r14b
cmpq -0x48(%rbp), %r10
movq %r12, %r9
movq %r11, %r12
setl %r11b
andb %r14b, %r11b
movl %r15d, %r14d
cmpb $0x1, %r11b
movq %r12, %r11
movq %r9, %r12
movl -0x38(%rbp), %r9d
jne 0x7fc4
addl -0x70(%rbp), %r10d
imull %edi, %r10d
movl %r10d, %r14d
addl %r9d, %r14d
movslq %r14d, %r10
movzbl (%r13,%r10), %r10d
cvtsi2sd %r10d, %xmm0
mulsd (%rbx,%rax,4), %xmm0
cvttsd2si %xmm0, %r10d
movl %r10d, (%r8,%rax,2)
incq %rcx
addq $0x2, %rax
subl %edi, %r15d
jmp 0x7f7f
movl -0x7c(%rbp), %eax
incl %eax
addq -0x58(%rbp), %rbx
movq -0xb8(%rbp), %r10
addq %r10, %r8
movl -0x68(%rbp), %r15d
addl -0x74(%rbp), %r15d
movq -0xc8(%rbp), %r14
jmp 0x7f4f
xorl %edx, %edx
xorl %eax, %eax
movq -0x60(%rbp), %rdi
movq -0x98(%rbp), %r8
movq -0x88(%rbp), %r9
cmpq %rdi, %rdx
je 0x8048
xorl %ecx, %ecx
cmpq %rcx, %r9
je 0x8040
addl (%rsi,%rcx,4), %eax
incq %rcx
jmp 0x8033
incq %rdx
addq %r10, %rsi
jmp 0x802c
movq -0xa8(%rbp), %rdx
movl 0x8(%rdx), %ecx
imull %r14d, %ecx
addl %r12d, %ecx
imull 0x10(%rdx), %ecx
movq 0x18(%rdx), %rdx
movl -0x38(%rbp), %esi
addl %esi, %ecx
movslq %ecx, %rcx
movb %al, (%rdx,%rcx)
movq -0xb0(%rbp), %rsp
incl %esi
jmp 0x7ece
incq %r12
incl -0x50(%rbp)
jmp 0x7ebf
incl %r14d
incl -0x4c(%rbp)
jmp 0x7ea5
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop