// File: /workspace/github_cpp_makefile_star2_O1/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 0x23404
movq %rbx, %rdi
movl 0x28(%r12), %ebp
movl 0x2c(%r12), %ebx
xorl %ecx, %ecx
movq %rcx, (%rdi)
movq %rcx, (%r13)
cmpl $0x1, %eax
je 0xf605
testl %eax, %eax
jne 0xf666
testl %r15d, %r15d
jle 0xf798
leal -0x1(%r15), %eax
movq 0x38(%r12), %rcx
imull %ebp, %eax
addl %r14d, %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
movl $0x1, %eax
jmp 0xf79e
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 0x23404
testl %eax, %eax
je 0xf769
cmpl $0x1, %eax
je 0xfb05
testl %r15d, %r15d
movq %r13, %rdi
jle 0xf9cf
leal -0x1(%r15), %eax
movq 0x38(%r12), %rcx
imull 0x28(%r12), %eax
addl %r14d, %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
movl $0x1, %eax
jmp 0xf9d5
testl %r14d, %r14d
setle %al
testl %r15d, %r15d
setle %cl
orb %al, %cl
jne 0xf697
leal -0x1(%r15), %eax
movq 0x38(%r12), %rcx
imull %ebp, %eax
addl %r14d, %eax
decl %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
movl $0x1, %eax
jmp 0xf69d
xorl %eax, %eax
xorpd %xmm0, %xmm0
testl %r15d, %r15d
setle %dl
leal -0x1(%rbp), %ecx
cmpl %r14d, %ecx
setle %sil
orb %dl, %sil
jne 0xf6ca
leal -0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
incl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %eax
cmpl %r14d, %ecx
setg %dl
decl %ebx
cmpl %r15d, %ebx
setg %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xf6fa
leal 0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
incl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %eax
cmpl %r15d, %ebx
setg %dl
testl %r14d, %r14d
setg %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xf728
leal 0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
decl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %eax
testl %eax, %eax
jle 0xfae6
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%r13)
testl %r15d, %r15d
jle 0xf8e5
leal -0x1(%r15), %eax
movq 0x38(%r12), %rdx
imull %ebp, %eax
addl %r14d, %eax
xorpd %xmm0, %xmm0
addsd (%rdx,%rax,8), %xmm0
movl $0x1, %eax
jmp 0xf8eb
testl %r14d, %r14d
jle 0xf964
movq 0x38(%r12), %rax
movl 0x28(%r12), %ecx
imull %r15d, %ecx
addl %r14d, %ecx
decl %ecx
xorpd %xmm0, %xmm0
addsd (%rax,%rcx,8), %xmm0
movl $0x1, %eax
jmp 0xf96a
xorl %eax, %eax
xorpd %xmm0, %xmm0
leal -0x1(%rbp), %ecx
cmpl %r14d, %ecx
jle 0xf7bd
movq 0x38(%r12), %rdx
movl %ebp, %esi
imull %r15d, %esi
addl %r14d, %esi
incl %esi
addsd (%rdx,%rsi,8), %xmm0
incl %eax
decl %ebx
cmpl %r15d, %ebx
jle 0xf7da
leal 0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
addsd (%rsi,%rdx,8), %xmm0
incl %eax
testl %r14d, %r14d
jle 0xf7f6
movq 0x38(%r12), %rdx
movl %ebp, %esi
imull %r15d, %esi
addl %r14d, %esi
decl %esi
addsd (%rdx,%rsi,8), %xmm0
incl %eax
testl %eax, %eax
jle 0xfac7
testl %r14d, %r14d
setle %dl
testl %r15d, %r15d
cvtsi2sd %eax, %xmm1
setle %al
divsd %xmm1, %xmm0
movsd %xmm0, (%r13)
orb %dl, %al
jne 0xf83d
leal -0x1(%r15), %eax
movq 0x38(%r12), %rdx
imull %ebp, %eax
addl %r14d, %eax
decl %eax
xorpd %xmm0, %xmm0
addsd (%rdx,%rax,8), %xmm0
movl $0x1, %eax
jmp 0xf843
xorl %eax, %eax
xorpd %xmm0, %xmm0
cmpl %r14d, %ecx
setle %dl
testl %r15d, %r15d
setle %sil
orb %dl, %sil
jne 0xf86d
leal -0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
incl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %eax
cmpl %r15d, %ebx
setle %dl
cmpl %r14d, %ecx
setle %cl
orb %dl, %cl
jne 0xf895
leal 0x1(%r15), %ecx
movq 0x38(%r12), %rdx
imull %ebp, %ecx
addl %r14d, %ecx
incl %ecx
addsd (%rdx,%rcx,8), %xmm0
incl %eax
testl %r14d, %r14d
setle %cl
cmpl %r15d, %ebx
setle %dl
orb %cl, %dl
jne 0xf8be
incl %r15d
movq 0x38(%r12), %rcx
imull %r15d, %ebp
leal (%r14,%rbp), %edx
decl %edx
addsd (%rcx,%rdx,8), %xmm0
incl %eax
testl %eax, %eax
jg 0xfaa9
leaq 0x1cc4a(%rip), %rdi     # 0x2c517
leaq 0x1cbf4(%rip), %rsi     # 0x2c4c8
leaq 0x1cc48(%rip), %rcx     # 0x2c523
movl $0xa7, %edx
callq 0x31c0
xorl %eax, %eax
xorpd %xmm0, %xmm0
cmpl %r14d, %ecx
jle 0xf907
movq 0x38(%r12), %rcx
movl %ebp, %edx
imull %r15d, %edx
addl %r14d, %edx
incl %edx
addsd (%rcx,%rdx,8), %xmm0
incl %eax
cmpl %r15d, %ebx
jle 0xf922
leal 0x1(%r15), %ecx
movq 0x38(%r12), %rdx
imull %ebp, %ecx
addl %r14d, %ecx
addsd (%rdx,%rcx,8), %xmm0
incl %eax
testl %r14d, %r14d
jle 0xf93d
movq 0x38(%r12), %rcx
imull %r15d, %ebp
leal (%r14,%rbp), %edx
decl %edx
addsd (%rcx,%rdx,8), %xmm0
incl %eax
testl %eax, %eax
jg 0xfaa9
leaq 0x1cbcb(%rip), %rdi     # 0x2c517
leaq 0x1cb75(%rip), %rsi     # 0x2c4c8
leaq 0x1cbc9(%rip), %rcx     # 0x2c523
movl $0x123, %edx            # imm = 0x123
callq 0x31c0
xorl %eax, %eax
xorpd %xmm0, %xmm0
movq %r13, %rdi
cmpl %r14d, %ebp
movq (%rsp), %rsi
jle 0xf990
movq 0x38(%r12), %rcx
movl 0x28(%r12), %edx
imull %r15d, %edx
addl %r14d, %edx
incl %edx
addsd (%rcx,%rdx,8), %xmm0
incl %eax
testl %eax, %eax
jle 0xfb24
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rsi)
testl %r15d, %r15d
jle 0xfa35
leal -0x1(%r15), %eax
movq 0x38(%r12), %rcx
imull 0x28(%r12), %eax
addl %r14d, %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
movl $0x1, %eax
jmp 0xfa3b
xorl %eax, %eax
xorpd %xmm0, %xmm0
movq (%rsp), %rsi
decl %ebx
cmpl %r15d, %ebx
jle 0xf9f9
leal 0x1(%r15), %ecx
movq 0x38(%r12), %rdx
imull 0x28(%r12), %ecx
addl %r14d, %ecx
addsd (%rdx,%rcx,8), %xmm0
incl %eax
testl %eax, %eax
jle 0xfb43
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rsi)
testl %r14d, %r14d
jle 0xfa7e
movq 0x38(%r12), %rax
movl 0x28(%r12), %ecx
imull %r15d, %ecx
addl %r14d, %ecx
decl %ecx
xorpd %xmm0, %xmm0
addsd (%rax,%rcx,8), %xmm0
movl $0x1, %eax
jmp 0xfa84
xorl %eax, %eax
xorpd %xmm0, %xmm0
decl %ebx
cmpl %r15d, %ebx
jle 0xfa5b
incl %r15d
movq 0x38(%r12), %rcx
imull 0x28(%r12), %r15d
addl %r14d, %r15d
addsd (%rcx,%r15,8), %xmm0
incl %eax
testl %eax, %eax
jg 0xfaa9
leaq 0x1cab1(%rip), %rdi     # 0x2c517
leaq 0x1ca5b(%rip), %rsi     # 0x2c4c8
leaq 0x1caaf(%rip), %rcx     # 0x2c523
movl $0xce, %edx
callq 0x31c0
xorl %eax, %eax
xorpd %xmm0, %xmm0
cmpl %r14d, %ebp
jle 0xfaa1
movq 0x38(%r12), %rcx
imull 0x28(%r12), %r15d
leal (%r14,%r15), %edx
incl %edx
addsd (%rcx,%rdx,8), %xmm0
incl %eax
testl %eax, %eax
jle 0xfb62
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rdi)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ca49(%rip), %rdi     # 0x2c517
leaq 0x1c9f3(%rip), %rsi     # 0x2c4c8
leaq 0x1ca47(%rip), %rcx     # 0x2c523
movl $0x8e, %edx
callq 0x31c0
leaq 0x1ca2a(%rip), %rdi     # 0x2c517
leaq 0x1c9d4(%rip), %rsi     # 0x2c4c8
leaq 0x1ca28(%rip), %rcx     # 0x2c523
movl $0x10a, %edx            # imm = 0x10A
callq 0x31c0
leaq 0x1c9ac(%rip), %rdi     # 0x2c4b8
leaq 0x1c9b5(%rip), %rsi     # 0x2c4c8
leaq 0x1ca09(%rip), %rcx     # 0x2c523
movl $0xb0, %edx
callq 0x31c0
leaq 0x1c9ec(%rip), %rdi     # 0x2c517
leaq 0x1c996(%rip), %rsi     # 0x2c4c8
leaq 0x1c9ea(%rip), %rcx     # 0x2c523
movl $0xbf, %edx
callq 0x31c0
leaq 0x1c9cd(%rip), %rdi     # 0x2c517
leaq 0x1c977(%rip), %rsi     # 0x2c4c8
leaq 0x1c9cb(%rip), %rcx     # 0x2c523
movl $0xdf, %edx
callq 0x31c0
leaq 0x1c9ae(%rip), %rdi     # 0x2c517
leaq 0x1c958(%rip), %rsi     # 0x2c4c8
leaq 0x1c9ac(%rip), %rcx     # 0x2c523
movl $0xee, %edx
callq 0x31c0