// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
cmpl $0x2, %edi
jne 0x1c82b
movq 0x8(%rbx), %rsi
leaq 0x58(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1cd10
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x1c2ef
leaq 0x58(%rsp), %rdi
callq 0x20c0
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
cmpq $0xc00, %rcx            # imm = 0xC00
jne 0x1c948
movq 0x8(%rax), %rcx
subq (%rax), %rcx
cmpq $0xc00, %rcx            # imm = 0xC00
jne 0x1c948
callq 0x2030
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1bd60
callq 0x2030
movq %rax, %r14
movq 0x9594b(%rip), %rdi     # 0xb1fe8
leaq 0x2b67(%rip), %rsi      # 0x1f20b
callq 0x21c0
subq %rbx, %r14
cvtsi2sd %r14, %xmm0
divsd 0x2977(%rip), %xmm0     # 0x1f030
movq %rax, %rdi
callq 0x2270
leaq 0x2b58(%rip), %rsi      # 0x1f220
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x20d0
leaq 0x2b46(%rip), %rsi      # 0x1f225
leaq 0x78(%rsp), %r14
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
callq 0x1cd10
leaq 0x98(%rsp), %r15
leaq 0x2b2b(%rip), %rsi      # 0x1f22b
leaq 0xb(%rsp), %rdx
movq %r15, %rdi
callq 0x1cd10
leaq 0xb8(%rsp), %r15
leaq 0x2b19(%rip), %rsi      # 0x1f235
leaq 0xa(%rsp), %rdx
movq %r15, %rdi
callq 0x1cd10
leaq 0xd8(%rsp), %r15
leaq 0x2b03(%rip), %rsi      # 0x1f23b
leaq 0x9(%rsp), %rdx
movq %r15, %rdi
callq 0x1cd10
leaq 0xf8(%rsp), %r15
leaq 0x2af2(%rip), %rsi      # 0x1f246
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x1cd10
leaq 0x28(%rsp), %rdi
leaq 0x78(%rsp), %rsi
pushq $0x5
popq %rdx
leaq 0x7(%rsp), %rcx
callq 0x1cdaa
movl $0x80, %ebx
leaq (%rsp,%rbx), %rdi
addq $0x78, %rdi
callq 0x20c0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x1c77d
leaq 0x80(%rsp), %r13
andl $0x0, (%r13)
andq $0x0, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
andq $0x0, 0x20(%r13)
xorl %r12d, %r12d
leaq 0x78(%rsp), %rbx
leaq 0xc(%rsp), %r14
xorl %ebp, %ebp
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %rbp
jae 0x1c868
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %rcx
subq %r15, %rcx
sarq $0x5, %rcx
cmpq %rcx, %rbp
jae 0x1c913
movss (%rax,%rbp,4), %xmm0
mulss 0x2805(%rip), %xmm0     # 0x1f008
movss %xmm0, 0xc(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1cde4
addq %r12, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x2110
incq %rbp
addq $0x20, %r12
jmp 0x1c7c2
movq 0x957b6(%rip), %rdi     # 0xb1fe8
leaq 0x2976(%rip), %rsi      # 0x1f1af
callq 0x21c0
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x21c0
leaq 0x2967(%rip), %rsi      # 0x1f1b7
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x20d0
pushq $0x2
popq %rax
jmp 0x1c901
movq 0x90(%rsp), %r15
movq 0x95749(%rip), %rbx     # 0xb1fc0
leaq 0x2936(%rip), %r14      # 0x1f1b4
leaq 0x29e4(%rip), %r12      # 0x1f269
cmpq %r13, %r15
je 0x1c8d7
leaq 0x28(%r15), %rsi
movq %rbx, %rdi
callq 0x21b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21c0
movss 0x20(%r15), %xmm0
xorpd 0x2771(%rip), %xmm0     # 0x1f020
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
movq %r12, %rsi
callq 0x21c0
movq %rax, %rdi
callq 0x20d0
movq %r15, %rdi
callq 0x2140
movq %rax, %r15
jmp 0x1c885
leaq 0x78(%rsp), %rdi
callq 0x1ce62
leaq 0x28(%rsp), %rdi
callq 0x1ce36
leaq 0x40(%rsp), %rdi
callq 0x1cef2
leaq 0x10(%rsp), %rdi
callq 0x1cba4
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x2928(%rip), %rsi      # 0x1f24d
movq %rax, %rdi
callq 0x2230
movq 0x9569c(%rip), %rsi     # 0xb1fd0
movq 0x9567d(%rip), %rdx     # 0xb1fb8
movq %r14, %rdi
callq 0x22c0
jmp 0x1c9cb
movq 0x95699(%rip), %rdi     # 0xb1fe8
leaq 0x2871(%rip), %rsi      # 0x1f1c7
callq 0x21c0
movl $0x80, %esi
movq %rax, %rdi
callq 0x2130
leaq 0x2806(%rip), %rsi      # 0x1f175
movq %rax, %rdi
callq 0x21c0
movl $0x80, %esi
movq %rax, %rdi
callq 0x2130
leaq 0x2863(%rip), %rsi      # 0x1f1ee
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x20d0
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x2849(%rip), %rsi      # 0x1f1f6
movq %rax, %rdi
callq 0x2090
movq 0x95634(%rip), %rsi     # 0xb1ff0
movq 0x955ed(%rip), %rdx     # 0xb1fb0
movq %r14, %rdi
callq 0x22c0
movq %rax, %rbx
movq %r14, %rdi
callq 0x2160
jmp 0x1ca6d
movq %rax, %rbx
movl $0x80, %r14d
leaq (%rsp,%r14), %rdi
addq $0x78, %rdi
callq 0x20c0
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x1c9e4
jmp 0x1ca63
jmp 0x1ca03
jmp 0x1ca03
jmp 0x1ca03
movq %rax, %rbx
addq $-0x20, %r15
movq %r15, %rdi
callq 0x20c0
cmpq %r14, %r15
jne 0x1ca06
jmp 0x1ca63
jmp 0x1ca36
jmp 0x1ca31
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x20c0
jmp 0x1ca77
movq %rax, %rbx
jmp 0x1ca77
movq %rax, %rbx
jmp 0x1ca6d
movq %rax, %rbx
jmp 0x1ca63
jmp 0x1ca4c
movq %rax, %rbx
movq %r14, %rdi
callq 0x2160
jmp 0x1ca4f
jmp 0x1ca4c
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x1ce62
leaq 0x28(%rsp), %rdi
callq 0x1ce36
leaq 0x40(%rsp), %rdi
callq 0x1cef2
leaq 0x10(%rsp), %rdi
callq 0x1cba4
movq %rbx, %rdi
callq 0x22d0
nop