// File: /workspace/github_cpp_makefile_star2_O2/kebwi[P]Trifid/src/DebayerProcs.cpp
// Function: hue_constructRedOrBlueAtBlueOrRed(ImageReal&, Image3ChnlReal&, ImageReal&, int, int)
void hue_constructRedOrBlueAtBlueOrRed(
	ImageReal &grayImage, Image3ChnlReal &rgbImage,
	ImageReal &rgbImageRorB, int x, int y)
{
	if (&rgbImageRorB == rgbImage[0])
		assert(determineBayerColor(x, y) == B);
	else assert(determineBayerColor(x, y) == R);
	
	int width = grayImage.width(), height = grayImage.height();
	
	Float_t color1L = rgbImage(G, x, y);
	Float_t color2L = 0;
	int divisor = 0;
	if (x > 0 && y > 0)
	{
		color2L += (Float_t)grayImage(x - 1, y - 1) /
					(Float_t)rgbImage(G, x - 1, y - 1);
		divisor++;
	}
	if (x < width - 1 && y > 0)
	{
		color2L += (Float_t)grayImage(x + 1, y - 1) /
					(Float_t)rgbImage(G, x + 1, y - 1);
		divisor++;
	}
	if (x < width - 1 && y < height - 1)
	{
		color2L += (Float_t)grayImage(x + 1, y + 1) /
					(Float_t)rgbImage(G, x + 1, y + 1);
		divisor++;
	}
	if (x > 0 && y < height - 1)
	{
		color2L += (Float_t)grayImage(x - 1, y + 1) /
					(Float_t)rgbImage(G, x - 1, y + 1);
		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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebx
movl %ecx, %r14d
movq %rdx, %r12
movq %rdi, %r13
movq %rsi, 0x10(%rsp)
movq 0x38(%rsi), %rax
movq (%rax), %r15
movl %ecx, %edi
movl %r8d, %esi
callq 0x1c294
movq %r12, 0x30(%rsp)
cmpq %r12, %r15
je 0xd123
testl %eax, %eax
je 0xd12c
leaq 0x16587(%rip), %rdi     # 0x23692
leaq 0x1638e(%rip), %rsi     # 0x234a0
leaq 0x1651c(%rip), %rcx     # 0x23635
movl $0x1ac, %edx            # imm = 0x1AC
callq 0x31a0
cmpl $0x2, %eax
jne 0xd33e
movl 0x28(%r13), %r12d
movl 0x2c(%r13), %eax
movl %eax, 0x18(%rsp)
pushq $0x1
popq %rbp
movq 0x10(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %edx
movl %ebx, %ecx
callq 0xb868
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
testl %r14d, %r14d
setle %al
testl %ebx, %ebx
setle %cl
orb %al, %cl
jne 0xd1a8
leal -0x1(%r14), %edx
leal -0x1(%rbx), %ecx
movq 0x38(%r13), %rax
movl 0x28(%r13), %esi
imull %ecx, %esi
addl %r14d, %esi
decl %esi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movl %ebp, %esi
callq 0xb868
movsd 0x8(%rsp), %xmm0
divsd (%rax), %xmm0
xorpd %xmm2, %xmm2
addsd %xmm0, %xmm2
jmp 0xd1ae
xorl %ebp, %ebp
xorpd %xmm2, %xmm2
testl %ebx, %ebx
setle %al
decl %r12d
cmpl %r14d, %r12d
setle %cl
orb %al, %cl
movl 0x18(%rsp), %r15d
jne 0xd210
leal 0x1(%r14), %edx
leal -0x1(%rbx), %ecx
movq 0x38(%r13), %rax
movl 0x28(%r13), %esi
imull %ecx, %esi
addl %r14d, %esi
incl %esi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, 0x20(%rsp)
pushq $0x1
popq %rsi
movq 0x10(%rsp), %rdi
movsd %xmm2, 0x8(%rsp)
callq 0xb868
movsd 0x8(%rsp), %xmm2
movsd 0x20(%rsp), %xmm0
divsd (%rax), %xmm0
addsd %xmm0, %xmm2
incl %ebp
cmpl %r14d, %r12d
setg %al
decl %r15d
cmpl %ebx, %r15d
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xd276
leal 0x1(%r14), %edx
leal 0x1(%rbx), %ecx
movq 0x38(%r13), %rax
movl 0x28(%r13), %esi
imull %ecx, %esi
addl %r14d, %esi
incl %esi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, 0x18(%rsp)
pushq $0x1
popq %rsi
movq 0x10(%rsp), %r12
movq %r12, %rdi
movsd %xmm2, 0x8(%rsp)
callq 0xb868
movsd 0x8(%rsp), %xmm2
movsd 0x18(%rsp), %xmm0
divsd (%rax), %xmm0
addsd %xmm0, %xmm2
incl %ebp
jmp 0xd27b
movq 0x10(%rsp), %r12
cmpl %ebx, %r15d
setg %al
testl %r14d, %r14d
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xd2d9
leal -0x1(%r14), %edx
leal 0x1(%rbx), %ecx
movq 0x38(%r13), %rax
movl 0x28(%r13), %esi
imull %ecx, %esi
addl %r14d, %esi
decl %esi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, 0x10(%rsp)
pushq $0x1
popq %rsi
movq %r12, %rdi
movsd %xmm2, 0x8(%rsp)
callq 0xb868
movsd 0x8(%rsp), %xmm2
movsd 0x10(%rsp), %xmm0
divsd (%rax), %xmm0
addsd %xmm0, %xmm2
incl %ebp
jmp 0xd2dd
testl %ebp, %ebp
je 0xd31f
cvtsi2sd %ebp, %xmm0
movsd 0x28(%rsp), %xmm1
divsd %xmm0, %xmm1
mulsd %xmm2, %xmm1
movsd 0x15cc9(%rip), %xmm0    # 0x22fc0
minsd %xmm1, %xmm0
movq 0x30(%rsp), %rcx
movq 0x38(%rcx), %rax
imull 0x28(%rcx), %ebx
addl %r14d, %ebx
movsd %xmm0, (%rax,%rbx,8)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x161c9(%rip), %rdi     # 0x234ef
leaq 0x16173(%rip), %rsi     # 0x234a0
leaq 0x16301(%rip), %rcx     # 0x23635
movl $0x1cc, %edx            # imm = 0x1CC
callq 0x31a0
leaq 0x162d1(%rip), %rdi     # 0x23616
leaq 0x16154(%rip), %rsi     # 0x234a0
leaq 0x162e2(%rip), %rcx     # 0x23635
movl $0x1ab, %edx            # imm = 0x1AB
callq 0x31a0