// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/region_layer.c
// Function: get_region_detections
void get_region_detections(layer l, int w, int h, int netw, int neth, float thresh, int *map, float tree_thresh, int relative, detection *dets)
{
    int i,j,n,z;
    float *predictions = l.output;
    if (l.batch == 2) {
        float *flip = l.output + l.outputs;
        for (j = 0; j < l.h; ++j) {
            for (i = 0; i < l.w/2; ++i) {
                for (n = 0; n < l.n; ++n) {
                    for(z = 0; z < l.classes + l.coords + 1; ++z){
                        int i1 = z*l.w*l.h*l.n + n*l.w*l.h + j*l.w + i;
                        int i2 = z*l.w*l.h*l.n + n*l.w*l.h + j*l.w + (l.w - i - 1);
                        float swap = flip[i1];
                        flip[i1] = flip[i2];
                        flip[i2] = swap;
                        if(z == 0){
                            flip[i1] = -flip[i1];
                            flip[i2] = -flip[i2];
                        }
                    }
                }
            }
        }
        for(i = 0; i < l.outputs; ++i){
            l.output[i] = (l.output[i] + flip[i])/2.;
        }
    }
    for (i = 0; i < l.w*l.h; ++i){
        int row = i / l.w;
        int col = i % l.w;
        for(n = 0; n < l.n; ++n){
            int index = n*l.w*l.h + i;
            for(j = 0; j < l.classes; ++j){
                dets[index].prob[j] = 0;
            }
            int obj_index  = entry_index(l, 0, n*l.w*l.h + i, l.coords);
            int box_index  = entry_index(l, 0, n*l.w*l.h + i, 0);
            int mask_index = entry_index(l, 0, n*l.w*l.h + i, 4);
            float scale = l.background ? 1 : predictions[obj_index];
            dets[index].bbox = get_region_box(predictions, l.biases, n, box_index, col, row, l.w, l.h, l.w*l.h);
            dets[index].objectness = scale > thresh ? scale : 0;
            if(dets[index].mask){
                for(j = 0; j < l.coords - 4; ++j){
                    dets[index].mask[j] = l.output[mask_index + j*l.w*l.h];
                }
            }

            int class_index = entry_index(l, 0, n*l.w*l.h + i, l.coords + !l.background);
            if(l.softmax_tree){

                hierarchy_predictions(predictions + class_index, l.classes, l.softmax_tree, 0, l.w*l.h);
                if(map){
                    for(j = 0; j < 200; ++j){
                        int class_index = entry_index(l, 0, n*l.w*l.h + i, l.coords + 1 + map[j]);
                        float prob = scale*predictions[class_index];
                        dets[index].prob[j] = (prob > thresh) ? prob : 0;
                    }
                } else {
                    int j =  hierarchy_top_prediction(predictions + class_index, l.softmax_tree, tree_thresh, l.w*l.h);
                    dets[index].prob[j] = (scale > thresh) ? scale : 0;
                }
            } else {
                if(dets[index].objectness){
                    for(j = 0; j < l.classes; ++j){
                        int class_index = entry_index(l, 0, n*l.w*l.h + i, l.coords + 1 + j);
                        float prob = scale*predictions[class_index];
                        dets[index].prob[j] = (prob > thresh) ? prob : 0;
                    }
                }
            }
        }
    }
    correct_region_boxes(dets, l.w*l.h*l.n, w, h, netw, neth, relative);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, 0x98(%rsp)
movss %xmm1, 0x5c(%rsp)
movq %r8, 0xa8(%rsp)
movl %ecx, 0x58(%rsp)
movl %edx, 0x54(%rsp)
movl %esi, 0x50(%rsp)
movl %edi, 0x4c(%rsp)
leaq 0x100(%rsp), %rsi
movq 0x268(%rsi), %rbx
cmpl $0x2, 0x48(%rsi)
jne 0x3e4d4
movslq 0x58(%rsi), %rax
movq %rax, 0x40(%rsp)
leaq (%rbx,%rax,4), %rdx
movl 0x6c(%rsi), %r15d
testl %r15d, %r15d
jle 0x3e49c
leaq 0x100(%rsp), %rcx
movl 0x70(%rcx), %esi
movl 0x84(%rcx), %edi
movl %esi, %eax
shrl $0x1f, %eax
addl %esi, %eax
sarl %eax
movl %eax, 0x70(%rsp)
movl 0xfc(%rcx), %eax
movl 0x100(%rcx), %ecx
leal (%rcx,%rax), %r9d
leal (%rcx,%rax), %r10d
incl %r10d
movl %r15d, %r11d
imull %esi, %r11d
movl %r11d, %ebp
imull %edi, %ebp
leal -0x1(%rsi), %eax
movl %eax, 0x8(%rsp)
movq $0x0, (%rsp)
movaps 0x16cdf(%rip), %xmm3    # 0x55090
xorl %ecx, %ecx
movq %r15, 0x38(%rsp)
movq %rsi, 0x20(%rsp)
movl %ecx, 0x28(%rsp)
cmpl $0x2, %esi
jl 0x3e475
xorl %ecx, %ecx
movl 0x8(%rsp), %eax
movl %eax, 0x10(%rsp)
movq (%rsp), %rax
movl %eax, 0x30(%rsp)
movl %ecx, 0x80(%rsp)
testl %edi, %edi
jle 0x3e45a
xorl %esi, %esi
movl 0x10(%rsp), %eax
movl 0x30(%rsp), %r15d
testl %r9d, %r9d
js 0x3e44e
movl %eax, %r14d
movl %r15d, %ecx
xorl %r12d, %r12d
movslq %ecx, %r13
movss (%rdx,%r13,4), %xmm1
movslq %r14d, %r8
movss (%rdx,%r8,4), %xmm2
movss %xmm2, (%rdx,%r13,4)
movss %xmm1, (%rdx,%r8,4)
testq %r12, %r12
jne 0x3e441
movss (%rdx,%r13,4), %xmm1
xorps %xmm3, %xmm1
movss %xmm1, (%rdx,%r13,4)
movss (%rdx,%r8,4), %xmm1
xorps %xmm3, %xmm1
movss %xmm1, (%rdx,%r8,4)
incq %r12
addl %ebp, %ecx
addl %ebp, %r14d
cmpq %r12, %r10
jne 0x3e400
incl %esi
addl %r11d, %r15d
addl %r11d, %eax
cmpl %edi, %esi
jne 0x3e3f2
movl 0x80(%rsp), %ecx
incl %ecx
incl 0x30(%rsp)
decl 0x10(%rsp)
cmpl 0x70(%rsp), %ecx
jne 0x3e3dc
movl 0x28(%rsp), %ecx
incl %ecx
movq 0x20(%rsp), %rsi
movq (%rsp), %rax
addl %esi, %eax
movq %rax, (%rsp)
addl %esi, 0x8(%rsp)
movq 0x38(%rsp), %r15
cmpl %r15d, %ecx
jne 0x3e3bd
movq 0x40(%rsp), %rcx
testl %ecx, %ecx
jle 0x3e4da
xorl %eax, %eax
movss 0x16db5(%rip), %xmm2    # 0x55264
leaq 0x100(%rsp), %rsi
movss (%rbx,%rax,4), %xmm1
addss (%rdx,%rax,4), %xmm1
mulss %xmm2, %xmm1
movss %xmm1, (%rbx,%rax,4)
incq %rax
cmpq %rax, %rcx
jne 0x3e4b7
jmp 0x3e4e2
movl 0x6c(%rsi), %r15d
jmp 0x3e4e2
leaq 0x100(%rsp), %rsi
movl 0x70(%rsi), %ecx
movl 0x84(%rsi), %eax
movq %rax, 0x8(%rsp)
movq %r15, 0x38(%rsp)
movq %rcx, 0x20(%rsp)
imull %ecx, %r15d
testl %r15d, %r15d
jle 0x3e831
movl 0xfc(%rsi), %edi
movl 0x100(%rsi), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x18(%rsp)
leal (%rcx,%rdi), %eax
incl %eax
movl %eax, 0x68(%rsp)
movl 0x104(%rsi), %eax
xorl %edx, %edx
movl %eax, 0x64(%rsp)
testl %eax, %eax
sete %dl
movl %edx, 0x60(%rsp)
movq 0x230(%rsi), %rax
movq %rax, 0xb8(%rsp)
movq %rcx, 0x10(%rsp)
leal -0x4(%rcx), %r14d
movq 0x490(%rsi), %rax
movq %rax, 0x28(%rsp)
leaq (,%rdi,4), %rax
movq %rax, 0xa0(%rsp)
xorl %ecx, %ecx
movss %xmm0, 0x1c(%rsp)
movq %rdi, (%rsp)
movl %ecx, %eax
cltd
idivl 0x20(%rsp)
movl %edx, 0x40(%rsp)
movl %eax, 0x6c(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x3e826
xorl %r8d, %r8d
movq %rcx, 0xc0(%rsp)
movl %r15d, %ebp
imull %r8d, %ebp
addl %ecx, %ebp
movslq %ebp, %r13
testl %edi, %edi
jle 0x3e5de
leaq (,%r13,2), %rax
addq %r13, %rax
shlq $0x4, %rax
movq 0x5a0(%rsp), %rcx
movq 0x18(%rcx,%rax), %rdi
xorl %esi, %esi
movq 0xa0(%rsp), %rdx
movq %r8, %r12
callq 0x31c0
movq %r12, %r8
movl %ebp, %eax
cltd
idivl %r15d
movl %edx, %ebp
movl %eax, %r12d
imull 0x68(%rsp), %r12d
movss 0x16a11(%rip), %xmm0    # 0x55008
cmpl $0x0, 0x64(%rsp)
jne 0x3e613
movq 0x10(%rsp), %rax
addl %r12d, %eax
imull %r15d, %eax
addl %ebp, %eax
cltq
movss (%rbx,%rax,4), %xmm0
movaps %xmm0, 0x80(%rsp)
movl %r12d, %ecx
imull %r15d, %ecx
addl %ebp, %ecx
cmpl $0x5, 0x10(%rsp)
setl 0x70(%rsp)
leaq (%r13,%r13,2), %r13
shlq $0x4, %r13
subq $0x8, %rsp
movq %rbx, %rdi
movq 0xc0(%rsp), %rsi
movq %r8, 0x38(%rsp)
movl %r8d, %edx
movl 0x48(%rsp), %r8d
movl 0x74(%rsp), %r9d
pushq %r15
pushq 0x48(%rsp)
pushq 0x38(%rsp)
callq 0x3dd70
movaps 0xa0(%rsp), %xmm3
addq $0x20, %rsp
movlhps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movq 0x5a0(%rsp), %rax
movups %xmm0, (%rax,%r13)
movss 0x1c(%rsp), %xmm0
movaps %xmm0, %xmm2
cmpltss %xmm3, %xmm2
andps %xmm3, %xmm2
movss %xmm2, 0x28(%rax,%r13)
movq 0x20(%rax,%r13), %rax
testq %rax, %rax
sete %cl
orb 0x70(%rsp), %cl
jne 0x3e6d1
leal 0x4(%r12), %ecx
imull %r15d, %ecx
addl %ebp, %ecx
xorl %edx, %edx
movslq %ecx, %rcx
movss (%rbx,%rcx,4), %xmm1
movss %xmm1, (%rax,%rdx,4)
incq %rdx
addl %r15d, %ecx
cmpq %rdx, %r14
jne 0x3e6b9
addq 0x5a0(%rsp), %r13
movq 0x28(%rsp), %rcx
testq %rcx, %rcx
je 0x3e784
movaps %xmm2, 0x70(%rsp)
movq 0x10(%rsp), %rax
addl %r12d, %eax
addl 0x60(%rsp), %eax
imull %r15d, %eax
addl %ebp, %eax
cltq
leaq (%rbx,%rax,4), %rdi
movq %rdi, 0xb0(%rsp)
movq (%rsp), %rsi
movq %rcx, %rdx
xorl %ecx, %ecx
movl %r15d, %r8d
callq 0x3eeda
movq 0xa8(%rsp), %rsi
testq %rsi, %rsi
je 0x3e7dc
addl 0x18(%rsp), %r12d
movq 0x18(%r13), %rax
xorl %ecx, %ecx
movss 0x1c(%rsp), %xmm0
movq (%rsp), %rdi
movaps 0x80(%rsp), %xmm3
movl (%rsi,%rcx,4), %edx
addl %r12d, %edx
imull %r15d, %edx
addl %ebp, %edx
movslq %edx, %rdx
movss (%rbx,%rdx,4), %xmm2
mulss %xmm3, %xmm2
movaps %xmm0, %xmm1
cmpltss %xmm2, %xmm1
andps %xmm2, %xmm1
movss %xmm1, (%rax,%rcx,4)
incq %rcx
cmpq $0xc8, %rcx
jne 0x3e74b
jmp 0x3e80b
movq (%rsp), %rdi
testl %edi, %edi
setle %al
xorps %xmm1, %xmm1
ucomiss 0x28(%r13), %xmm1
setnp %cl
sete %dl
andb %cl, %dl
orb %al, %dl
jne 0x3e80b
movq 0x18(%r13), %rax
addl 0x18(%rsp), %r12d
imull %r15d, %r12d
addl %r12d, %ebp
xorl %ecx, %ecx
movslq %ebp, %rbp
movss (%rbx,%rbp,4), %xmm2
mulss %xmm3, %xmm2
movaps %xmm0, %xmm1
cmpltss %xmm2, %xmm1
andps %xmm2, %xmm1
movss %xmm1, (%rax,%rcx,4)
incq %rcx
addl %r15d, %ebp
cmpq %rcx, %rdi
jne 0x3e7b3
jmp 0x3e80b
movq 0xb0(%rsp), %rdi
movq 0x28(%rsp), %rsi
movss 0x5c(%rsp), %xmm0
movl %r15d, %edx
callq 0x3ef4f
movq 0x18(%r13), %rcx
cltq
movaps 0x70(%rsp), %xmm0
movss %xmm0, (%rcx,%rax,4)
movq (%rsp), %rdi
movq 0x30(%rsp), %r8
incq %r8
cmpq 0x8(%rsp), %r8
movq 0xc0(%rsp), %rcx
jne 0x3e59d
incl %ecx
cmpl %r15d, %ecx
jne 0x3e578
movq 0x8(%rsp), %rsi
imull %r15d, %esi
subq $0x8, %rsp
movq 0x5a8(%rsp), %rdi
movl 0x54(%rsp), %edx
movl 0x58(%rsp), %ecx
movl 0x5c(%rsp), %r8d
movl 0x60(%rsp), %r9d
pushq 0xa0(%rsp)
callq 0x3e21e
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq