// File: /workspace/github_cpp_makefile_star2_O3/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 0x1e257
movq 0x8(%r14), %rsi
leaq 0x58(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1e9ae
leaq 0x28(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1da17
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1defa
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 0x1e336
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0xc00, %rcx            # imm = 0xC00
jne 0x1e336
callq 0x2040
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1cfcb
callq 0x2040
movq %rax, %r14
movq 0x9309a(%rip), %rdi     # 0xb0fe8
leaq 0x22de(%rip), %rsi      # 0x20233
movl $0x14, %edx
callq 0x2200
subq %rbx, %r14
cvtsi2sd %r14, %xmm0
divsd 0x20e9(%rip), %xmm0     # 0x20058
movq 0x93072(%rip), %rdi     # 0xb0fe8
callq 0x2260
movq %rax, %rbx
leaq 0x22c3(%rip), %rsi      # 0x20248
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 0x2281(%rip), %rsi      # 0x2024d
leaq 0x227f(%rip), %rdx      # 0x20252
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x1ef00
leaq 0x98(%rsp), %r15
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2258(%rip), %rsi      # 0x20253
leaq 0x225a(%rip), %rdx      # 0x2025c
movq %r15, %rdi
callq 0x1ef00
leaq 0xb8(%rsp), %r15
leaq 0xc8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2238(%rip), %rsi      # 0x2025d
leaq 0x2236(%rip), %rdx      # 0x20262
movq %r15, %rdi
callq 0x1ef00
leaq 0xd8(%rsp), %r15
leaq 0xe8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2214(%rip), %rsi      # 0x20263
leaq 0x2217(%rip), %rdx      # 0x2026d
movq %r15, %rdi
callq 0x1ef00
leaq 0xf8(%rsp), %r15
leaq 0x108(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x21f5(%rip), %rsi      # 0x2026e
leaq 0x21f4(%rip), %rdx      # 0x20274
movq %r15, %rdi
callq 0x1ef00
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0xc(%rsp), %rcx
movl $0x5, %edx
callq 0x1ea4c
movq $-0xa0, %r14
movq -0x10(%rbx), %rdi
cmpq %rdi, %rbx
je 0x1e0bc
movq (%rbx), %rsi
incq %rsi
callq 0x21e0
addq $-0x20, %rbx
addq $0x20, %r14
jne 0x1e0a8
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 0x1e21b
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 0x1e2ff
movss (%rax,%r13,4), %xmm0
mulss 0x1f25(%rip), %xmm0     # 0x20054
movss %xmm0, 0xc(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1ea94
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 0x1e107
movq 0x90(%rsp), %rbx
cmpq %rbp, %rbx
je 0x1e21b
movq 0x92e3d(%rip), %r14     # 0xb0fc0
leaq 0x2052(%rip), %r15      # 0x201dc
leaq 0x2100(%rip), %r12      # 0x20291
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 0x1e70(%rip), %xmm0     # 0x20030
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 0x1e191
leaq 0x78(%rsp), %rdi
callq 0x1eb68
leaq 0x40(%rsp), %rdi
callq 0x1eafe
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1e246
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
leaq 0x28(%rsp), %rdi
callq 0x1e7c4
xorl %eax, %eax
jmp 0x1e2ed
movq 0x92d8a(%rip), %rbx     # 0xb0fe8
leaq 0x1f72(%rip), %rsi      # 0x201d7
movl $0x7, %edx
movq %rbx, %rdi
callq 0x2200
movq (%r14), %r14
testq %r14, %r14
je 0x1e296
movq %r14, %rdi
callq 0x20d0
movq 0x92d5f(%rip), %rdi     # 0xb0fe8
movq %r14, %rsi
movq %rax, %rdx
callq 0x2200
jmp 0x1e2ad
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x22b0
leaq 0x1f2b(%rip), %rsi      # 0x201df
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 0x1f62(%rip), %rsi      # 0x20275
movq %rax, %rdi
callq 0x2220
movq 0x92cae(%rip), %rsi     # 0xb0fd0
movq 0x92c8f(%rip), %rdx     # 0xb0fb8
movq %r14, %rdi
callq 0x22c0
jmp 0x1e3d4
movq 0x92cab(%rip), %rdi     # 0xb0fe8
leaq 0x1eab(%rip), %rsi      # 0x201ef
movl $0x26, %edx
callq 0x2200
movq 0x92c93(%rip), %rdi     # 0xb0fe8
movl $0x80, %esi
callq 0x2140
movq %rax, %rbx
leaq 0x1e34(%rip), %rsi      # 0x2019d
movl $0x1, %edx
movq %rax, %rdi
callq 0x2200
movl $0x80, %esi
movq %rbx, %rdi
callq 0x2140
movq %rax, %rbx
leaq 0x1e89(%rip), %rsi      # 0x20216
movl $0x7, %edx
movq %rax, %rdi
callq 0x2200
movq %rbx, %rdi
callq 0x20e0
movl $0x10, %edi
callq 0x20f0
movq %rax, %r14
leaq 0x1e68(%rip), %rsi      # 0x2021e
movq %rax, %rdi
callq 0x20b0
movq 0x92c2b(%rip), %rsi     # 0xb0ff0
movq 0x92be4(%rip), %rdx     # 0xb0fb0
movq %r14, %rdi
callq 0x22c0
movq %rax, %rbx
movq %r14, %rdi
callq 0x2180
jmp 0x1e4a3
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x2310
jmp 0x1e48c
jmp 0x1e404
jmp 0x1e404
jmp 0x1e404
movq %rax, %rbx
addq $-0x10, %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x1e41f
movq (%r15), %rsi
incq %rsi
callq 0x21e0
leaq -0x20(%r15), %rax
addq $-0x10, %r15
cmpq %r14, %r15
movq %rax, %r15
jne 0x1e40b
jmp 0x1e48c
jmp 0x1e45f
jmp 0x1e45a
movq %rax, %rbx
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1e4ad
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21e0
jmp 0x1e4ad
movq %rax, %rbx
jmp 0x1e4ad
movq %rax, %rbx
jmp 0x1e4a3
movq %rax, %rbx
jmp 0x1e48c
jmp 0x1e475
movq %rax, %rbx
movq %r14, %rdi
callq 0x2180
jmp 0x1e478
jmp 0x1e475
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x1eb68
leaq 0x40(%rsp), %rdi
callq 0x1eafe
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1e4a3
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21e0
leaq 0x28(%rsp), %rdi
callq 0x1e7c4
movq %rbx, %rdi
callq 0x22d0
nop