// File: /workspace/github_c_makefile_star2_O1/SimpleDoger[P]Darknet_CPU_Only/coco.c
// Function: validate_coco
void validate_coco(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/";
    list *plist = get_paths("data/coco_val_5k.list");
    //list *plist = get_paths("/home/pjreddie/data/people-art/test.txt");
    //list *plist = get_paths("/home/pjreddie/data/voc/test/2007_test.txt");
    char **paths = (char **)list_to_array(plist);

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

    char buff[1024];
    snprintf(buff, 1024, "%s/coco_results.json", base);
    FILE *fp = fopen(buff, "w");
    fprintf(fp, "[\n");

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

    float thresh = .01;
    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];
            int image_id = get_coco_image_id(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_cocos(fp, image_id, dets, l.side*l.side*l.n, classes, w, h);
            free_detections(dets, nboxes);
            free_image(val[t]);
            free_image(val_resized[t]);
        }
    }
    fseek(fp, -2, SEEK_CUR); 
    fprintf(fp, "\n]\n");
    fclose(fp);

    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 $0x618, %rsp            # imm = 0x618
xorl %r15d, %r15d
xorl %edx, %edx
callq 0x2f9e4
movq %rax, %r12
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x302d4
movq 0x5f309(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
cvtss2sd 0x34(%r12), %xmm0
cvtss2sd 0x38(%r12), %xmm1
cvtss2sd 0x3c(%r12), %xmm2
leaq 0x4d18a(%rip), %rsi     # 0x57e98
movb $0x3, %al
callq 0x3280
xorl %edi, %edi
callq 0x32d0
movl %eax, %edi
callq 0x3230
leaq 0x4e1f2(%rip), %rdi     # 0x58f1c
callq 0x296f8
movq %rax, %rbx
movq %rax, %rdi
callq 0x10fa0
movq %rax, 0xc0(%rsp)
movq 0x20(%r12), %rax
movslq (%r12), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x41c(%rax,%rcx), %edx
movq %rdx, 0xb0(%rsp)
movl -0x40c(%rax,%rcx), %edx
movl %edx, 0xf0(%rsp)
movl -0x3a4(%rax,%rcx), %eax
movq %rax, 0xe8(%rsp)
leaq 0x4e1ad(%rip), %rdx     # 0x58f32
leaq 0x4e187(%rip), %rcx     # 0x58f13
leaq 0x210(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
xorl %eax, %eax
callq 0x3190
leaq 0x4e425(%rip), %rsi     # 0x591cf
movq %r14, %rdi
callq 0x33a0
movq %rax, %r13
leaq 0x4e18b(%rip), %rdi     # 0x58f47
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x3450
movl (%rbx), %eax
movl %eax, 0xa8(%rsp)
movq %rax, 0xd0(%rsp)
pushq $0x8
popq %r14
pushq $0x18
popq %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, 0xe0(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, 0xd8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, 0xb8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3260
movq %rax, %rbp
movq %r14, %rdi
movq %r14, %rsi
callq 0x3260
movq %rax, %rbx
leaq 0x168(%rsp), %r14
movl $0xa8, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x31d0
movl 0x94(%r12), %eax
movl %eax, 0x2c(%r14)
movq %r12, 0x130(%rsp)
movl 0x90(%r12), %eax
movl %eax, 0x28(%r14)
movl $0x4, 0x98(%r14)
pushq $0x15
popq %r14
movq 0xb8(%rsp), %r12
movq %rbp, 0x110(%rsp)
movq 0xc0(%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x178(%rsp)
movq %r12, 0x1f0(%rsp)
movq %rbp, 0x1f8(%rsp)
movq %r14, %rcx
movq %rsp, %rdi
leaq 0x168(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2dc84
movq %rax, (%rbx,%r15,8)
incq %r15
addq $0x18, %rbp
addq $0x18, %r12
cmpq $0x8, %r15
jne 0xae8d
movq %rbx, 0x108(%rsp)
xorl %edi, %edi
callq 0x32d0
movq %rax, 0x120(%rsp)
cmpl $0x0, 0xa8(%rsp)
movq 0xc0(%rsp), %rbp
pushq $0x8
popq %rcx
jle 0xb372
movq 0xb0(%rsp), %rax
movl 0xf0(%rsp), %edx
imull %edx, %eax
imull %edx, %eax
movq %rax, 0xb0(%rsp)
movq %rbp, %rax
addq $0x40, %rax
movq %rax, 0x100(%rsp)
movq 0xe8(%rsp), %rax
leaq (,%rax,4), %r12
xorl %ebx, %ebx
movq 0x5f0a7(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
leaq 0x4d4e6(%rip), %rsi     # 0x58441
movq %rcx, 0xc8(%rsp)
movq %rcx, %rdx
xorl %eax, %eax
callq 0x3280
movq %rbx, 0x128(%rsp)
movq 0x108(%rsp), %r14
xorl %r15d, %r15d
cmpq 0xd0(%rsp), %rbx
jge 0xaff0
movq (%r14), %rdi
xorl %esi, %esi
callq 0x3480
movq 0xb8(%rsp), %rdx
movq 0x10(%rdx,%r15), %rax
movq 0xe0(%rsp), %rcx
movq %rax, 0x10(%rcx,%r15)
movups (%rdx,%r15), %xmm0
movups %xmm0, (%rcx,%r15)
movq 0x110(%rsp), %rax
movups (%rax,%r15), %xmm0
movq 0xd8(%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 0xaf80
movq 0xb8(%rsp), %rbx
movq 0x110(%rsp), %r14
xorl %r15d, %r15d
movq 0xc8(%rsp), %rcx
leaq (%rcx,%r15), %rax
cmpq 0xd0(%rsp), %rax
jae 0xb078
movq 0x100(%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 0x2dc84
movq 0xc8(%rsp), %rcx
movq 0x108(%rsp), %rdx
movq %rax, (%rdx,%r15,8)
incq %r15
addq $0x18, %r14
addq $0x18, %rbx
cmpq $0x8, %r15
jne 0xb00b
movl 0xa8(%rsp), %eax
movq %rax, 0x138(%rsp)
xorl %r14d, %r14d
cmpq 0x138(%rsp), %r14
je 0xb340
movq %r14, %rax
orq %rcx, %rax
movq -0x40(%rbp,%rax,8), %rdi
pushq $0x5f
popq %rsi
callq 0x31a0
leaq 0x1(%rax), %rdi
callq 0x3410
movl %eax, %ebx
movq %r14, 0x148(%rsp)
imulq $0x18, %r14, %r15
movq 0xd8(%rsp), %rax
movq 0x10(%rax,%r15), %rsi
movq 0x130(%rsp), %r14
movq %r14, %rdi
callq 0x307ea
movq 0xe0(%rsp), %rax
movl (%rax,%r15), %ebp
movq %r15, 0x140(%rsp)
movl 0x4(%rax,%r15), %r15d
andl $0x0, 0xac(%rsp)
xorps %xmm1, %xmm1
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
movss 0x4b475(%rip), %xmm0    # 0x56588
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0xac(%rsp), %r9
callq 0x30bbb
movq %rax, 0x118(%rsp)
movq %rax, %rdi
movq 0xb0(%rsp), %r14
movl %r14d, %esi
movq 0xe8(%rsp), %rdx
movss 0x480e9(%rip), %xmm0    # 0x53234
callq 0x36827
testl %r14d, %r14d
jle 0xb2c0
cvtsi2ss %ebp, %xmm0
movss %xmm0, 0xfc(%rsp)
cvtsi2ss %r15d, %xmm0
movss %xmm0, 0xf8(%rsp)
xorl %r15d, %r15d
cmpl $0x0, 0xe8(%rsp)
jle 0xb2af
imulq $0x30, %r15, %rax
movq 0x118(%rsp), %rcx
leaq (%rcx,%rax), %rbp
cvtss2sd 0xc(%rcx,%rax), %xmm0
movsd 0x47f7d(%rip), %xmm4    # 0x53120
mulsd %xmm4, %xmm0
cvtss2sd 0x4(%rcx,%rax), %xmm1
movapd %xmm0, %xmm2
addsd %xmm1, %xmm2
cvtsd2ss %xmm2, %xmm2
movss 0xf8(%rsp), %xmm3
minss %xmm2, %xmm3
subsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
xorps %xmm1, %xmm1
maxss %xmm0, %xmm1
subss %xmm1, %xmm3
cvtss2sd 0x8(%rcx,%rax), %xmm0
mulsd %xmm4, %xmm0
cvtss2sd (%rcx,%rax), %xmm2
movapd %xmm0, %xmm4
addsd %xmm2, %xmm4
cvtsd2ss %xmm4, %xmm4
movss 0xfc(%rsp), %xmm5
minss %xmm4, %xmm5
subsd %xmm0, %xmm2
cvtsd2ss %xmm2, %xmm0
xorps %xmm2, %xmm2
maxss %xmm0, %xmm2
subss %xmm2, %xmm5
cvtss2sd %xmm2, %xmm0
movsd %xmm0, 0xf0(%rsp)
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x160(%rsp)
cvtss2sd %xmm5, %xmm0
movsd %xmm0, 0x158(%rsp)
cvtss2sd %xmm3, %xmm0
movsd %xmm0, 0x150(%rsp)
xorl %r14d, %r14d
movq 0x18(%rbp), %rax
movss (%rax,%r14), %xmm0
ucomiss 0x47e1c(%rip), %xmm0    # 0x53078
jne 0xb260
jnp 0xb2a6
leaq 0x5f359(%rip), %rax     # 0x6a5c0
movl (%r14,%rax), %ecx
cvtss2sd %xmm0, %xmm4
movq %r13, %rdi
leaq 0x4dda5(%rip), %rsi     # 0x5901e
movl %ebx, %edx
movsd 0xf0(%rsp), %xmm0
movsd 0x160(%rsp), %xmm1
movsd 0x158(%rsp), %xmm2
movsd 0x150(%rsp), %xmm3
movb $0x5, %al
callq 0x3280
addq $0x4, %r14
cmpq %r14, %r12
jne 0xb24b
incq %r15
cmpq 0xb0(%rsp), %r15
jne 0xb177
movq 0xd8(%rsp), %rax
movq 0x140(%rsp), %r14
leaq (%rax,%r14), %rbx
addq 0xe0(%rsp), %r14
movl 0xac(%rsp), %esi
movq 0x118(%rsp), %rdi
callq 0x30c1d
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
movq 0x148(%rsp), %r14
incq %r14
cmpq $0x8, %r14
movq 0xc0(%rsp), %rbp
movq 0xc8(%rsp), %rcx
jne 0xb08a
leaq 0x8(%rcx), %rax
addl $-0x8, 0xa8(%rsp)
movq 0x128(%rsp), %rbx
addq $0x8, %rbx
addq $0x40, 0x100(%rsp)
cmpq 0xd0(%rsp), %rcx
movq %rax, %rcx
jb 0xaf4a
pushq $-0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rdi
callq 0x3350
leaq 0x4dbc3(%rip), %rdi     # 0x58f4a
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rcx
callq 0x3450
movq %r13, %rdi
callq 0x3140
movq 0x5ec54(%rip), %rax     # 0x69ff8
movq (%rax), %rbx
xorl %edi, %edi
callq 0x32d0
subq 0x120(%rsp), %rax
cvtsi2sd %rax, %xmm0
leaq 0x4db8c(%rip), %rsi     # 0x58f4e
movq %rbx, %rdi
movb $0x1, %al
callq 0x3280
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq