// File: /workspace/github_cpp_makefile_star2_O2/kebwi[P]Trifid/src/DebayerProcs.cpp
// Function: bilinear_calcMissingColors(ImageReal&, Image3ChnlReal&, int, int, double&, double&)
void bilinear_calcMissingColors(
	ImageReal &grayImage, Image3ChnlReal &rgbImage,
	int x, int y, Float_t &color1, Float_t &color2)
{
	Color color = determineBayerColor(x, y);
	int width = grayImage.width(), height = grayImage.height();
	
	Float_t color1L = 0, color2L = 0;
	color1 = color2 = 0;
	int divisor;
	
	if (color == R)
	{
		//Determine green component
		divisor = 0;
		if (y > 0)
		{
			color1L += grayImage(x, y - 1);
			divisor++;
		}
		if (x < width - 1)
		{
			color1L += grayImage(x + 1, y);
			divisor++;
		}
		if (y < height - 1)
		{
			color1L += grayImage(x, y + 1);
			divisor++;
		}
		if (x > 0)
		{
			color1L += grayImage(x - 1, y);
			divisor++;
		}
		assert(divisor > 0);
		color1 = color1L / (Float_t)divisor;
		
		//Determine blue component
		divisor = 0;
		if (x > 0 && y > 0)
		{
			color2L += grayImage(x - 1, y - 1);
			divisor++;
		}
		if (x < width - 1 && y > 0)
		{
			color2L += grayImage(x + 1, y - 1);
			divisor++;
		}
		if (x < width - 1 && y < height - 1)
		{
			color2L += grayImage(x + 1, y + 1);
			divisor++;
		}
		if (x > 0 && y < height - 1)
		{
			color2L += grayImage(x - 1, y + 1);
			divisor++;
		}
		assert(divisor > 0);
		color2 = color2L / (Float_t)divisor;
	}
	else if (color == G)
	{
		Color colorRight;
		if (x < width - 1)
			colorRight = determineBayerColor(x + 1, y);
		else colorRight = determineBayerColor(x - 1, y);
		assert(colorRight != G);
		if (colorRight == R)
		{
			//Determine red component
			divisor = 0;
			if (x > 0)
			{
				color1L += grayImage(x - 1, y);
				divisor++;
			}
			if (x < width - 1)
			{
				color1L += grayImage(x + 1, y);
				divisor++;
			}
			assert(divisor > 0);
			color1 = color1L / (Float_t)divisor;
			
			//Determine blue component
			divisor = 0;
			if (y > 0)
			{
				color2L += grayImage(x, y - 1);
				divisor++;
			}
			if (y < height - 1)
			{
				color2L += grayImage(x, y + 1);
				divisor++;
			}
			assert(divisor > 0);
			color2 = color2L / (Float_t)divisor;
		}
		else //if (colorRight == B)
		{
			//Determine red component
			divisor = 0;
			if (y > 0)
			{
				color1L += grayImage(x, y - 1);
				divisor++;
			}
			if (y < height - 1)
			{
				color1L += grayImage(x, y + 1);
				divisor++;
			}
			assert(divisor > 0);
			color1 = color1L / (Float_t)divisor;
			
			//Determine blue component
			divisor = 0;
			if (x > 0)
			{
				color2L += grayImage(x - 1, y);
				divisor++;
			}
			if (x < width - 1)
			{
				color2L += grayImage(x + 1, y);
				divisor++;
			}
			assert(divisor > 0);
			color2 = color2L / (Float_t)divisor;
		}
	}
	else //if (color == B)
	{
		//Determine red component
		divisor = 0;
		if (x > 0 && y > 0)
		{
			color1L += grayImage(x - 1, y - 1);
			divisor++;
		}
		if (x < width - 1 && y > 0)
		{
			color1L += grayImage(x + 1, y - 1);
			divisor++;
		}
		if (x < width - 1 && y < height - 1)
		{
			color1L += grayImage(x + 1, y + 1);
			divisor++;
		}
		if (x > 0 && y < height - 1)
		{
			color1L += grayImage(x - 1, y + 1);
			divisor++;
		}
		assert(divisor > 0);
		color1 = color1L / (Float_t)divisor;
		
		//Determine green component
		divisor = 0;
		if (y > 0)
		{
			color2L += grayImage(x, y - 1);
			divisor++;
		}
		if (x < width - 1)
		{
			color2L += grayImage(x + 1, y);
			divisor++;
		}
		if (y < height - 1)
		{
			color2L += grayImage(x, y + 1);
			divisor++;
		}
		if (x > 0)
		{
			color2L += grayImage(x - 1, y);
			divisor++;
		}
		assert(divisor > 0);
		color2 = color2L / (Float_t)divisor;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movq %r8, %r13
movl %ecx, %r15d
movl %edx, %r14d
movq %rdi, %r12
movl %edx, %edi
movl %ecx, %esi
callq 0x1c294
movq %rbx, %rdi
movl 0x28(%r12), %ebp
movl 0x2c(%r12), %ebx
andq $0x0, (%rdi)
andq $0x0, (%r13)
cmpl $0x1, %eax
je 0xc6aa
testl %eax, %eax
jne 0xc71d
testl %r15d, %r15d
jle 0xc85c
leal -0x1(%r15), %eax
movq 0x38(%r12), %rcx
imull %ebp, %eax
addl %r14d, %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
pushq $0x1
popq %rcx
jmp 0xc862
movq %r13, (%rsp)
movq %rdi, %r13
decl %ebp
xorl %eax, %eax
cmpl %r14d, %ebp
setg %al
leal (%r14,%rax,2), %edi
decl %edi
movl %r15d, %esi
callq 0x1c294
testl %eax, %eax
je 0xc81e
cmpl $0x1, %eax
je 0xcb74
testl %r15d, %r15d
movq %r13, %rdi
jle 0xca48
leal -0x1(%r15), %eax
movq 0x38(%r12), %rcx
imull 0x28(%r12), %eax
addl %r14d, %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
decl %ebx
cmpl %r15d, %ebx
movq (%rsp), %rdx
jle 0xcaf7
movsd 0x16d40(%rip), %xmm1    # 0x23458
jmp 0xca63
testl %r14d, %r14d
setle %al
testl %r15d, %r15d
setle %cl
orb %al, %cl
jne 0xc74c
leal -0x1(%r15), %eax
movq 0x38(%r12), %rcx
imull %ebp, %eax
addl %r14d, %eax
decl %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
pushq $0x1
popq %rcx
jmp 0xc752
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
testl %r15d, %r15d
setle %dl
leal -0x1(%rbp), %eax
cmpl %r14d, %eax
setle %sil
orb %dl, %sil
jne 0xc77f
leal -0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
incl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %ecx
cmpl %r14d, %eax
setg %dl
decl %ebx
cmpl %r15d, %ebx
setg %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xc7af
leal 0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
incl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %ecx
cmpl %r15d, %ebx
setg %dl
testl %r14d, %r14d
setg %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xc7df
leal 0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
decl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %ecx
jmp 0xc7e7
testl %ecx, %ecx
je 0xcb93
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%r13)
testl %r15d, %r15d
jle 0xc995
pushq $0x1
popq %rcx
leal -0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
xorpd %xmm0, %xmm0
addsd (%rsi,%rdx,8), %xmm0
jmp 0xc99b
testl %r14d, %r14d
jle 0xca12
movl 0x28(%r12), %eax
imull %r15d, %eax
movq 0x38(%r12), %rcx
addl %r14d, %eax
decl %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
cmpl %r14d, %ebp
movq %r13, %rdi
jle 0xca7f
movsd 0x16c01(%rip), %xmm1    # 0x23458
jmp 0xca2a
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
leal -0x1(%rbp), %eax
cmpl %r14d, %eax
jle 0xc881
movq 0x38(%r12), %rdx
movl %ebp, %esi
imull %r15d, %esi
addl %r14d, %esi
incl %esi
addsd (%rdx,%rsi,8), %xmm0
incl %ecx
decl %ebx
cmpl %r15d, %ebx
jle 0xc89e
leal 0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
addsd (%rsi,%rdx,8), %xmm0
incl %ecx
testl %r14d, %r14d
jle 0xc8bc
movq 0x38(%r12), %rdx
movl %ebp, %esi
imull %r15d, %esi
addl %r14d, %esi
decl %esi
addsd (%rdx,%rsi,8), %xmm0
incl %ecx
jmp 0xc8c4
testl %ecx, %ecx
je 0xcbb2
testl %r14d, %r14d
setle %dl
testl %r15d, %r15d
cvtsi2sd %ecx, %xmm1
setle %cl
divsd %xmm1, %xmm0
movsd %xmm0, (%r13)
orb %dl, %cl
jne 0xc901
leal -0x1(%r15), %ecx
movq 0x38(%r12), %rdx
imull %ebp, %ecx
addl %r14d, %ecx
decl %ecx
xorpd %xmm0, %xmm0
addsd (%rdx,%rcx,8), %xmm0
pushq $0x1
popq %rcx
jmp 0xc907
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
cmpl %r14d, %eax
setle %dl
testl %r15d, %r15d
setle %sil
orb %dl, %sil
jne 0xc931
leal -0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
incl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %ecx
cmpl %r15d, %ebx
setle %dl
cmpl %r14d, %eax
setle %al
orb %dl, %al
jne 0xc959
leal 0x1(%r15), %eax
movq 0x38(%r12), %rdx
imull %ebp, %eax
addl %r14d, %eax
incl %eax
addsd (%rdx,%rax,8), %xmm0
incl %ecx
testl %r14d, %r14d
setle %al
cmpl %r15d, %ebx
setle %dl
orb %al, %dl
je 0xc990
testl %ecx, %ecx
jne 0xc9f7
leaq 0x16b77(%rip), %rdi     # 0x234ef
leaq 0x16b21(%rip), %rsi     # 0x234a0
leaq 0x16b75(%rip), %rcx     # 0x234fb
movl $0xa7, %edx
callq 0x31a0
incl %r15d
jmp 0xc9d7
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
cmpl %r14d, %eax
jle 0xc9b7
movq 0x38(%r12), %rax
movl %ebp, %edx
imull %r15d, %edx
addl %r14d, %edx
incl %edx
addsd (%rax,%rdx,8), %xmm0
incl %ecx
cmpl %r15d, %ebx
jle 0xc9d2
leal 0x1(%r15), %eax
movq 0x38(%r12), %rdx
imull %ebp, %eax
addl %r14d, %eax
addsd (%rdx,%rax,8), %xmm0
incl %ecx
testl %r14d, %r14d
jle 0xc9ef
movq 0x38(%r12), %rax
imull %r15d, %ebp
leal (%r14,%rbp), %edx
decl %edx
addsd (%rax,%rdx,8), %xmm0
incl %ecx
jmp 0xc9f7
testl %ecx, %ecx
je 0xcbd1
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rdi)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r14d, %ebp
jle 0xcbf0
movq %r13, %rdi
xorpd %xmm0, %xmm0
movsd 0x1562e(%rip), %xmm1    # 0x22058
movq (%rsp), %rdx
movq 0x38(%r12), %rax
movl 0x28(%r12), %ecx
imull %r15d, %ecx
addl %r14d, %ecx
incl %ecx
addsd (%rax,%rcx,8), %xmm0
jmp 0xca8b
decl %ebx
cmpl %r15d, %ebx
movq (%rsp), %rdx
jle 0xcc0f
xorpd %xmm0, %xmm0
movsd 0x155f5(%rip), %xmm1    # 0x22058
leal 0x1(%r15), %eax
imull 0x28(%r12), %eax
movq 0x38(%r12), %rcx
addl %r14d, %eax
addsd (%rcx,%rax,8), %xmm0
jmp 0xcaff
movsd 0x155d1(%rip), %xmm1    # 0x22058
movq (%rsp), %rdx
divsd %xmm1, %xmm0
movsd %xmm0, (%rdx)
testl %r15d, %r15d
jle 0xcac4
leal -0x1(%r15), %eax
movq 0x38(%r12), %rcx
imull 0x28(%r12), %eax
addl %r14d, %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
decl %ebx
cmpl %r15d, %ebx
jle 0xcb37
movsd 0x16996(%rip), %xmm1    # 0x23458
jmp 0xcadb
decl %ebx
cmpl %r15d, %ebx
jle 0xcc2e
xorpd %xmm0, %xmm0
movsd 0x1557d(%rip), %xmm1    # 0x22058
incl %r15d
imull 0x28(%r12), %r15d
movq 0x38(%r12), %rax
addl %r14d, %r15d
addsd (%rax,%r15,8), %xmm0
jmp 0xc9fb
movsd 0x15559(%rip), %xmm1    # 0x22058
divsd %xmm1, %xmm0
movsd %xmm0, (%rdx)
testl %r14d, %r14d
jle 0xcb44
movl 0x28(%r12), %eax
imull %r15d, %eax
movq 0x38(%r12), %rcx
addl %r14d, %eax
decl %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
cmpl %r14d, %ebp
jle 0xcb37
movsd 0x16923(%rip), %xmm1    # 0x23458
jmp 0xcb59
movsd 0x15519(%rip), %xmm1    # 0x22058
jmp 0xc9fb
cmpl %r14d, %ebp
jle 0xcc4d
xorpd %xmm0, %xmm0
movsd 0x154ff(%rip), %xmm1    # 0x22058
imull 0x28(%r12), %r15d
movq 0x38(%r12), %rax
leal (%r14,%r15), %ecx
incl %ecx
addsd (%rax,%rcx,8), %xmm0
jmp 0xc9fb
leaq 0x16915(%rip), %rdi     # 0x23490
leaq 0x1691e(%rip), %rsi     # 0x234a0
leaq 0x16972(%rip), %rcx     # 0x234fb
movl $0xb0, %edx
callq 0x31a0
leaq 0x16955(%rip), %rdi     # 0x234ef
leaq 0x168ff(%rip), %rsi     # 0x234a0
leaq 0x16953(%rip), %rcx     # 0x234fb
movl $0x10a, %edx            # imm = 0x10A
callq 0x31a0
leaq 0x16936(%rip), %rdi     # 0x234ef
leaq 0x168e0(%rip), %rsi     # 0x234a0
leaq 0x16934(%rip), %rcx     # 0x234fb
movl $0x8e, %edx
callq 0x31a0
leaq 0x16917(%rip), %rdi     # 0x234ef
leaq 0x168c1(%rip), %rsi     # 0x234a0
leaq 0x16915(%rip), %rcx     # 0x234fb
movl $0x123, %edx            # imm = 0x123
callq 0x31a0
leaq 0x168f8(%rip), %rdi     # 0x234ef
leaq 0x168a2(%rip), %rsi     # 0x234a0
leaq 0x168f6(%rip), %rcx     # 0x234fb
movl $0xbf, %edx
callq 0x31a0
leaq 0x168d9(%rip), %rdi     # 0x234ef
leaq 0x16883(%rip), %rsi     # 0x234a0
leaq 0x168d7(%rip), %rcx     # 0x234fb
movl $0xdf, %edx
callq 0x31a0
leaq 0x168ba(%rip), %rdi     # 0x234ef
leaq 0x16864(%rip), %rsi     # 0x234a0
leaq 0x168b8(%rip), %rcx     # 0x234fb
movl $0xce, %edx
callq 0x31a0
leaq 0x1689b(%rip), %rdi     # 0x234ef
leaq 0x16845(%rip), %rsi     # 0x234a0
leaq 0x16899(%rip), %rcx     # 0x234fb
movl $0xee, %edx
callq 0x31a0