// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/detector.c
// Function: validate_detector
void validate_detector(char *datacfg, char *cfgfile, char *weightfile, char *outfile)
{
    int j;
    list *options = read_data_cfg(datacfg);
    char *valid_images = option_find_str(options, "valid", "data/train.list");
    char *name_list = option_find_str(options, "names", "data/names.list");
    char *prefix = option_find_str(options, "results", "results");
    char **names = get_labels(name_list);
    char *mapf = option_find_str(options, "map", 0);
    int *map = 0;
    if (mapf) map = read_map(mapf);

    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(valid_images);
    char **paths = (char **)list_to_array(plist);

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

    char buff[1024];
    char *type = option_find_str(options, "eval", "voc");
    FILE *fp = 0;
    FILE **fps = 0;
    int coco = 0;
    int imagenet = 0;
    if(0==strcmp(type, "coco")){
        if(!outfile) outfile = "coco_results";
        snprintf(buff, 1024, "%s/%s.json", prefix, outfile);
        fp = fopen(buff, "w");
        fprintf(fp, "[\n");
        coco = 1;
    } else if(0==strcmp(type, "imagenet")){
        if(!outfile) outfile = "imagenet-detection";
        snprintf(buff, 1024, "%s/%s.txt", prefix, outfile);
        fp = fopen(buff, "w");
        imagenet = 1;
        classes = 200;
    } else {
        if(!outfile) outfile = "comp4_det_test_";
        fps = calloc(classes, sizeof(FILE *));
        for(j = 0; j < classes; ++j){
            snprintf(buff, 1024, "%s/%s%s.txt", prefix, outfile, names[j]);
            fps[j] = fopen(buff, "w");
        }
    }


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

    float thresh = .005;
    float nms = .45;

    int nthreads = 4;
    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;
    args.type = LETTERBOX_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);
    }
    double start = what_time_is_it_now();
    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, .5, map, 0, &nboxes);
            if (nms) do_nms_sort(dets, nboxes, classes, nms);
            if (coco){
                print_cocos(fp, path, dets, nboxes, classes, w, h);
            } else if (imagenet){
                print_imagenet_detections(fp, i+t-nthreads+1, dets, nboxes, classes, w, h);
            } else {
                print_detector_detections(fps, id, dets, nboxes, classes, w, h);
            }
            free_detections(dets, nboxes);
            free(id);
            free_image(val[t]);
            free_image(val_resized[t]);
        }
    }
    for(j = 0; j < classes; ++j){
        if(fps) fclose(fps[j]);
    }
    if(coco){
        fseek(fp, -2, SEEK_CUR); 
        fprintf(fp, "\n]\n");
        fclose(fp);
    }
    fprintf(stderr, "Total Detection Time: %f Seconds\n", what_time_is_it_now() - start);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x618, %rsp            # imm = 0x618
movq %rcx, 0xb0(%rsp)
movq %rdx, %r14
movq %rsi, %rbp
callq 0x36cb4
movq %rax, %r15
leaq 0x4aca9(%rip), %rsi     # 0x58064
leaq 0x4d8ae(%rip), %rdx     # 0x5ac70
movq %rax, %rdi
callq 0x36e77
movq %rax, %r12
leaq 0x4c415(%rip), %rsi     # 0x597e9
leaq 0x4ded1(%rip), %rdx     # 0x5b2ac
movq %r15, %rdi
callq 0x36e77
movq %rax, %r13
leaq 0x4dedd(%rip), %rdx     # 0x5b2ca
movq %r15, %rdi
movq %rdx, %rsi
callq 0x36e77
movq %rax, 0xc8(%rsp)
movq %r13, %rdi
callq 0x2d26c
movq %rax, 0xe0(%rsp)
leaq 0x4bf03(%rip), %rsi     # 0x5931a
movq $0x0, 0x118(%rsp)
movq %r15, %rdi
xorl %edx, %edx
callq 0x36e77
testq %rax, %rax
je 0xd442
movq %rax, %rdi
callq 0xe8a2
movq %rax, 0x118(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x316bc
movq %rax, %rbx
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x320a7
movq 0x5eb94(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
cvtss2sd 0x34(%rbx), %xmm0
cvtss2sd 0x38(%rbx), %xmm1
cvtss2sd 0x3c(%rbx), %xmm2
leaq 0x4cb53(%rip), %rsi     # 0x59fd0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
movq %r12, %rdi
callq 0x2af38
movq %rax, %r13
movq %rax, %rdi
callq 0x11928
movq %rax, %rbp
movq 0x20(%rbx), %rax
movq %rbx, 0x120(%rsp)
movslq (%rbx), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x3a4(%rax,%rcx), %ebx
leaq 0x4cf4e(%rip), %rsi     # 0x5a41a
leaq 0x4dde9(%rip), %rdx     # 0x5b2bc
movq %r15, %rdi
callq 0x36e77
movq %rax, %r14
leaq 0x4dddb(%rip), %rsi     # 0x5b2c0
movq %rax, %rdi
callq 0x3260
movl %eax, 0xec(%rsp)
testl %eax, %eax
jne 0xd587
movq %rbx, 0xc0(%rsp)
movq 0xb0(%rsp), %rax
testq %rax, %rax
leaq 0x4ddaf(%rip), %r8      # 0x5b2c5
cmovneq %rax, %r8
leaq 0x4ddb1(%rip), %rdx     # 0x5b2d2
movq $0x0, 0xd8(%rsp)
leaq 0x210(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
movq 0xc8(%rsp), %rcx
xorl %eax, %eax
callq 0x3180
leaq 0x4ddd4(%rip), %rsi     # 0x5b327
movq %r14, %rdi
callq 0x3390
leaq 0x4db3d(%rip), %rdi     # 0x5b09f
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
movq %rax, 0xd0(%rsp)
callq 0x3440
movb $0x1, %al
movq %rax, 0xf0(%rsp)
jmp 0xd700
leaq 0x4dd4f(%rip), %rsi     # 0x5b2dd
movq %r14, %rdi
callq 0x3260
testl %eax, %eax
movq 0xc8(%rsp), %r12
jne 0xd61a
movq 0xb0(%rsp), %rax
testq %rax, %rax
leaq 0x4dd32(%rip), %r8      # 0x5b2e6
cmovneq %rax, %r8
leaq 0x4dd3a(%rip), %rdx     # 0x5b2f9
movq $0x0, 0xf0(%rsp)
leaq 0x210(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x3180
leaq 0x4dd3b(%rip), %rsi     # 0x5b327
movq %r14, %rdi
callq 0x3390
movq %rax, 0xd0(%rsp)
movl $0xc8, %eax
movq %rax, 0xc0(%rsp)
movq $0x0, 0xd8(%rsp)
jmp 0xd700
movq %rbx, 0xc0(%rsp)
movslq %ebx, %r15
movq 0xb0(%rsp), %rax
testq %rax, %rax
leaq 0x4da99(%rip), %rbx     # 0x5b0d0
cmovneq %rax, %rbx
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x3250
movq %rax, 0xd8(%rsp)
movb $0x1, %al
movq %rax, 0xf0(%rsp)
testl %r15d, %r15d
jle 0xd6f4
movq %r13, 0xb0(%rsp)
movq %rbp, 0xf8(%rsp)
movq $0x0, 0xd0(%rsp)
leaq 0x210(%rsp), %r12
movq %rbx, %rbp
xorl %ebx, %ebx
movq 0xc0(%rsp), %r13
movq 0xd8(%rsp), %r15
movq 0xe0(%rsp), %r14
movq (%r14,%rbx,8), %r9
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
leaq 0x4dc4e(%rip), %rdx     # 0x5b303
movq 0xc8(%rsp), %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x3180
movq %r12, %rdi
leaq 0x4dc56(%rip), %rsi     # 0x5b327
callq 0x3390
movq %rax, (%r15,%rbx,8)
incq %rbx
cmpq %rbx, %r13
jne 0xd6a2
movq 0xf8(%rsp), %rbp
movq 0xb0(%rsp), %r13
jmp 0xd700
movq $0x0, 0xd0(%rsp)
movl (%r13), %eax
movq %rax, 0x108(%rsp)
pushq $0x4
popq %rbx
pushq $0x18
popq %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0xc8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0xb0(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, %r13
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x3250
movq %rax, %r14
leaq 0x168(%rsp), %r15
xorl %ebx, %ebx
movl $0xa8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x31c0
movq 0x120(%rsp), %rax
movq 0x90(%rax), %rax
movq %rax, 0x28(%r15)
movl $0xd, 0x98(%r15)
pushq $0x15
popq %r15
movq %r12, 0x140(%rsp)
movq %r13, 0x138(%rsp)
movq (%rbp,%rbx,8), %rax
movq %rax, 0x178(%rsp)
movq %r12, 0x1f0(%rsp)
movq %r13, 0x1f8(%rsp)
movq %r15, %rcx
movq %rsp, %rdi
leaq 0x168(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq %rax, (%r14,%rbx,8)
incq %rbx
addq $0x18, %r13
addq $0x18, %r12
cmpq $0x4, %rbx
jne 0xd7ae
movq %r14, 0x130(%rsp)
xorl %eax, %eax
callq 0xe79c
movsd %xmm0, 0x148(%rsp)
movq 0x108(%rsp), %r12
testl %r12d, %r12d
pushq $0x4
popq %r13
jle 0xdb66
movq %rbp, %rax
addq $0x20, %rax
movq %rax, 0x128(%rsp)
xorl %ebx, %ebx
movl %r12d, %edx
movq %rbp, 0xf8(%rsp)
movl %edx, 0x104(%rsp)
movl %edx, %eax
imulq $0x18, %rax, %rax
movq %rax, 0x158(%rsp)
movq 0x5e79d(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
leaq 0x4cd34(%rip), %rsi     # 0x5a599
movl %r13d, %edx
xorl %eax, %eax
callq 0x3270
movq %rbx, 0x110(%rsp)
movq 0x130(%rsp), %r14
xorl %r15d, %r15d
cmpq %r12, %rbx
jge 0xd8ea
movq (%r14), %rdi
xorl %esi, %esi
callq 0x3470
movq 0x140(%rsp), %rdx
movq 0x10(%rdx,%r15), %rax
movq 0xc8(%rsp), %rcx
movq %rax, 0x10(%rcx,%r15)
movups (%rdx,%r15), %xmm0
movups %xmm0, (%rcx,%r15)
movq 0x138(%rsp), %rax
movups (%rax,%r15), %xmm0
movq 0xb0(%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 $0x60, %r15
jne 0xd882
movq 0x140(%rsp), %rbx
movq 0x138(%rsp), %r14
xorl %r15d, %r15d
leaq (%r15,%r13), %rax
cmpq %r12, %rax
jae 0xd95d
movq 0x128(%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x178(%rsp)
movq %rbx, 0x1f0(%rsp)
movq %r14, 0x1f8(%rsp)
pushq $0x15
popq %rcx
movq %rsp, %rdi
leaq 0x168(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq 0x130(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
addq $0x18, %r14
addq $0x18, %rbx
cmpq $0x4, %r15
jne 0xd8fd
movq %r13, 0x150(%rsp)
movq 0x110(%rsp), %rbx
xorl %r14d, %r14d
cmpq %r14, 0x158(%rsp)
je 0xdb2a
movq (%rbp,%rbx,8), %rdi
movq %rdi, 0x160(%rsp)
callq 0xef02
movq %rax, 0xe0(%rsp)
movq 0xb0(%rsp), %rax
movq 0x10(%rax,%r14), %rsi
movq 0x120(%rsp), %r12
movq %r12, %rdi
callq 0x32690
movq 0xc8(%rsp), %rax
movl (%rax,%r14), %r15d
movl 0x4(%rax,%r14), %ebp
andl $0x0, 0xbc(%rsp)
movq %r12, %rdi
movl %r15d, %esi
movl %ebp, %edx
movss 0x4d87e(%rip), %xmm0    # 0x5b25c
movss 0x4787e(%rip), %xmm1    # 0x55264
movq 0x118(%rsp), %rcx
xorl %r8d, %r8d
leaq 0xbc(%rsp), %r9
callq 0x32a67
movq %rax, %r12
movl 0xbc(%rsp), %esi
movq %rax, %rdi
movq 0xc0(%rsp), %r13
movl %r13d, %edx
movss 0x4d842(%rip), %xmm0    # 0x5b260
callq 0x38a2a
movl 0xbc(%rsp), %ecx
cmpl $0x0, 0xec(%rsp)
je 0xda69
cmpb $0x0, 0xf0(%rsp)
je 0xda8c
movl %ebp, (%rsp)
movq 0xd8(%rsp), %rdi
movq 0xe0(%rsp), %rbp
movq %rbp, %rsi
movq %r12, %rdx
movq 0xc0(%rsp), %r8
movl %r15d, %r9d
callq 0x4feed
jmp 0xdab5
movl %ebp, (%rsp)
movq 0xd0(%rsp), %rdi
movq 0x160(%rsp), %rsi
movq %r12, %rdx
movl %r13d, %r8d
movl %r15d, %r9d
callq 0x5021d
jmp 0xdaad
leal 0x1(%rbx), %esi
movl %ebp, (%rsp)
movq 0xd0(%rsp), %rdi
movq %r12, %rdx
movq 0xc0(%rsp), %r8
movl %r15d, %r9d
callq 0x50096
movq 0xe0(%rsp), %rbp
movq 0xb0(%rsp), %rax
leaq (%rax,%r14), %r15
movq 0xc8(%rsp), %rax
leaq (%rax,%r14), %r13
movl 0xbc(%rsp), %esi
movq %r12, %rdi
callq 0x32ac9
movq %rbp, %rdi
callq 0x3040
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
addq $0x18, %r14
incq %rbx
cmpq $0x60, %r14
movq 0xf8(%rsp), %rbp
jne 0xd970
movq 0x150(%rsp), %rcx
leaq 0x4(%rcx), %r13
movl 0x104(%rsp), %edx
addl $-0x4, %edx
movq 0x110(%rsp), %rbx
addq $0x4, %rbx
addq $0x20, 0x128(%rsp)
movq 0x108(%rsp), %r12
cmpq %r12, %rcx
jb 0xd83f
movq 0xc0(%rsp), %rax
testl %eax, %eax
movq 0xd8(%rsp), %r15
jle 0xdb95
movl %eax, %ebx
xorl %r14d, %r14d
testq %r15, %r15
je 0xdb8d
movq (%r15,%r14,8), %rdi
callq 0x3130
incq %r14
cmpq %r14, %rbx
jne 0xdb7f
cmpl $0x0, 0xec(%rsp)
jne 0xdbd2
pushq $-0x2
popq %rsi
pushq $0x1
popq %rdx
movq 0xd0(%rsp), %rbx
movq %rbx, %rdi
callq 0x3340
leaq 0x4d4e6(%rip), %rdi     # 0x5b0a2
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x3440
movq %rbx, %rdi
callq 0x3130
movq 0x5e41f(%rip), %rax     # 0x6bff8
movq (%rax), %rbx
xorl %eax, %eax
callq 0xe79c
subsd 0x148(%rsp), %xmm0
leaq 0x4d4b3(%rip), %rsi     # 0x5b0a6
movq %rbx, %rdi
movb $0x1, %al
callq 0x3270
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq