// File: /workspace/github_c_makefile_star2_O3/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 $0x40, %rsp
movslq 0xc0(%rsp), %rax
movq %rax, -0x20(%rsp)
testq %rax, %rax
jle 0x2ac2f
leaq 0x518(%rsp), %rax
leaq 0x78(%rsp), %rdx
movl 0xa8(%rdx), %esi
movl %esi, %ecx
shrl $0x1f, %ecx
addl %esi, %ecx
sarl %ecx
negl %ecx
movl 0x74(%rdx), %esi
movl 0x7c(%rdx), %edi
movl 0x78(%rdx), %r9d
movl 0x90(%rdx), %r8d
movl 0x98(%rdx), %r14d
movl 0x6c(%rdx), %r10d
movl 0x70(%rdx), %r11d
movq 0xd8(%rax), %rbx
movq 0x268(%rdx), %rax
movq %rax, 0x28(%rsp)
movq 0x1a0(%rdx), %rax
movq %rax, 0x20(%rsp)
movq %rsi, -0x50(%rsp)
movslq %esi, %rax
leal 0x1(%r11), %edx
imull %ecx, %edx
movq %rdx, -0x58(%rsp)
movl %r10d, %edx
imull %r11d, %edx
movq %rax, -0x30(%rsp)
movq %rdx, -0x8(%rsp)
imull %edx, %eax
movq %rax, -0x28(%rsp)
movq %r14, -0x40(%rsp)
imull %r11d, %r14d
movq %r14, 0x18(%rsp)
movss 0x2ddaa(%rip), %xmm0    # 0x587f0
movq %rdi, -0x38(%rsp)
movslq %edi, %rax
movq %rax, 0x8(%rsp)
movq %r9, -0x48(%rsp)
movslq %r9d, %rax
movq %rax, -0x18(%rsp)
movl %ecx, %eax
movq %rax, (%rsp)
movq $0x0, -0x80(%rsp)
cmpl $0x0, -0x50(%rsp)
jle 0x2ac0d
movq -0x80(%rsp), %rax
imulq -0x30(%rsp), %rax
movq %rax, -0x10(%rsp)
movq -0x58(%rsp), %rax
movq %rax, -0x70(%rsp)
movq $0x0, -0x78(%rsp)
cmpl $0x0, -0x48(%rsp)
jle 0x2abe6
movq -0x10(%rsp), %rax
movq -0x78(%rsp), %rdx
addq %rdx, %rax
imulq -0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
movq -0x70(%rsp), %rax
movq %rax, -0x60(%rsp)
movq $0x0, -0x68(%rsp)
cmpl $0x0, -0x38(%rsp)
jle 0x2abbf
movq 0x10(%rsp), %rax
movq -0x68(%rsp), %rdx
addq %rdx, %rax
imulq 0x8(%rsp), %rax
movq %rax, 0x30(%rsp)
movl %edx, %edi
imull -0x40(%rsp), %edi
movq -0x60(%rsp), %rbp
movq (%rsp), %rax
xorl %edx, %edx
testl %r8d, %r8d
movq %rbp, 0x38(%rsp)
jle 0x2ab7c
xorl %esi, %esi
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movaps %xmm0, %xmm1
leal (%rsi,%rcx), %r15d
addl %edi, %r15d
xorl %r13d, %r13d
movaps %xmm1, %xmm2
movq %rbp, %r9
addq %r13, %r9
movaps %xmm0, %xmm1
testl %r15d, %r15d
js 0x2ab5d
movaps %xmm0, %xmm1
cmpl %r10d, %r15d
jge 0x2ab5d
leaq (%rax,%r13), %r14
movaps %xmm0, %xmm1
testl %r14d, %r14d
js 0x2ab5d
movaps %xmm0, %xmm1
cmpl %r11d, %r14d
jge 0x2ab5d
movslq %r9d, %r14
movss (%rbx,%r14,4), %xmm1
ucomiss %xmm2, %xmm1
cmoval %r9d, %r12d
maxss %xmm2, %xmm1
incq %r13
cmpq %r13, %r8
jne 0x2ab27
incl %esi
addq %r11, %rbp
cmpl %r8d, %esi
jne 0x2ab1d
jmp 0x2ab85
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movaps %xmm0, %xmm1
movq 0x30(%rsp), %rsi
addq %rdx, %rsi
movq 0x28(%rsp), %r9
movss %xmm1, (%r9,%rsi,4)
movq 0x20(%rsp), %r9
movl %r12d, (%r9,%rsi,4)
incq %rdx
movq -0x40(%rsp), %rsi
addq %rsi, %rax
movq 0x38(%rsp), %rbp
addq %rsi, %rbp
cmpq -0x38(%rsp), %rdx
jne 0x2ab08
movq -0x68(%rsp), %rdx
incq %rdx
movq -0x60(%rsp), %rax
addq 0x18(%rsp), %rax
movq %rax, -0x60(%rsp)
movq %rdx, -0x68(%rsp)
cmpq -0x48(%rsp), %rdx
jne 0x2aad3
movq -0x78(%rsp), %rdx
incq %rdx
movq -0x70(%rsp), %rax
addq -0x8(%rsp), %rax
movq %rax, -0x70(%rsp)
movq %rdx, -0x78(%rsp)
cmpq -0x50(%rsp), %rdx
jne 0x2aa9d
movq -0x80(%rsp), %rdx
incq %rdx
movq -0x28(%rsp), %rax
addq %rax, -0x58(%rsp)
movq %rdx, -0x80(%rsp)
cmpq -0x20(%rsp), %rdx
jne 0x2aa6f
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq