// File: /workspace/github_c_makefile_star2_O1/SimpleDoger[P]Darknet_CPU_Only/box.c
// Function: do_nms_sort
void do_nms_sort(detection *dets, int total, int classes, float thresh)
{
    int i, j, k;
    k = total-1;
    for(i = 0; i <= k; ++i){
        if(dets[i].objectness == 0){
            detection swap = dets[i];
            dets[i] = dets[k];
            dets[k] = swap;
            --k;
            --i;
        }
    }
    total = k+1;

    for(k = 0; k < classes; ++k){
        for(i = 0; i < total; ++i){
            dets[i].sort_class = k;
        }
        qsort(dets, total, sizeof(detection), nms_comparator);
        for(i = 0; i < total; ++i){
            if(dets[i].prob[k] == 0) continue;
            box a = dets[i].bbox;
            for(j = i+1; j < total; ++j){
                box b = dets[j].bbox;
                if (box_iou(a, b) > thresh){
                    dets[j].prob[k] = 0;
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movss %xmm0, 0x4(%rsp)
movq %rdi, %r12
leal -0x1(%rsi), %ebx
testl %esi, %esi
jle 0x368eb
xorl %eax, %eax
xorps %xmm0, %xmm0
movslq %eax, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movss 0x28(%r12,%rcx), %xmm1
ucomiss %xmm0, %xmm1
jne 0x368de
jp 0x368de
addq %r12, %rcx
movups (%rcx), %xmm1
movups 0x10(%rcx), %xmm2
movups 0x20(%rcx), %xmm3
movaps %xmm3, 0x90(%rsp)
movaps %xmm2, 0x80(%rsp)
movaps %xmm1, 0x70(%rsp)
movslq %ebx, %rbx
leaq (%rbx,%rbx,2), %rsi
shlq $0x4, %rsi
movups (%r12,%rsi), %xmm1
movups 0x10(%r12,%rsi), %xmm2
movups 0x20(%r12,%rsi), %xmm3
movups %xmm3, 0x20(%rcx)
movups %xmm2, 0x10(%rcx)
movups %xmm1, (%rcx)
movaps 0x70(%rsp), %xmm1
movaps 0x80(%rsp), %xmm2
movaps 0x90(%rsp), %xmm3
movups %xmm3, 0x20(%r12,%rsi)
movups %xmm2, 0x10(%r12,%rsi)
movups %xmm1, (%r12,%rsi)
decl %ebx
decl %eax
leal 0x1(%rax), %ecx
cmpl %ebx, %eax
movl %ecx, %eax
jl 0x36851
testl %edx, %edx
jle 0x36a34
leal 0x1(%rbx), %eax
movslq %eax, %rcx
movq %rcx, 0x30(%rsp)
movslq %ebx, %rcx
movl %edx, %edx
movq %rdx, 0x28(%rsp)
movq %rcx, 0x40(%rsp)
movl %ecx, %ecx
movq %rcx, 0x18(%rsp)
movq %rax, 0x48(%rsp)
shlq $0x4, %rax
leaq (%rax,%rax,2), %rcx
leaq 0x48(%r12), %rax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
movq %r12, 0x8(%rsp)
movq %rbx, 0x38(%rsp)
movq %rcx, 0x20(%rsp)
testl %ebx, %ebx
js 0x36951
xorl %eax, %eax
movl %r15d, 0x2c(%r12,%rax)
addq $0x30, %rax
cmpq %rax, %rcx
jne 0x36943
movl $0x30, %edx
movq %r12, %rdi
movq 0x30(%rsp), %rsi
leaq -0x449(%rip), %rcx      # 0x3651c
callq 0x30d0
testl %ebx, %ebx
js 0x36a1c
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
xorl %r13d, %r13d
leaq (,%r13,2), %rax
addq %r13, %rax
shlq $0x4, %rax
movq 0x18(%r12,%rax), %rcx
movss (%rcx,%r15,4), %xmm0
ucomiss 0x1c6d8(%rip), %xmm0    # 0x53078
jne 0x369a4
jnp 0x36a02
cmpq 0x40(%rsp), %r13
jge 0x36a02
addq 0x8(%rsp), %rax
movsd (%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
movsd 0x8(%rax), %xmm0
movaps %xmm0, 0x50(%rsp)
movq %r14, %r12
movq %rbx, %rbp
movsd -0x18(%r12), %xmm2
movsd -0x10(%r12), %xmm3
movaps 0x60(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
callq 0x36754
ucomiss 0x4(%rsp), %xmm0
jbe 0x369f9
movq (%r12), %rax
movl $0x0, (%rax,%r15,4)
addq $0x30, %r12
decq %rbp
jne 0x369c9
incq %r13
decq %rbx
addq $0x30, %r14
cmpq 0x48(%rsp), %r13
movq 0x8(%rsp), %r12
jne 0x3697f
incq %r15
cmpq 0x28(%rsp), %r15
movq 0x38(%rsp), %rbx
movq 0x20(%rsp), %rcx
jne 0x3693d
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq