// File: /workspace/github_c_makefile_star2_O3/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 $0xb8, %rsp
movss %xmm0, 0x4(%rsp)
movq %rdi, %r12
leal -0x1(%rsi), %ebx
testl %esi, %esi
jle 0x38afc
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 0x38aef
jp 0x38aef
addq %r12, %rcx
movups (%rcx), %xmm1
movups 0x10(%rcx), %xmm2
movups 0x20(%rcx), %xmm3
movaps %xmm3, 0xa0(%rsp)
movaps %xmm2, 0x90(%rsp)
movaps %xmm1, 0x80(%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 0x80(%rsp), %xmm1
movdqa 0x90(%rsp), %xmm2
movdqa 0xa0(%rsp), %xmm3
movdqu %xmm3, 0x20(%r12,%rsi)
movdqu %xmm2, 0x10(%r12,%rsi)
movups %xmm1, (%r12,%rsi)
decl %ebx
decl %eax
leal 0x1(%rax), %ecx
cmpl %ebx, %eax
movl %ecx, %eax
jl 0x38a54
testl %edx, %edx
jle 0x38d69
leal 0x1(%rbx), %ecx
movslq %ecx, %rax
movq %rax, 0x8(%rsp)
movslq %ebx, %rax
movl %edx, %edx
movq %rdx, 0x30(%rsp)
movq %rax, 0x40(%rsp)
movl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rcx, %rax
shlq $0x4, %rax
movq %rcx, 0x48(%rsp)
decq %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm5     # xmm5 = xmm0[0,1,0,1]
addq $0x30, %rax
andq $-0x40, %rax
leaq (%rax,%rax,2), %rdx
leaq 0x48(%r12), %rax
movq %rax, 0x18(%rsp)
xorl %r14d, %r14d
movdqa 0x1c531(%rip), %xmm6    # 0x55090
pxor %xmm6, %xmm5
pcmpeqd %xmm7, %xmm7
movdqa 0x1c610(%rip), %xmm8    # 0x55180
movq %rbx, 0x38(%rsp)
movdqa %xmm5, 0x50(%rsp)
movq %rdx, 0x28(%rsp)
movq %r12, 0x10(%rsp)
testl %ebx, %ebx
js 0x38d1d
xorl %eax, %eax
movdqa 0x1c4e9(%rip), %xmm0    # 0x55080
movdqa 0x1c5d1(%rip), %xmm1    # 0x55170
movdqa %xmm0, %xmm2
pxor %xmm6, %xmm2
movdqa %xmm2, %xmm3
pcmpgtd %xmm5, %xmm3
pcmpeqd %xmm5, %xmm2
pshufd $0xf5, %xmm2, %xmm4     # xmm4 = xmm2[1,1,3,3]
pand %xmm3, %xmm4
pshufd $0xf5, %xmm3, %xmm2     # xmm2 = xmm3[1,1,3,3]
por %xmm4, %xmm2
movd %xmm2, %ecx
notl %ecx
testb $0x1, %cl
je 0x38bd5
movl %r14d, 0x2c(%r12,%rax)
pxor %xmm7, %xmm2
pextrw $0x4, %xmm2, %ecx
testb $0x1, %cl
je 0x38be8
movl %r14d, 0x5c(%r12,%rax)
movdqa %xmm1, %xmm2
pxor %xmm6, %xmm2
movdqa %xmm2, %xmm3
pcmpgtd %xmm5, %xmm3
pcmpeqd %xmm5, %xmm2
pshufd $0xf5, %xmm2, %xmm4     # xmm4 = xmm2[1,1,3,3]
pand %xmm3, %xmm4
pshufd $0xf5, %xmm3, %xmm2     # xmm2 = xmm3[1,1,3,3]
por %xmm4, %xmm2
pxor %xmm7, %xmm2
pextrw $0x0, %xmm2, %ecx
testb $0x1, %cl
je 0x38c24
movl %r14d, 0x8c(%r12,%rax)
pextrw $0x4, %xmm2, %ecx
testb $0x1, %cl
je 0x38c36
movl %r14d, 0xbc(%r12,%rax)
paddq %xmm8, %xmm0
paddq %xmm8, %xmm1
addq $0xc0, %rax
cmpq %rax, %rdx
jne 0x38b9f
movl $0x30, %edx
movq %r12, %rdi
movq 0x8(%rsp), %rsi
leaq -0x5e3(%rip), %rcx      # 0x38680
callq 0x30c0
testl %ebx, %ebx
js 0x38d36
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %rbx
xorl %r13d, %r13d
leaq (,%r13,2), %rax
addq %r13, %rax
shlq $0x4, %rax
movq 0x18(%r12,%rax), %rcx
movss (%rcx,%r14,4), %xmm0
ucomiss 0x1c402(%rip), %xmm0    # 0x550a0
jne 0x38ca2
jnp 0x38d01
cmpq 0x40(%rsp), %r13
jge 0x38d01
addq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movaps %xmm0, 0x70(%rsp)
movsd 0x8(%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
movq %r15, %r12
movq %rbx, %rbp
movq -0x18(%r12), %xmm2
movq -0x10(%r12), %xmm3
movaps 0x70(%rsp), %xmm0
movdqa 0x60(%rsp), %xmm1
callq 0x389b3
ucomiss 0x4(%rsp), %xmm0
jbe 0x38cf8
movq (%r12), %rax
movl $0x0, (%rax,%r14,4)
addq $0x30, %r12
decq %rbp
jne 0x38cc7
incq %r13
decq %rbx
addq $0x30, %r15
cmpq 0x48(%rsp), %r13
movq 0x10(%rsp), %r12
jne 0x38c7d
jmp 0x38d36
movl $0x30, %edx
movq %r12, %rdi
movq 0x8(%rsp), %rsi
leaq -0x6b1(%rip), %rcx      # 0x38680
callq 0x30c0
incq %r14
cmpq 0x30(%rsp), %r14
movq 0x38(%rsp), %rbx
movdqa 0x50(%rsp), %xmm5
movq 0x28(%rsp), %rdx
movdqa 0x1c33a(%rip), %xmm6    # 0x55090
pcmpeqd %xmm7, %xmm7
movdqa 0x1c41d(%rip), %xmm8    # 0x55180
jne 0x38b85
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq