// File: /workspace/github_c_makefile_star2_O1/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 0x2f9e4
movq %rax, %rbx
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x302d4
movq 0x5e760(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
cvtss2sd 0x34(%rbx), %xmm0
cvtss2sd 0x38(%rbx), %xmm1
cvtss2sd 0x3c(%rbx), %xmm2
leaq 0x4c5e7(%rip), %rsi     # 0x57e98
movb $0x3, %al
callq 0x3280
xorl %edi, %edi
callq 0x32d0
movl %eax, %edi
callq 0x3230
leaq 0x4d7fc(%rip), %rdi     # 0x590c9
callq 0x296f8
movq %rax, 0xb8(%rsp)
movq %rax, %rdi
callq 0x10fa0
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 0x3260
movq %rax, %r14
movq %rbx, 0xf0(%rsp)
testq %rbx, %rbx
jle 0xb9a3
movq 0xf0(%rsp), %rax
leaq (,%rax,8), %rbp
leaq 0x4d61a(%rip), %r15     # 0x58f70
leaq 0x150(%rsp), %r12
leaq 0x4d86a(%rip), %r13     # 0x591cf
xorl %ebx, %ebx
leaq 0x5ed92(%rip), %rax     # 0x6a700
movq (%rbx,%rax), %r8
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
leaq 0x4d82d(%rip), %rdx     # 0x591ae
movq %r15, %rcx
xorl %eax, %eax
callq 0x3190
movq %r12, %rdi
movq %r13, %rsi
callq 0x33a0
movq %rax, (%r14,%rbx)
addq $0x8, %rbx
cmpq %rbx, %rbp
jne 0xb967
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 0x3260
movq %rax, 0x120(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, 0xb8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, %r13
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, %r12
movq %r14, %rdi
movq %r14, %rsi
callq 0x3260
movq %rax, %rbp
leaq 0x150(%rsp), %r14
xorl %ebx, %ebx
movl $0xa8, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x31d0
movq 0xf8(%rsp), %rcx
movl 0x94(%rcx), %eax
movl %eax, 0x2c(%r14)
movl 0x90(%rcx), %eax
movl %eax, 0x28(%r14)
movl $0x4, 0x98(%r14)
pushq $0x15
popq %r15
movq %r13, 0x118(%rsp)
movq %r13, %r14
movq %r12, 0x110(%rsp)
movq 0xc8(%rsp), %r13
movq (%r13,%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 0x2dc84
movq %rax, (%rbp,%rbx,8)
incq %rbx
addq $0x18, %r12
addq $0x18, %r14
cmpq $0x8, %rbx
jne 0xba73
movq %rbp, 0x108(%rsp)
xorl %edi, %edi
callq 0x32d0
movq %rax, 0x128(%rsp)
movq 0xe8(%rsp), %r12
testl %r12d, %r12d
pushq $0x8
popq %rbp
jle 0xbdd5
movl 0xb4(%rsp), %eax
movl 0xd0(%rsp), %ecx
imull %ecx, %eax
imull %ecx, %eax
movl %eax, 0xb4(%rsp)
movq %r13, %rax
addq $0x40, %rax
movq %rax, 0x100(%rsp)
xorl %ebx, %ebx
movl %r12d, %edx
movl %edx, 0xdc(%rsp)
movl %edx, %eax
imulq $0x18, %rax, %rax
movq %rax, 0x148(%rsp)
movq 0x5e4c6(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
leaq 0x4c905(%rip), %rsi     # 0x58441
movl %ebp, %edx
xorl %eax, %eax
callq 0x3280
movq %rbx, 0x130(%rsp)
movq 0x108(%rsp), %r14
xorl %r15d, %r15d
cmpq %r12, %rbx
jge 0xbbc3
movq (%r14), %rdi
xorl %esi, %esi
callq 0x3480
movq 0x118(%rsp), %rdx
movq 0x10(%rdx,%r15), %rax
movq 0x120(%rsp), %rcx
movq %rax, 0x10(%rcx,%r15)
movups (%rdx,%r15), %xmm0
movups %xmm0, (%rcx,%r15)
movq 0x110(%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 0xbb58
movq 0x118(%rsp), %rbx
movq 0x110(%rsp), %r14
xorl %r15d, %r15d
leaq (%r15,%rbp), %rax
cmpq %r12, %rax
jae 0xbc36
movq 0x100(%rsp), %rax
movq (%rax,%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 0x2dc84
movq 0x108(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
addq $0x18, %r14
addq $0x18, %rbx
cmpq $0x8, %r15
jne 0xbbd6
movq %rbp, 0x138(%rsp)
movq %r13, 0xc8(%rsp)
xorl %r14d, %r14d
cmpq %r14, 0x148(%rsp)
je 0xbd8d
movq (%r13), %rdi
movq %r13, 0xd0(%rsp)
callq 0xe717
movq %rax, %r12
movq 0xb8(%rsp), %rax
movq 0x10(%rax,%r14), %rsi
movq 0xf8(%rsp), %rbx
movq %rbx, %rdi
callq 0x307ea
movq 0x120(%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 0x4a8c6(%rip), %xmm0    # 0x56584
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0xc4(%rsp), %r9
callq 0x30bbb
movq %rax, %rbx
movq %rax, %rdi
movl 0xb4(%rsp), %ebp
movl %ebp, %esi
movq 0xf0(%rsp), %r15
movl %r15d, %edx
movss 0x47542(%rip), %xmm0    # 0x53234
callq 0x36827
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 0x4cf0b
movl 0xc4(%rsp), %esi
movq %rbx, %rdi
callq 0x30c1d
movq %r12, %rdi
callq 0x3040
movq 0x10(%r13,%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r13,%r14), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
movq 0xb8(%rsp), %rcx
movq 0x10(%rcx,%r14), %rax
movq %rax, 0x10(%rsp)
movups (%rcx,%r14), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
movq 0xd0(%rsp), %r13
addq $0x18, %r14
addq $0x8, %r13
cmpq $0xc0, %r14
jne 0xbc49
movq 0x138(%rsp), %rcx
leaq 0x8(%rcx), %rbp
movl 0xdc(%rsp), %edx
addl $-0x8, %edx
movq 0x130(%rsp), %rbx
addq $0x8, %rbx
addq $0x40, 0x100(%rsp)
movq 0xc8(%rsp), %r13
addq $0x40, %r13
movq 0xe8(%rsp), %r12
cmpq %r12, %rcx
jb 0xbb16
movq 0x5e21c(%rip), %rax     # 0x69ff8
movq (%rax), %rbx
xorl %edi, %edi
callq 0x32d0
subq 0x128(%rsp), %rax
cvtsi2sd %rax, %xmm0
leaq 0x4d154(%rip), %rsi     # 0x58f4e
movq %rbx, %rdi
movb $0x1, %al
callq 0x3280
addq $0x558, %rsp            # imm = 0x558
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq