// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movl %ecx, %ebx
movl %edx, %r14d
movq %rsi, 0x18(%rsp)
movq %rdi, %r12
movl %edx, %edi
movl %ecx, %esi
callq 0x1c294
movl 0x28(%r12), %r13d
movl 0x2c(%r12), %ebp
movq 0x38(%r12), %rcx
movl %r13d, %esi
imull %ebx, %esi
leal (%rsi,%r14), %edx
leal 0x1(%r14), %r15d
xorps %xmm3, %xmm3
xorps %xmm0, %xmm0
cmpl %r13d, %r15d
jge 0xc3b0
addl %r15d, %esi
movsd (%rcx,%rsi,8), %xmm0
leal 0x1(%rbx), %r12d
cmpl %ebp, %r12d
jge 0xc3d8
movl %r13d, %esi
imull %r12d, %esi
leal (%rsi,%r14), %edi
movsd (%rcx,%rdi,8), %xmm2
cmpl %r13d, %r15d
jge 0xc3db
addl %r15d, %esi
movsd (%rcx,%rsi,8), %xmm3
jmp 0xc3db
xorps %xmm2, %xmm2
movsd (%rcx,%rdx,8), %xmm1
cmpl $0x2, %eax
je 0xc4e5
movsd %xmm0, 0x20(%rsp)
cmpl $0x1, %eax
je 0xc461
movsd %xmm3, (%rsp)
movl %ebp, 0xc(%rsp)
testl %eax, %eax
movq 0x18(%rsp), %rbp
jne 0xc5b1
movq %rbp, %rdi
xorl %esi, %esi
movl %r14d, %edx
movl %ebx, %ecx
movsd %xmm1, 0x10(%rsp)
callq 0xb868
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
cmpl %r13d, %r15d
jge 0xc5b1
pushq $0x1
popq %rsi
movq %rbp, %rdi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xb868
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd (%rsp), %xmm1
cmpl 0xc(%rsp), %r12d
jl 0xc593
jmp 0xc5b1
movsd %xmm2, (%rsp)
movsd %xmm1, 0x10(%rsp)
leal -0x1(%r13), %eax
leal -0x1(%r14), %edi
cmpl %r14d, %eax
cmovgl %r15d, %edi
movl %ebx, %esi
callq 0x1c294
testl %eax, %eax
je 0xc546
cmpl $0x1, %eax
je 0xc5c0
cmpl %ebp, %r12d
jge 0xc4b2
movq 0x18(%rsp), %rdi
xorl %esi, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xb868
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
pushq $0x1
popq %rsi
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xb868
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x20(%rsp), %xmm1
cmpl %r13d, %r15d
jl 0xc593
jmp 0xc5b1
cmpl %r13d, %r15d
jge 0xc53f
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x20(%rsp)
cmpl %ebp, %r12d
movq 0x18(%rsp), %rbp
jge 0xc51d
movq %rbp, %rdi
xorl %esi, %esi
movl %r14d, %edx
movl %ebx, %ecx
movsd %xmm3, (%rsp)
callq 0xb868
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
pushq $0x1
popq %rsi
movq %rbp, %rdi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xb868
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x10(%rsp), %xmm1
jmp 0xc593
movq 0x18(%rsp), %rbp
jmp 0xc593
movl %ebp, 0xc(%rsp)
cmpl %r13d, %r15d
movq 0x18(%rsp), %rbp
jge 0xc56d
movq %rbp, %rdi
xorl %esi, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xb868
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rax)
pushq $0x1
popq %rsi
movq %rbp, %rdi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xb868
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
cmpl 0xc(%rsp), %r12d
movsd (%rsp), %xmm1
jge 0xc5b1
movsd %xmm1, (%rsp)
pushq $0x2
popq %rsi
movq %rbp, %rdi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xb868
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16ec9(%rip), %rdi     # 0x23490
leaq 0x16ed2(%rip), %rsi     # 0x234a0
leaq 0x16edc(%rip), %rcx     # 0x234b1
pushq $0x40
popq %rdx
callq 0x31a0