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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movl (%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x9f94
jmp 0x9fb3
leaq 0x173c3(%rip), %rdi     # 0x2135e
leaq 0x17268(%rip), %rsi     # 0x2120a
movl $0x212, %edx            # imm = 0x212
leaq 0x173c6(%rip), %rcx     # 0x21374
callq 0x40f0
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
shll %ecx
cmpl %ecx, %eax
jne 0x9fc9
jmp 0x9fe8
leaq 0x173cd(%rip), %rdi     # 0x2139d
leaq 0x17233(%rip), %rsi     # 0x2120a
movl $0x213, %edx            # imm = 0x213
leaq 0x17391(%rip), %rcx     # 0x21374
callq 0x40f0
movq -0x50(%rbp), %rcx
movq 0x18(%rcx), %rax
movslq (%rcx), %rsi
xorl %edx, %edx
subq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rax
movq %rax, -0x18(%rbp)
movq 0x18(%rcx), %rax
movq %rax, -0x20(%rbp)
movq 0x18(%rcx), %rax
movslq (%rcx), %rdx
shlq $0x3, %rdx
addq %rdx, %rax
movq %rax, -0x28(%rbp)
movq 0x18(%rcx), %rax
movl (%rcx), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0xa21b
cmpl $0x0, -0x3c(%rbp)
jne 0xa0cb
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xa0c6
movq -0x20(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rdx
movq %rdx, %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rcx
movq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x6180
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xa063
jmp 0xa1b9
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xa148
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xa146
movq -0x20(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdx
movq %rdx, %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movq -0x38(%rbp), %rcx
movq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x6180
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xa0e3
jmp 0xa1b7
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xa1b5
movq -0x18(%rbp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rsi
movq %rsi, %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rdx
movq %rdx, %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rcx
movq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %r8
movq %r8, %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
callq 0x6080
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xa14f
jmp 0xa1b7
jmp 0xa1b9
movq -0x50(%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 -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xa046
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)