// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rsi, -0xc8(%rbp)
movq %rdi, -0x38(%rbp)
movl $0x1, %eax
subl %edx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
leal -0x1(%rdx), %eax
shrl $0x1f, %eax
leal (%rdx,%rax), %esi
decl %esi
sarl %esi
movq %rdx, -0xa8(%rbp)
movl %edx, %edx
movq %rdx, -0x80(%rbp)
imulq %rdx, %rdx
movq %rsp, %rdi
movq %rdx, -0x88(%rbp)
leaq 0xf(,%rdx,8), %rax
andq $-0x10, %rax
subq %rax, %rdi
movq %rdi, -0x68(%rbp)
movq %rdi, %rsp
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0xa0(%rbp)
movq %rdx, %rsp
movl %ecx, -0x2c(%rbp)
movl %esi, -0x3c(%rbp)
cmpl %esi, %ecx
jg 0x9358
movl -0x3c(%rbp), %eax
movl %eax, %r14d
movl -0x2c(%rbp), %eax
subl %eax, %r14d
incl %r14d
movq -0x80(%rbp), %rcx
leaq (,%rcx,8), %rcx
movq %rcx, -0x90(%rbp)
movl %eax, %edi
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
leaq 0x8312(%rip), %r15      # 0x115f0
movq -0x68(%rbp), %rbx
movl %eax, %r9d
movq %rdi, -0x78(%rbp)
movl %r9d, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
xorl %r13d, %r13d
movsd %xmm0, -0x70(%rbp)
movsd %xmm0, -0x50(%rbp)
leal (%rdi,%r13), %r12d
movsd -0x50(%rbp), %xmm0
callq 0x2110
movq -0x78(%rbp), %rdi
movsd %xmm0, (%rbx,%r13,8)
movsd -0x50(%rbp), %xmm0
shrl $0x1f, %r12d
addsd (%r15,%r12,8), %xmm0
incq %r13
cmpq %r13, %r14
jne 0x92f9
movl -0x40(%rbp), %r9d
movl %r9d, %eax
shrl $0x1f, %eax
movsd -0x70(%rbp), %xmm0
addsd (%r15,%rax,8), %xmm0
incl %r9d
movq -0x48(%rbp), %rcx
incq %rcx
addq -0x90(%rbp), %rbx
cmpq %r14, %rcx
jne 0x92e9
movq -0xa8(%rbp), %rdi
testl %edi, %edi
movq -0x80(%rbp), %rsi
movq -0x68(%rbp), %r9
jle 0x93d6
leaq (,%rsi,8), %rax
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
movq %r9, %rdx
movq %rsi, %r8
xorl %esi, %esi
addsd (%rdx,%rsi,8), %xmm0
incq %rsi
cmpq %rsi, %r8
jne 0x9381
incq %rcx
addq %rax, %rdx
cmpq %r8, %rcx
movq %r8, %rsi
jne 0x937c
testl %edi, %edi
jle 0x93d6
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 0x93ae
incq %rcx
addq %rax, %rdx
addq %rax, %r9
cmpq %r8, %rcx
movq %r8, %rsi
jne 0x93a9
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
testl %ecx, %ecx
jle 0x9694
movq -0x88(%rbp), %r9
leaq (,%r9,4), %rax
movq %rax, -0xb8(%rbp)
movl -0x2c(%rbp), %edx
movl -0x3c(%rbp), %eax
cmpl %eax, %edx
movl %eax, %ebx
cmovgl %edx, %ebx
movslq %edx, %rax
movq %rax, -0xb0(%rbp)
subl %edx, %ebx
incl %ebx
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movl %edx, %r8d
negl %r8d
movl %r8d, -0x94(%rbp)
leaq (,%rsi,8), %r8
movq %r8, -0xe0(%rbp)
leaq (,%rsi,4), %r14
movq $0x0, -0x60(%rbp)
leaq 0xf(,%r9,4), %rsi
andq $-0x10, %rsi
movq %rsi, -0xc0(%rbp)
movl %edx, -0x54(%rbp)
movq %r14, -0xd8(%rbp)
testl %eax, %eax
jle 0x967f
movq -0x38(%rbp), %rcx
movl 0x10(%rcx), %ecx
movq -0xb0(%rbp), %rdx
movq %rdx, -0x70(%rbp)
movl -0x94(%rbp), %edx
movl %edx, -0x58(%rbp)
movq $0x0, -0x48(%rbp)
testl %ecx, %ecx
jle 0x965a
movl $0x0, -0x50(%rbp)
movq %rsp, -0xd0(%rbp)
movq %rsp, %r13
subq -0xc0(%rbp), %r13
movq %r13, %rsp
testl %edi, %edi
jle 0x94c9
movq %r13, %rdi
xorl %esi, %esi
movq -0xb8(%rbp), %rdx
callq 0x20c0
movl -0x3c(%rbp), %eax
cmpl %eax, -0x2c(%rbp)
jg 0x95e7
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
movl %ecx, -0x88(%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, -0x78(%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, -0x90(%rbp)
movl %edx, -0x68(%rbp)
movl %edx, %eax
addl -0x60(%rbp), %eax
setns %r8b
cmpl -0x88(%rbp), %eax
setl %dil
andb %r8b, %dil
imull -0x78(%rbp), %eax
movl %r11d, -0x40(%rbp)
movq -0xb0(%rbp), %r15
xorl %r8d, %r8d
movl %r11d, %r12d
testb %dil, %dil
je 0x9585
movq -0x70(%rbp), %r12
addq %r8, %r12
movq %rbx, %r14
setns %bl
cmpq -0x78(%rbp), %r12
setl %dl
andb %bl, %dl
movq %r14, %rbx
movl %r11d, %r12d
cmpb $0x1, %dl
jne 0x9585
movq -0x48(%rbp), %rdx
leaq (%r15,%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,%r8,8), %xmm0
cvttsd2si %xmm0, %edx
movl %edx, (%r9,%r8,4)
incq %r15
incq %r8
subl %ecx, %r11d
cmpq %r8, %rbx
jne 0x954d
movl -0x68(%rbp), %edx
incl %edx
movq -0x90(%rbp), %rax
incq %rax
movl -0x40(%rbp), %r11d
addl -0x98(%rbp), %r11d
addq -0xe0(%rbp), %r10
movq -0xd8(%rbp), %r14
addq %r14, %r9
cmpq %rbx, %rax
jne 0x951b
xorl %eax, %eax
movq -0xa8(%rbp), %rdi
testl %edi, %edi
jle 0x9614
xorl %ecx, %ecx
movq -0x80(%rbp), %rsi
xorl %edx, %edx
addl (%r13,%rdx,4), %eax
incq %rdx
cmpq %rdx, %rsi
jne 0x95fc
incq %rcx
addq %r14, %r13
cmpq %rsi, %rcx
jne 0x95fa
movq -0xd0(%rbp), %rsp
movq -0xc8(%rbp), %rsi
movq 0x18(%rsi), %rcx
movl 0x8(%rsi), %edx
imull -0x60(%rbp), %edx
addl -0x48(%rbp), %edx
imull 0x10(%rsi), %edx
movl -0x50(%rbp), %esi
addl %esi, %edx
movslq %edx, %rdx
movb %al, (%rcx,%rdx)
incl %esi
movq -0x38(%rbp), %rax
movl 0x10(%rax), %ecx
movl %esi, -0x50(%rbp)
cmpl %ecx, %esi
jl 0x94a0
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x48(%rbp), %r8
incq %r8
movslq %eax, %rdx
incl -0x58(%rbp)
incq -0x70(%rbp)
movq %r8, -0x48(%rbp)
cmpq %rdx, %r8
jl 0x9491
movq -0x38(%rbp), %rcx
movl 0xc(%rcx), %ecx
movq -0x60(%rbp), %rdx
incl %edx
incl -0x54(%rbp)
movq %rdx, -0x60(%rbp)
cmpl %ecx, %edx
jl 0x9466
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop