// File: /workspace/github_cpp_makefile_star2_O2/kylegranger[P]ImageScaling/linear16.cpp
// Function: CLinear16::Downsample(CLinear16*)
void CLinear16::Downsample(CLinear16 *bmp)
{
	assert((mWidth  & 0xfffe) == bmp->mWidth*2);
	assert((mHeight & 0xfffe) == bmp->mHeight*2);
	color_t *src1 = mData - 1 - mWidth;
	color_t *src2 = mData - 1;
	color_t *src3 = mData - 1 + mWidth;
	color_t *src4 = mData - 1 + mWidth * 2;
	color_t *dst = bmp->mData;
	int padw = mWidth & 1;
	for (int y = 0; y < bmp->mHeight; y++)
	{
		if (y == 0)
		{
			DownfilterLeft(src4, src2, src3, dst++);
			src1 += 2;
			src2 += 2;
			src3 += 2;
			src4 += 2;
			for (int x = 1; x < bmp->mWidth-1; x++)
			{
				Downfilter(src4, src2, src3, dst++);
				src1 += 2;
				src2 += 2;
				src3 += 2;
				src4 += 2;
			}
			DownfilterRight(src4, src2, src3, dst++);
			src1 += 2 + padw;
			src2 += 2 + padw;
			src3 += 2 + padw;
			src4 += 2 + padw;
		}
		else if (y == bmp->mHeight - 1)
		{
			DownfilterLeft(src1, src2, src3, dst++);
			src1 += 2;
			src2 += 2;
			src3 += 2;
			src4 += 2;
			for (int x = 1; x < bmp->mWidth-1; x++)
			{
				Downfilter(src1, src2, src3, dst++);
				src1 += 2;
				src2 += 2;
				src3 += 2;
				src4 += 2;
			}
			DownfilterRight(src1, src2, src3, dst++);
			src1 += 2 + padw;
			src2 += 2 + padw;
			src3 += 2 + padw;
			src4 += 2 + padw;
		}
		else
		{
			DownfilterLeft(src1, src2, src3, src4, dst++);
			src1 += 2;
			src2 += 2;
			src3 += 2;
			src4 += 2;
			for (int x = 1; x < bmp->mWidth-1; x++)
			{
				Downfilter(src1, src2, src3, src4, dst++);
				src1 += 2;
				src2 += 2;
				src3 += 2;
				src4 += 2;
			}
			DownfilterRight(src1, src2, src3, src4, dst++);
			src1 += 2 + padw;
			src2 += 2 + padw;
			src3 += 2 + padw;
			src4 += 2 + padw;
		}
		src1 += mWidth;
		src2 += mWidth;
		src3 += mWidth;
		src4 += mWidth;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movslq (%rdi), %rcx
movl %ecx, %eax
andl $0xfffe, %eax           # imm = 0xFFFE
movl (%rsi), %edx
addl %edx, %edx
cmpl %edx, %eax
jne 0x71e0
movl $0xfffe, %edx           # imm = 0xFFFE
andl 0x4(%rdi), %edx
movl 0x4(%rsi), %eax
leal (%rax,%rax), %r8d
cmpl %r8d, %edx
jne 0x71ff
movl %ecx, %r9d
movq 0x18(%rdi), %rdx
leaq -0x8(%rdx), %r15
leaq (,%rcx,8), %r8
negq %r8
leaq (%rdx,%r8), %r12
addq $-0x8, %r12
leaq -0x8(%rdx,%rcx,8), %r13
addl %ecx, %ecx
movslq %ecx, %rcx
leaq (%rdx,%rcx,8), %rbp
addq $-0x8, %rbp
movq 0x18(%rsi), %r14
andl $0x1, %r9d
orq $0x2, %r9
xorl %ecx, %ecx
shll $0x3, %r9d
movq %r9, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, 0x20(%rsp)
cmpl %eax, %ecx
jge 0x71d1
testl %ecx, %ecx
movl %ecx, 0x14(%rsp)
je 0x70c6
decl %eax
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
cmpl %eax, %ecx
jne 0x7132
movq %r14, %rcx
callq 0x599c
addq $0x10, %r15
addq $0x10, %r13
addq $0x10, %rbp
addq $0x10, %r14
addq $0x10, %r12
pushq $0x1
popq %rbx
leaq -0x8(%r14), %rcx
movq 0x8(%rsp), %rax
movl (%rax), %eax
decl %eax
movq %r12, %rdi
cmpl %eax, %ebx
jge 0x7125
movq %r15, %rsi
movq %r13, %rdx
callq 0x5760
incl %ebx
addq $0x10, %r15
addq $0x10, %r13
addq $0x10, %rbp
addq $0x8, %r14
addq $0x10, %r12
jmp 0x708b
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x599c
addq $0x10, %r15
addq $0x10, %r13
addq $0x10, %rbp
addq $0x10, %r14
addq $0x10, %r12
pushq $0x1
popq %rbx
leaq -0x8(%r14), %rcx
movq 0x8(%rsp), %rax
movl (%rax), %eax
decl %eax
movq %rbp, %rdi
cmpl %eax, %ebx
jge 0x7125
movq %r15, %rsi
movq %r13, %rdx
callq 0x5760
incl %ebx
addq $0x10, %r15
addq $0x10, %r13
addq $0x10, %rbp
addq $0x8, %r14
addq $0x10, %r12
jmp 0x70ee
movq %r15, %rsi
movq %r13, %rdx
callq 0x5bac
jmp 0x7193
movq %rbp, %rcx
movq %r14, %r8
callq 0x587c
addq $0x10, %r15
addq $0x10, %r13
addq $0x10, %rbp
addq $0x10, %r14
addq $0x10, %r12
pushq $0x1
popq %rbx
leaq -0x8(%r14), %r8
movq 0x8(%rsp), %rax
movl (%rax), %eax
decl %eax
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbp, %rcx
cmpl %eax, %ebx
jge 0x718e
callq 0x5659
incl %ebx
addq $0x10, %r15
addq $0x10, %r13
addq $0x10, %rbp
addq $0x8, %r14
addq $0x10, %r12
jmp 0x7154
callq 0x5a90
movq 0x18(%rsp), %rax
addq %rax, %r12
addq %rax, %r15
addq %rax, %r13
addq %rax, %rbp
movq 0x20(%rsp), %rax
movslq (%rax), %rax
leaq (%r12,%rax,8), %r12
leaq (%r15,%rax,8), %r15
leaq (%r13,%rax,8), %r13
leaq (%rbp,%rax,8), %rbp
movl 0x14(%rsp), %ecx
incl %ecx
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
jmp 0x7049
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1712a(%rip), %rdi     # 0x1e311
leaq 0x170a2(%rip), %rsi     # 0x1e290
leaq 0x1713f(%rip), %rcx     # 0x1e334
movl $0x19c, %edx            # imm = 0x19C
callq 0x4100
leaq 0x17156(%rip), %rdi     # 0x1e35c
leaq 0x17083(%rip), %rsi     # 0x1e290
leaq 0x17120(%rip), %rcx     # 0x1e334
movl $0x19d, %edx            # imm = 0x19D
callq 0x4100