// File: 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
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movl $0x1, %eax
subl %ecx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %ecx, %eax
sarl %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %ecx
movl %ecx, %edx
decl %edx
movl %ecx, %eax
shrl $0x1f, %edx
movl %edx, %ecx
leal -0x1(%rax,%rcx), %eax
sarl %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x18(%rbp), %eax
movq %rax, -0xf8(%rbp)
movq %rsp, %rcx
movq %rcx, -0x30(%rbp)
movq %rax, %rcx
imulq %rcx, %rcx
leaq 0xf(,%rcx,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xf0(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl -0x18(%rbp), %eax
movl %eax, %ecx
movq %rcx, %rax
movq %rax, -0xe8(%rbp)
movq %rcx, %rdx
imulq %rdx, %rdx
leaq 0xf(,%rdx,8), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0xe0(%rbp)
movq %rdx, %rsp
movq %rcx, -0x50(%rbp)
movq %rax, -0x58(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0xe7c1
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xe778
movsd -0x68(%rbp), %xmm1
movsd 0xdb3c(%rip), %xmm0     # 0x1c240
callq 0x2350
movq -0xf8(%rbp), %rdx
movq -0xf0(%rbp), %rax
movslq -0x70(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x78(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
cmpl $0x0, -0x74(%rbp)
jge 0xe747
movsd 0xdb2b(%rip), %xmm0     # 0x1c268
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
cmpl $0x0, -0x74(%rbp)
jl 0xe75f
movsd 0xdd7b(%rip), %xmm0     # 0x1c4d0
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0xe761
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0xe6eb
cmpl $0x0, -0x6c(%rbp)
jge 0xe790
movsd 0xdae2(%rip), %xmm0     # 0x1c268
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
cmpl $0x0, -0x6c(%rbp)
jl 0xe7a8
movsd 0xdd32(%rip), %xmm0     # 0x1c4d0
addsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0xe7aa
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0xe6c8
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xe827
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xe81a
movq -0xf0(%rbp), %rax
movq -0xf8(%rbp), %rdx
movslq -0x7c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x80(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0xe7d7
jmp 0xe81c
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0xe7c8
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xe8d9
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xe8c3
movq -0xe0(%rbp), %rax
movq -0xe8(%rbp), %rdx
movq -0xf0(%rbp), %rcx
movq -0xf8(%rbp), %rdi
movslq -0x84(%rbp), %rsi
imulq %rdi, %rsi
shlq $0x3, %rsi
addq %rsi, %rcx
movslq -0x88(%rbp), %rsi
movsd (%rcx,%rsi,8), %xmm0
divsd -0x48(%rbp), %xmm0
movslq -0x84(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x88(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0xe84a
jmp 0xe8c5
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0xe831
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0xeced
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xecd7
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0xecc1
movl -0x18(%rbp), %eax
movl %eax, %ecx
movq %rcx, %rax
movq %rax, -0x108(%rbp)
movq %rsp, %rdx
movq %rdx, -0xa0(%rbp)
movq %rcx, %rdx
imulq %rdx, %rdx
leaq 0xf(,%rdx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x100(%rbp)
movq %rdx, %rsp
movq %rcx, -0xa8(%rbp)
movq %rax, -0xb0(%rbp)
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xe9f6
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xe9e3
movq -0x100(%rbp), %rax
movq -0x108(%rbp), %rdx
movslq -0xb4(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xb8(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0xe999
jmp 0xe9e5
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0xe984
movl $0x0, -0xbc(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0xc0(%rbp)
movl $0x0, -0xc4(%rbp)
movl -0xc0(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xebfd
movl -0x24(%rbp), %eax
movl %eax, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
movl -0xc8(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0xebd8
movl -0x8c(%rbp), %eax
addl -0xc0(%rbp), %eax
cmpl $0x0, %eax
jl 0xeb2c
movl -0x8c(%rbp), %eax
addl -0xc0(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0xeb2c
movl -0x90(%rbp), %eax
addl -0xc8(%rbp), %eax
cmpl $0x0, %eax
jl 0xeb2c
movl -0x90(%rbp), %eax
addl -0xc8(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xeb2c
movq -0x8(%rbp), %rdi
movl -0x8c(%rbp), %esi
addl -0xc0(%rbp), %esi
movl -0x90(%rbp), %edx
addl -0xc8(%rbp), %edx
movl -0x94(%rbp), %ecx
callq 0x83b0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rcx
movq -0x108(%rbp), %rsi
movl %eax, %edx
movq -0x100(%rbp), %rax
cvtsi2sd %edx, %xmm0
movslq -0xc4(%rbp), %rdx
imulq %rdi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movslq -0xcc(%rbp), %rdx
mulsd (%rcx,%rdx,8), %xmm0
cvttsd2si %xmm0, %edx
movslq -0xc4(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xcc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xebb3
movq -0x8(%rbp), %rdi
movl -0x8c(%rbp), %esi
addl -0xc0(%rbp), %esi
movl -0x90(%rbp), %edx
subl -0xc8(%rbp), %edx
movl -0x94(%rbp), %ecx
callq 0x83b0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rcx
movq -0x108(%rbp), %rsi
movl %eax, %edx
movq -0x100(%rbp), %rax
cvtsi2sd %edx, %xmm0
movslq -0xc4(%rbp), %rdx
imulq %rdi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movslq -0xcc(%rbp), %rdx
mulsd (%rcx,%rdx,8), %xmm0
cvttsd2si %xmm0, %edx
movslq -0xc4(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xcc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xebb5
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0xea35
jmp 0xebda
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0xea13
movl $0x0, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xec81
movl $0x0, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xec6e
movq -0x100(%rbp), %rax
movq -0x108(%rbp), %rdx
movslq -0xd0(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0xd4(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0xbc(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0xec1c
jmp 0xec70
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0xec07
movq -0x10(%rbp), %rdi
movl -0x8c(%rbp), %esi
movl -0x90(%rbp), %edx
movl -0x94(%rbp), %ecx
movl -0xbc(%rbp), %r8d
callq 0x83f0
movq -0xa0(%rbp), %rax
movq %rax, %rsp
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0xe91d
jmp 0xecc3
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0xe900
jmp 0xecd9
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0xe8e3
movq -0x30(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)