// File: /workspace/github_cpp_makefile_star2_O1/kylegranger[P]ImageScaling/linear16.cpp
// Function: CLinear16::DrawMonochromeAnaglyph(CLinear16*, CLinear16*)
void CLinear16::DrawMonochromeAnaglyph(CLinear16 *left, CLinear16 *right)
{
	if (left && right)
	{
		assert(left->mWidth == mWidth);
		assert(left->mHeight == mHeight);
		assert(right->mWidth == mWidth);
		assert(right->mHeight == mHeight);
		color_t *src1 = left->mData;
		color_t *src2 = right->mData;
		color_t *dst = mData;
		for (int y = 0; y < mHeight; y++)
		{
			for (int x = 0; x < mWidth; x++)
			{
				int luma1 = src1->r * 2126 + src1->g * 7152 + src1->b * 722 + 5000;
				int luma2 = src2->r * 2126 + src2->g * 7152 + src2->b * 722 + 5000;
				luma1 /= 10000;
				luma2 /= 10000;
				dst->r = luma1;
				dst->g = luma2 * 3 / 4;
				dst->b = luma2;
				dst->a = 0xffff;
				dst++;
			}
		}
	}
	else if (left)
	{
		assert(left->mWidth == mWidth);
		assert(left->mHeight == mHeight);
		color_t *src = left->mData;
		color_t *dst = mData;
		for (int y = 0; y < mHeight; y++)
		{
			for (int x = 0; x < mWidth; x++)
			{
				int luma1 = src->r * 2126 + src->g * 7152 + src->b * 722 + 5000;
				luma1 /= 10000;
				dst->r = luma1;
				dst->a = 0xffff;
				dst++;
				src++;
			}
		}
	}
	else if (right)
	{
		assert(right->mWidth == mWidth);
		assert(right->mHeight == mHeight);
		color_t *src = right->mData;
		color_t *dst = mData;
		for (int y = 0; y < mHeight; y++)
		{
			for (int x = 0; x < mWidth; x++)
			{
				int luma2 = src->r * 2126 + src->g * 7152 + src->b * 722 + 5000;
				luma2 /= 10000;
				dst->g = luma2 * 3 / 4;
				dst->b = luma2;
				dst++;
				src++;
			}
		}
	}
	else
		assert(0);

}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
testq %rsi, %rsi
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
jne 0x8c37
movl (%rdi), %eax
cmpl %eax, (%rsi)
jne 0x8d82
movl 0x4(%rdi), %ecx
cmpl %ecx, 0x4(%rsi)
jne 0x8da1
cmpl %eax, (%rdx)
jne 0x8dc0
cmpl %ecx, 0x4(%rdx)
jne 0x8ddf
testl %ecx, %ecx
jle 0x8d7b
movq 0x18(%rsi), %rsi
movq 0x18(%rdx), %rdx
movq 0x18(%rdi), %rdi
xorl %r8d, %r8d
movl $0x1388, %r9d           # imm = 0x1388
movl %eax, %r10d
testl %eax, %eax
jle 0x8c26
movzwl 0x4(%rsi), %r11d
imull $0x84e, %r11d, %r11d    # imm = 0x84E
movzwl 0x2(%rsi), %ebx
imull $0x1bf0, %ebx, %ebx     # imm = 0x1BF0
addl %r11d, %ebx
movzwl (%rsi), %r11d
imull $0x2d2, %r11d, %r11d    # imm = 0x2D2
addl %r9d, %r11d
addl %ebx, %r11d
movzwl 0x4(%rdx), %ebx
imull $0x84e, %ebx, %ebx      # imm = 0x84E
movzwl 0x2(%rdx), %ebp
imull $0x1bf0, %ebp, %ebp     # imm = 0x1BF0
addl %ebx, %ebp
movzwl (%rdx), %ebx
imull $0x2d2, %ebx, %ebx      # imm = 0x2D2
addl %r9d, %ebx
addl %ebp, %ebx
imulq $0x68db8bad, %r11, %r11 # imm = 0x68DB8BAD
shrq $0x2c, %r11
imulq $0x68db8bad, %rbx, %rbx # imm = 0x68DB8BAD
shrq $0x2c, %rbx
movw %r11w, 0x4(%rdi)
leal (%rbx,%rbx,2), %r11d
shrl $0x2, %r11d
movw %r11w, 0x2(%rdi)
movw %bx, (%rdi)
movw $0xffff, 0x6(%rdi)      # imm = 0xFFFF
addq $0x8, %rdi
decl %r10d
jne 0x8b9a
incl %r8d
cmpl %ecx, %r8d
jne 0x8b8f
jmp 0x8d7b
testq %rsi, %rsi
je 0x8cdb
movl (%rdi), %eax
cmpl %eax, (%rsi)
jne 0x8dfe
movl 0x4(%rdi), %ecx
cmpl %ecx, 0x4(%rsi)
jne 0x8e1d
testl %ecx, %ecx
jle 0x8d7b
movq 0x18(%rdi), %rdx
movq 0x18(%rsi), %rsi
xorl %edi, %edi
testl %eax, %eax
jle 0x8cd0
xorl %r8d, %r8d
xorl %r9d, %r9d
movzwl 0x4(%rsi,%r9,8), %r10d
imull $0x84e, %r10d, %r10d    # imm = 0x84E
movzwl 0x2(%rsi,%r9,8), %r11d
imull $0x1bf0, %r11d, %r11d   # imm = 0x1BF0
addl %r10d, %r11d
movzwl (%rsi,%r9,8), %r10d
imull $0x2d2, %r10d, %r10d    # imm = 0x2D2
addl %r11d, %r10d
addl $0x1388, %r10d          # imm = 0x1388
imulq $0x68db8bad, %r10, %r10 # imm = 0x68DB8BAD
shrq $0x2c, %r10
movw %r10w, 0x4(%rdx,%r9,8)
movw $0xffff, 0x6(%rdx,%r9,8) # imm = 0xFFFF
incq %r9
addq $-0x8, %r8
cmpl %r9d, %eax
jne 0x8c72
subq %r8, %rdx
subq %r8, %rsi
incl %edi
cmpl %ecx, %edi
jne 0x8c68
jmp 0x8d7b
testq %rdx, %rdx
je 0x8e3c
movl (%rdi), %eax
cmpl %eax, (%rdx)
jne 0x8e5b
movl 0x4(%rdi), %ecx
cmpl %ecx, 0x4(%rdx)
jne 0x8e7a
testl %ecx, %ecx
jle 0x8d7b
movq 0x18(%rdi), %rsi
movq 0x18(%rdx), %rdx
xorl %edi, %edi
testl %eax, %eax
jle 0x8d75
xorl %r8d, %r8d
xorl %r9d, %r9d
movzwl 0x4(%rdx,%r9,8), %r10d
imull $0x84e, %r10d, %r10d    # imm = 0x84E
movzwl 0x2(%rdx,%r9,8), %r11d
imull $0x1bf0, %r11d, %r11d   # imm = 0x1BF0
addl %r10d, %r11d
movzwl (%rdx,%r9,8), %r10d
imull $0x2d2, %r10d, %r10d    # imm = 0x2D2
addl %r11d, %r10d
addl $0x1388, %r10d          # imm = 0x1388
imulq $0x68db8bad, %r10, %r10 # imm = 0x68DB8BAD
shrq $0x2c, %r10
leal (%r10,%r10,2), %r11d
shrl $0x2, %r11d
movw %r11w, 0x2(%rsi,%r9,8)
movw %r10w, (%rsi,%r9,8)
incq %r9
addq $-0x8, %r8
cmpl %r9d, %eax
jne 0x8d12
subq %r8, %rsi
subq %r8, %rdx
incl %edi
cmpl %ecx, %edi
jne 0x8d08
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x166ec(%rip), %rdi     # 0x1f475
leaq 0x16474(%rip), %rsi     # 0x1f204
leaq 0x166f5(%rip), %rcx     # 0x1f48c
movl $0x39d, %edx            # imm = 0x39D
callq 0x4100
leaq 0x16725(%rip), %rdi     # 0x1f4cd
leaq 0x16455(%rip), %rsi     # 0x1f204
leaq 0x166d6(%rip), %rcx     # 0x1f48c
movl $0x39e, %edx            # imm = 0x39E
callq 0x4100
leaq 0x1671f(%rip), %rdi     # 0x1f4e6
leaq 0x16436(%rip), %rsi     # 0x1f204
leaq 0x166b7(%rip), %rcx     # 0x1f48c
movl $0x39f, %edx            # imm = 0x39F
callq 0x4100
leaq 0x16718(%rip), %rdi     # 0x1f4fe
leaq 0x16417(%rip), %rsi     # 0x1f204
leaq 0x16698(%rip), %rcx     # 0x1f48c
movl $0x3a0, %edx            # imm = 0x3A0
callq 0x4100
leaq 0x16670(%rip), %rdi     # 0x1f475
leaq 0x163f8(%rip), %rsi     # 0x1f204
leaq 0x16679(%rip), %rcx     # 0x1f48c
movl $0x3b6, %edx            # imm = 0x3B6
callq 0x4100
leaq 0x166a9(%rip), %rdi     # 0x1f4cd
leaq 0x163d9(%rip), %rsi     # 0x1f204
leaq 0x1665a(%rip), %rcx     # 0x1f48c
movl $0x3b7, %edx            # imm = 0x3B7
callq 0x4100
leaq 0x1654c(%rip), %rdi     # 0x1f38f
leaq 0x163ba(%rip), %rsi     # 0x1f204
leaq 0x1663b(%rip), %rcx     # 0x1f48c
movl $0x3db, %edx            # imm = 0x3DB
callq 0x4100
leaq 0x16684(%rip), %rdi     # 0x1f4e6
leaq 0x1639b(%rip), %rsi     # 0x1f204
leaq 0x1661c(%rip), %rcx     # 0x1f48c
movl $0x3c9, %edx            # imm = 0x3C9
callq 0x4100
leaq 0x1667d(%rip), %rdi     # 0x1f4fe
leaq 0x1637c(%rip), %rsi     # 0x1f204
leaq 0x165fd(%rip), %rcx     # 0x1f48c
movl $0x3ca, %edx            # imm = 0x3CA
callq 0x4100
nop