// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/image.c
// Function: draw_detections
void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes)
{
    int i,j;

    for(i = 0; i < num; ++i){
        char labelstr[4096] = {0};
        int class = -1;
        for(j = 0; j < classes; ++j){
            if (dets[i].prob[j] > thresh){
                if (class < 0) {
                    strcat(labelstr, names[j]);
                    class = j;
                } else {
                    strcat(labelstr, ", ");
                    strcat(labelstr, names[j]);
                }
                printf("%s: %.0f%%\n", names[j], dets[i].prob[j]*100);
            }
        }
        if(class >= 0){
            int width = im.h * .006;

            /*
               if(0){
               width = pow(prob, 1./2.)*10+1;
               alphabet = 0;
               }
             */

            //printf("%d %s: %.0f%%\n", i, names[class], prob*100);
            int offset = class*123457 % classes;
            float red = get_color(2,offset,classes);
            float green = get_color(1,offset,classes);
            float blue = get_color(0,offset,classes);
            float rgb[3];

            //width = prob*20+2;

            rgb[0] = red;
            rgb[1] = green;
            rgb[2] = blue;
            box b = dets[i].bbox;
            //printf("%f %f %f %f\n", b.x, b.y, b.w, b.h);

            int left  = (b.x-b.w/2.)*im.w;
            int right = (b.x+b.w/2.)*im.w;
            int top   = (b.y-b.h/2.)*im.h;
            int bot   = (b.y+b.h/2.)*im.h;

            if(left < 0) left = 0;
            if(right > im.w-1) right = im.w-1;
            if(top < 0) top = 0;
            if(bot > im.h-1) bot = im.h-1;

            draw_box_width(im, left, top, right, bot, width, red, green, blue);
            if (alphabet) {
                image label = get_label(alphabet, labelstr, (im.h*.03));
                draw_label(im, top + width, left, label, rgb);
                free_image(label);
            }
            if (dets[i].mask){
                image mask = float_to_image(14, 14, 1, dets[i].mask);
                image resized_mask = resize_image(mask, b.w*im.w, b.h*im.h);
                image tmask = threshold_image(resized_mask, .5);
                embed_image(tmask, im, left, top);
                free_image(mask);
                free_image(resized_mask);
                free_image(tmask);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1178, %rsp           # imm = 0x1178
movl %r8d, 0x34(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, 0x80(%rsp)
movss %xmm0, 0x5c(%rsp)
movq %rdi, 0x48(%rsp)
testl %esi, %esi
jle 0x170d8
leaq 0x11b0(%rsp), %rcx
movl 0x34(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x58(%rsp)
movq (%rcx), %rcx
movq %rcx, %xmm3
pshufd $0x55, %xmm3, %xmm0     # xmm0 = xmm3[1,1,1,1]
cvtdq2pd %xmm3, %xmm1
movd %xmm0, %edx
movapd %xmm1, 0x140(%rsp)
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movsd 0x409ea(%rip), %xmm2    # 0x57540
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %edi
movq %rdi, 0x38(%rsp)
decl %ecx
movq %rcx, 0xd0(%rsp)
mulsd 0x409d3(%rip), %xmm1    # 0x57548
cvttsd2si %xmm1, %ecx
movl %ecx, 0x50(%rsp)
decl %edx
movl %edx, 0x54(%rsp)
movdqa %xmm3, 0x150(%rsp)
cvtdq2ps %xmm3, %xmm1
movaps %xmm1, 0x130(%rsp)
cvtdq2ps %xmm0, %xmm0
movaps %xmm0, 0x120(%rsp)
movl %esi, %r13d
movl %eax, %eax
movq %rax, 0xd8(%rsp)
xorl %ebx, %ebx
movq %r13, 0x68(%rsp)
movl $0x1000, %edx           # imm = 0x1000
leaq 0x170(%rsp), %rdi
xorl %esi, %esi
callq 0x31c0
cmpl $0x0, 0x34(%rsp)
jle 0x170cc
movq %rbx, 0x78(%rsp)
leaq (%rbx,%rbx,2), %rcx
shlq $0x4, %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x70(%rsp)
leaq (%rax,%rcx), %r14
addq $0x18, %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movq (%r14), %r15
movss (%r15,%r12,4), %xmm0
ucomiss 0x5c(%rsp), %xmm0
jbe 0x16c91
testl %ebp, %ebp
js 0x16c4f
leaq 0x170(%rsp), %r13
movq %r13, %rdi
callq 0x3140
movw $0x202c, 0x170(%rsp,%rax) # imm = 0x202C
movb $0x0, 0x172(%rsp,%rax)
movq 0x80(%rsp), %rax
movq (%rax,%r12,8), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3410
jmp 0x16c6e
movq 0x80(%rsp), %rax
movq (%rax,%r12,8), %rbx
leaq 0x170(%rsp), %rdi
movq %rbx, %rsi
callq 0x3410
movl %r12d, %ebp
movss (%r15,%r12,4), %xmm0
mulss 0x3e5f8(%rip), %xmm0    # 0x55274
cvtss2sd %xmm0, %xmm0
leaq 0x40afc(%rip), %rdi     # 0x57783
movq %rbx, %rsi
movb $0x1, %al
callq 0x3160
incq %r12
cmpq %r12, 0xd8(%rsp)
jne 0x16bfc
testl %ebp, %ebp
movq 0x78(%rsp), %rbx
movq 0x68(%rsp), %r13
js 0x170cc
imull $0x1e241, %ebp, %eax    # imm = 0x1E241
xorl %edx, %edx
divl 0x34(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
divss 0x58(%rsp), %xmm0
mulss 0x3e59b(%rip), %xmm0    # 0x55270
movaps %xmm0, 0xa0(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0xb0(%rsp)
callq 0x33e0
movaps %xmm0, 0xc0(%rsp)
cvttsd2si %xmm0, %ebx
movsd 0xb0(%rsp), %xmm0
callq 0x3480
cvttsd2si %xmm0, %eax
cvttpd2dq 0xc0(%rsp), %xmm0
cvtdq2ps %xmm0, %xmm0
movaps 0xa0(%rsp), %xmm4
subss %xmm0, %xmm4
movss 0x3e2db(%rip), %xmm3    # 0x55008
subss %xmm4, %xmm3
movslq %ebx, %rcx
cltq
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rax,2), %rax
leaq 0x5556b(%rip), %rdx     # 0x6c2b0
movss (%rdx,%rax,4), %xmm0
mulss %xmm4, %xmm0
movss (%rdx,%rcx,4), %xmm2
mulss %xmm3, %xmm2
addss %xmm0, %xmm2
movsd 0x4(%rdx,%rcx,4), %xmm0
movsd 0x4(%rdx,%rax,4), %xmm1
shufps $0x0, %xmm4, %xmm4      # xmm4 = xmm4[0,0,0,0]
mulps %xmm1, %xmm4
shufps $0x0, %xmm3, %xmm3      # xmm3 = xmm3[0,0,0,0]
mulps %xmm0, %xmm3
addps %xmm4, %xmm3
movaps %xmm3, 0xa0(%rsp)
movaps %xmm3, %xmm0
shufps $0xe1, %xmm3, %xmm0     # xmm0 = xmm0[1,0],xmm3[2,3]
movlps %xmm0, 0xf8(%rsp)
movss %xmm2, 0x100(%rsp)
movq 0x48(%rsp), %rax
movq 0x70(%rsp), %rcx
movsd 0x8(%rax,%rcx), %xmm1
cvtps2pd (%rax,%rcx), %xmm0
movaps %xmm1, 0x160(%rsp)
cvtps2pd %xmm1, %xmm1
mulpd 0x3e521(%rip), %xmm1    # 0x552e0
movapd %xmm0, %xmm4
subpd %xmm1, %xmm4
movapd 0x140(%rsp), %xmm3
mulpd %xmm3, %xmm4
cvttsd2si %xmm4, %eax
unpckhpd %xmm4, %xmm4            # xmm4 = xmm4[1,1]
cvttsd2si %xmm4, %edx
addpd %xmm0, %xmm1
mulpd %xmm3, %xmm1
cvttpd2dq %xmm1, %xmm0
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
movl %eax, 0x30(%rsp)
movdqa 0x150(%rsp), %xmm1
pcmpgtd %xmm0, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
movmskpd %xmm1, %eax
movd %xmm0, %r14d
testb $0x1, %al
cmovel 0xd0(%rsp), %r14d
testl %edx, %edx
cmovlel %ecx, %edx
movq %rdx, 0x40(%rsp)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %ebx
testb $0x2, %al
cmovel 0x54(%rsp), %ebx
cmpl $0x0, 0x38(%rsp)
leaq 0x11b0(%rsp), %r13
jle 0x16ec5
movaps 0xa0(%rsp), %xmm0
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, 0xb0(%rsp)
movl 0x30(%rsp), %r12d
movq 0x40(%rsp), %rax
movl %eax, %ebp
movq 0x38(%rsp), %rax
movl %eax, %r15d
movss %xmm2, 0xc0(%rsp)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movl %r12d, %edi
movl %ebp, %esi
movl %r14d, %edx
movl %ebx, %ecx
movdqa 0xb0(%rsp), %xmm0
movapd 0xa0(%rsp), %xmm1
callq 0x16712
movss 0xc0(%rsp), %xmm2
decl %ebx
decl %r14d
incl %ebp
incl %r12d
decl %r15d
jne 0x16e7a
cmpq $0x0, 0x60(%rsp)
je 0x16f49
leaq 0x88(%rsp), %rdi
movq 0x60(%rsp), %rsi
leaq 0x170(%rsp), %rdx
movl 0x50(%rsp), %ecx
callq 0x16413
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
leal (%rcx,%rax), %edi
movq 0x98(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movdqu (%r13), %xmm0
movdqu %xmm0, (%rsp)
movl 0x30(%rsp), %esi
leaq 0xf8(%rsp), %rdx
callq 0x1658a
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x16f49
callq 0x3040
movq 0x70(%rsp), %rax
addq 0x48(%rsp), %rax
movq 0x20(%rax), %r12
testq %r12, %r12
movq 0x68(%rsp), %r13
je 0x170c7
movabsq $0xe0000000e, %rax      # imm = 0xE0000000E
movq %rax, 0x88(%rsp)
movl $0x1, 0x90(%rsp)
movq %r12, 0x98(%rsp)
movaps 0x160(%rsp), %xmm1
movaps %xmm1, %xmm0
mulss 0x130(%rsp), %xmm0
cvttss2si %xmm0, %esi
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
mulss 0x120(%rsp), %xmm1
cvttss2si %xmm1, %edx
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x108(%rsp), %rdi
callq 0x170fa
movl 0x108(%rsp), %eax
movl 0x10c(%rsp), %r15d
movl 0x110(%rsp), %ecx
movq 0x118(%rsp), %r14
movl %r15d, 0xe4(%rsp)
movl %eax, 0xe0(%rsp)
movl %ecx, 0xe8(%rsp)
imull %eax, %r15d
imull %ecx, %r15d
movslq %r15d, %rbp
movl $0x4, %esi
movq %rbp, %rdi
callq 0x3250
movq %rax, %rbx
movq %rax, 0xf0(%rsp)
testl %ebp, %ebp
movss 0x3e22a(%rip), %xmm1    # 0x55264
movss 0x3dfc6(%rip), %xmm2    # 0x55008
jle 0x17063
movl %r15d, %eax
xorl %ecx, %ecx
movaps %xmm1, %xmm0
cmpltss (%r14,%rcx,4), %xmm0
andps %xmm2, %xmm0
movss %xmm0, (%rbx,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x17049
leaq 0x11b0(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x28(%rsp)
movups (%rcx), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x10(%rsp)
movdqu 0xe0(%rsp), %xmm0
movdqu %xmm0, (%rsp)
movl 0x30(%rsp), %edi
movq 0x40(%rsp), %rsi
callq 0x162c2
movq %r12, %rdi
callq 0x3040
testq %r14, %r14
je 0x170ba
movq %r14, %rdi
callq 0x3040
testq %rbx, %rbx
je 0x170c7
movq %rbx, %rdi
callq 0x3040
movq 0x78(%rsp), %rbx
incq %rbx
cmpq %r13, %rbx
jne 0x16bb6
addq $0x1178, %rsp           # imm = 0x1178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq