// File: /workspace/github_cpp_makefile_star2_O2/rishabh-battulwar[P]imageprocessing/./include/ImageProc.h
// Function: ImageProc::median_filter(Image&, Image&, int)
void ImageProc::median_filter(Image &img_orig, Image &img_modified, int window_size)
{
	int ws = window_size;
	int kernel_radius = ws / 2;
	int values[ws*ws];
	int index = 0;
	int median_value;

	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++)
		 	{
				for(index = 0; index < (ws*ws); index++)
					values[index] = 0;

				index = 0;

				for(int m = -kernel_radius; m <= kernel_radius; m++)
					for(int n = -kernel_radius; n <= kernel_radius; n++)
					{
						if((i+m >= 0) && (i+m < img_orig.rows) && (j+n >= 0) && (j+n < img_orig.cols))
							values[index] = img_orig.getvalue((i+m),(j+n),k);
						else
							values[index] = img_orig.getvalue((i+m),(j-n),k);
						index++;
					}

				mergesort(values, 0, ((ws*ws)-1));
				median_value = get_median(values, (ws*ws));

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

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %r8d
movq %rsi, -0x80(%rbp)
pushq $0x2
popq %rcx
movl %edx, %eax
cltd
idivl %ecx
imull %r8d, %r8d
movq %rsp, %r13
leaq 0xf(,%r8,4), %rcx
andq $-0x10, %rcx
subq %rcx, %r13
movq %r13, %rsp
movl %eax, %ecx
negl %ecx
movl %r8d, %edx
decl %edx
movl %edx, -0x34(%rbp)
movslq %ecx, %rdx
leal 0x1(%rax), %esi
cmpl %esi, %edx
movq %rdx, -0x58(%rbp)
cmovgl %edx, %esi
movl %esi, -0x40(%rbp)
movq %rax, -0x70(%rbp)
cltq
leaq 0x1(,%rax,2), %rax
movq %rax, -0x88(%rbp)
xorl %ebx, %ebx
movl %ecx, -0x38(%rbp)
movl %ecx, -0x2c(%rbp)
movq %r8, -0x50(%rbp)
movq %rdi, -0x78(%rbp)
cmpl 0xc(%rdi), %ebx
jge 0x78df
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x70(%rbp), %rax
movl %eax, -0x30(%rbp)
xorl %r8d, %r8d
movq %rbx, -0x90(%rbp)
movslq 0x8(%rdi), %rax
cmpq %rax, %r8
jge 0x78d5
xorl %r15d, %r15d
movq %r8, -0x68(%rbp)
movl 0x10(%rdi), %eax
cmpl %eax, %r15d
jge 0x78c6
xorl %ecx, %ecx
movq -0x50(%rbp), %rdx
cmpq %rcx, %rdx
je 0x77be
andl $0x0, (%r13,%rcx,4)
incq %rcx
jmp 0x77ae
movl 0xc(%rdi), %ecx
movl %ecx, -0x3c(%rbp)
movslq 0x8(%rdi), %rdx
movq 0x18(%rdi), %rsi
movl -0x2c(%rbp), %edi
imull %edx, %edi
addl -0x30(%rbp), %edi
xorl %r8d, %r8d
movl -0x38(%rbp), %r10d
cmpl -0x40(%rbp), %r10d
je 0x787f
movl %r10d, -0x44(%rbp)
addl %ebx, %r10d
setns %cl
cmpl -0x3c(%rbp), %r10d
setl %r11b
andb %cl, %r11b
imull %edx, %r10d
movslq %r8d, %r8
movq -0x60(%rbp), %r12
movl %edi, -0x48(%rbp)
movq -0x88(%rbp), %rcx
movq -0x58(%rbp), %rbx
subq $0x1, %rcx
jb 0x7867
movl %edi, %r9d
testb %r11b, %r11b
je 0x7846
testq %r12, %r12
setns %r9b
cmpq %rdx, %r12
setl %r14b
andb %r9b, %r14b
movl %edi, %r9d
cmpb $0x1, %r14b
jne 0x7846
movq -0x68(%rbp), %r9
addq %rbx, %r9
addl %r10d, %r9d
imull %eax, %r9d
addl %r15d, %r9d
movslq %r9d, %r9
movzbl (%rsi,%r9), %r9d
movl %r9d, (%r13,%r8,4)
incq %r8
incq %rbx
decl %edi
incq %r12
jmp 0x7814
movl -0x44(%rbp), %r10d
incl %r10d
movl -0x48(%rbp), %edi
addl %edx, %edi
movq -0x90(%rbp), %rbx
jmp 0x77dc
movq %r13, %rdi
xorl %esi, %esi
movl -0x34(%rbp), %edx
callq 0x82a0
movq %r13, %rdi
movq -0x50(%rbp), %rsi
callq 0x82f4
movq -0x80(%rbp), %rsi
movq 0x18(%rsi), %rcx
movl 0x8(%rsi), %edx
imull %ebx, %edx
movq -0x68(%rbp), %r8
addl %r8d, %edx
imull 0x10(%rsi), %edx
addl %r15d, %edx
movslq %edx, %rdx
movb %al, (%rcx,%rdx)
incl %r15d
movq -0x78(%rbp), %rdi
jmp 0x779c
incq %r8
incl -0x30(%rbp)
incq -0x60(%rbp)
jmp 0x7788
incl %ebx
incl -0x2c(%rbp)
jmp 0x7766
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq