// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/maxpool_layer.c
// Function: forward_maxpool_layer
void forward_maxpool_layer(const maxpool_layer l, network net)
{
    int b,i,j,k,m,n;
    int w_offset = -l.pad/2;
    int h_offset = -l.pad/2;

    int h = l.out_h;
    int w = l.out_w;
    int c = l.c;

    for(b = 0; b < l.batch; ++b){
        for(k = 0; k < c; ++k){
            for(i = 0; i < h; ++i){
                for(j = 0; j < w; ++j){
                    int out_index = j + w*(i + h*(k + c*b));
                    float max = -FLT_MAX;
                    int max_i = -1;
                    for(n = 0; n < l.size; ++n){
                        for(m = 0; m < l.size; ++m){
                            int cur_h = h_offset + i*l.stride + n;
                            int cur_w = w_offset + j*l.stride + m;
                            int index = cur_w + l.w*(cur_h + l.h*(k + b*l.c));
                            int valid = (cur_h >= 0 && cur_h < l.h &&
                                         cur_w >= 0 && cur_w < l.w);
                            float val = (valid != 0) ? net.input[index] : -FLT_MAX;
                            max_i = (val > max) ? index : max_i;
                            max   = (val > max) ? val   : max;
                        }
                    }
                    l.output[out_index] = max;
                    l.indexes[out_index] = max_i;
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl 0x108(%rsp), %eax
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
cltd
idivl %ecx
movl %eax, %ecx
movslq 0xd8(%rsp), %rax
movslq 0xdc(%rsp), %rdx
movslq 0xd4(%rsp), %rsi
movl 0xf0(%rsp), %edi
movl 0xd0(%rsp), %r8d
xorl %r9d, %r9d
testl %edi, %edi
movl $0x0, %r10d
movq %rdi, 0x20(%rsp)
cmovgl %edi, %r10d
testl %edx, %edx
movl $0x0, %edi
movq %rdx, -0x38(%rsp)
cmovgl %edx, %edi
movq %rdi, 0x10(%rsp)
testl %eax, %eax
movl $0x0, %edx
movq %rax, -0x50(%rsp)
cmovgl %eax, %edx
movq %rdx, -0x18(%rsp)
testl %esi, %esi
movl $0x0, %eax
cmovgl %esi, %eax
movq %rax, -0x40(%rsp)
movl 0xa8(%rsp), %eax
testl %eax, %eax
cmovlel %r9d, %eax
movq %rax, -0x58(%rsp)
movl 0xcc(%rsp), %ebp
leal 0x1(%r8), %edx
movq %rcx, %rax
imull %ecx, %edx
movl %edx, -0x7c(%rsp)
movl %ebp, %ecx
imull %r8d, %ecx
movl %ecx, -0x70(%rsp)
movq %rsi, -0x60(%rsp)
imull %esi, %ecx
movl %ecx, -0x74(%rsp)
movl 0xf8(%rsp), %ecx
movl %ecx, -0x78(%rsp)
imull %r8d, %ecx
movl %ecx, -0x6c(%rsp)
movss 0x333b5(%rip), %xmm0    # 0x4f740
movq 0x5d8(%rsp), %r12
movq 0x2c8(%rsp), %rcx
movq %rcx, (%rsp)
movq 0x200(%rsp), %rcx
movq %rcx, -0x8(%rsp)
cmpq -0x58(%rsp), %r9
je 0x1c52b
movq %r9, %rcx
imulq -0x60(%rsp), %rcx
movq %rcx, -0x48(%rsp)
movl -0x7c(%rsp), %ecx
movl %ecx, -0x80(%rsp)
xorl %edx, %edx
movq %r9, -0x30(%rsp)
cmpq -0x40(%rsp), %rdx
je 0x1c51b
movq -0x48(%rsp), %rcx
addq %rdx, %rcx
imulq -0x50(%rsp), %rcx
movq %rcx, -0x28(%rsp)
movl -0x80(%rsp), %esi
xorl %edi, %edi
movq %rdx, -0x20(%rsp)
cmpq -0x18(%rsp), %rdi
je 0x1c507
movq -0x28(%rsp), %rcx
addq %rdi, %rcx
imulq -0x38(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movl -0x78(%rsp), %r15d
movq %rdi, -0x10(%rsp)
imull %edi, %r15d
movl %esi, -0x68(%rsp)
movl %esi, %ecx
movl %eax, %r13d
xorl %esi, %esi
cmpq 0x10(%rsp), %rsi
je 0x1c4e8
movq %rsi, 0x18(%rsp)
xorl %r11d, %r11d
movl %ecx, -0x64(%rsp)
movaps %xmm0, %xmm1
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpl %r10d, %r11d
je 0x1c4b2
leal (%r11,%rax), %esi
addl %r15d, %esi
movl %ecx, %edx
movl %r13d, %ebx
movq 0x20(%rsp), %rdi
subq $0x1, %rdi
jb 0x1c4aa
movaps %xmm0, %xmm2
testl %esi, %esi
js 0x1c496
movaps %xmm0, %xmm2
cmpl %ebp, %esi
jge 0x1c496
movaps %xmm0, %xmm2
testl %ebx, %ebx
js 0x1c496
movaps %xmm0, %xmm2
cmpl %r8d, %ebx
jge 0x1c496
movslq %edx, %r14
movss (%r12,%r14,4), %xmm2
ucomiss %xmm1, %xmm2
cmoval %edx, %r9d
maxss %xmm1, %xmm2
incl %ebx
incl %edx
movaps %xmm2, %xmm1
jmp 0x1c46a
incl %r11d
addl %r8d, %ecx
jmp 0x1c454
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %rsi
addq %rsi, %rcx
movq (%rsp), %rdx
movss %xmm1, (%rdx,%rcx,4)
movq -0x8(%rsp), %rdx
movl %r9d, (%rdx,%rcx,4)
incq %rsi
movl -0x78(%rsp), %ecx
addl %ecx, %r13d
movl -0x64(%rsp), %edx
addl %ecx, %edx
movl %edx, %ecx
jmp 0x1c434
movq -0x10(%rsp), %rdi
incq %rdi
movl -0x68(%rsp), %esi
addl -0x6c(%rsp), %esi
movq -0x30(%rsp), %r9
movq -0x20(%rsp), %rdx
jmp 0x1c3fd
incq %rdx
movl -0x80(%rsp), %ecx
addl -0x70(%rsp), %ecx
movl %ecx, -0x80(%rsp)
jmp 0x1c3d4
incq %r9
movl -0x74(%rsp), %ecx
addl %ecx, -0x7c(%rsp)
jmp 0x1c3ac
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq