// File: /workspace/github_cpp_makefile_star2_O3/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 0x837d
movl (%rsi), %eax
cmpl (%rdi), %eax
jne 0x84c8
movl 0x4(%rsi), %ecx
cmpl 0x4(%rdi), %ecx
jne 0x84e7
cmpl %eax, (%rdx)
jne 0x8506
cmpl %ecx, 0x4(%rdx)
jne 0x8525
testl %ecx, %ecx
jle 0x84c1
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 0x836c
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 0x82e0
incl %r8d
cmpl %ecx, %r8d
jne 0x82d5
jmp 0x84c1
testq %rsi, %rsi
je 0x8421
movl (%rsi), %eax
cmpl (%rdi), %eax
jne 0x8544
movl 0x4(%rsi), %ecx
cmpl 0x4(%rdi), %ecx
jne 0x8563
testl %ecx, %ecx
jle 0x84c1
movq 0x18(%rdi), %rdx
movq 0x18(%rsi), %rsi
xorl %edi, %edi
testl %eax, %eax
jle 0x8416
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 0x83b8
subq %r8, %rdx
subq %r8, %rsi
incl %edi
cmpl %ecx, %edi
jne 0x83ae
jmp 0x84c1
testq %rdx, %rdx
je 0x8582
movl (%rdx), %eax
cmpl (%rdi), %eax
jne 0x85a1
movl 0x4(%rdx), %ecx
cmpl 0x4(%rdi), %ecx
jne 0x85c0
testl %ecx, %ecx
jle 0x84c1
movq 0x18(%rdi), %rsi
movq 0x18(%rdx), %rdx
xorl %edi, %edi
testl %eax, %eax
jle 0x84bb
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 0x8458
subq %r8, %rsi
subq %r8, %rdx
incl %edi
cmpl %ecx, %edi
jne 0x844e
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x16062(%rip), %rdi     # 0x1e531
leaq 0x15dea(%rip), %rsi     # 0x1e2c0
leaq 0x1606b(%rip), %rcx     # 0x1e548
movl $0x39d, %edx            # imm = 0x39D
callq 0x4100
leaq 0x1609b(%rip), %rdi     # 0x1e589
leaq 0x15dcb(%rip), %rsi     # 0x1e2c0
leaq 0x1604c(%rip), %rcx     # 0x1e548
movl $0x39e, %edx            # imm = 0x39E
callq 0x4100
leaq 0x16095(%rip), %rdi     # 0x1e5a2
leaq 0x15dac(%rip), %rsi     # 0x1e2c0
leaq 0x1602d(%rip), %rcx     # 0x1e548
movl $0x39f, %edx            # imm = 0x39F
callq 0x4100
leaq 0x1608e(%rip), %rdi     # 0x1e5ba
leaq 0x15d8d(%rip), %rsi     # 0x1e2c0
leaq 0x1600e(%rip), %rcx     # 0x1e548
movl $0x3a0, %edx            # imm = 0x3A0
callq 0x4100
leaq 0x15fe6(%rip), %rdi     # 0x1e531
leaq 0x15d6e(%rip), %rsi     # 0x1e2c0
leaq 0x15fef(%rip), %rcx     # 0x1e548
movl $0x3b6, %edx            # imm = 0x3B6
callq 0x4100
leaq 0x1601f(%rip), %rdi     # 0x1e589
leaq 0x15d4f(%rip), %rsi     # 0x1e2c0
leaq 0x15fd0(%rip), %rcx     # 0x1e548
movl $0x3b7, %edx            # imm = 0x3B7
callq 0x4100
leaq 0x15ec2(%rip), %rdi     # 0x1e44b
leaq 0x15d30(%rip), %rsi     # 0x1e2c0
leaq 0x15fb1(%rip), %rcx     # 0x1e548
movl $0x3db, %edx            # imm = 0x3DB
callq 0x4100
leaq 0x15ffa(%rip), %rdi     # 0x1e5a2
leaq 0x15d11(%rip), %rsi     # 0x1e2c0
leaq 0x15f92(%rip), %rcx     # 0x1e548
movl $0x3c9, %edx            # imm = 0x3C9
callq 0x4100
leaq 0x15ff3(%rip), %rdi     # 0x1e5ba
leaq 0x15cf2(%rip), %rsi     # 0x1e2c0
leaq 0x15f73(%rip), %rcx     # 0x1e548
movl $0x3ca, %edx            # imm = 0x3CA
callq 0x4100
nop