// File: /workspace/github_c_makefile_star2_O1/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
movslq 0xa8(%rsp), %rax
movq %rax, -0x28(%rsp)
testq %rax, %rax
jle 0x293ee
leaq 0x500(%rsp), %rax
leaq 0x60(%rsp), %rdx
movl 0xa8(%rdx), %esi
movl %esi, %ecx
shrl $0x1f, %ecx
addl %esi, %ecx
sarl %ecx
negl %ecx
movslq 0x78(%rdx), %rsi
movq %rsi, -0x60(%rsp)
movslq 0x7c(%rdx), %rsi
movq %rsi, -0x48(%rsp)
movslq 0x74(%rdx), %rsi
movl 0x90(%rdx), %r8d
movl 0x98(%rdx), %edi
movl 0x6c(%rdx), %r10d
movl 0x70(%rdx), %r11d
movq 0xd8(%rax), %rbx
movq 0x268(%rdx), %rax
movq %rax, 0x10(%rsp)
movq 0x1a0(%rdx), %rax
movq %rax, 0x8(%rsp)
leal 0x1(%r11), %eax
imull %ecx, %eax
movq %rax, -0x40(%rsp)
movl %r10d, %eax
imull %r11d, %eax
movq %rax, -0x18(%rsp)
movq %rsi, -0x78(%rsp)
imull %esi, %eax
movq %rax, -0x30(%rsp)
movq %rdi, -0x38(%rsp)
imull %r11d, %edi
movq %rdi, (%rsp)
movss 0x2d500(%rip), %xmm0    # 0x56720
movl %ecx, %eax
movq %rax, -0x10(%rsp)
movq $0x0, -0x80(%rsp)
cmpl $0x0, -0x78(%rsp)
jle 0x293cc
movq -0x80(%rsp), %rax
imulq -0x78(%rsp), %rax
movq %rax, -0x20(%rsp)
movq -0x40(%rsp), %rax
movq %rax, -0x68(%rsp)
movq $0x0, -0x70(%rsp)
cmpl $0x0, -0x60(%rsp)
jle 0x293a5
movq -0x20(%rsp), %rax
movq -0x70(%rsp), %rdx
addq %rdx, %rax
imulq -0x60(%rsp), %rax
movq %rax, -0x8(%rsp)
movq -0x68(%rsp), %rax
movq %rax, -0x50(%rsp)
movq $0x0, -0x58(%rsp)
cmpl $0x0, -0x48(%rsp)
jle 0x2937f
movq -0x8(%rsp), %rax
movq -0x58(%rsp), %rdx
addq %rdx, %rax
imulq -0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
movl %edx, %r13d
imull -0x38(%rsp), %r13d
movq -0x50(%rsp), %r12
movq -0x10(%rsp), %rax
xorl %edx, %edx
testl %r8d, %r8d
movq %r12, 0x20(%rsp)
jle 0x2933d
xorl %r14d, %r14d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movaps %xmm0, %xmm1
leal (%r14,%rcx), %esi
addl %r13d, %esi
xorl %ebp, %ebp
movaps %xmm1, %xmm2
leaq (%r12,%rbp), %r9
movaps %xmm0, %xmm1
testl %esi, %esi
js 0x2931d
movaps %xmm0, %xmm1
cmpl %r10d, %esi
jge 0x2931d
leaq (%rax,%rbp), %r15
movaps %xmm0, %xmm1
testl %r15d, %r15d
js 0x2931d
movaps %xmm0, %xmm1
cmpl %r11d, %r15d
jge 0x2931d
movslq %r9d, %r15
movss (%rbx,%r15,4), %xmm1
ucomiss %xmm2, %xmm1
cmoval %r9d, %edi
maxss %xmm2, %xmm1
incq %rbp
cmpq %rbp, %r8
jne 0x292ea
incl %r14d
addq %r11, %r12
cmpl %r8d, %r14d
jne 0x292e1
jmp 0x29345
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movaps %xmm0, %xmm1
movq 0x18(%rsp), %rsi
addq %rdx, %rsi
movq 0x10(%rsp), %r9
movss %xmm1, (%r9,%rsi,4)
movq 0x8(%rsp), %r9
movl %edi, (%r9,%rsi,4)
incq %rdx
movq -0x38(%rsp), %rsi
addq %rsi, %rax
movq 0x20(%rsp), %r12
addq %rsi, %r12
cmpq -0x48(%rsp), %rdx
jne 0x292cc
movq -0x58(%rsp), %rdx
incq %rdx
movq -0x50(%rsp), %rax
addq (%rsp), %rax
movq %rax, -0x50(%rsp)
movq %rdx, -0x58(%rsp)
cmpq -0x60(%rsp), %rdx
jne 0x29294
movq -0x70(%rsp), %rdx
incq %rdx
movq -0x68(%rsp), %rax
addq -0x18(%rsp), %rax
movq %rax, -0x68(%rsp)
movq %rdx, -0x70(%rsp)
cmpq -0x78(%rsp), %rdx
jne 0x2925e
movq -0x80(%rsp), %rdx
incq %rdx
movq -0x30(%rsp), %rax
addq %rax, -0x40(%rsp)
movq %rdx, -0x80(%rsp)
cmpq -0x28(%rsp), %rdx
jne 0x29230
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq