// File: /workspace/github_c_makefile_star2_O1/SimpleDoger[P]Darknet_CPU_Only/detector.c
// Function: validate_detector_flip
void validate_detector_flip(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, 2);
    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));

    image input = make_image(net->w, net->h, net->c*2);

    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);
            copy_cpu(net->w*net->h*net->c, val_resized[t].data, 1, input.data, 1);
            flip_image(val_resized[t]);
            copy_cpu(net->w*net->h*net->c, val_resized[t].data, 1, input.data + net->w*net->h*net->c, 1);

            network_predict(net, input.data);
            int w = val[t].w;
            int h = val[t].h;
            int num = 0;
            detection *dets = get_network_boxes(net, w, h, thresh, .5, map, 0, &num);
            if (nms) do_nms_sort(dets, num, classes, nms);
            if (coco){
                print_cocos(fp, path, dets, num, classes, w, h);
            } else if (imagenet){
                print_imagenet_detections(fp, i+t-nthreads+1, dets, num, classes, w, h);
            } else {
                print_detector_detections(fps, id, dets, num, classes, w, h);
            }
            free_detections(dets, num);
            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 $0x628, %rsp            # imm = 0x628
movq %rcx, 0xa8(%rsp)
movq %rdx, %r14
movq %rsi, %r13
callq 0x34b9c
movq %rax, %rbp
leaq 0x49cbc(%rip), %rsi     # 0x55f8c
leaq 0x4c849(%rip), %rdx     # 0x58b20
movq %rax, %rdi
callq 0x34d5b
movq %rax, %r15
leaq 0x4b400(%rip), %rsi     # 0x576e9
leaq 0x4ce64(%rip), %rdx     # 0x59154
movq %rbp, %rdi
callq 0x34d5b
movq %rax, %r12
leaq 0x4ce70(%rip), %rdx     # 0x59172
movq %rbp, %rdi
movq %rdx, %rsi
callq 0x34d5b
movq %rax, 0xc0(%rsp)
movq %r12, %rdi
callq 0x2b6d3
movq %rax, 0xd8(%rsp)
leaq 0x4aeee(%rip), %rsi     # 0x5721a
movq $0x0, 0x118(%rsp)
movq %rbp, %rdi
xorl %edx, %edx
callq 0x34d5b
testq %rax, %rax
je 0xc357
movq %rax, %rdi
callq 0xe0bf
movq %rax, 0x118(%rsp)
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2f9e4
movq %rax, %rbx
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x302d4
movq 0x5dc7f(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
cvtss2sd 0x34(%rbx), %xmm0
cvtss2sd 0x38(%rbx), %xmm1
cvtss2sd 0x3c(%rbx), %xmm2
leaq 0x4bb06(%rip), %rsi     # 0x57e98
movb $0x3, %al
callq 0x3280
xorl %edi, %edi
callq 0x32d0
movl %eax, %edi
callq 0x3230
movq %r15, %rdi
callq 0x296f8
movq %rax, %r12
movq %rax, %rdi
callq 0x10fa0
movq %rax, 0xf0(%rsp)
movq 0x20(%rbx), %rax
movq %rbx, 0x120(%rsp)
movslq (%rbx), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x3a4(%rax,%rcx), %ebx
leaq 0x4befc(%rip), %rsi     # 0x582e2
leaq 0x4cd77(%rip), %rdx     # 0x59164
movq %rbp, %rdi
callq 0x34d5b
movq %rax, %r14
leaq 0x4cd69(%rip), %rsi     # 0x59168
movq %rax, %rdi
callq 0x3270
movl %eax, 0xe4(%rsp)
testl %eax, %eax
jne 0xc4a1
movq %rbx, 0xb8(%rsp)
movq 0xa8(%rsp), %rax
testq %rax, %rax
leaq 0x4cd3d(%rip), %r8      # 0x5916d
cmovneq %rax, %r8
leaq 0x4cd3f(%rip), %rdx     # 0x5917a
movq $0x0, 0xd0(%rsp)
leaq 0x220(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
movq 0xc0(%rsp), %rcx
xorl %eax, %eax
callq 0x3190
leaq 0x4cd62(%rip), %rsi     # 0x591cf
movq %r14, %rdi
callq 0x33a0
leaq 0x4cacb(%rip), %rdi     # 0x58f47
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
movq %rax, 0xc8(%rsp)
callq 0x3450
movb $0x1, %al
movq %rax, 0xe8(%rsp)
jmp 0xc60b
leaq 0x4ccdd(%rip), %rsi     # 0x59185
movq %r14, %rdi
callq 0x3270
testl %eax, %eax
movq 0xc0(%rsp), %r15
jne 0xc534
movq 0xa8(%rsp), %rax
testq %rax, %rax
leaq 0x4ccc0(%rip), %r8      # 0x5918e
cmovneq %rax, %r8
leaq 0x4ccc8(%rip), %rdx     # 0x591a1
movq $0x0, 0xe8(%rsp)
leaq 0x220(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x3190
leaq 0x4ccc9(%rip), %rsi     # 0x591cf
movq %r14, %rdi
callq 0x33a0
movq %rax, 0xc8(%rsp)
movl $0xc8, %eax
movq %rax, 0xb8(%rsp)
movq $0x0, 0xd0(%rsp)
jmp 0xc60b
movq %rbx, 0xb8(%rsp)
movslq %ebx, %r14
movq 0xa8(%rsp), %rax
testq %rax, %rax
leaq 0x4ca27(%rip), %rbx     # 0x58f78
cmovneq %rax, %rbx
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x3260
movq %rax, 0xd0(%rsp)
movb $0x1, %al
movq %rax, 0xe8(%rsp)
testl %r14d, %r14d
jle 0xc5ff
movq %r12, 0xa8(%rsp)
movq $0x0, 0xc8(%rsp)
movq %rbx, %rbp
xorl %ebx, %ebx
movq 0xb8(%rsp), %r12
movq 0xd0(%rsp), %r14
movq 0xd8(%rsp), %r13
movq (%r13,%rbx,8), %r9
movl $0x400, %esi            # imm = 0x400
leaq 0x220(%rsp), %r15
movq %r15, %rdi
leaq 0x4cbe3(%rip), %rdx     # 0x591ab
movq 0xc0(%rsp), %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x3190
movq %r15, %rdi
leaq 0x4cbeb(%rip), %rsi     # 0x591cf
callq 0x33a0
movq %rax, (%r14,%rbx,8)
incq %rbx
cmpq %rbx, %r12
jne 0xc5ac
movq 0xa8(%rsp), %r12
jmp 0xc60b
movq $0x0, 0xc8(%rsp)
movl (%r12), %eax
movq %rax, 0x100(%rsp)
pushq $0x4
popq %r14
pushq $0x18
popq %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, 0xc0(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, 0xa8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, %r12
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, %r13
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x3260
movq %rax, %rbp
movq 0x120(%rsp), %r14
movl 0x90(%r14), %edx
movl 0x94(%r14), %esi
movl 0x98(%r14), %ecx
addl %ecx, %ecx
leaq 0x160(%rsp), %rdi
callq 0x1529e
leaq 0x178(%rsp), %rbx
xorl %r15d, %r15d
movl $0xa8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31d0
movl 0x94(%r14), %eax
movl %eax, 0x2c(%rbx)
movl 0x90(%r14), %eax
movl %eax, 0x28(%rbx)
movl $0xd, 0x98(%rbx)
pushq $0x15
popq %r14
movq %r12, 0x140(%rsp)
movq %r13, 0x130(%rsp)
movq 0xf0(%rsp), %rbx
movq (%rbx,%r15,8), %rax
movq %rax, 0x188(%rsp)
movq %r12, 0x200(%rsp)
movq %r13, 0x208(%rsp)
movq %r14, %rcx
movq %rsp, %rdi
leaq 0x178(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2dc84
movq %rax, (%rbp,%r15,8)
incq %r15
addq $0x18, %r13
addq $0x18, %r12
cmpq $0x4, %r15
jne 0xc6ee
movq %rbp, 0x108(%rsp)
xorl %eax, %eax
callq 0xdfdc
movsd %xmm0, 0x138(%rsp)
movq 0x100(%rsp), %r12
testl %r12d, %r12d
pushq $0x4
popq %r13
jle 0xcb2e
movq 0xf0(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x128(%rsp)
xorl %ebx, %ebx
movl %r12d, %edx
movl %edx, 0xfc(%rsp)
movl %edx, %eax
imulq $0x18, %rax, %rax
movq %rax, 0x150(%rsp)
movq 0x5d860(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
leaq 0x4bc9f(%rip), %rsi     # 0x58441
movl %r13d, %edx
xorl %eax, %eax
callq 0x3280
movq %rbx, 0x110(%rsp)
movq 0x108(%rsp), %r14
xorl %r15d, %r15d
movq 0x140(%rsp), %rbp
cmpq %r12, %rbx
jge 0xc828
movq (%r14), %rdi
xorl %esi, %esi
callq 0x3480
movq 0x10(%rbp,%r15), %rax
movq 0xc0(%rsp), %rcx
movq %rax, 0x10(%rcx,%r15)
movups (%rbp,%r15), %xmm0
movups %xmm0, (%rcx,%r15)
movq 0x130(%rsp), %rax
movups (%rax,%r15), %xmm0
movq 0xa8(%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 0xc7c7
movq %rbp, %rbx
movq 0x130(%rsp), %r14
xorl %r15d, %r15d
movq 0x108(%rsp), %rbp
leaq (%r15,%r13), %rax
cmpq %r12, %rax
jae 0xc897
movq 0x128(%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x188(%rsp)
movq %rbx, 0x200(%rsp)
movq %r14, 0x208(%rsp)
pushq $0x15
popq %rcx
movq %rsp, %rdi
leaq 0x178(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2dc84
movq %rax, (%rbp,%r15,8)
incq %r15
addq $0x18, %r14
addq $0x18, %rbx
cmpq $0x4, %r15
jne 0xc83e
movq %r13, 0x148(%rsp)
movq 0x110(%rsp), %r15
xorl %ebp, %ebp
cmpq %rbp, 0x150(%rsp)
je 0xcaf2
movq 0xf0(%rsp), %rax
movq (%rax,%r15,8), %rdi
movq %rdi, 0x158(%rsp)
callq 0xe717
movq %rax, 0xd8(%rsp)
movq 0x120(%rsp), %r12
movl 0x90(%r12), %edi
imull 0x94(%r12), %edi
imull 0x98(%r12), %edi
movq 0xa8(%rsp), %rbx
movq 0x10(%rbx,%rbp), %rsi
movq 0x170(%rsp), %rcx
pushq $0x1
popq %r14
movl %r14d, %edx
movl %r14d, %r8d
callq 0x2879c
movq 0x10(%rbx,%rbp), %rax
movq %rax, 0x10(%rsp)
movups (%rbx,%rbp), %xmm0
movups %xmm0, (%rsp)
callq 0x16f91
movslq 0x94(%r12), %rax
movslq 0x90(%r12), %rcx
imulq %rax, %rcx
movslq 0x98(%r12), %rdi
imulq %rcx, %rdi
movq 0x10(%rbx,%rbp), %rsi
movq %rdi, %rcx
shlq $0x2, %rcx
addq 0x170(%rsp), %rcx
movl %r14d, %edx
movl %r14d, %r8d
callq 0x2879c
movq 0x170(%rsp), %rsi
movq %r12, %rdi
callq 0x307ea
movq 0xc0(%rsp), %rax
movl (%rax,%rbp), %ebx
movl 0x4(%rax,%rbp), %r14d
andl $0x0, 0xb4(%rsp)
movq %r12, %rdi
movl %ebx, %esi
movl %r14d, %edx
movss 0x4c758(%rip), %xmm0    # 0x59104
movss 0x46880(%rip), %xmm1    # 0x53234
movq 0x118(%rsp), %rcx
xorl %r8d, %r8d
leaq 0xb4(%rsp), %r9
callq 0x30bbb
movq %rax, %r12
movl 0xb4(%rsp), %esi
movq %rax, %rdi
movq 0xb8(%rsp), %r13
movl %r13d, %edx
movss 0x4c71c(%rip), %xmm0    # 0x59108
callq 0x36827
movl 0xb4(%rsp), %ecx
cmpl $0x0, 0xe4(%rsp)
je 0xca38
cmpb $0x0, 0xe8(%rsp)
je 0xca5c
movl %r14d, (%rsp)
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %r13
movq %r13, %rsi
movq %r12, %rdx
movq 0xb8(%rsp), %r8
movl %ebx, %r9d
callq 0x4dc39
jmp 0xca87
movl %r14d, (%rsp)
movq 0xc8(%rsp), %rdi
movq 0x158(%rsp), %rsi
movq %r12, %rdx
movl %r13d, %r8d
movl %ebx, %r9d
callq 0x4df86
jmp 0xca7f
leal 0x1(%r15), %esi
movl %r14d, (%rsp)
movq 0xc8(%rsp), %rdi
movq %r12, %rdx
movq 0xb8(%rsp), %r8
movl %ebx, %r9d
callq 0x4ddee
movq 0xd8(%rsp), %r13
movq 0xa8(%rsp), %rax
leaq (%rax,%rbp), %rbx
movq 0xc0(%rsp), %rax
leaq (%rax,%rbp), %r14
movl 0xb4(%rsp), %esi
movq %r12, %rdi
callq 0x30c1d
movq %r13, %rdi
callq 0x3040
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
addq $0x18, %rbp
incq %r15
cmpq $0x60, %rbp
jne 0xc8a9
movq 0x148(%rsp), %rcx
leaq 0x4(%rcx), %r13
movl 0xfc(%rsp), %edx
addl $-0x4, %edx
movq 0x110(%rsp), %rbx
addq $0x4, %rbx
addq $0x20, 0x128(%rsp)
movq 0x100(%rsp), %r12
cmpq %r12, %rcx
jb 0xc77c
movq 0xb8(%rsp), %rax
testl %eax, %eax
movq 0xd0(%rsp), %r15
jle 0xcb5d
movl %eax, %ebx
xorl %r14d, %r14d
testq %r15, %r15
je 0xcb55
movq (%r15,%r14,8), %rdi
callq 0x3140
incq %r14
cmpq %r14, %rbx
jne 0xcb47
cmpl $0x0, 0xe4(%rsp)
jne 0xcb9a
pushq $-0x2
popq %rsi
pushq $0x1
popq %rdx
movq 0xc8(%rsp), %rbx
movq %rbx, %rdi
callq 0x3350
leaq 0x4c3c6(%rip), %rdi     # 0x58f4a
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3140
movq 0x5d457(%rip), %rax     # 0x69ff8
movq (%rax), %rbx
xorl %eax, %eax
callq 0xdfdc
subsd 0x138(%rsp), %xmm0
leaq 0x4c393(%rip), %rsi     # 0x58f4e
movq %rbx, %rdi
movb $0x1, %al
callq 0x3280
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq