// File: kylegranger[P]ImageScaling/demo.cpp
// Function: doUpsample()
void doUpsample() {
    std::string filename = "images/small.bmp";
    auto image = new CLinear16();
    if (!image->ReadBmp(filename)) {
        printf("could not read upsample image\n");
        return;
    }
    printf("loaded image, width %d height %d\n", image->mWidth, image->mHeight);

    auto x2 = image->Upsample();
    x2->WriteBmp("images/small_up_x2.bmp");
    delete image;

    auto x4 = x2->Upsample();
    x4->WriteBmp("images/small_up_x4.bmp");
    delete x2;

    auto x8 = x4->Upsample();
    x8->WriteBmp("images/small_up_x8.bmp");
    delete x4;

    auto x16 = x8->Upsample();
    x16->WriteBmp("images/small_up_x16.bmp");
    delete x8;

    auto x32 = x16->Upsample();
    x32->WriteBmp("images/small_up_32.bmp");
    delete x16;
    delete x32;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
leaq -0x21(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0xccd0
movq -0x160(%rbp), %rdx
leaq 0x1bced(%rip), %rsi     # 0x210d6
leaq -0x20(%rbp), %rdi
callq 0x5a60
jmp 0x53f4
leaq -0x21(%rbp), %rdi
callq 0xccf0
movl $0x20, %edi
callq 0xcb50
movq %rax, -0x168(%rbp)
jmp 0x5410
movq -0x168(%rbp), %rdi
callq 0x81f0
jmp 0x541e
movq -0x168(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x10180
jmp 0x5443
movq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x8340
movb %al, -0x171(%rbp)
jmp 0x545b
movb -0x171(%rbp), %al
xorb $-0x1, %al
movb %al, -0x172(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd9f0
movb -0x172(%rbp), %al
testb $0x1, %al
jne 0x5481
jmp 0x5504
leaq 0x1bc5f(%rip), %rdi     # 0x210e7
xorl %eax, %eax
callq 0x4050
jmp 0x5491
movl $0x1, -0x64(%rbp)
jmp 0x58f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x21(%rbp), %rdi
callq 0xccf0
jmp 0x5a1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x5a13
movq -0x168(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x20, %esi
callq 0xbca0
jmp 0x5a13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd9f0
jmp 0x5a13
movq -0x40(%rbp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
leaq 0x1bb22(%rip), %rdi     # 0x21036
xorl %eax, %eax
callq 0x4050
jmp 0x551d
movq -0x40(%rbp), %rdi
callq 0x8dc0
movq %rax, -0x180(%rbp)
jmp 0x552f
movq -0x180(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq -0x91(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0xccd0
movq -0x188(%rbp), %rdx
leaq 0x1bba0(%rip), %rsi     # 0x21106
leaq -0x90(%rbp), %rdi
callq 0x5a60
jmp 0x5574
movq -0x190(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x8b80
jmp 0x5589
leaq -0x90(%rbp), %rdi
callq 0xd9f0
leaq -0x91(%rbp), %rdi
callq 0xccf0
movq -0x40(%rbp), %rax
movq %rax, -0x198(%rbp)
cmpq $0x0, %rax
je 0x55cf
movq -0x198(%rbp), %rdi
callq 0x82f0
movq -0x198(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movq -0x70(%rbp), %rdi
callq 0x8dc0
movq %rax, -0x1a0(%rbp)
jmp 0x55e1
movq -0x1a0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0xccd0
movq -0x1a8(%rbp), %rdx
leaq 0x1baff(%rip), %rsi     # 0x2111d
leaq -0xc0(%rbp), %rdi
callq 0x5a60
jmp 0x562c
movq -0x1b0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x8b80
jmp 0x5641
leaq -0xc0(%rbp), %rdi
callq 0xd9f0
leaq -0xc1(%rbp), %rdi
callq 0xccf0
movq -0x70(%rbp), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, %rax
je 0x5687
movq -0x1b8(%rbp), %rdi
callq 0x82f0
movq -0x1b8(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movq -0xa0(%rbp), %rdi
callq 0x8dc0
movq %rax, -0x1c0(%rbp)
jmp 0x569c
movq -0x1c0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x1d0(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0xccd0
movq -0x1c8(%rbp), %rdx
leaq 0x1ba5b(%rip), %rsi     # 0x21134
leaq -0xf0(%rbp), %rdi
callq 0x5a60
jmp 0x56e7
movq -0x1d0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x8b80
jmp 0x56fc
leaq -0xf0(%rbp), %rdi
callq 0xd9f0
leaq -0xf1(%rbp), %rdi
callq 0xccf0
movq -0xa0(%rbp), %rax
movq %rax, -0x1d8(%rbp)
cmpq $0x0, %rax
je 0x5745
movq -0x1d8(%rbp), %rdi
callq 0x82f0
movq -0x1d8(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movq -0xd0(%rbp), %rdi
callq 0x8dc0
movq %rax, -0x1e0(%rbp)
jmp 0x575a
movq -0x1e0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0x1f0(%rbp)
leaq -0x121(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0xccd0
movq -0x1e8(%rbp), %rdx
leaq 0x1b9b4(%rip), %rsi     # 0x2114b
leaq -0x120(%rbp), %rdi
callq 0x5a60
jmp 0x57a5
movq -0x1f0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x8b80
jmp 0x57ba
leaq -0x120(%rbp), %rdi
callq 0xd9f0
leaq -0x121(%rbp), %rdi
callq 0xccf0
movq -0xd0(%rbp), %rax
movq %rax, -0x1f8(%rbp)
cmpq $0x0, %rax
je 0x5803
movq -0x1f8(%rbp), %rdi
callq 0x82f0
movq -0x1f8(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movq -0x100(%rbp), %rdi
callq 0x8dc0
movq %rax, -0x200(%rbp)
jmp 0x5818
movq -0x200(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x210(%rbp)
leaq -0x151(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0xccd0
movq -0x208(%rbp), %rdx
leaq 0x1b90e(%rip), %rsi     # 0x21163
leaq -0x150(%rbp), %rdi
callq 0x5a60
jmp 0x5863
movq -0x210(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x8b80
jmp 0x5878
leaq -0x150(%rbp), %rdi
callq 0xd9f0
leaq -0x151(%rbp), %rdi
callq 0xccf0
movq -0x100(%rbp), %rax
movq %rax, -0x218(%rbp)
cmpq $0x0, %rax
je 0x58c1
movq -0x218(%rbp), %rdi
callq 0x82f0
movq -0x218(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movq -0x130(%rbp), %rax
movq %rax, -0x220(%rbp)
cmpq $0x0, %rax
je 0x58f2
movq -0x220(%rbp), %rdi
callq 0x82f0
movq -0x220(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movl $0x0, -0x64(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xd9f0
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x5931
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xd9f0
leaq -0x91(%rbp), %rdi
callq 0xccf0
jmp 0x5a13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x5968
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xd9f0
leaq -0xc1(%rbp), %rdi
callq 0xccf0
jmp 0x5a13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x599f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0xd9f0
leaq -0xf1(%rbp), %rdi
callq 0xccf0
jmp 0x5a13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x59d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x120(%rbp), %rdi
callq 0xd9f0
leaq -0x121(%rbp), %rdi
callq 0xccf0
jmp 0x5a13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x5a07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x150(%rbp), %rdi
callq 0xd9f0
leaq -0x151(%rbp), %rdi
callq 0xccf0
leaq -0x20(%rbp), %rdi
callq 0xd9f0
movq -0x30(%rbp), %rdi
callq 0x4300
nopw %cs:(%rax,%rax)