// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movslq (%rdi), %rcx
movl %ecx, %eax
andl $0xfffe, %eax           # imm = 0xFFFE
movl (%rsi), %edx
addl %edx, %edx
cmpl %edx, %eax
jne 0x7dc9
movq %rsi, %rbx
movl $0xfffe, %eax           # imm = 0xFFFE
andl 0x4(%rdi), %eax
movl 0x4(%rsi), %edx
addl %edx, %edx
cmpl %edx, %eax
jne 0x7de8
movl 0x4(%rbx), %eax
testl %eax, %eax
jle 0x7dba
movl %ecx, %r8d
andl $0x1, %r8d
movq 0x18(%rbx), %r15
movq 0x18(%rdi), %rdx
leaq -0x8(%rdx), %r12
movq %rcx, %rsi
shlq $0x4, %rsi
leaq (%rdx,%rsi), %r13
addq $-0x8, %r13
leaq (%rdx,%rcx,8), %rbp
addq $-0x8, %rbp
shlq $0x3, %rcx
negq %rcx
leaq (%rdx,%rcx), %r14
addq $-0x8, %r14
orl $0x2, %r8d
xorl %ecx, %ecx
leal (,%r8,8), %edx
movq %rdx, 0x20(%rsp)
movq %r8, 0x28(%rsp)
leal (,%r8,8), %edx
movq %rdx, 0x18(%rsp)
movq %rdi, 0x30(%rsp)
movq %rbx, 0x8(%rsp)
testl %ecx, %ecx
movl %ecx, 0x14(%rsp)
je 0x7c38
decl %eax
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
cmpl %eax, %ecx
jne 0x7ca2
movq %r15, %rcx
callq 0x5f4d
addq $0x10, %rbp
addq $0x10, %r12
addq $0x10, %r14
cmpl $0x3, (%rbx)
jl 0x7d38
movl $0x1, %ebx
addq $0x8, %r15
addq $0x10, %r13
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x5bac
incl %ebx
addq $0x10, %rbp
addq $0x10, %r12
addq $0x10, %r14
movq 0x8(%rsp), %rax
movl (%rax), %eax
decl %eax
cmpl %eax, %ebx
jl 0x7bf6
leaq 0x8(%r15), %rcx
movq 0x8(%rsp), %rbx
jmp 0x7d3c
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x5f4d
addq $0x10, %r13
addq $0x10, %rbp
addq $0x10, %r12
cmpl $0x3, (%rbx)
jl 0x7d0d
movl $0x1, %ebx
addq $0x8, %r15
addq $0x10, %r14
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x5bac
incl %ebx
addq $0x10, %r13
addq $0x10, %rbp
addq $0x10, %r12
movq 0x8(%rsp), %rax
movl (%rax), %eax
decl %eax
cmpl %eax, %ebx
jl 0x7c63
leaq 0x8(%r15), %rcx
movq 0x8(%rsp), %rbx
jmp 0x7d11
movq %r13, %rcx
movq %r15, %r8
callq 0x5d81
addq $0x10, %r13
addq $0x10, %rbp
addq $0x10, %r12
addq $0x10, %r14
cmpl $0x3, (%rbx)
jl 0x7d65
movl $0x1, %ebx
addq $0x8, %r15
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x598b
incl %ebx
addq $0x10, %r13
addq $0x10, %rbp
addq $0x10, %r12
addq $0x10, %r14
movq 0x8(%rsp), %rax
movl (%rax), %eax
decl %eax
cmpl %eax, %ebx
jl 0x7ccb
leaq 0x8(%r15), %r8
movq 0x8(%rsp), %rbx
jmp 0x7d69
leaq 0x8(%r15), %rcx
addq $0x10, %r15
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x6284
movq 0x28(%rsp), %rax
leal (,%rax,8), %eax
addq %rax, %r14
addq $0x10, %r14
jmp 0x7d86
leaq 0x8(%r15), %rcx
addq $0x10, %r15
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x6284
movq 0x20(%rsp), %rax
addq %rax, %r14
addq %rax, %r12
addq %rax, %rbp
addq %rax, %r13
addq $0x10, %r13
jmp 0x7d8f
leaq 0x8(%r15), %r8
addq $0x10, %r15
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x60bc
movq 0x18(%rsp), %rax
addq %rax, %r14
addq %rax, %r12
addq %rax, %rbp
addq %rax, %r13
movq 0x30(%rsp), %rax
movslq (%rax), %rax
leaq (%r14,%rax,8), %r14
leaq (%r12,%rax,8), %r12
leaq (%rbp,%rax,8), %rbp
leaq (%r13,%rax,8), %r13
movl 0x14(%rsp), %ecx
incl %ecx
movl 0x4(%rbx), %eax
cmpl %eax, %ecx
jl 0x7bb9
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x174b5(%rip), %rdi     # 0x1f285
leaq 0x1742d(%rip), %rsi     # 0x1f204
leaq 0x174ca(%rip), %rcx     # 0x1f2a8
movl $0x19c, %edx            # imm = 0x19C
callq 0x4100
leaq 0x174e1(%rip), %rdi     # 0x1f2d0
leaq 0x1740e(%rip), %rsi     # 0x1f204
leaq 0x174ab(%rip), %rcx     # 0x1f2a8
movl $0x19d, %edx            # imm = 0x19D
callq 0x4100
nop