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

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

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

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

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

    auto x32 = x16->Downsample();
    x32->WriteBmp("images/large_down_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 0x1c28b(%rip), %rsi     # 0x21004
leaq -0x20(%rbp), %rdi
callq 0x5a60
jmp 0x4d84
leaq -0x21(%rbp), %rdi
callq 0xccf0
movl $0x20, %edi
callq 0xcb50
movq %rax, -0x168(%rbp)
jmp 0x4da0
movq -0x168(%rbp), %rdi
callq 0x81f0
jmp 0x4dae
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 0x4dd3
movq -0x170(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x8340
movb %al, -0x171(%rbp)
jmp 0x4deb
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 0x4e11
jmp 0x4e94
leaq 0x1c1fd(%rip), %rdi     # 0x21015
xorl %eax, %eax
callq 0x4050
jmp 0x4e21
movl $0x1, -0x64(%rbp)
jmp 0x5289
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x21(%rbp), %rdi
callq 0xccf0
jmp 0x53ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x53a3
movq -0x168(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x20, %esi
callq 0xbca0
jmp 0x53a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd9f0
jmp 0x53a3
movq -0x40(%rbp), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
leaq 0x1c192(%rip), %rdi     # 0x21036
xorl %eax, %eax
callq 0x4050
jmp 0x4ead
movq -0x40(%rbp), %rdi
callq 0x96d0
movq %rax, -0x180(%rbp)
jmp 0x4ebf
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 0x1c162(%rip), %rsi     # 0x21058
leaq -0x90(%rbp), %rdi
callq 0x5a60
jmp 0x4f04
movq -0x190(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x8b80
jmp 0x4f19
leaq -0x90(%rbp), %rdi
callq 0xd9f0
leaq -0x91(%rbp), %rdi
callq 0xccf0
movq -0x40(%rbp), %rax
movq %rax, -0x198(%rbp)
cmpq $0x0, %rax
je 0x4f5f
movq -0x198(%rbp), %rdi
callq 0x82f0
movq -0x198(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movq -0x70(%rbp), %rdi
callq 0x96d0
movq %rax, -0x1a0(%rbp)
jmp 0x4f71
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 0x1c0c3(%rip), %rsi     # 0x21071
leaq -0xc0(%rbp), %rdi
callq 0x5a60
jmp 0x4fbc
movq -0x1b0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x8b80
jmp 0x4fd1
leaq -0xc0(%rbp), %rdi
callq 0xd9f0
leaq -0xc1(%rbp), %rdi
callq 0xccf0
movq -0x70(%rbp), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, %rax
je 0x5017
movq -0x1b8(%rbp), %rdi
callq 0x82f0
movq -0x1b8(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movq -0xa0(%rbp), %rdi
callq 0x96d0
movq %rax, -0x1c0(%rbp)
jmp 0x502c
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 0x1c021(%rip), %rsi     # 0x2108a
leaq -0xf0(%rbp), %rdi
callq 0x5a60
jmp 0x5077
movq -0x1d0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x8b80
jmp 0x508c
leaq -0xf0(%rbp), %rdi
callq 0xd9f0
leaq -0xf1(%rbp), %rdi
callq 0xccf0
movq -0xa0(%rbp), %rax
movq %rax, -0x1d8(%rbp)
cmpq $0x0, %rax
je 0x50d5
movq -0x1d8(%rbp), %rdi
callq 0x82f0
movq -0x1d8(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movq -0xd0(%rbp), %rdi
callq 0x96d0
movq %rax, -0x1e0(%rbp)
jmp 0x50ea
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 0x1bf7c(%rip), %rsi     # 0x210a3
leaq -0x120(%rbp), %rdi
callq 0x5a60
jmp 0x5135
movq -0x1f0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x8b80
jmp 0x514a
leaq -0x120(%rbp), %rdi
callq 0xd9f0
leaq -0x121(%rbp), %rdi
callq 0xccf0
movq -0xd0(%rbp), %rax
movq %rax, -0x1f8(%rbp)
cmpq $0x0, %rax
je 0x5193
movq -0x1f8(%rbp), %rdi
callq 0x82f0
movq -0x1f8(%rbp), %rdi
movl $0x20, %esi
callq 0xbca0
movq -0x100(%rbp), %rdi
callq 0x96d0
movq %rax, -0x200(%rbp)
jmp 0x51a8
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 0x1bed8(%rip), %rsi     # 0x210bd
leaq -0x150(%rbp), %rdi
callq 0x5a60
jmp 0x51f3
movq -0x210(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x8b80
jmp 0x5208
leaq -0x150(%rbp), %rdi
callq 0xd9f0
leaq -0x151(%rbp), %rdi
callq 0xccf0
movq -0x100(%rbp), %rax
movq %rax, -0x218(%rbp)
cmpq $0x0, %rax
je 0x5251
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 0x5282
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 0x52c1
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 0x53a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x52f8
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 0x53a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x532f
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 0x53a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x5363
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 0x53a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x5397
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)