// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rdx, %r14
movq %rsi, %r13
callq 0x29598
movq %rax, %rbp
leaq 0x8d6b(%rip), %rsi      # 0x4ef84
leaq 0xb910(%rip), %rdx      # 0x51b30
movq %rax, %rdi
callq 0x29737
movq %rax, %r15
leaq 0xa507(%rip), %rsi      # 0x50739
leaq 0xbf33(%rip), %rdx      # 0x5216c
movq %rbp, %rdi
callq 0x29737
movq %rax, %rbx
leaq 0xbf3f(%rip), %rdx      # 0x5218a
movq %rbp, %rdi
movq %rdx, %rsi
callq 0x29737
movq %rax, 0xb8(%rsp)
movq %rbx, %rdi
callq 0x1e673
movq %rax, 0xd8(%rsp)
leaq 0x9ff5(%rip), %rsi      # 0x5026a
movq $0x0, 0x110(%rsp)
movq %rbp, %rdi
xorl %edx, %edx
callq 0x29737
testq %rax, %rax
je 0x462a0
movq %rax, %rdi
callq 0x3ca1
movq %rax, 0x110(%rsp)
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x22658
movq %rax, %rbx
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x22f00
movq 0x1dd36(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
cvtss2sd 0x34(%rbx), %xmm0
cvtss2sd 0x38(%rbx), %xmm1
cvtss2sd 0x3c(%rbx), %xmm2
leaq 0xabf5(%rip), %rsi      # 0x50ed0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
movq %r15, %rdi
callq 0x1c8c8
movq %rax, %r15
movq %rax, %rdi
callq 0x72f5
movq %rax, 0xf8(%rsp)
movq 0x20(%rbx), %rax
movq %rbx, 0x120(%rsp)
movslq (%rbx), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x3a4(%rax,%rcx), %r14d
leaq 0xafea(%rip), %rsi      # 0x5131a
leaq 0xbe45(%rip), %rdx      # 0x5217c
movq %rbp, %rdi
callq 0x29737
movq %rax, %rbx
leaq 0xbe37(%rip), %rsi      # 0x52180
movq %rax, %rdi
callq 0x3260
movl %eax, 0xe4(%rsp)
testl %eax, %eax
jne 0x463e3
movq %r14, 0xc0(%rsp)
testq %r12, %r12
leaq 0xbe13(%rip), %r8       # 0x52185
cmovneq %r12, %r8
leaq 0xbe15(%rip), %rdx      # 0x52192
movq $0x0, 0xc8(%rsp)
leaq 0x220(%rsp), %rbx
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq 0xb8(%rsp), %rcx
xorl %eax, %eax
callq 0x3180
leaq 0xbe38(%rip), %rsi      # 0x521e7
movq %rbx, %rdi
callq 0x3390
leaq 0xbba1(%rip), %rdi      # 0x51f5f
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 0x4652a
leaq 0xbdb3(%rip), %rsi      # 0x5219d
movq %rbx, %rdi
callq 0x3260
testl %eax, %eax
jne 0x4646b
testq %r12, %r12
leaq 0xbda6(%rip), %r8       # 0x521a6
cmovneq %r12, %r8
leaq 0xbdae(%rip), %rdx      # 0x521b9
movq $0x0, 0xf0(%rsp)
leaq 0x220(%rsp), %rbx
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdi
movq 0xb8(%rsp), %rcx
xorl %eax, %eax
callq 0x3180
leaq 0xbdaa(%rip), %rsi      # 0x521e7
movq %rbx, %rdi
callq 0x3390
movq %rax, 0xd0(%rsp)
movl $0xc8, %eax
movq %rax, 0xc0(%rsp)
movq $0x0, 0xc8(%rsp)
jmp 0x4652a
movq %r15, 0xe8(%rsp)
movq %r14, 0xc0(%rsp)
movslq %r14d, %r14
testq %r12, %r12
leaq 0xbb08(%rip), %r13      # 0x51f90
cmovneq %r12, %r13
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x3250
movq %rax, 0xc8(%rsp)
xorl %ecx, %ecx
testl %r14d, %r14d
movl $0x0, %eax
movq %rax, 0xd0(%rsp)
cmovlel %ecx, %r14d
leaq 0xbd07(%rip), %rbp      # 0x521c3
leaq 0x220(%rsp), %r15
leaq 0xbd1c(%rip), %rbx      # 0x521e7
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x46518
movq 0xd8(%rsp), %rax
movq (%rax,%r12,8), %r9
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdi
movq %rbp, %rdx
movq 0xb8(%rsp), %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x3180
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3390
movq 0xc8(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
jmp 0x464ce
movb $0x1, %al
movq %rax, 0xf0(%rsp)
movq 0xe8(%rsp), %r15
movslq (%r15), %rax
movq %rax, 0x118(%rsp)
pushq $0x4
popq %rbx
pushq $0x18
popq %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0xb8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, %rbp
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, 0xd8(%rsp)
movq 0x120(%rsp), %r15
movl 0x90(%r15), %edx
movl 0x94(%r15), %esi
movl 0x98(%r15), %ecx
addl %ecx, %ecx
leaq 0x160(%rsp), %rdi
callq 0xb45a
leaq 0x178(%rsp), %r14
xorl %ebx, %ebx
movl $0xa8, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x31c0
movq 0x90(%r15), %rax
movq %rax, 0x28(%r14)
movl $0xd, 0x98(%r14)
pushq $0x15
popq %r15
movq %r12, 0x148(%rsp)
movq %r13, 0x130(%rsp)
cmpq $0x4, %rbx
je 0x4664f
movq 0xf8(%rsp), %rax
movq (%rax,%rbx,8), %rax
movq %rax, 0x188(%rsp)
movq %r12, 0x200(%rsp)
movq %r13, 0x208(%rsp)
movq %r15, %rcx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x20b03
movq 0xd8(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
addq $0x18, %r13
addq $0x18, %r12
jmp 0x465fb
xorl %eax, %eax
callq 0x3bc0
movsd %xmm0, 0x138(%rsp)
movq 0x118(%rsp), %r12
leal 0x4(%r12), %eax
cltq
movq %rax, 0x140(%rsp)
movq 0xf8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x128(%rsp)
movq $0x0, 0x108(%rsp)
pushq $0x4
popq %r13
cmpq 0x140(%rsp), %r13
movq 0x148(%rsp), %r15
jge 0x46a2d
movq 0x1d941(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
leaq 0xad90(%rip), %rsi      # 0x51451
movl %r13d, %edx
xorl %eax, %eax
callq 0x3270
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpq $0x3, %r14
ja 0x46738
movq 0x108(%rsp), %rax
addq %r14, %rax
cmpq %r12, %rax
jge 0x46738
movq 0xd8(%rsp), %rax
movq (%rax,%r14,8), %rdi
xorl %esi, %esi
callq 0x3470
movq 0x10(%r15,%rbx), %rax
movq 0xb8(%rsp), %rcx
movq %rax, 0x10(%rcx,%rbx)
movups (%r15,%rbx), %xmm0
movups %xmm0, (%rcx,%rbx)
movq 0x130(%rsp), %rcx
movq 0x10(%rcx,%rbx), %rax
movq %rax, 0x10(%rbp,%rbx)
movups (%rcx,%rbx), %xmm0
movups %xmm0, (%rbp,%rbx)
incq %r14
addq $0x18, %rbx
jmp 0x466d0
movq %r15, %rbx
movq 0x130(%rsp), %r14
xorl %r15d, %r15d
cmpq $0x4, %r15
je 0x467a8
leaq (%r15,%r13), %rax
cmpq %r12, %rax
jge 0x467a8
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 0x20b03
movq 0xd8(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
addq $0x18, %r14
addq $0x18, %rbx
jmp 0x46746
movq 0x108(%rsp), %rbx
xorl %r15d, %r15d
movq %r13, 0x150(%rsp)
cmpq $0x60, %r15
je 0x46a12
cmpq %r12, %rbx
jge 0x46a12
movq 0xf8(%rsp), %rax
movq %rbx, 0x100(%rsp)
movq (%rax,%rbx,8), %rdi
movq %rdi, 0x158(%rsp)
callq 0x41c8
movq %rax, 0xe8(%rsp)
movq 0x120(%rsp), %r13
movl 0x90(%r13), %edi
imull 0x94(%r13), %edi
imull 0x98(%r13), %edi
movq 0x10(%rbp,%r15), %rsi
movq 0x170(%rsp), %rcx
pushq $0x1
popq %rbx
movl %ebx, %edx
movl %ebx, %r8d
callq 0x1b5a3
movq 0x10(%rbp,%r15), %rax
movq %rax, 0x10(%rsp)
movups (%rbp,%r15), %xmm0
movups %xmm0, (%rsp)
callq 0xcb93
movslq 0x94(%r13), %rax
movslq 0x90(%r13), %rcx
imulq %rax, %rcx
movslq 0x98(%r13), %rdi
imulq %rcx, %rdi
movq 0x10(%rbp,%r15), %rsi
movq %rdi, %rcx
shlq $0x2, %rcx
addq 0x170(%rsp), %rcx
movl %ebx, %edx
movl %ebx, %r8d
callq 0x1b5a3
movq 0x170(%rsp), %rsi
movq %r13, %rdi
callq 0x233e2
movq 0xb8(%rsp), %rax
movl (%rax,%r15), %r14d
movl 0x4(%rax,%r15), %r12d
andl $0x0, 0xb4(%rsp)
movq %r13, %rdi
movl %r14d, %esi
movl %r12d, %edx
movss 0xb85e(%rip), %xmm0     # 0x5211c
movss 0x596e(%rip), %xmm1     # 0x4c234
movq 0x110(%rsp), %rcx
xorl %r8d, %r8d
leaq 0xb4(%rsp), %r9
callq 0x2379c
movq %rax, %r13
movl 0xb4(%rsp), %esi
movq %rax, %rdi
movq 0xc0(%rsp), %rbx
movl %ebx, %edx
movss 0xb823(%rip), %xmm0     # 0x52120
callq 0x2b219
movl 0xb4(%rsp), %ecx
cmpl $0x0, 0xe4(%rsp)
je 0x46946
cmpb $0x0, 0xf0(%rsp)
je 0x46972
movl %r12d, (%rsp)
movq 0xc8(%rsp), %rdi
movq 0xe8(%rsp), %rsi
movq %r13, %rdx
movq 0xc0(%rsp), %r8
movl %r14d, %r9d
callq 0x45ee9
jmp 0x46968
movl %r12d, (%rsp)
movq 0xd0(%rsp), %rdi
movq 0x158(%rsp), %rsi
movq %r13, %rdx
movl %ebx, %r8d
movl %r14d, %r9d
callq 0x46ad8
movq 0x100(%rsp), %rbx
jmp 0x4699c
movq 0x100(%rsp), %rbx
leal 0x1(%rbx), %esi
movl %r12d, (%rsp)
movq 0xd0(%rsp), %rdi
movq %r13, %rdx
movq 0xc0(%rsp), %r8
movl %r14d, %r9d
callq 0x4607f
leaq (%r15,%rbp), %r14
movq 0xb8(%rsp), %rax
leaq (%rax,%r15), %r12
movl 0xb4(%rsp), %esi
movq %r13, %rdi
callq 0x237fe
movq 0xe8(%rsp), %rdi
callq 0x3040
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
addq $0x18, %r15
incq %rbx
movq 0x118(%rsp), %r12
movq 0x150(%rsp), %r13
jmp 0x467bb
addq $0x4, %r13
addq $0x4, 0x108(%rsp)
addq $0x20, 0x128(%rsp)
jmp 0x4669a
xorl %ebx, %ebx
movq 0xc0(%rsp), %r14
testl %r14d, %r14d
cmovlel %ebx, %r14d
movq 0xc8(%rsp), %r15
cmpq %rbx, %r14
je 0x46a5e
testq %r15, %r15
je 0x46a59
movq (%r15,%rbx,8), %rdi
callq 0x3130
incq %rbx
jmp 0x46a46
cmpl $0x0, 0xe4(%rsp)
jne 0x46a9b
pushq $-0x2
popq %rsi
pushq $0x1
popq %rdx
movq 0xd0(%rsp), %rbx
movq %rbx, %rdi
callq 0x3340
leaq 0xb4dd(%rip), %rdi      # 0x51f62
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x3440
movq %rbx, %rdi
callq 0x3130
movq 0x1d556(%rip), %rax     # 0x63ff8
movq (%rax), %rbx
xorl %eax, %eax
callq 0x3bc0
subsd 0x138(%rsp), %xmm0
leaq 0xb4aa(%rip), %rsi      # 0x51f66
movq %rbx, %rdi
movb $0x1, %al
callq 0x3270
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq