// File: kylegranger[P]ImageScaling/linear16.cpp
// Function: CLinear16::Flip(bool, bool)
void CLinear16::Flip(bool flipX, bool flipY)
{
	color_t *src;
	color_t *dst;
	color_t temp;

	if (flipY)
	{
		for (int y = 0; y < mHeight/2; y++)
		{
			src = mData + y * mWidth;
			dst = mData + (mHeight - 1 - y) * mWidth;
			if (flipX)
			{
				dst += mWidth - 1;
				for (int x = 0; x < mWidth; x++)
				{
					temp = *src;
					*src++ = *dst;
					*dst-- = temp;
				}
			}
			else
			{
				for (int x = 0; x < mWidth; x++)
				{
					temp = *src;
					*src++ = *dst;
					*dst++ = temp;
				}
			}
		}
	}
	else if (flipX)
	{
		for (int y = 0; y < mHeight; y++)
		{
			src = mData + y * mWidth;
			dst = src + mWidth - 1;
			for (int x = 0; x < mWidth/2; x++)
			{
				temp = *src;
				*src++ = *dst;
				*dst-- = temp;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb %dl, %al
movb %sil, %cl
movq %rdi, -0x8(%rbp)
andb $0x1, %cl
movb %cl, -0x9(%rbp)
andb $0x1, %al
movb %al, -0xa(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
testb $0x1, -0xa(%rbp)
je 0xb975
movl $0x0, -0x2c(%rbp)
movq -0x48(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, -0x4c(%rbp)
movl 0x4(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4c(%rbp), %eax
cmpl %ecx, %eax
jge 0xb970
movq -0x48(%rbp), %rdx
movq 0x18(%rdx), %rax
movl -0x2c(%rbp), %ecx
imull (%rdx), %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq 0x18(%rdx), %rax
movl 0x4(%rdx), %ecx
subl $0x1, %ecx
subl -0x2c(%rbp), %ecx
imull (%rdx), %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
testb $0x1, -0x9(%rbp)
je 0xb907
movq -0x48(%rbp), %rax
movl (%rax), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x48(%rbp), %rcx
movl -0x30(%rbp), %eax
cmpl (%rcx), %eax
jge 0xb905
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x18(%rbp)
movq (%rcx), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $-0x8, %rcx
movq %rcx, -0x20(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb8b5
jmp 0xb960
movl $0x0, -0x34(%rbp)
movq -0x48(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
jge 0xb95e
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x18(%rbp)
movq (%rcx), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x20(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xb90e
jmp 0xb960
jmp 0xb962
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb831
jmp 0xba45
testb $0x1, -0x9(%rbp)
je 0xba43
movl $0x0, -0x38(%rbp)
movq -0x48(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0xba41
movq -0x48(%rbp), %rcx
movq 0x18(%rcx), %rax
movl -0x38(%rbp), %edx
imull (%rcx), %edx
movslq %edx, %rdx
shlq $0x3, %rdx
addq %rdx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movslq (%rcx), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x48(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, -0x50(%rbp)
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x50(%rbp), %eax
cmpl %ecx, %eax
jge 0xba31
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x18(%rbp)
movq (%rcx), %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $-0x8, %rcx
movq %rcx, -0x20(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xb9cf
jmp 0xba33
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xb986
jmp 0xba43
jmp 0xba45
popq %rbp
retq
nopw (%rax,%rax)