// File: /workspace/github_c_makefile_star2_O1/SimpleDoger[P]Darknet_CPU_Only/detector.c
// Function: validate_detector_recall
void validate_detector_recall(char *cfgfile, char *weightfile)
{
    network *net = load_network(cfgfile, weightfile, 0);
    set_batch_network(net, 1);
    fprintf(stderr, "Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
    srand(time(0));

    list *plist = get_paths("data/coco_val_5k.list");
    char **paths = (char **)list_to_array(plist);

    layer l = net->layers[net->n-1];

    int j, k;

    int m = plist->size;
    int i=0;

    float thresh = .001;
    float iou_thresh = .5;
    float nms = .4;

    int total = 0;
    int correct = 0;
    int proposals = 0;
    float avg_iou = 0;

    for(i = 0; i < m; ++i){
        char *path = paths[i];
        image orig = load_image_color(path, 0, 0);
        image sized = resize_image(orig, net->w, net->h);
        char *id = basecfg(path);
        network_predict(net, sized.data);
        int nboxes = 0;
        detection *dets = get_network_boxes(net, sized.w, sized.h, thresh, .5, 0, 1, &nboxes);
        if (nms) do_nms_obj(dets, nboxes, 1, nms);

        char labelpath[4096];
        find_replace(path, "images", "labels", labelpath);
        find_replace(labelpath, "JPEGImages", "labels", labelpath);
        find_replace(labelpath, ".jpg", ".txt", labelpath);
        find_replace(labelpath, ".JPEG", ".txt", labelpath);

        int num_labels = 0;
        box_label *truth = read_boxes(labelpath, &num_labels);
        for(k = 0; k < nboxes; ++k){
            if(dets[k].objectness > thresh){
                ++proposals;
            }
        }
        for (j = 0; j < num_labels; ++j) {
            ++total;
            box t = {truth[j].x, truth[j].y, truth[j].w, truth[j].h};
            float best_iou = 0;
            for(k = 0; k < l.w*l.h*l.n; ++k){
                float iou = box_iou(dets[k].bbox, t);
                if(dets[k].objectness > thresh && iou > best_iou){
                    best_iou = iou;
                }
            }
            avg_iou += best_iou;
            if(best_iou > iou_thresh){
                ++correct;
            }
        }

        fprintf(stderr, "%5d %5d %5d\tRPs/Img: %.2f\tIOU: %.2f%%\tRecall:%.2f%%\n", i, correct, total, (float)proposals/(i+1), avg_iou*100/total, 100.*correct/total);
        free(id);
        free_image(orig);
        free_image(sized);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10c8, %rsp           # imm = 0x10C8
xorl %ebx, %ebx
xorl %edx, %edx
callq 0x2f9e4
movq %rax, %r14
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x302d4
movq 0x5cb67(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
cvtss2sd 0x34(%r14), %xmm0
cvtss2sd 0x38(%r14), %xmm1
cvtss2sd 0x3c(%r14), %xmm2
leaq 0x4a9eb(%rip), %rsi     # 0x57e98
movb $0x3, %al
callq 0x3280
xorl %edi, %edi
callq 0x32d0
movl %eax, %edi
callq 0x3230
leaq 0x4ba53(%rip), %rdi     # 0x58f1c
callq 0x296f8
movq %rax, %r15
movq %rax, %rdi
callq 0x10fa0
movq %rax, 0x38(%rsp)
movslq (%r15), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
jle 0xd84f
movq 0x20(%r14), %rax
movslq (%r14), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x430(%rax,%rcx), %edx
imull -0x434(%rax,%rcx), %edx
imull -0x41c(%rax,%rcx), %edx
movq %rdx, 0x58(%rsp)
imulq $0x30, %rdx, %rbp
xorps %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
xorl %ecx, %ecx
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r14, 0x28(%rsp)
movl %r13d, 0x18(%rsp)
movq 0x38(%rsp), %rax
movq %rcx, 0x48(%rsp)
movq (%rax,%rcx,8), %r13
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x160b6
movl 0x90(%r14), %edx
movl 0x94(%r14), %esi
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x60(%rsp), %rdi
callq 0x1676b
movq %r13, %rdi
callq 0xe717
movq %rax, 0x40(%rsp)
movq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x307ea
andl $0x0, 0x24(%rsp)
movl 0x60(%rsp), %esi
movl 0x64(%rsp), %edx
movq %r14, %rdi
movss 0x48fcd(%rip), %xmm0    # 0x56584
movss 0x45c75(%rip), %xmm1    # 0x53234
xorl %ecx, %ecx
pushq $0x1
popq %r8
leaq 0x24(%rsp), %r9
callq 0x30bbb
movq %rax, %r15
movl 0x24(%rsp), %esi
movq %rax, %rdi
pushq $0x1
popq %rdx
movss 0x4b6d8(%rip), %xmm0    # 0x58cbc
callq 0x3655c
movq %r13, %rdi
leaq 0x4935c(%rip), %rsi     # 0x5694f
leaq 0x4935c(%rip), %rdx     # 0x56956
leaq 0xc0(%rsp), %r13
movq %r13, %rcx
callq 0xe842
movq %r13, %rdi
leaq 0x49349(%rip), %rsi     # 0x5695d
leaq 0x4933b(%rip), %rdx     # 0x56956
movq %r13, %rcx
callq 0xe842
movq %r13, %rdi
leaq 0x48127(%rip), %rsi     # 0x55754
leaq 0x4b185(%rip), %rdx     # 0x587b9
movq %r13, %rcx
callq 0xe842
movq %r13, %rdi
leaq 0x49327(%rip), %rsi     # 0x5696d
leaq 0x4b16c(%rip), %rdx     # 0x587b9
movq %r13, %rcx
callq 0xe842
andl $0x0, 0x20(%rsp)
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x29b2e
movq %rax, 0x50(%rsp)
movslq 0x24(%rsp), %rax
testq %rax, %rax
jle 0xd6a4
imulq $0x30, %rax, %rax
xorl %ecx, %ecx
movss 0x48f00(%rip), %xmm1    # 0x56584
movl 0x18(%rsp), %esi
movss 0x28(%r15,%rcx), %xmm0
xorl %edx, %edx
ucomiss %xmm1, %xmm0
seta %dl
addl %edx, %esi
addq $0x30, %rcx
cmpq %rcx, %rax
jne 0xd688
jmp 0xd6a8
movl 0x18(%rsp), %esi
movl %esi, 0x18(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0xd792
xorl %r13d, %r13d
movq %rbx, %r14
cmpl $0x0, 0x58(%rsp)
jle 0xd75a
imulq $0x24, %r13, %rax
movq 0x50(%rsp), %rcx
movsd 0x4(%rcx,%rax), %xmm0
movaps %xmm0, 0xa0(%rsp)
movsd 0xc(%rcx,%rax), %xmm0
movaps %xmm0, 0x90(%rsp)
xorps %xmm1, %xmm1
xorl %ebx, %ebx
movaps %xmm1, 0xb0(%rsp)
movsd (%r15,%rbx), %xmm0
movsd 0x8(%r15,%rbx), %xmm1
movaps 0xa0(%rsp), %xmm2
movaps 0x90(%rsp), %xmm3
callq 0x36754
movaps 0xb0(%rsp), %xmm4
movaps %xmm4, %xmm1
cmpltps %xmm0, %xmm1
movss 0x28(%r15,%rbx), %xmm2
movss 0x48e4a(%rip), %xmm3    # 0x56584
cmpltps %xmm2, %xmm3
andps %xmm1, %xmm3
movd %xmm3, %eax
testb $0x1, %al
jne 0xd74c
movaps %xmm4, %xmm0
addq $0x30, %rbx
movaps %xmm0, %xmm1
cmpq %rbx, %rbp
jne 0xd6f2
jmp 0xd75d
xorps %xmm0, %xmm0
movq %r14, %rbx
incl %ebx
movss 0x1c(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x1c(%rsp)
xorl %eax, %eax
ucomiss 0x45ab9(%rip), %xmm0    # 0x53234
seta %al
addl %eax, %r12d
incq %r13
movslq 0x20(%rsp), %rax
cmpq %rax, %r13
jl 0xd6ba
movl 0x18(%rsp), %r13d
cvtsi2ss %r13d, %xmm0
movq 0x48(%rsp), %rdx
leaq 0x1(%rdx), %r15
cvtsi2ss %r15d, %xmm1
movq 0x5c847(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x1c(%rsp), %xmm1
mulss 0x45a7a(%rip), %xmm1    # 0x53244
cvtsi2ss %ebx, %xmm2
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
cvtsi2sd %r12d, %xmm2
mulsd 0x4a9cd(%rip), %xmm2    # 0x581b0
cvtsi2sd %ebx, %xmm3
divsd %xmm3, %xmm2
leaq 0x4b7c1(%rip), %rsi     # 0x58fb3
movl %r12d, %ecx
movl %ebx, %r8d
movb $0x3, %al
callq 0x3280
movq 0x40(%rsp), %rdi
callq 0x3040
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
movq %r15, %rcx
cmpq 0x30(%rsp), %r15
movq 0x28(%rsp), %r14
jne 0xd533
addq $0x10c8, %rsp           # imm = 0x10C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq