// File: /workspace/github_cpp_makefile_star2_O2/cannam[P]mini-cpp-convnet/flower.cpp
// Function: maxPool(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&, unsigned long, unsigned long)
vector<vector<vector<float>>>
maxPool(const vector<vector<vector<float>>> &in,
        size_t pool_y,
        size_t pool_x)
{
    size_t out_height = in.size() / pool_y;
    if (out_height < 1) {
        throw runtime_error("Input too small in maxPool");
    }

    size_t out_width = in[0].size() / pool_x;
    if (out_width < 1) {
        throw runtime_error("Input too small in maxPool");
    }
    
    size_t depth = in[0][0].size();
    
#ifdef VERBOSE
    cerr << "maxPool: input size " << in[0].size() << "x" << in.size()
         << "; pool size " << pool_x << "x" << pool_y << "; output size "
         << out_width << "x" << out_height << " and depth " << depth << endl;
#endif
    
    auto out =
        vector<vector<vector<float>>>
        (out_height,
         vector<vector<float>>
         (out_width,
          vector<float>
          (depth,
           -INFINITY)));

    for (size_t y = 0; y < out_height; ++y) {
        for (size_t x = 0; x < out_width; ++x) {
            for (size_t i = 0; i < pool_y; ++i) {
                for (size_t j = 0; j < pool_x; ++j) {
                    for (size_t c = 0; c < depth; ++c) {
                        float value = in[y * pool_y + i][x * pool_x + j][c];
                        out[y][x][c] = max(out[y][x][c], value);
                    }
                }
            }
        }
    }

    return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, %rbx
movq %rdx, %r8
movq %rsi, %r12
movq %rdi, %r15
movq (%rsi), %rdi
movq 0x8(%rsi), %rax
subq %rdi, %rax
pushq $0x18
popq %rsi
cqto
idivq %rsi
movq %rax, %rcx
xorl %edx, %edx
divq %r8
movq %rax, 0x10(%rsp)
movq %r8, 0x20(%rsp)
cmpq %r8, %rcx
jb 0x1b526
movq (%rdi), %r8
movq 0x8(%rdi), %rax
subq %r8, %rax
cqto
idivq %rsi
movq %rax, %rcx
xorl %edx, %edx
divq %rbx
movq %rax, 0x18(%rsp)
cmpq %rbx, %rcx
jb 0x1b542
movq 0x8(%r8), %r13
subq (%r8), %r13
sarq $0x2, %r13
leaq 0x44(%rsp), %rdx
movl $0xff800000, (%rdx)     # imm = 0xFF800000
leaq 0x48(%rsp), %rdi
leaq 0xf(%rsp), %rcx
movq %r13, %rsi
callq 0x1ca80
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rdx
leaq 0xe(%rsp), %rcx
movq 0x18(%rsp), %rsi
callq 0x1cad6
leaq 0x60(%rsp), %rdx
leaq 0xd(%rsp), %rcx
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0x1cb2c
leaq 0x60(%rsp), %rdi
callq 0x1cb82
leaq 0x48(%rsp), %rdi
callq 0x1cef2
xorl %edx, %edx
cmpq 0x10(%rsp), %rdx
jae 0x1b514
movq %rdx, %rax
imulq 0x20(%rsp), %rax
imulq $0x18, %rax, %rcx
movq %rdx, 0x28(%rsp)
imulq $0x18, %rdx, %rdx
xorl %esi, %esi
cmpq 0x18(%rsp), %rsi
jae 0x1b507
movq %rsi, %rax
imulq %rbx, %rax
imulq $0x18, %rax, %rdi
movq %rsi, 0x30(%rsp)
imulq $0x18, %rsi, %r8
xorl %eax, %eax
cmpq 0x20(%rsp), %rax
je 0x1b4fa
movq %rax, 0x38(%rsp)
imulq $0x18, %rax, %r10
xorl %r11d, %r11d
cmpq %rbx, %r11
je 0x1b4f0
movq (%r12), %rax
addq %rcx, %rax
addq %r10, %rax
movq (%r15), %rbp
addq %rdx, %rbp
imulq $0x18, %r11, %rsi
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x1b4eb
movq (%rax), %r9
addq %rdi, %r9
movq (%rsi,%r9), %r9
movss (%r9,%r14,4), %xmm0
movq (%rbp), %r9
movq (%r9,%r8), %r9
maxss (%r9,%r14,4), %xmm0
movss %xmm0, (%r9,%r14,4)
incq %r14
jmp 0x1b4bd
incq %r11
jmp 0x1b4a1
movq 0x38(%rsp), %rax
incq %rax
jmp 0x1b48e
movq 0x30(%rsp), %rsi
incq %rsi
jmp 0x1b46d
movq 0x28(%rsp), %rdx
incq %rdx
jmp 0x1b44a
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x3b63(%rip), %rsi      # 0x1f09b
movq %rax, %rdi
callq 0x2090
jmp 0x1b55c
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x3b47(%rip), %rsi      # 0x1f09b
movq %rax, %rdi
callq 0x2090
movq 0x96a8d(%rip), %rsi     # 0xb1ff0
movq 0x96a46(%rip), %rdx     # 0xb1fb0
movq %r14, %rdi
callq 0x22c0
jmp 0x1b574
movq %rax, %rbx
movq %r14, %rdi
callq 0x2160
jmp 0x1b5a2
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x1cb82
jmp 0x1b593
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x1cef2
jmp 0x1b5a2
movq %rax, %rbx
movq %rbx, %rdi
callq 0x22d0