// File: /workspace/github_c_makefile_star2_O2/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 $0x1148, %rsp           # imm = 0x1148
movq %rdx, 0x60(%rsp)
movss %xmm0, 0x5c(%rsp)
movq %rdi, 0x38(%rsp)
leaq 0x1180(%rsp), %rax
movq (%rax), %rax
movq %rax, %xmm3
pshufd $0x55, %xmm3, %xmm0     # xmm0 = xmm3[1,1,1,1]
movd %xmm0, %edx
cvtdq2pd %xmm3, %xmm1
movapd %xmm1, 0x110(%rsp)
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movsd 0x424c5(%rip), %xmm2    # 0x4e460
mulsd %xmm1, %xmm2
cvttsd2si %xmm2, %edi
decl %eax
movq %rax, 0x98(%rsp)
decl %edx
movl %edx, 0x50(%rsp)
mulsd 0x424ad(%rip), %xmm1    # 0x4e468
cvttsd2si %xmm1, %eax
movl %eax, 0x4c(%rsp)
movdqa %xmm3, 0x120(%rsp)
cvtdq2ps %xmm3, %xmm1
movaps %xmm1, 0x100(%rsp)
cvtdq2ps %xmm0, %xmm0
movaps %xmm0, 0xf0(%rsp)
xorl %eax, %eax
testl %r8d, %r8d
movl $0x0, %ebp
movl %r8d, 0x54(%rsp)
cmovgl %r8d, %ebp
testl %esi, %esi
cmovlel %eax, %esi
movq %rsi, 0xa8(%rsp)
xorl %ebx, %ebx
movq %rcx, 0xa0(%rsp)
movq %rdi, 0x90(%rsp)
cmpq 0xa8(%rsp), %rbx
je 0xc3cc
movl $0x1000, %edx           # imm = 0x1000
leaq 0x140(%rsp), %rdi
xorl %esi, %esi
callq 0x31c0
movq %rbx, 0xb8(%rsp)
imulq $0x30, %rbx, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0xb0(%rsp)
leaq (%rax,%rcx), %r12
addq $0x18, %r12
xorl %r13d, %r13d
pushq $-0x1
popq %r14
movq %r12, 0x40(%rsp)
cmpq %r13, %rbp
je 0xc116
movq (%r12), %r15
movss (%r15,%r13,4), %xmm0
ucomiss 0x5c(%rsp), %xmm0
jbe 0xc10e
testl %r14d, %r14d
js 0xc0cf
movl %r14d, %r12d
movq %rbp, %r14
leaq 0x140(%rsp), %rbp
movq %rbp, %rdi
callq 0x3140
movw $0x202c, 0x140(%rsp,%rax) # imm = 0x202C
movb $0x0, 0x142(%rsp,%rax)
movq 0x60(%rsp), %rax
movq (%rax,%r13,8), %rbx
movq %rbp, %rdi
movq %r14, %rbp
movl %r12d, %r14d
movq 0x40(%rsp), %r12
movq %rbx, %rsi
callq 0x3410
jmp 0xc0eb
movq 0x60(%rsp), %rax
movq (%rax,%r13,8), %rbx
leaq 0x140(%rsp), %rdi
movq %rbx, %rsi
callq 0x3410
movl %r13d, %r14d
movss (%r15,%r13,4), %xmm0
mulss 0x4014b(%rip), %xmm0    # 0x4c244
cvtss2sd %xmm0, %xmm0
leaq 0x4259f(%rip), %rdi     # 0x4e6a3
movq %rbx, %rsi
movb $0x1, %al
callq 0x3160
incq %r13
jmp 0xc063
testl %r14d, %r14d
js 0xc3bc
imull $0x1e241, %r14d, %eax   # imm = 0x1E241
cltd
movl 0x54(%rsp), %r14d
idivl %r14d
movl %edx, %ebx
pushq $0x2
popq %rdi
movl %edx, %esi
movl %r14d, %edx
callq 0xb250
movss %xmm0, 0x40(%rsp)
pushq $0x1
popq %rdi
movl %ebx, %esi
movl %r14d, %edx
callq 0xb250
movss %xmm0, 0x58(%rsp)
xorl %edi, %edi
movl %ebx, %esi
movl %r14d, %edx
callq 0xb250
movaps %xmm0, %xmm2
movss 0x40(%rsp), %xmm0
movss %xmm0, 0x84(%rsp)
movss 0x58(%rsp), %xmm1
movss %xmm1, 0x88(%rsp)
movss %xmm2, 0x8c(%rsp)
movq 0x38(%rsp), %rax
movq 0xb0(%rsp), %r13
movsd 0x8(%rax,%r13), %xmm3
cvtps2pd (%rax,%r13), %xmm5
movaps %xmm3, 0x130(%rsp)
cvtps2pd %xmm3, %xmm6
mulpd 0x400e7(%rip), %xmm6    # 0x4c2a0
movapd %xmm5, %xmm3
subpd %xmm6, %xmm3
movapd 0x110(%rsp), %xmm4
mulpd %xmm4, %xmm3
cvttsd2si %xmm3, %r12d
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
cvttsd2si %xmm3, %ebx
addpd %xmm5, %xmm6
mulpd %xmm4, %xmm6
cvttpd2dq %xmm6, %xmm3
testl %r12d, %r12d
movl $0x0, %ecx
cmovlel %ecx, %r12d
movdqa 0x120(%rsp), %xmm4
pcmpgtd %xmm3, %xmm4
pshufd $0x50, %xmm4, %xmm4     # xmm4 = xmm4[0,0,1,1]
movmskpd %xmm4, %eax
movd %xmm3, %edx
testb $0x1, %al
cmovel 0x98(%rsp), %edx
testl %ebx, %ebx
cmovlel %ecx, %ebx
pshufd $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
movd %xmm3, %ecx
testb $0x2, %al
cmovel 0x50(%rsp), %ecx
leaq 0x1180(%rsp), %r14
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm3
movups %xmm3, (%rsp)
movl %r12d, %edi
movl %ebx, %esi
movq 0x90(%rsp), %r15
movl %r15d, %r8d
callq 0xbd0b
movq 0xa0(%rsp), %rsi
testq %rsi, %rsi
je 0xc2c0
leaq 0x68(%rsp), %rdi
leaq 0x140(%rsp), %rdx
movl 0x4c(%rsp), %ecx
callq 0xb976
leal (%rbx,%r15), %edi
movq 0x78(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x68(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
movl %r12d, %esi
leaq 0x84(%rsp), %rdx
callq 0xba92
movq 0x78(%rsp), %rdi
callq 0x3040
addq 0x38(%rsp), %r13
movq 0x20(%r13), %r13
testq %r13, %r13
je 0xc3bc
movabsq $0xe0000000e, %rax      # imm = 0xE0000000E
movq %rax, 0x68(%rsp)
movl $0x1, 0x70(%rsp)
movq %r13, 0x78(%rsp)
movaps 0x130(%rsp), %xmm1
movaps %xmm1, %xmm0
mulss 0x100(%rsp), %xmm0
cvttss2si %xmm0, %esi
shufps $0x55, %xmm1, %xmm1     # xmm1 = xmm1[1,1,1,1]
mulss 0xf0(%rsp), %xmm1
cvttss2si %xmm1, %edx
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x68(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xd8(%rsp), %rdi
callq 0xc3ee
movq 0xe8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xd8(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xc0(%rsp), %rdi
movss 0x3fed4(%rip), %xmm0    # 0x4c234
callq 0xc85c
movq 0x10(%r14), %rax
movq %rax, 0x28(%rsp)
movups (%r14), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xc0(%rsp), %xmm0
movups %xmm0, (%rsp)
movl %r12d, %edi
movl %ebx, %esi
callq 0xb8af
movq %r13, %rdi
callq 0x3040
movq 0xe8(%rsp), %rdi
callq 0x3040
movq 0xd0(%rsp), %rdi
callq 0x3040
movq 0xb8(%rsp), %rbx
incq %rbx
jmp 0xc014
addq $0x1148, %rsp           # imm = 0x1148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq