// File: /workspace/github_c_makefile_star2_O1/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 $0xd8, %rsp
movq %r9, 0xa0(%rsp)
movss %xmm1, 0x70(%rsp)
movq %r8, 0xb0(%rsp)
movl %ecx, 0x68(%rsp)
movl %edx, 0x64(%rsp)
movl %esi, 0x60(%rsp)
movl %edi, 0x5c(%rsp)
leaq 0x110(%rsp), %rax
movq 0x268(%rax), %rbx
cmpl $0x2, 0x48(%rax)
jne 0x3c301
movslq 0x58(%rax), %rcx
movq %rcx, 0x48(%rsp)
leaq (%rbx,%rcx,4), %rcx
movl 0x6c(%rax), %eax
movl %eax, 0xc(%rsp)
testl %eax, %eax
jle 0x3c2d3
leaq 0x110(%rsp), %rdx
movl 0x70(%rdx), %esi
movl 0x84(%rdx), %edi
movl %esi, %eax
shrl $0x1f, %eax
addl %esi, %eax
sarl %eax
movl %eax, 0x80(%rsp)
movl 0xfc(%rdx), %eax
movl 0x100(%rdx), %edx
leal (%rdx,%rax), %r9d
leal (%rdx,%rax), %r10d
incl %r10d
movl 0xc(%rsp), %r11d
imull %esi, %r11d
movl %r11d, %ebp
imull %edi, %ebp
leal -0x1(%rsi), %eax
movl %eax, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
movaps 0x16f65(%rip), %xmm3    # 0x53150
xorl %edx, %edx
movq %rsi, 0x50(%rsp)
movl %edx, 0x38(%rsp)
cmpl $0x2, %esi
jl 0x3c2ae
xorl %edx, %edx
movl 0x20(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x10(%rsp), %rax
movl %eax, 0x40(%rsp)
movl %edx, 0x90(%rsp)
testl %edi, %edi
jle 0x3c290
xorl %esi, %esi
movl 0x18(%rsp), %eax
movl 0x40(%rsp), %r15d
testl %r9d, %r9d
js 0x3c284
movl %eax, %r14d
movl %r15d, %edx
xorl %r12d, %r12d
movslq %edx, %r13
movss (%rcx,%r13,4), %xmm1
movslq %r14d, %r8
movss (%rcx,%r8,4), %xmm2
movss %xmm2, (%rcx,%r13,4)
movss %xmm1, (%rcx,%r8,4)
testq %r12, %r12
jne 0x3c277
movss (%rcx,%r13,4), %xmm1
xorps %xmm3, %xmm1
movss %xmm1, (%rcx,%r13,4)
movss (%rcx,%r8,4), %xmm1
xorps %xmm3, %xmm1
movss %xmm1, (%rcx,%r8,4)
incq %r12
addl %ebp, %edx
addl %ebp, %r14d
cmpq %r12, %r10
jne 0x3c236
incl %esi
addl %r11d, %r15d
addl %r11d, %eax
cmpl %edi, %esi
jne 0x3c228
movl 0x90(%rsp), %edx
incl %edx
incl 0x40(%rsp)
decl 0x18(%rsp)
cmpl 0x80(%rsp), %edx
jne 0x3c212
movl 0x38(%rsp), %edx
incl %edx
movq 0x50(%rsp), %rsi
movq 0x10(%rsp), %rax
addl %esi, %eax
movq %rax, 0x10(%rsp)
addl %esi, 0x20(%rsp)
cmpl 0xc(%rsp), %edx
jne 0x3c1f2
movq 0x48(%rsp), %rdx
testl %edx, %edx
jle 0x3c301
xorl %eax, %eax
movss 0x16f4e(%rip), %xmm2    # 0x53234
movss (%rbx,%rax,4), %xmm1
addss (%rcx,%rax,4), %xmm1
mulss %xmm2, %xmm1
movss %xmm1, (%rbx,%rax,4)
incq %rax
cmpq %rax, %rdx
jne 0x3c2e6
leaq 0x110(%rsp), %rax
movl 0x70(%rax), %ecx
movl 0x6c(%rax), %eax
movl %ecx, 0x6c(%rsp)
imull %ecx, %eax
movl %eax, 0x2c(%rsp)
testl %eax, %eax
jle 0x3c68d
leaq 0x110(%rsp), %rax
movl 0x84(%rax), %ecx
movq %rcx, 0x20(%rsp)
movl 0x6c(%rax), %r15d
movl 0x70(%rax), %ecx
movq %r15, 0xd0(%rsp)
movq %rcx, 0xc8(%rsp)
imull %ecx, %r15d
movl 0xfc(%rax), %edi
movl 0x100(%rax), %edx
leal 0x1(%rdx), %ecx
movl %ecx, 0x30(%rsp)
leal (%rdx,%rdi), %ecx
incl %ecx
movl %ecx, 0x7c(%rsp)
movl 0x104(%rax), %ecx
xorl %esi, %esi
movl %ecx, 0x78(%rsp)
testl %ecx, %ecx
sete %sil
movl %esi, 0x74(%rsp)
movq 0x230(%rax), %rcx
movq %rcx, 0xc0(%rsp)
movq %rdx, 0x18(%rsp)
leal -0x4(%rdx), %r14d
movq 0x490(%rax), %rax
movq %rax, 0x38(%rsp)
leaq (,%rdi,4), %rax
movq %rax, 0xa8(%rsp)
xorl %ecx, %ecx
movss %xmm0, 0x34(%rsp)
movq %rdi, 0x10(%rsp)
movl %ecx, %eax
cltd
idivl 0x6c(%rsp)
movl %edx, 0xc(%rsp)
movl %eax, 0x50(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0x3c681
xorl %r8d, %r8d
movq %rcx, 0x48(%rsp)
movl %r15d, %ebp
imull %r8d, %ebp
addl %ecx, %ebp
movslq %ebp, %r13
testl %edi, %edi
jle 0x3c426
leaq (,%r13,2), %rax
addq %r13, %rax
shlq $0x4, %rax
movq 0x5b0(%rsp), %rcx
movq 0x18(%rcx,%rax), %rdi
xorl %esi, %esi
movq 0xa8(%rsp), %rdx
movq %r8, %r12
callq 0x31d0
movq %r12, %r8
movl %ebp, %eax
cltd
idivl %r15d
movl %edx, %ebp
movl %eax, %r12d
imull 0x7c(%rsp), %r12d
movss 0x16bc9(%rip), %xmm0    # 0x53008
cmpl $0x0, 0x78(%rsp)
jne 0x3c45b
movq 0x18(%rsp), %rax
addl %r12d, %eax
imull %r15d, %eax
addl %ebp, %eax
cltq
movss (%rbx,%rax,4), %xmm0
movaps %xmm0, 0x90(%rsp)
movl %r12d, %ecx
imull %r15d, %ecx
addl %ebp, %ecx
cmpl $0x5, 0x18(%rsp)
setl 0x80(%rsp)
leaq (%r13,%r13,2), %r13
shlq $0x4, %r13
subq $0x8, %rsp
movq %rbx, %rdi
movq 0xc8(%rsp), %rsi
movq %r8, 0x48(%rsp)
movl %r8d, %edx
movl 0x14(%rsp), %r8d
movl 0x58(%rsp), %r9d
pushq %r15
pushq 0xe0(%rsp)
pushq 0xe0(%rsp)
callq 0x3bb20
movaps 0xb0(%rsp), %xmm3
addq $0x20, %rsp
movlhps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movq 0x5b0(%rsp), %rax
movups %xmm0, (%rax,%r13)
movss 0x34(%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 0x80(%rsp), %cl
jne 0x3c525
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 0x3c50d
addq 0x5b0(%rsp), %r13
movq 0x38(%rsp), %rcx
testq %rcx, %rcx
je 0x3c5dd
movaps %xmm2, 0x80(%rsp)
movq 0x18(%rsp), %rax
addl %r12d, %eax
addl 0x74(%rsp), %eax
imull %r15d, %eax
addl %ebp, %eax
cltq
leaq (%rbx,%rax,4), %rdi
movq %rdi, 0xb8(%rsp)
movq 0x10(%rsp), %rsi
movq %rcx, %rdx
xorl %ecx, %ecx
movl %r15d, %r8d
callq 0x3cc56
movq 0xb0(%rsp), %rsi
testq %rsi, %rsi
je 0x3c636
addl 0x30(%rsp), %r12d
movq 0x18(%r13), %rax
xorl %ecx, %ecx
movss 0x34(%rsp), %xmm0
movq 0x10(%rsp), %rdi
movaps 0x90(%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 0x3c5a4
jmp 0x3c669
movq 0x10(%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 0x3c669
movq 0x18(%r13), %rax
addl 0x30(%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 0x3c60d
jmp 0x3c669
movq 0xb8(%rsp), %rdi
movq 0x38(%rsp), %rsi
movss 0x70(%rsp), %xmm0
movl %r15d, %edx
callq 0x3ccd8
movq 0x18(%r13), %rcx
cltq
movaps 0x80(%rsp), %xmm0
movss %xmm0, (%rcx,%rax,4)
movq 0x10(%rsp), %rdi
movq 0x40(%rsp), %r8
incq %r8
cmpq 0x20(%rsp), %r8
movq 0x48(%rsp), %rcx
jne 0x3c3e5
incl %ecx
cmpl 0x2c(%rsp), %ecx
jne 0x3c3c3
leaq 0x110(%rsp), %rax
movl 0x2c(%rsp), %esi
imull 0x84(%rax), %esi
subq $0x8, %rsp
movq 0x5b8(%rsp), %rdi
movl 0x64(%rsp), %edx
movl 0x68(%rsp), %ecx
movl 0x6c(%rsp), %r8d
movl 0x70(%rsp), %r9d
pushq 0xa8(%rsp)
callq 0x3bfca
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq