// File: /workspace/github_cpp_makefile_star2_O1/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 $0xb8, %rsp
movl %edx, %r12d
movq %rsi, -0xc8(%rbp)
movq %rdi, -0x40(%rbp)
movl $0x1, %eax
subl %edx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
leal -0x1(%r12), %eax
shrl $0x1f, %eax
leal (%r12,%rax), %edx
decl %edx
sarl %edx
movl %r12d, %esi
movq %rsi, %rax
imulq %rsi, %rax
movq %rsp, %rdi
movq %rax, -0x80(%rbp)
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rdi
movq %rdi, -0x48(%rbp)
movq %rdi, %rsp
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, -0xa0(%rbp)
movq %rdi, %rsp
movl %ecx, -0x2c(%rbp)
movl %edx, -0x30(%rbp)
cmpl %edx, %ecx
movq %rsi, -0x78(%rbp)
jg 0x92c1
movl -0x30(%rbp), %eax
movl %eax, %r14d
movl -0x2c(%rbp), %eax
subl %eax, %r14d
incl %r14d
leaq (,%rsi,8), %rcx
movq %rcx, -0x88(%rbp)
movl %eax, %r15d
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
movq -0x48(%rbp), %rbx
movl %eax, -0x38(%rbp)
movq %rcx, -0x68(%rbp)
xorl %r13d, %r13d
movsd %xmm0, -0x90(%rbp)
movapd %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
movsd %xmm0, -0x70(%rbp)
callq 0x2120
movsd -0x50(%rbp), %xmm1
movsd %xmm0, (%rbx,%r13,8)
movl %r15d, %eax
addl %r13d, %eax
addsd 0x803a(%rip), %xmm1     # 0x11288
movapd %xmm1, %xmm0
js 0x9259
movsd -0x70(%rbp), %xmm0
addsd 0x801f(%rip), %xmm0     # 0x11280
js 0x9267
movapd %xmm0, %xmm1
incq %r13
movapd %xmm1, %xmm0
cmpq %r13, %r14
jne 0x9226
movsd -0x90(%rbp), %xmm2
movapd %xmm2, %xmm0
addsd 0x8001(%rip), %xmm0     # 0x11288
movapd %xmm0, %xmm1
movl -0x38(%rbp), %eax
testl %eax, %eax
js 0x9296
movapd %xmm2, %xmm1
addsd 0x7fe2(%rip), %xmm1     # 0x11280
movq -0x78(%rbp), %rsi
movq -0x68(%rbp), %rcx
js 0x92ac
movapd %xmm1, %xmm0
incl %eax
incq %rcx
addq -0x88(%rbp), %rbx
cmpq %r14, %rcx
jne 0x9210
testl %r12d, %r12d
jle 0x9301
leaq (,%rsi,8), %rax
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
movq -0x48(%rbp), %r9
movq %r9, %rdx
movq -0x40(%rbp), %rdi
movq %rsi, %r8
xorl %esi, %esi
addsd (%rdx,%rsi,8), %xmm0
incq %rsi
cmpq %rsi, %r8
jne 0x92e4
incq %rcx
addq %rax, %rdx
cmpq %r8, %rcx
movq %r8, %rsi
jne 0x92df
jmp 0x930d
xorpd %xmm0, %xmm0
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %r9
testl %r12d, %r12d
jle 0x9350
leaq (,%rsi,8), %rax
xorl %ecx, %ecx
movq -0xa0(%rbp), %rdx
movq %rsi, %r8
xorl %esi, %esi
movsd (%r9,%rsi,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %r8
jne 0x9328
incq %rcx
addq %rax, %rdx
addq %rax, %r9
cmpq %r8, %rcx
movq %r8, %rsi
jne 0x9323
cmpl $0x0, 0xc(%rdi)
jle 0x9604
movq -0x80(%rbp), %rsi
leaq (,%rsi,4), %rax
movq %rax, -0xb0(%rbp)
movl -0x2c(%rbp), %eax
movslq %eax, %rcx
movq %rcx, -0xa8(%rbp)
movl -0x30(%rbp), %ecx
cmpl %ecx, %eax
movl %ecx, %r14d
cmovgl %eax, %r14d
subl %eax, %r14d
incl %r14d
movl %eax, %ecx
negl %ecx
movl %ecx, -0x94(%rbp)
movq -0x78(%rbp), %rcx
leaq (,%rcx,8), %rdx
movq %rdx, -0xe0(%rbp)
leaq (,%rcx,4), %rbx
movq $0x0, -0x60(%rbp)
leaq 0xf(,%rsi,4), %rcx
andq $-0x10, %rcx
movq %rcx, -0xb8(%rbp)
movl %eax, -0x54(%rbp)
movq %r12, -0xc0(%rbp)
movq %rbx, -0xd8(%rbp)
cmpl $0x0, 0x8(%rdi)
jle 0x95ee
movq -0xa8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x58(%rbp)
movq $0x0, -0x38(%rbp)
cmpl $0x0, 0x10(%rdi)
jle 0x95cf
movl $0x0, -0x50(%rbp)
movq %rsp, -0xd0(%rbp)
movq %rsp, %r13
subq -0xb8(%rbp), %r13
movq %r13, %rsp
testl %r12d, %r12d
jle 0x943e
movq %r13, %rdi
xorl %esi, %esi
movq -0xb0(%rbp), %rdx
callq 0x20c0
movl -0x30(%rbp), %eax
cmpl %eax, -0x2c(%rbp)
jg 0x955e
movq -0x40(%rbp), %rax
movl 0xc(%rax), %ecx
movl %ecx, -0x80(%rbp)
movl 0x10(%rax), %ecx
movslq 0x8(%rax), %rdx
movq 0x18(%rax), %rsi
movl -0x54(%rbp), %r11d
imull %edx, %r11d
addl -0x58(%rbp), %r11d
imull %ecx, %r11d
movq %rdx, -0x70(%rbp)
movl %edx, %eax
imull %ecx, %eax
movl %eax, -0x98(%rbp)
movq %r13, %r9
movq -0xa0(%rbp), %r10
xorl %eax, %eax
movl -0x2c(%rbp), %edx
movq %rax, -0x88(%rbp)
movl %edx, -0x48(%rbp)
movl %edx, %eax
addl -0x60(%rbp), %eax
setns %r8b
cmpl -0x80(%rbp), %eax
setl %dil
andb %r8b, %dil
imull -0x70(%rbp), %eax
movl %r11d, -0x90(%rbp)
movq -0xa8(%rbp), %r8
xorl %r15d, %r15d
movl %r11d, %r12d
testb %dil, %dil
je 0x94f9
movq -0x68(%rbp), %r12
addq %r15, %r12
movq %r14, %rbx
setns %r14b
cmpq -0x70(%rbp), %r12
setl %dl
andb %r14b, %dl
movq %rbx, %r14
movl %r11d, %r12d
cmpb $0x1, %dl
jne 0x94f9
movq -0x38(%rbp), %rdx
leaq (%r8,%rdx), %r12
addl %eax, %r12d
imull %ecx, %r12d
addl -0x50(%rbp), %r12d
movslq %r12d, %rdx
movzbl (%rsi,%rdx), %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
mulsd (%r10,%r15,8), %xmm0
cvttsd2si %xmm0, %edx
movl %edx, (%r9,%r15,4)
incq %r8
incq %r15
subl %ecx, %r11d
cmpq %r15, %r14
jne 0x94bf
movl -0x48(%rbp), %edx
incl %edx
movq -0x88(%rbp), %rax
incq %rax
movl -0x90(%rbp), %r11d
addl -0x98(%rbp), %r11d
addq -0xe0(%rbp), %r10
movq -0xd8(%rbp), %rbx
addq %rbx, %r9
cmpq %r14, %rax
jne 0x948d
xorl %eax, %eax
movq -0xc0(%rbp), %r12
testl %r12d, %r12d
jle 0x9592
xorl %ecx, %ecx
movq -0x40(%rbp), %rdi
movq -0x78(%rbp), %rsi
xorl %edx, %edx
addl (%r13,%rdx,4), %eax
incq %rdx
cmpq %rdx, %rsi
jne 0x9578
incq %rcx
addq %rbx, %r13
cmpq %rsi, %rcx
jne 0x9576
jmp 0x9596
movq -0x40(%rbp), %rdi
movq -0xd0(%rbp), %rsp
movq -0xc8(%rbp), %rsi
movq 0x18(%rsi), %rcx
movl 0x8(%rsi), %edx
imull -0x60(%rbp), %edx
addl -0x38(%rbp), %edx
imull 0x10(%rsi), %edx
movl -0x50(%rbp), %esi
addl %esi, %edx
movslq %edx, %rdx
movb %al, (%rcx,%rdx)
incl %esi
movl %esi, -0x50(%rbp)
cmpl 0x10(%rdi), %esi
jl 0x9414
movq -0x38(%rbp), %rdx
incq %rdx
movslq 0x8(%rdi), %rax
incl -0x58(%rbp)
incq -0x68(%rbp)
movq %rdx, -0x38(%rbp)
cmpq %rax, %rdx
jl 0x9403
movq -0x60(%rbp), %rax
incl %eax
incl -0x54(%rbp)
movq %rax, -0x60(%rbp)
cmpl 0xc(%rdi), %eax
jl 0x93dd
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop