// File: kebwi[P]Trifid/src/DebayerProcs.cpp
// Function: hue_constructHorizontalRedOrBlueAtGreen(ImageReal&, Image3ChnlReal&, ImageReal&, int, int)
void hue_constructHorizontalRedOrBlueAtGreen(
	ImageReal &grayImage, Image3ChnlReal &rgbImage,
	ImageReal &rgbImageRorB, int x, int y)
{
	assert(determineBayerColor(x, y) == G);
	if (&rgbImageRorB == rgbImage[0] && x > 0)
		assert(determineBayerColor(x - 1, y) == R);
	else if (&rgbImageRorB == rgbImage[2] && x > 0)
		assert(determineBayerColor(x - 1, y) == B);
	
	int width = grayImage.width();
	
	Float_t color1L = rgbImage(G, x, y);
	Float_t color2L = 0;
	int divisor = 0;
	
	if (x > 0)
	{
		color2L += (Float_t)grayImage(x - 1, y) /
					(Float_t)rgbImage(G, x - 1, y);
		divisor++;
	}
	if (x < width - 1)
	{
		color2L += (Float_t)grayImage(x + 1, y) /
					(Float_t)rgbImage(G, x + 1, y);
		divisor++;
	}
	
	assert(divisor > 0);
	color1L = ((Float_t)color1L / (Float_t)divisor) * color2L;
	if (color1L > pow(2, sBitDepth) - 1)
		color1L = pow(2, sBitDepth) - 1;
	
	rgbImageRorB(x, y) = color1L;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl -0x1c(%rbp), %edi
movl -0x20(%rbp), %esi
callq 0x380a0
cmpl $0x1, %eax
jne 0x1aead
jmp 0x1aecc
leaq 0x2f8cd(%rip), %rdi     # 0x4a781
leaq 0x2f6b5(%rip), %rsi     # 0x4a570
movl $0x1d8, %edx            # imm = 0x1D8
leaq 0x2f8d9(%rip), %rcx     # 0x4a7a0
callq 0x4240
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xef40
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jne 0x1af27
cmpl $0x0, -0x1c(%rbp)
jle 0x1af27
movl -0x1c(%rbp), %edi
subl $0x1, %edi
movl -0x20(%rbp), %esi
callq 0x380a0
cmpl $0x0, %eax
jne 0x1af06
jmp 0x1af25
leaq 0x2f8f6(%rip), %rdi     # 0x4a803
leaq 0x2f65c(%rip), %rsi     # 0x4a570
movl $0x1da, %edx            # imm = 0x1DA
leaq 0x2f880(%rip), %rcx     # 0x4a7a0
callq 0x4240
jmp 0x1af87
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0xef40
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jne 0x1af85
cmpl $0x0, -0x1c(%rbp)
jle 0x1af85
movl -0x1c(%rbp), %edi
subl $0x1, %edi
movl -0x20(%rbp), %esi
callq 0x380a0
cmpl $0x2, %eax
jne 0x1af64
jmp 0x1af83
leaq 0x2f8bb(%rip), %rdi     # 0x4a826
leaq 0x2f5fe(%rip), %rsi     # 0x4a570
movl $0x1dc, %edx            # imm = 0x1DC
leaq 0x2f822(%rip), %rcx     # 0x4a7a0
callq 0x4240
jmp 0x1af85
jmp 0x1af87
movq -0x8(%rbp), %rdi
callq 0xedd0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl $0x1, %esi
callq 0x17990
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x1b013
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
subl $0x1, %esi
movl -0x20(%rbp), %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
subl $0x1, %edx
movl -0x20(%rbp), %ecx
movl $0x1, %esi
callq 0x17990
movsd -0x58(%rbp), %xmm0
divsd (%rax), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1b06e
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
addl $0x1, %esi
movl -0x20(%rbp), %edx
callq 0x16fd0
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
movl -0x20(%rbp), %ecx
movl $0x1, %esi
callq 0x17990
movsd -0x60(%rbp), %xmm0
divsd (%rax), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jle 0x1b076
jmp 0x1b095
leaq 0x2f542(%rip), %rdi     # 0x4a5bf
leaq 0x2f4ec(%rip), %rsi     # 0x4a570
movl $0x1f1, %edx            # imm = 0x1F1
leaq 0x2f710(%rip), %rcx     # 0x4a7a0
callq 0x4240
movsd -0x30(%rbp), %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm1
divsd %xmm1, %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movl 0x3f2bb(%rip), %esi     # 0x5a378
movl $0x2, %edi
callq 0x1d7f0
movaps %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
movsd 0x2df49(%rip), %xmm2    # 0x49020
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1b102
movl 0x3f291(%rip), %esi     # 0x5a378
movl $0x2, %edi
callq 0x1d7f0
movsd 0x2df27(%rip), %xmm1    # 0x49020
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x16fd0
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rax)
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)