// File: /workspace/github_cpp_makefile_star2_O3/kebwi[P]Trifid/src/DebayerProcs.cpp
// Function: nn_procOnePixel(ImageReal&, Image3ChnlReal&, int, int)
void nn_procOnePixel(
	ImageReal &grayImage, Image3ChnlReal &rgbImage,
	int x, int y)
{
	Color color = determineBayerColor(x, y);
	int width = grayImage.width(), height = grayImage.height();
	
	Float_t bayerValue = 0, bayerValueRight = 0, bayerValueDown = 0, bayerValueRightDown = 0;
	bool rightEdge = false, bottomEdge = false;
	
	bayerValue = grayImage(x, y);
	if (x + 1 < width)
		bayerValueRight = grayImage(x + 1, y);
	else rightEdge = true;
	if (y + 1 < height)
		bayerValueDown = grayImage(x, y + 1);
	else bottomEdge = true;
	if (x + 1 < width && y + 1 < height)
		bayerValueRightDown = grayImage(x + 1, y + 1);
	
	//Fill in the output
	switch (color)
	{
		case R:
			rgbImage(R, x, y) = bayerValue;
			if (!rightEdge)
			{
				rgbImage(G, x, y) = bayerValueRight;
				if (!bottomEdge)
					rgbImage(B, x, y) = bayerValueRightDown;
			}
			break;
		case G:
			{
				Color colorRight;
				if (x < width - 1)
					colorRight = determineBayerColor(x + 1, y);
				else colorRight = determineBayerColor(x - 1, y);
				assert(colorRight != G);
				if (colorRight == R)
				{
					if (!rightEdge)
						rgbImage(R, x, y) = bayerValueRight;
					rgbImage(G, x, y) = bayerValue;
					if (!bottomEdge)
						rgbImage(B, x, y) = bayerValueDown;
				}
				else //if (colorRight == B)
				{
					if (!bottomEdge)
						rgbImage(R, x, y) = bayerValueDown;
					rgbImage(G, x, y) = bayerValue;
					if (!rightEdge)
						rgbImage(B, x, y) = bayerValueRight;
				}
			}
			break;
		case B:
			if (!rightEdge)
			{
				if (!bottomEdge)
					rgbImage(R, x, y) = bayerValueRightDown;
				rgbImage(G, x, y) = bayerValueRight;
			}
			rgbImage(B, x, y) = bayerValue;
			break;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebx
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %r12
movl %edx, %edi
movl %ecx, %esi
callq 0x23198
movl 0x28(%r12), %r13d
movl 0x2c(%r12), %esi
movq 0x38(%r12), %rcx
movl %r13d, %edi
imull %ebx, %edi
leal (%rdi,%r14), %edx
leal 0x1(%r14), %ebp
cmpl %r13d, %ebp
jge 0xf22b
addl %ebp, %edi
movsd (%rcx,%rdi,8), %xmm0
leal 0x1(%rbx), %edi
cmpl %esi, %edi
jge 0xf246
imull %r13d, %edi
leal (%rdi,%r14), %esi
movsd (%rcx,%rsi,8), %xmm1
addl %ebp, %edi
movsd (%rcx,%rdi,8), %xmm3
movb $0x1, %r12b
jmp 0xf257
leal 0x1(%rbx), %edi
xorps %xmm0, %xmm0
cmpl %esi, %edi
jge 0xf24e
imull %r13d, %edi
addl %r14d, %edi
movsd (%rcx,%rdi,8), %xmm1
movb $0x1, %r12b
jmp 0xf254
xorps %xmm1, %xmm1
xorl %r12d, %r12d
jmp 0xf254
xorl %r12d, %r12d
xorps %xmm1, %xmm1
xorps %xmm3, %xmm3
movsd (%rcx,%rdx,8), %xmm2
cmpl $0x2, %eax
je 0xf352
movsd %xmm0, 0x10(%rsp)
cmpl $0x1, %eax
je 0xf2d4
movsd %xmm3, (%rsp)
testl %eax, %eax
jne 0xf411
movq %r15, %rdi
xorl %esi, %esi
movl %r14d, %edx
movl %ebx, %ecx
movsd %xmm2, 0x8(%rsp)
callq 0xe49a
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
cmpl %r13d, %ebp
jge 0xf411
movq %r15, %rdi
movl $0x1, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xe49a
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd (%rsp), %xmm2
testb %r12b, %r12b
jne 0xf3f1
jmp 0xf411
movsd %xmm2, 0x8(%rsp)
movsd %xmm1, (%rsp)
leal -0x1(%r13), %eax
leal -0x1(%r14), %edi
cmpl %r14d, %eax
cmovgl %ebp, %edi
movl %ebx, %esi
callq 0x23198
testl %eax, %eax
je 0xf3ad
cmpl $0x1, %eax
je 0xf420
testb %r12b, %r12b
je 0xf322
movq %r15, %rdi
xorl %esi, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xe49a
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
movl $0x1, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xe49a
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x10(%rsp), %xmm2
cmpl %r13d, %ebp
jl 0xf3f1
jmp 0xf411
cmpl %r13d, %ebp
jge 0xf3f1
movsd %xmm2, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
testb %r12b, %r12b
je 0xf389
movq %r15, %rdi
xorl %esi, %esi
movl %r14d, %edx
movl %ebx, %ecx
movsd %xmm3, (%rsp)
callq 0xe49a
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
movl $0x1, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xe49a
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x8(%rsp), %xmm2
jmp 0xf3f1
cmpl %r13d, %ebp
jge 0xf3cb
movq %r15, %rdi
xorl %esi, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xe49a
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
movl $0x1, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xe49a
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
testb %r12b, %r12b
movsd (%rsp), %xmm2
je 0xf411
movsd %xmm2, (%rsp)
movq %r15, %rdi
movl $0x2, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xe49a
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c079(%rip), %rdi     # 0x2b4a0
leaq 0x1c082(%rip), %rsi     # 0x2b4b0
leaq 0x1c08c(%rip), %rcx     # 0x2b4c1
movl $0x40, %edx
callq 0x31c0