// File: /workspace/github_cpp_makefile_star2_O3/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 0x23198
movq %rbx, %rdi
movl 0x28(%r12), %ebp
movl 0x2c(%r12), %ebx
xorl %ecx, %ecx
movq %rcx, (%rdi)
movq %rcx, (%r13)
cmpl $0x1, %eax
je 0xf506
testl %eax, %eax
jne 0xf579
testl %r15d, %r15d
jle 0xf6bc
leal -0x1(%r15), %eax
movq 0x38(%r12), %rcx
imull %ebp, %eax
addl %r14d, %eax
xorpd %xmm0, %xmm0
addsd (%rcx,%rax,8), %xmm0
movl $0x1, %ecx
jmp 0xf6c2
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 0x23198
testl %eax, %eax
je 0xf67e
cmpl $0x1, %eax
je 0xfa01
testl %r15d, %r15d
movq %r13, %rdi
jle 0xf8d5
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 0xf984
movsd 0x1bef4(%rip), %xmm1    # 0x2b468
jmp 0xf8f0
testl %r14d, %r14d
setle %al
testl %r15d, %r15d
setle %cl
orb %al, %cl
jne 0xf5aa
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, %ecx
jmp 0xf5b0
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
testl %r15d, %r15d
setle %dl
leal -0x1(%rbp), %eax
cmpl %r14d, %eax
setle %sil
orb %dl, %sil
jne 0xf5dd
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 0xf60d
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 0xf63d
leal 0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
decl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %ecx
jmp 0xf645
testl %ecx, %ecx
je 0xfa20
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%r13)
testl %r15d, %r15d
jle 0xf79a
leal -0x1(%r15), %ecx
movq 0x38(%r12), %rdx
imull %ebp, %ecx
addl %r14d, %ecx
xorpd %xmm0, %xmm0
addsd (%rdx,%rcx,8), %xmm0
movl $0x1, %ecx
jmp 0xf7a0
testl %r14d, %r14d
jle 0xf89f
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 0xf90c
movsd 0x1bdb1(%rip), %xmm1    # 0x2b468
jmp 0xf8b7
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
leal -0x1(%rbp), %eax
cmpl %r14d, %eax
jle 0xf6e1
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 0xf6fe
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 0xf74e
movl %ebp, %esi
imull %r15d, %esi
incl %ecx
movq 0x38(%r12), %rdx
addl %r14d, %esi
decl %esi
addsd (%rdx,%rsi,8), %xmm0
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%r13)
testl %r15d, %r15d
jle 0xf807
leal -0x1(%r14), %ecx
leal -0x1(%r15), %esi
imull %ebp, %esi
addl %ecx, %esi
xorpd %xmm0, %xmm0
addsd (%rdx,%rsi,8), %xmm0
movl $0x1, %ecx
jmp 0xf76a
testl %ecx, %ecx
je 0xfa3f
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%r13)
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
cmpl %r14d, %eax
setle %dl
testl %r15d, %r15d
setle %sil
orb %dl, %sil
jne 0xf80d
leal -0x1(%r15), %edx
movq 0x38(%r12), %rsi
imull %ebp, %edx
addl %r14d, %edx
incl %edx
addsd (%rsi,%rdx,8), %xmm0
incl %ecx
jmp 0xf80d
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
cmpl %r14d, %eax
jle 0xf7bc
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 0xf7d7
leal 0x1(%r15), %eax
movq 0x38(%r12), %rdx
imull %ebp, %eax
addl %r14d, %eax
addsd (%rdx,%rax,8), %xmm0
incl %ecx
testl %r14d, %r14d
jg 0xf86b
testl %ecx, %ecx
jne 0xf881
leaq 0x1bd10(%rip), %rdi     # 0x2b4ff
leaq 0x1bcba(%rip), %rsi     # 0x2b4b0
leaq 0x1bd0e(%rip), %rcx     # 0x2b50b
movl $0x123, %edx            # imm = 0x123
callq 0x31c0
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
cmpl %r15d, %ebx
setle %dl
cmpl %r14d, %eax
setle %al
orb %dl, %al
jne 0xf835
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 0xf868
testl %ecx, %ecx
jne 0xf881
leaq 0x1bcaf(%rip), %rdi     # 0x2b4ff
leaq 0x1bc59(%rip), %rsi     # 0x2b4b0
leaq 0x1bcad(%rip), %rcx     # 0x2b50b
movl $0xa7, %edx
callq 0x31c0
incl %r15d
movq 0x38(%r12), %rax
imull %r15d, %ebp
leal (%r14,%rbp), %edx
decl %edx
addsd (%rax,%rdx,8), %xmm0
incl %ecx
xorps %xmm1, %xmm1
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 0xfa5e
movq %r13, %rdi
xorpd %xmm0, %xmm0
movsd 0x1a7a1(%rip), %xmm1    # 0x2a058
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 0xf918
decl %ebx
cmpl %r15d, %ebx
movq (%rsp), %rdx
jle 0xfa7d
xorpd %xmm0, %xmm0
movsd 0x1a768(%rip), %xmm1    # 0x2a058
leal 0x1(%r15), %eax
imull 0x28(%r12), %eax
movq 0x38(%r12), %rcx
addl %r14d, %eax
addsd (%rcx,%rax,8), %xmm0
jmp 0xf98c
movsd 0x1a744(%rip), %xmm1    # 0x2a058
movq (%rsp), %rdx
divsd %xmm1, %xmm0
movsd %xmm0, (%rdx)
testl %r15d, %r15d
jle 0xf951
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 0xf9c4
movsd 0x1bb19(%rip), %xmm1    # 0x2b468
jmp 0xf968
decl %ebx
cmpl %r15d, %ebx
jle 0xfa9c
xorpd %xmm0, %xmm0
movsd 0x1a6f0(%rip), %xmm1    # 0x2a058
incl %r15d
imull 0x28(%r12), %r15d
movq 0x38(%r12), %rax
addl %r14d, %r15d
addsd (%rax,%r15,8), %xmm0
jmp 0xf888
movsd 0x1a6cc(%rip), %xmm1    # 0x2a058
divsd %xmm1, %xmm0
movsd %xmm0, (%rdx)
testl %r14d, %r14d
jle 0xf9d1
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 0xf9c4
movsd 0x1baa6(%rip), %xmm1    # 0x2b468
jmp 0xf9e6
movsd 0x1a68c(%rip), %xmm1    # 0x2a058
jmp 0xf888
cmpl %r14d, %ebp
jle 0xfabb
xorpd %xmm0, %xmm0
movsd 0x1a672(%rip), %xmm1    # 0x2a058
imull 0x28(%r12), %r15d
movq 0x38(%r12), %rax
leal (%r14,%r15), %ecx
incl %ecx
addsd (%rax,%rcx,8), %xmm0
jmp 0xf888
leaq 0x1ba98(%rip), %rdi     # 0x2b4a0
leaq 0x1baa1(%rip), %rsi     # 0x2b4b0
leaq 0x1baf5(%rip), %rcx     # 0x2b50b
movl $0xb0, %edx
callq 0x31c0
leaq 0x1bad8(%rip), %rdi     # 0x2b4ff
leaq 0x1ba82(%rip), %rsi     # 0x2b4b0
leaq 0x1bad6(%rip), %rcx     # 0x2b50b
movl $0x10a, %edx            # imm = 0x10A
callq 0x31c0
leaq 0x1bab9(%rip), %rdi     # 0x2b4ff
leaq 0x1ba63(%rip), %rsi     # 0x2b4b0
leaq 0x1bab7(%rip), %rcx     # 0x2b50b
movl $0x8e, %edx
callq 0x31c0
leaq 0x1ba9a(%rip), %rdi     # 0x2b4ff
leaq 0x1ba44(%rip), %rsi     # 0x2b4b0
leaq 0x1ba98(%rip), %rcx     # 0x2b50b
movl $0xbf, %edx
callq 0x31c0
leaq 0x1ba7b(%rip), %rdi     # 0x2b4ff
leaq 0x1ba25(%rip), %rsi     # 0x2b4b0
leaq 0x1ba79(%rip), %rcx     # 0x2b50b
movl $0xdf, %edx
callq 0x31c0
leaq 0x1ba5c(%rip), %rdi     # 0x2b4ff
leaq 0x1ba06(%rip), %rsi     # 0x2b4b0
leaq 0x1ba5a(%rip), %rcx     # 0x2b50b
movl $0xce, %edx
callq 0x31c0
leaq 0x1ba3d(%rip), %rdi     # 0x2b4ff
leaq 0x1b9e7(%rip), %rsi     # 0x2b4b0
leaq 0x1ba3b(%rip), %rcx     # 0x2b50b
movl $0xee, %edx
callq 0x31c0