// File: /workspace/github_cpp_makefile_star2_O1/cannam[P]mini-cpp-convnet/flower.cpp
// Function: main
int main(int argc, char **argv)
{
    if (argc != 2) {
        cerr << "Usage: " << argv[0] << " <filename.png>" << endl;
        return 2;
    }

    auto image = read_image(argv[1]);

    size_t expected_width = 128;
    size_t expected_height = 128;

    if (image.size() != expected_height ||
        image[0].size() != expected_width) {
        cerr << "Image has wrong size: must be exactly " << expected_width
             << "x" << expected_height << " pixels" << endl;
        throw runtime_error("Image has wrong size");
    }

    auto before = chrono::high_resolution_clock::now();
    
    auto result = classify(image);

    auto after = chrono::high_resolution_clock::now();

    chrono::duration<double> diff = after - before;
    
    cerr << "Classification took " << diff.count() << " sec" << endl;

    vector<string> labels {
        "daisy", "dandelion", "roses", "sunflowers", "tulips"
    };

    map<float, string> ranking;
    
    for (size_t i = 0; i < result.size(); ++i) {
        if (i >= labels.size()) {
            throw logic_error("Too many result categories!");
        }
        ranking[- result[i] * 100.0] = labels[i];
    }

    for (auto r = ranking.begin(); r != ranking.end(); ++r) {
        cout << r->second << ": " << -r->first << "%" << endl;
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r14
cmpl $0x2, %edi
jne 0x1e85a
movq 0x8(%r14), %rsi
leaq 0x58(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1eeb8
leaq 0x28(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1e046
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1e501
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21e0
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
subq %rax, %rcx
cmpq $0xc00, %rcx            # imm = 0xC00
jne 0x1e939
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0xc00, %rcx            # imm = 0xC00
jne 0x1e939
callq 0x2040
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1d646
callq 0x2040
movq %rax, %r14
movq 0x93a93(%rip), %rdi     # 0xb1fe8
leaq 0x2caf(%rip), %rsi      # 0x2120b
movl $0x14, %edx
callq 0x2200
subq %rbx, %r14
cvtsi2sd %r14, %xmm0
divsd 0x2aba(%rip), %xmm0     # 0x21030
movq 0x93a6b(%rip), %rdi     # 0xb1fe8
callq 0x2260
movq %rax, %rbx
leaq 0x2c94(%rip), %rsi      # 0x21220
movl $0x4, %edx
movq %rax, %rdi
callq 0x2200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2c52(%rip), %rsi      # 0x21225
leaq 0x2c50(%rip), %rdx      # 0x2122a
leaq 0x78(%rsp), %r15
movq %r15, %rdi
callq 0x1f404
leaq 0x98(%rsp), %r14
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2c29(%rip), %rsi      # 0x2122b
leaq 0x2c2b(%rip), %rdx      # 0x21234
movq %r14, %rdi
callq 0x1f404
leaq 0xb8(%rsp), %r14
leaq 0xc8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2c09(%rip), %rsi      # 0x21235
leaq 0x2c07(%rip), %rdx      # 0x2123a
movq %r14, %rdi
callq 0x1f404
leaq 0xd8(%rsp), %r14
leaq 0xe8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2be5(%rip), %rsi      # 0x2123b
leaq 0x2be8(%rip), %rdx      # 0x21245
movq %r14, %rdi
callq 0x1f404
leaq 0xf8(%rsp), %r14
leaq 0x108(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x2bc6(%rip), %rsi      # 0x21246
leaq 0x2bc5(%rip), %rdx      # 0x2124c
movq %r14, %rdi
callq 0x1f404
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0xc(%rsp), %rcx
movl $0x5, %edx
callq 0x1ef56
movq $-0xa0, %r14
movq -0x10(%rbx), %rdi
cmpq %rdi, %rbx
je 0x1e6c3
movq (%rbx), %rsi
incq %rsi
callq 0x21e0
addq $-0x20, %rbx
addq $0x20, %r14
jne 0x1e6af
leaq 0x80(%rsp), %rbp
movl $0x0, (%rbp)
xorl %eax, %eax
movq %rax, 0x8(%rbp)
movq %rbp, 0x10(%rbp)
movq %rbp, 0x18(%rbp)
movq %rax, 0x20(%rbp)
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x1e76e
xorl %r12d, %r12d
leaq 0x78(%rsp), %rbx
leaq 0xc(%rsp), %r14
xorl %r13d, %r13d
movq 0x40(%rsp), %r15
movq 0x48(%rsp), %rcx
subq %r15, %rcx
sarq $0x5, %rcx
cmpq %rcx, %r13
jae 0x1e902
movss (%rax,%r13,4), %xmm0
mulss 0x28da(%rip), %xmm0     # 0x2100c
movss %xmm0, 0xc(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1ef9e
addq %r12, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x2120
incq %r13
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
addq $0x20, %r12
cmpq %rcx, %r13
jb 0x1e70a
movq 0x90(%rsp), %rbx
cmpq %rbp, %rbx
je 0x1e81e
movq 0x9383a(%rip), %r14     # 0xb1fc0
leaq 0x2a27(%rip), %r15      # 0x211b4
leaq 0x2ad5(%rip), %r12      # 0x21269
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rdx
movq %r14, %rdi
callq 0x2200
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2200
movss 0x20(%rbx), %xmm0
xorps 0x285d(%rip), %xmm0     # 0x21020
cvtss2sd %xmm0, %xmm0
movq %r13, %rdi
callq 0x2260
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2200
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rbx, %rdi
callq 0x2160
movq %rax, %rbx
cmpq %rbp, %rax
jne 0x1e794
leaq 0x78(%rsp), %rdi
callq 0x1f06c
leaq 0x40(%rsp), %rdi
callq 0x1f006
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1e849
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
leaq 0x28(%rsp), %rdi
callq 0x1ecd4
xorl %eax, %eax
jmp 0x1e8f0
movq 0x93787(%rip), %rbx     # 0xb1fe8
leaq 0x2947(%rip), %rsi      # 0x211af
movl $0x7, %edx
movq %rbx, %rdi
callq 0x2200
movq (%r14), %r14
testq %r14, %r14
je 0x1e899
movq %r14, %rdi
callq 0x20d0
movq 0x9375c(%rip), %rdi     # 0xb1fe8
movq %r14, %rsi
movq %rax, %rdx
callq 0x2200
jmp 0x1e8b0
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x22b0
leaq 0x2900(%rip), %rsi      # 0x211b7
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movl $0x2, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x20f0
movq %rax, %r14
leaq 0x2937(%rip), %rsi      # 0x2124d
movq %rax, %rdi
callq 0x2220
movq 0x936ab(%rip), %rsi     # 0xb1fd0
movq 0x9368c(%rip), %rdx     # 0xb1fb8
movq %r14, %rdi
callq 0x22c0
jmp 0x1e9d7
movq 0x936a8(%rip), %rdi     # 0xb1fe8
leaq 0x2880(%rip), %rsi      # 0x211c7
movl $0x26, %edx
callq 0x2200
movq 0x93690(%rip), %rdi     # 0xb1fe8
movl $0x80, %esi
callq 0x2140
movq %rax, %rbx
leaq 0x2809(%rip), %rsi      # 0x21175
movl $0x1, %edx
movq %rax, %rdi
callq 0x2200
movl $0x80, %esi
movq %rbx, %rdi
callq 0x2140
movq %rax, %rbx
leaq 0x285e(%rip), %rsi      # 0x211ee
movl $0x7, %edx
movq %rax, %rdi
callq 0x2200
movq %rbx, %rdi
callq 0x20e0
movl $0x10, %edi
callq 0x20f0
movq %rax, %r14
leaq 0x283d(%rip), %rsi      # 0x211f6
movq %rax, %rdi
callq 0x20b0
movq 0x93628(%rip), %rsi     # 0xb1ff0
movq 0x935e1(%rip), %rdx     # 0xb1fb0
movq %r14, %rdi
callq 0x22c0
movq %rax, %rbx
movq %r14, %rdi
callq 0x2180
jmp 0x1eac2
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x2310
movb $0x1, %al
jmp 0x1ea15
jmp 0x1ea06
jmp 0x1ea06
jmp 0x1ea06
movq %rax, %rbx
xorl %eax, %eax
jmp 0x1ea15
movq %rax, %rbx
xorl %eax, %eax
movq %r15, %r14
cmpq %r14, %r15
sete %cl
orb %al, %cl
jne 0x1eaab
addq $-0x10, %r14
leaq 0x78(%rsp), %r15
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x1ea40
movq (%r14), %rsi
incq %rsi
callq 0x21e0
leaq -0x20(%r14), %rax
addq $-0x10, %r14
cmpq %r15, %r14
movq %rax, %r14
jne 0x1ea2c
jmp 0x1eaab
jmp 0x1ea79
movq %rax, %rbx
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1eacc
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21e0
jmp 0x1eacc
movq %rax, %rbx
jmp 0x1eacc
movq %rax, %rbx
jmp 0x1eac2
movq %rax, %rbx
jmp 0x1eaab
jmp 0x1ea94
movq %rax, %rbx
movq %r14, %rdi
callq 0x2180
jmp 0x1ea97
jmp 0x1ea94
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x1f06c
leaq 0x40(%rsp), %rdi
callq 0x1f006
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1eac2
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
leaq 0x28(%rsp), %rdi
callq 0x1ecd4
movq %rbx, %rdi
callq 0x22d0