// File: cannam[P]mini-cpp-convnet/flower.cpp
// Function: flatten(std::vector<std::vector<std::vector<float, std::allocator<float>>, std::allocator<std::vector<float, std::allocator<float>>>>, std::allocator<std::vector<std::vector<float, std::allocator<float>>, std::allocator<std::vector<float, std::allocator<float>>>>>> const&)
vector<float>
flatten(const vector<vector<vector<float>>> &in)
{
    size_t height = in.size();
    if (height < 1) {
        throw runtime_error("Input too small in flatten");
    }

    size_t width = in[0].size();
    if (width < 1) {
        throw runtime_error("Input too small in flatten");
    }
    
    size_t depth = in[0][0].size();

#ifdef VERBOSE
    cerr << "flatten: input size " << in[0].size() << "x" << in.size()
         << " and depth " << depth << ", output length "
         << width * height * depth << endl;
#endif
    
    vector<float> out(width * height * depth, 0.f);

    size_t i = 0;
    
    for (size_t y = 0; y < height; ++y) {
        for (size_t x = 0; x < width; ++x) {
            for (size_t c = 0; c < depth; ++c) {
                out[i++] = in[y][x][c];
            }
        }
    }

    return out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x78(%rbp)
movq %rdi, %rax
movq %rax, -0x70(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4a740
movq %rax, -0x18(%rbp)
cmpq $0x1, -0x18(%rbp)
jae 0x48245
movl $0x10, %edi
callq 0x3120
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x80(%rbp)
leaq 0xaebc(%rip), %rsi      # 0x530c9
callq 0x30d0
jmp 0x48214
movq -0x80(%rbp), %rdi
movq 0xa0dd1(%rip), %rsi     # 0xe8ff0
movq 0xa0d8a(%rip), %rdx     # 0xe8fb0
callq 0x3390
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x31d0
jmp 0x48452
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4a770
movq %rax, %rdi
callq 0x4a7d0
movq %rax, -0x30(%rbp)
cmpq $0x1, -0x30(%rbp)
jae 0x482c1
movl $0x10, %edi
callq 0x3120
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x88(%rbp)
leaq 0xae46(%rip), %rsi      # 0x530c9
callq 0x30d0
jmp 0x4828a
movq -0x88(%rbp), %rdi
movq 0xa0d58(%rip), %rsi     # 0xe8ff0
movq 0xa0d11(%rip), %rdx     # 0xe8fb0
callq 0x3390
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
callq 0x31d0
jmp 0x48452
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0xa0(%rbp)
callq 0x4a770
movq -0xa0(%rbp), %rsi
movq %rax, %rdi
callq 0x4a790
movq %rax, %rdi
callq 0x4a7b0
movq %rax, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
imulq %rcx, %rax
movq -0x38(%rbp), %rcx
imulq %rcx, %rax
movq %rax, -0x98(%rbp)
movl $0x0, -0x40(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x4a800
movq -0x78(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rcx
leaq -0x40(%rbp), %rdx
callq 0x4a820
jmp 0x48343
leaq -0x41(%rbp), %rdi
callq 0x4aae0
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x48432
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x4841f
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x4840c
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x4a770
movq %rax, %rdi
movq -0x60(%rbp), %rsi
callq 0x4a790
movq %rax, %rdi
movq -0x68(%rbp), %rsi
callq 0x4ab00
movq -0x78(%rbp), %rdi
movss (%rax), %xmm0
movss %xmm0, -0xa4(%rbp)
movq -0x50(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
callq 0x4ab60
movss -0xa4(%rbp), %xmm0
movss %xmm0, (%rax)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x48388
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x4aae0
jmp 0x48452
jmp 0x4840e
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x48372
jmp 0x48421
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x4835c
movb $0x1, -0x39(%rbp)
testb $0x1, -0x39(%rbp)
jne 0x48445
movq -0x78(%rbp), %rdi
callq 0x4aa80
movq -0x70(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x33b0
nopl (%rax,%rax)