// File: /workspace/github_c_makefile_star2_O2/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 $0x548, %rsp            # imm = 0x548
xorl %edx, %edx
callq 0x22658
movq %rax, %rbx
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x22f00
movq 0x1f61a(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
cvtss2sd 0x34(%rbx), %xmm0
cvtss2sd 0x38(%rbx), %xmm1
cvtss2sd 0x3c(%rbx), %xmm2
leaq 0xc4d9(%rip), %rsi      # 0x50ed0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
leaq 0xd6ce(%rip), %rdi      # 0x520e1
callq 0x1c8c8
movq %rax, 0xb8(%rsp)
movq %rax, %rdi
callq 0x72f5
movq %rax, 0xd8(%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, 0xc0(%rsp)
movl -0x3a4(%rax,%rcx), %ebx
movslq %ebx, %r14
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x3250
testl %r14d, %r14d
movl $0x0, %ebp
movl %ebx, 0xe8(%rsp)
cmovgl %ebx, %ebp
movq %rax, 0x108(%rsp)
shlq $0x3, %rbp
leaq 0xd72a(%rip), %r14      # 0x521c6
leaq 0xd4e5(%rip), %r15      # 0x51f88
leaq 0x140(%rsp), %r12
leaq 0xd735(%rip), %r13      # 0x521e7
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0x44af6
leaq 0x1fc40(%rip), %rax     # 0x64700
movq (%rbx,%rax), %r8
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x3180
movq %r12, %rdi
movq %r13, %rsi
callq 0x3390
movq 0x108(%rsp), %rcx
movq %rax, (%rcx,%rbx)
addq $0x8, %rbx
jmp 0x44ab4
movq 0xb8(%rsp), %rax
movslq (%rax), %rax
movq %rax, 0xb8(%rsp)
pushq $0x8
popq %rbp
pushq $0x18
popq %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0xf0(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0xd0(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, %r14
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, %r12
movq %rbp, %rdi
movq %rbp, %rsi
callq 0x3250
movq %rax, 0xe0(%rsp)
leaq 0x140(%rsp), %r13
xorl %ebx, %ebx
movl $0xa8, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x31c0
movq 0xf8(%rsp), %rax
movq 0x90(%rax), %rax
movq %rax, 0x28(%r13)
movl $0x4, 0x98(%r13)
pushq $0x15
popq %r15
movq %r14, 0x118(%rsp)
movq %r12, 0x110(%rsp)
cmpq $0x8, %rbx
je 0x44c03
movq 0xd8(%rsp), %rax
movq (%rax,%rbx,8), %rax
movq %rax, 0x150(%rsp)
movq %r14, 0x1c8(%rsp)
movq %r12, 0x1d0(%rsp)
movq %r15, %rcx
movq %rsp, %rdi
movq %r13, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x20b03
movq 0xe0(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
addq $0x18, %r12
addq $0x18, %r14
jmp 0x44baf
xorl %edi, %edi
callq 0x32c0
movq %rax, 0x120(%rsp)
movq 0xb8(%rsp), %rax
addl $0x8, %eax
movl 0xb4(%rsp), %ecx
movl 0xc0(%rsp), %edx
imull %edx, %ecx
imull %edx, %ecx
movl %ecx, 0xb4(%rsp)
cltq
movq %rax, 0x128(%rsp)
movq 0xd8(%rsp), %rax
addq $0x40, %rax
movq %rax, 0x100(%rsp)
movq $0x0, 0xc0(%rsp)
movq 0xf0(%rsp), %r12
movq 0x1f387(%rip), %rax     # 0x63ff8
movq (%rax), %r15
cmpq 0x128(%rsp), %rbp
jge 0x44f06
movq %r15, %rdi
leaq 0xc7c5(%rip), %rsi      # 0x51451
movl %ebp, %edx
xorl %eax, %eax
callq 0x3270
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0xd0(%rsp), %r15
cmpq $0x7, %r14
ja 0x44d0f
movq 0xc0(%rsp), %rax
addq %r14, %rax
cmpq 0xb8(%rsp), %rax
jge 0x44d0f
movq 0xe0(%rsp), %rax
movq (%rax,%r14,8), %rdi
xorl %esi, %esi
callq 0x3470
movq 0x118(%rsp), %rcx
movq 0x10(%rcx,%rbx), %rax
movq %rax, 0x10(%r12,%rbx)
movups (%rcx,%rbx), %xmm0
movups %xmm0, (%r12,%rbx)
movq 0x110(%rsp), %rcx
movq 0x10(%rcx,%rbx), %rax
movq %rax, 0x10(%r15,%rbx)
movups (%rcx,%rbx), %xmm0
movups %xmm0, (%r15,%rbx)
incq %r14
addq $0x18, %rbx
jmp 0x44ca2
movq 0x118(%rsp), %rbx
movq 0x110(%rsp), %r14
xorl %r15d, %r15d
cmpq $0x8, %r15
je 0x44d89
leaq (%r15,%rbp), %rax
cmpq 0xb8(%rsp), %rax
jge 0x44d89
movq 0x100(%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x150(%rsp)
movq %rbx, 0x1c8(%rsp)
movq %r14, 0x1d0(%rsp)
pushq $0x15
popq %rcx
movq %rsp, %rdi
leaq 0x140(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x20b03
movq 0xe0(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
addq $0x18, %r14
addq $0x18, %rbx
jmp 0x44d22
movq 0xc0(%rsp), %rcx
xorl %r14d, %r14d
movq 0xd0(%rsp), %r15
movq %rbp, 0x130(%rsp)
cmpq $0xc0, %r14
je 0x44eeb
cmpq 0xb8(%rsp), %rcx
jge 0x44eeb
movq 0xd8(%rsp), %rax
movq (%rax,%rcx,8), %rdi
movq %rcx, 0x138(%rsp)
callq 0x41c8
movq %rax, %r13
movq 0x10(%r15,%r14), %rsi
movq 0xf8(%rsp), %rbx
movq %rbx, %rdi
callq 0x233e2
movl (%r12,%r14), %ebp
movl 0x4(%r12,%r14), %edx
movl %edx, 0xec(%rsp)
andl $0x0, 0xcc(%rsp)
xorps %xmm1, %xmm1
movq %rbx, %rdi
movl %ebp, %esi
movss 0xa78c(%rip), %xmm0     # 0x4f5a4
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0xcc(%rsp), %r9
callq 0x2379c
movq %rax, %rbx
movq %rax, %rdi
movl 0xb4(%rsp), %r12d
movl %r12d, %esi
movl 0xe8(%rsp), %r15d
movl %r15d, %edx
movss 0x73e6(%rip), %xmm0     # 0x4c234
callq 0x2b219
movq %rbx, (%rsp)
movq 0x108(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
movq 0xf0(%rsp), %r12
movl %r15d, %ecx
movq 0xd0(%rsp), %r15
movl %ebp, %r8d
movq 0x130(%rsp), %rbp
movl 0xec(%rsp), %r9d
callq 0x44845
movl 0xcc(%rsp), %esi
movq %rbx, %rdi
callq 0x237fe
movq %r13, %rdi
callq 0x3040
movq 0x10(%r12,%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r12,%r14), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x10(%r15,%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r15,%r14), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x138(%rsp), %rcx
addq $0x18, %r14
incq %rcx
jmp 0x44da4
addq $0x8, %rbp
addq $0x8, 0xc0(%rsp)
addq $0x40, 0x100(%rsp)
jmp 0x44c6a
xorl %edi, %edi
callq 0x32c0
subq 0x120(%rsp), %rax
cvtsi2sd %rax, %xmm0
leaq 0xd045(%rip), %rsi      # 0x51f66
movq %r15, %rdi
movb $0x1, %al
callq 0x3270
addq $0x548, %rsp            # imm = 0x548
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq