// File: rishabh-battulwar[P]imageprocessing/./include/ImageProc.h
// Function: ImageProc::unsharp_mask(Image&, Image&)
void ImageProc::unsharp_mask(Image &img_orig, Image &img_modified)
{
	int ws = 3;
	double kernel[ws][ws]; //discrete convolution operator

	// //gaussian_kernel(kernel, ws, sigma);
	// double kernel_sum = 0.0;
    int kernel_radius = ws / 2;
 //    //double coeff = 1.0 / (2.0 * M_PI * (sigma * sigma));
 //    double frac = 0.0;

 //    for (int row = -kernel_radius; row <= kernel_radius; row++)
 //        for (int col = -kernel_radius; col <= kernel_radius; col++)
 //        {
 //            frac = exp(-1.0 * ((row*row) + (col*col)) / (2.0 * (sigma*sigma)));

 //            kernel[row + kernel_radius][col + kernel_radius] = frac;

 //            kernel_sum += kernel[row + kernel_radius][col + kernel_radius];
 //        }

 //    for (int i = 0; i < ws; i++)
 //        for (int j = 0; j < ws; j++)
 //            kernel[i][j] = kernel[i][j] / kernel_sum; //Normalized

	kernel[0][0] = -1;	kernel[0][1] = -1;	kernel[0][2] = -1;
	kernel[1][0] = -1;	kernel[1][1] =  8;	kernel[1][2] = -1;
	kernel[2][0] = -1;	kernel[2][1] = -1;	kernel[2][2] = -1;


	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 = -kernel_radius, row = 0; m <= kernel_radius; m++, row++)
					for(int n = -kernel_radius, col = 0; n <= kernel_radius; 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) * kernel[row][col];
						}
						// else
						// {
						// 	values[row][col] = img_orig.getvalue((i+m),(j-n),k) * 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 $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x3, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq %rax, %rcx
movq %rcx, -0x90(%rbp)
movq %rsp, %rdx
movq %rdx, -0x20(%rbp)
movq %rax, %rdx
imulq %rdx, %rdx
leaq 0xf(,%rdx,8), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x88(%rbp)
movq %rdx, %rsp
movq %rax, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl $0x2, %esi
cltd
idivl %esi
movl %eax, %edx
movq -0x88(%rbp), %rax
movl %edx, -0x34(%rbp)
imulq $0x0, %rcx, %rdx
movsd 0x2524(%rip), %xmm0     # 0x1c4d0
movsd %xmm0, (%rax,%rdx,8)
imulq $0x0, %rcx, %rdx
movsd 0x2513(%rip), %xmm0     # 0x1c4d0
movsd %xmm0, 0x8(%rax,%rdx,8)
imulq $0x0, %rcx, %rdx
movsd 0x2501(%rip), %xmm0     # 0x1c4d0
movsd %xmm0, 0x10(%rax,%rdx,8)
movq %rcx, %rdx
shlq $0x0, %rdx
movsd 0x24ec(%rip), %xmm0     # 0x1c4d0
movsd %xmm0, (%rax,%rdx,8)
movq %rcx, %rdx
shlq $0x0, %rdx
movsd 0x2508(%rip), %xmm0     # 0x1c500
movsd %xmm0, 0x8(%rax,%rdx,8)
movq %rcx, %rdx
shlq $0x0, %rdx
movsd 0x24c3(%rip), %xmm0     # 0x1c4d0
movsd %xmm0, 0x10(%rax,%rdx,8)
movq %rcx, %rdx
shlq %rdx
movsd 0x24af(%rip), %xmm0     # 0x1c4d0
movsd %xmm0, (%rax,%rdx,8)
movq %rcx, %rdx
shlq %rdx
movsd 0x249c(%rip), %xmm0     # 0x1c4d0
movsd %xmm0, 0x8(%rax,%rdx,8)
shlq %rcx
movsd 0x248b(%rip), %xmm0     # 0x1c4d0
movsd %xmm0, 0x10(%rax,%rcx,8)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x1a2f1
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x1a2e1
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x1a2d1
movl -0x14(%rbp), %eax
movl %eax, %ecx
movq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq %rsp, %rdx
movq %rdx, -0x48(%rbp)
movq %rcx, %rdx
imulq %rdx, %rdx
leaq 0xf(,%rdx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x98(%rbp)
movq %rdx, %rsp
movq %rcx, -0x50(%rbp)
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1a12f
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1a122
movq -0x98(%rbp), %rax
movq -0xa0(%rbp), %rdx
movslq -0x5c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x60(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1a0e7
jmp 0x1a124
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1a0d8
movl $0x0, -0x64(%rbp)
xorl %eax, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x34(%rbp), %eax
jg 0x1a246
xorl %eax, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x34(%rbp), %eax
jg 0x1a22d
movl -0x38(%rbp), %eax
addl -0x68(%rbp), %eax
cmpl $0x0, %eax
jl 0x1a214
movl -0x38(%rbp), %eax
addl -0x68(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x1a214
movl -0x3c(%rbp), %eax
addl -0x70(%rbp), %eax
cmpl $0x0, %eax
jl 0x1a214
movl -0x3c(%rbp), %eax
addl -0x70(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x1a214
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
addl -0x68(%rbp), %esi
movl -0x3c(%rbp), %edx
addl -0x70(%rbp), %edx
movl -0x40(%rbp), %ecx
callq 0x83b0
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rcx
movq -0xa0(%rbp), %rsi
movl %eax, %edx
movq -0x98(%rbp), %rax
cvtsi2sd %edx, %xmm0
movslq -0x6c(%rbp), %rdx
imulq %rdi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movslq -0x74(%rbp), %rdx
mulsd (%rcx,%rdx,8), %xmm0
cvttsd2si %xmm0, %edx
movslq -0x6c(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x74(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x1a216
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x1a160
jmp 0x1a22f
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1a145
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1a2a6
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1a299
movq -0x98(%rbp), %rax
movq -0xa0(%rbp), %rdx
movslq -0x78(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x7c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x1a25c
jmp 0x1a29b
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x1a24d
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
movl -0x64(%rbp), %r8d
callq 0x83f0
movq -0x48(%rbp), %rax
movq %rax, %rsp
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1a080
jmp 0x1a2d3
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1a069
jmp 0x1a2e3
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1a052
movq -0x20(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)