// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/yolo.c
// Function: validate_yolo
void validate_yolo(char *cfg, char *weights)
{
    network *net = load_network(cfg, weights, 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));

    char *base = "results/comp4_det_test_";
    //list *plist = get_paths("data/voc.2007.test");
    list *plist = get_paths("/home/pjreddie/data/voc/2007_test.txt");
    //list *plist = get_paths("data/voc.2012.test");
    char **paths = (char **)list_to_array(plist);

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

    int j;
    FILE **fps = calloc(classes, sizeof(FILE *));
    for(j = 0; j < classes; ++j){
        char buff[1024];
        snprintf(buff, 1024, "%s%s.txt", base, voc_names[j]);
        fps[j] = fopen(buff, "w");
    }

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

    float thresh = .001;
    int nms = 1;
    float iou_thresh = .5;

    int nthreads = 8;
    image *val = calloc(nthreads, sizeof(image));
    image *val_resized = calloc(nthreads, sizeof(image));
    image *buf = calloc(nthreads, sizeof(image));
    image *buf_resized = calloc(nthreads, sizeof(image));
    pthread_t *thr = calloc(nthreads, sizeof(pthread_t));

    load_args args = {0};
    args.w = net->w;
    args.h = net->h;
    args.type = IMAGE_DATA;

    for(t = 0; t < nthreads; ++t){
        args.path = paths[i+t];
        args.im = &buf[t];
        args.resized = &buf_resized[t];
        thr[t] = load_data_in_thread(args);
    }
    time_t start = time(0);
    for(i = nthreads; i < m+nthreads; i += nthreads){
        fprintf(stderr, "%d\n", i);
        for(t = 0; t < nthreads && i+t-nthreads < m; ++t){
            pthread_join(thr[t], 0);
            val[t] = buf[t];
            val_resized[t] = buf_resized[t];
        }
        for(t = 0; t < nthreads && i+t < m; ++t){
            args.path = paths[i+t];
            args.im = &buf[t];
            args.resized = &buf_resized[t];
            thr[t] = load_data_in_thread(args);
        }
        for(t = 0; t < nthreads && i+t-nthreads < m; ++t){
            char *path = paths[i+t-nthreads];
            char *id = basecfg(path);
            float *X = val_resized[t].data;
            network_predict(net, X);
            int w = val[t].w;
            int h = val[t].h;
            int nboxes = 0;
            detection *dets = get_network_boxes(net, w, h, thresh, 0, 0, 0, &nboxes);
            if (nms) do_nms_sort(dets, l.side*l.side*l.n, classes, iou_thresh);
            print_yolo_detections(fps, id, l.side*l.side*l.n, classes, w, h, dets);
            free_detections(dets, nboxes);
            free(id);
            free_image(val[t]);
            free_image(val_resized[t]);
        }
    }
    fprintf(stderr, "Total Detection Time: %f Seconds\n", (double)(time(0) - start));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x558, %rsp            # imm = 0x558
xorl %edx, %edx
callq 0x316bc
movq %rax, %rbx
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x320a7
movq 0x5ffa7(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
cvtss2sd 0x34(%rbx), %xmm0
cvtss2sd 0x38(%rbx), %xmm1
cvtss2sd 0x3c(%rbx), %xmm2
leaq 0x4df66(%rip), %rsi     # 0x59fd0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
leaq 0x4f19b(%rip), %rdi     # 0x5b221
callq 0x2af38
movq %rax, 0xb8(%rsp)
movq %rax, %rdi
callq 0x11928
movq %rax, 0xc8(%rsp)
movq 0x20(%rbx), %rax
movq %rbx, 0xf8(%rsp)
movslq (%rbx), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x41c(%rax,%rcx), %edx
movl %edx, 0xb4(%rsp)
movl -0x40c(%rax,%rcx), %edx
movl %edx, 0xd0(%rsp)
movslq -0x3a4(%rax,%rcx), %rbx
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x3250
movq %rax, %r14
movq %rbx, 0xf0(%rsp)
testq %rbx, %rbx
jle 0xc15c
movq 0xf0(%rsp), %rax
leaq (,%rax,8), %rbp
leaq 0x4efb9(%rip), %r15     # 0x5b0c8
leaq 0x150(%rsp), %r12
leaq 0x4f209(%rip), %r13     # 0x5b327
xorl %ebx, %ebx
leaq 0x605c9(%rip), %rax     # 0x6c6f0
movq (%rbx,%rax), %r8
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
leaq 0x4f1cc(%rip), %rdx     # 0x5b306
movq %r15, %rcx
xorl %eax, %eax
callq 0x3180
movq %r12, %rdi
movq %r13, %rsi
callq 0x3390
movq %rax, (%r14,%rbx)
addq $0x8, %rbx
cmpq %rbx, %rbp
jne 0xc120
movq %r14, 0x140(%rsp)
movq 0xb8(%rsp), %rax
movl (%rax), %eax
movq %rax, 0xe8(%rsp)
pushq $0x8
popq %r14
pushq $0x18
popq %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0x118(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0xb8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, %rbp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, %r12
movq %r14, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, %r13
leaq 0x150(%rsp), %r14
xorl %ebx, %ebx
movl $0xa8, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x31c0
movq 0xf8(%rsp), %rax
movq 0x90(%rax), %rax
movq %rax, 0x28(%r14)
movl $0x4, 0x98(%r14)
pushq $0x15
popq %r15
movq %rbp, 0x110(%rsp)
movq %rbp, %r14
movq %r12, 0x108(%rsp)
movq 0xc8(%rsp), %rbp
movq (%rbp,%rbx,8), %rax
movq %rax, 0x160(%rsp)
movq %r14, 0x1d8(%rsp)
movq %r12, 0x1e0(%rsp)
movq %r15, %rcx
movq %rsp, %rdi
leaq 0x150(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq %rax, (%r13,%rbx,8)
incq %rbx
addq $0x18, %r12
addq $0x18, %r14
cmpq $0x8, %rbx
jne 0xc223
movq %r13, 0x100(%rsp)
xorl %edi, %edi
callq 0x32c0
movq %rax, 0x120(%rsp)
movq 0xe8(%rsp), %r12
testl %r12d, %r12d
pushq $0x8
popq %rbp
jle 0xc582
movl 0xb4(%rsp), %eax
movl 0xd0(%rsp), %ecx
imull %ecx, %eax
imull %ecx, %eax
movl %eax, 0xb4(%rsp)
movq 0xc8(%rsp), %r13
addq $0x40, %r13
xorl %ebx, %ebx
movl %r12d, %edx
movl %edx, 0xdc(%rsp)
movl %edx, %eax
imulq $0x18, %rax, %rax
movq %rax, 0x148(%rsp)
movq 0x5fd19(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
leaq 0x4e2b0(%rip), %rsi     # 0x5a599
movl %ebp, %edx
xorl %eax, %eax
callq 0x3270
movq %rbx, 0x128(%rsp)
movq 0x100(%rsp), %r14
xorl %r15d, %r15d
cmpq %r12, %rbx
jge 0xc370
movq (%r14), %rdi
xorl %esi, %esi
callq 0x3470
movq 0x110(%rsp), %rdx
movq 0x10(%rdx,%r15), %rax
movq 0x118(%rsp), %rcx
movq %rax, 0x10(%rcx,%r15)
movups (%rdx,%r15), %xmm0
movups %xmm0, (%rcx,%r15)
movq 0x108(%rsp), %rax
movups (%rax,%r15), %xmm0
movq 0xb8(%rsp), %rcx
movups %xmm0, (%rcx,%r15)
movq 0x10(%rax,%r15), %rax
movq %rax, 0x10(%rcx,%r15)
addq $0x18, %r15
addq $0x8, %r14
incq %rbx
cmpq $0xc0, %r15
jne 0xc305
movq 0x110(%rsp), %rbx
movq 0x108(%rsp), %r14
xorl %r15d, %r15d
leaq (%r15,%rbp), %rax
cmpq %r12, %rax
jae 0xc3dc
movq (%r13,%r15,8), %rax
movq %rax, 0x160(%rsp)
movq %rbx, 0x1d8(%rsp)
movq %r14, 0x1e0(%rsp)
pushq $0x15
popq %rcx
movq %rsp, %rdi
leaq 0x150(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq 0x100(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
addq $0x18, %r14
addq $0x18, %rbx
cmpq $0x8, %r15
jne 0xc383
movq %r13, 0x130(%rsp)
movq %rbp, 0x138(%rsp)
movq 0xc8(%rsp), %rax
xorl %r14d, %r14d
cmpq %r14, 0x148(%rsp)
je 0xc53a
movq (%rax), %rdi
movq %rax, 0xd0(%rsp)
callq 0xef02
movq %rax, %r12
movq 0xb8(%rsp), %rax
movq 0x10(%rax,%r14), %rsi
movq 0xf8(%rsp), %rbx
movq %rbx, %rdi
callq 0x32690
movq 0x118(%rsp), %r13
movl (%r13,%r14), %esi
movl %esi, 0xe0(%rsp)
movl 0x4(%r13,%r14), %edx
movl %edx, 0xe4(%rsp)
andl $0x0, 0xc4(%rsp)
xorps %xmm1, %xmm1
movq %rbx, %rdi
movss 0x4c1e9(%rip), %xmm0    # 0x58654
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0xc4(%rsp), %r9
callq 0x32a67
movq %rax, %rbx
movq %rax, %rdi
movl 0xb4(%rsp), %ebp
movl %ebp, %esi
movq 0xf0(%rsp), %r15
movl %r15d, %edx
movss 0x48dc5(%rip), %xmm0    # 0x55264
callq 0x38a2a
movq %rbx, (%rsp)
movq 0x140(%rsp), %rdi
movq %r12, %rsi
movl %ebp, %edx
movl %r15d, %ecx
movl 0xe0(%rsp), %r8d
movl 0xe4(%rsp), %r9d
callq 0x4f1c4
movl 0xc4(%rsp), %esi
movq %rbx, %rdi
callq 0x32ac9
movq %r12, %rdi
callq 0x3040
movq 0x10(%r13,%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r13,%r14), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0xb8(%rsp), %rcx
movq 0x10(%rcx,%r14), %rax
movq %rax, 0x10(%rsp)
movups (%rcx,%r14), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0xd0(%rsp), %rax
addq $0x18, %r14
addq $0x8, %rax
cmpq $0xc0, %r14
jne 0xc3f7
movq 0x138(%rsp), %rcx
leaq 0x8(%rcx), %rbp
movl 0xdc(%rsp), %edx
addl $-0x8, %edx
movq 0x128(%rsp), %rbx
addq $0x8, %rbx
movq 0x130(%rsp), %r13
addq $0x40, %r13
addq $0x40, 0xc8(%rsp)
movq 0xe8(%rsp), %r12
cmpq %r12, %rcx
jb 0xc2c3
movq 0x5fa6f(%rip), %rax     # 0x6bff8
movq (%rax), %rbx
xorl %edi, %edi
callq 0x32c0
subq 0x120(%rsp), %rax
cvtsi2sd %rax, %xmm0
leaq 0x4eaff(%rip), %rsi     # 0x5b0a6
movq %rbx, %rdi
movb $0x1, %al
callq 0x3270
addq $0x558, %rsp            # imm = 0x558
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq