// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movl (%rax), %eax
andl $0xfffe, %eax           # imm = 0xFFFE
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
shll %ecx
cmpl %ecx, %eax
jne 0x978d
jmp 0x97ac
leaq 0x17b19(%rip), %rdi     # 0x212ad
leaq 0x17a6f(%rip), %rsi     # 0x2120a
movl $0x19c, %edx            # imm = 0x19C
leaq 0x17b29(%rip), %rcx     # 0x212d0
callq 0x40f0
movq -0x58(%rbp), %rax
movl 0x4(%rax), %eax
andl $0xfffe, %eax           # imm = 0xFFFE
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
shll %ecx
cmpl %ecx, %eax
jne 0x97c7
jmp 0x97e6
leaq 0x17b2a(%rip), %rdi     # 0x212f8
leaq 0x17a35(%rip), %rsi     # 0x2120a
movl $0x19d, %edx            # imm = 0x19D
leaq 0x17aef(%rip), %rcx     # 0x212d0
callq 0x40f0
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rcx
addq $-0x8, %rcx
movslq (%rax), %rsi
xorl %edx, %edx
subq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, -0x18(%rbp)
movq 0x18(%rax), %rcx
addq $-0x8, %rcx
movq %rcx, -0x20(%rbp)
movq 0x18(%rax), %rcx
addq $-0x8, %rcx
movslq (%rax), %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, -0x28(%rbp)
movq 0x18(%rax), %rcx
addq $-0x8, %rcx
movl (%rax), %edx
shll %edx
movslq %edx, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, -0x30(%rbp)
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, -0x38(%rbp)
movl (%rax), %eax
andl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x9ccb
cmpl $0x0, -0x40(%rbp)
jne 0x99bd
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x6b80
movq -0x18(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x9938
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x65e0
movq -0x18(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x98cd
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x70b0
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x9c69
movl -0x40(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x9b19
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x6b80
movq -0x18(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x9a94
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x65e0
movq -0x18(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x9a29
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x70b0
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x9c67
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq %r8, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x68a0
movq -0x18(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x9be3
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq %r8, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x6270
movq -0x18(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x9b74
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq %r8, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x6dd0
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x9c69
movq -0x58(%rbp), %rax
movl (%rax), %edx
movq -0x18(%rbp), %rcx
movslq %edx, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, -0x18(%rbp)
movl (%rax), %edx
movq -0x20(%rbp), %rcx
movslq %edx, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, -0x20(%rbp)
movl (%rax), %edx
movq -0x28(%rbp), %rcx
movslq %edx, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movq %rcx, -0x28(%rbp)
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x985c
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)