// File: /workspace/github_c_makefile_star2_O3/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 $0x648, %rsp            # imm = 0x648
xorl %r15d, %r15d
xorl %edx, %edx
callq 0x316bc
movq %rax, %r12
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x320a7
movq 0x60b61(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
cvtss2sd 0x34(%r12), %xmm0
cvtss2sd 0x38(%r12), %xmm1
cvtss2sd 0x3c(%r12), %xmm2
leaq 0x4eb1a(%rip), %rsi     # 0x59fd0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
leaq 0x4fba2(%rip), %rdi     # 0x5b074
callq 0x2af38
movq %rax, %rbx
movq %rax, %rdi
callq 0x11928
movq %rax, 0xc8(%rsp)
movq 0x20(%r12), %rax
movslq (%r12), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x41c(%rax,%rcx), %edx
movq %rdx, 0xb8(%rsp)
movl -0x40c(%rax,%rcx), %edx
movl %edx, 0x100(%rsp)
movl -0x3a4(%rax,%rcx), %eax
movq %rax, 0xf0(%rsp)
leaq 0x4fb5d(%rip), %rdx     # 0x5b08a
leaq 0x4fb37(%rip), %rcx     # 0x5b06b
leaq 0x240(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
xorl %eax, %eax
callq 0x3180
leaq 0x4fdd5(%rip), %rsi     # 0x5b327
movq %r14, %rdi
callq 0x3390
movq %rax, %r13
leaq 0x4fb3b(%rip), %rdi     # 0x5b09f
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x3440
movl (%rbx), %eax
movl %eax, 0xb0(%rsp)
movq %rax, 0xd8(%rsp)
pushq $0x8
popq %r14
pushq $0x18
popq %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0xe8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0xe0(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0xc0(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, %rbp
movq %r14, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, %rbx
leaq 0x198(%rsp), %r14
movl $0xa8, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x31c0
movq %r12, 0x138(%rsp)
movq 0x90(%r12), %rax
movq %rax, 0x28(%r14)
movl $0x4, 0x98(%r14)
pushq $0x15
popq %r14
movq 0xc0(%rsp), %r12
movq %rbp, 0x120(%rsp)
movq 0xc8(%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x1a8(%rsp)
movq %r12, 0x220(%rsp)
movq %rbp, 0x228(%rsp)
movq %r14, %rcx
movq %rsp, %rdi
leaq 0x198(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq %rax, (%rbx,%r15,8)
incq %r15
addq $0x18, %rbp
addq $0x18, %r12
cmpq $0x8, %r15
jne 0xb629
movq %rbx, 0x118(%rsp)
xorl %edi, %edi
callq 0x32c0
movq %rax, 0x128(%rsp)
cmpl $0x0, 0xb0(%rsp)
movq 0xc8(%rsp), %rbp
pushq $0x8
popq %rcx
jle 0xbb16
movq 0xb8(%rsp), %rax
movl 0x100(%rsp), %edx
imull %edx, %eax
imull %edx, %eax
movq %rax, 0xb8(%rsp)
movq %rbp, %rax
addq $0x40, %rax
movq %rax, 0x110(%rsp)
movq 0xf0(%rsp), %rax
leaq (,%rax,4), %r12
xorl %ebx, %ebx
movq 0x6090b(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
leaq 0x4eea2(%rip), %rsi     # 0x5a599
movq %rcx, 0xd0(%rsp)
movq %rcx, %rdx
xorl %eax, %eax
callq 0x3270
movq %rbx, 0x130(%rsp)
movq 0x118(%rsp), %r14
xorl %r15d, %r15d
cmpq 0xd8(%rsp), %rbx
jge 0xb78c
movq (%r14), %rdi
xorl %esi, %esi
callq 0x3470
movq 0xc0(%rsp), %rdx
movq 0x10(%rdx,%r15), %rax
movq 0xe8(%rsp), %rcx
movq %rax, 0x10(%rcx,%r15)
movups (%rdx,%r15), %xmm0
movups %xmm0, (%rcx,%r15)
movq 0x120(%rsp), %rax
movups (%rax,%r15), %xmm0
movq 0xe0(%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 0xb71c
movq 0xc0(%rsp), %rbx
movq 0x120(%rsp), %r14
xorl %r15d, %r15d
movq 0xd0(%rsp), %rcx
leaq (%rcx,%r15), %rax
cmpq 0xd8(%rsp), %rax
jae 0xb814
movq 0x110(%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x1a8(%rsp)
movq %rbx, 0x220(%rsp)
movq %r14, 0x228(%rsp)
pushq $0x15
popq %rcx
movq %rsp, %rdi
leaq 0x198(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq 0xd0(%rsp), %rcx
movq 0x118(%rsp), %rdx
movq %rax, (%rdx,%r15,8)
incq %r15
addq $0x18, %r14
addq $0x18, %rbx
cmpq $0x8, %r15
jne 0xb7a7
movl 0xb0(%rsp), %eax
movq %rax, 0x140(%rsp)
xorl %ebx, %ebx
cmpq 0x140(%rsp), %rbx
je 0xbae4
movq %rbx, %rax
orq %rcx, %rax
movq -0x40(%rbp,%rax,8), %rdi
pushq $0x5f
popq %rsi
callq 0x3190
leaq 0x1(%rax), %rdi
callq 0x3400
movl %eax, %r14d
movq %rbx, 0x150(%rsp)
imulq $0x18, %rbx, %r15
movq 0xe0(%rsp), %rax
movq 0x10(%rax,%r15), %rsi
movq 0x138(%rsp), %rbx
movq %rbx, %rdi
callq 0x32690
movq 0xe8(%rsp), %rax
movq %r15, 0x148(%rsp)
movq (%rax,%r15), %rsi
movq %rsi, %xmm0
movdqa %xmm0, 0x100(%rsp)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %edx
andl $0x0, 0xb4(%rsp)
xorps %xmm1, %xmm1
movq %rbx, %rdi
movss 0x4cd9c(%rip), %xmm0    # 0x58658
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0xb4(%rsp), %r9
callq 0x32a67
movq %rax, 0xf8(%rsp)
movq %rax, %rdi
movq 0xb8(%rsp), %rbx
movl %ebx, %esi
movq 0xf0(%rsp), %rdx
movss 0x49971(%rip), %xmm0    # 0x55264
callq 0x38a2a
testl %ebx, %ebx
jle 0xba64
cvtdq2ps 0x100(%rsp), %xmm0
movaps %xmm0, 0x170(%rsp)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, 0x180(%rsp)
xorl %ebx, %ebx
cmpl $0x0, 0xf0(%rsp)
jle 0xba53
imulq $0x30, %rbx, %r15
movq 0xf8(%rsp), %rax
cvtps2pd 0x8(%rax,%r15), %xmm2
mulpd 0x4999a(%rip), %xmm2    # 0x552e0
cvtps2pd (%rax,%r15), %xmm1
movapd %xmm2, %xmm0
addpd %xmm1, %xmm0
cvtpd2ps %xmm0, %xmm4
movaps 0x170(%rsp), %xmm0
cmpltps %xmm4, %xmm0
unpcklps %xmm0, %xmm0            # xmm0 = xmm0[0,0,1,1]
movmskpd %xmm0, %eax
movaps 0x180(%rsp), %xmm0
testb $0x2, %al
jne 0xb97d
movaps %xmm4, %xmm0
shufps $0x55, %xmm4, %xmm0     # xmm0 = xmm0[1,1],xmm4[1,1]
movaps 0x170(%rsp), %xmm3
testb $0x1, %al
jne 0xb98c
movaps %xmm4, %xmm3
subpd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm2
movhlps %xmm1, %xmm1            # xmm1 = xmm1[1,1]
cvtsd2ss %xmm1, %xmm1
addq 0xf8(%rsp), %r15
xorps %xmm4, %xmm4
maxss %xmm1, %xmm4
subss %xmm4, %xmm0
xorps %xmm1, %xmm1
maxss %xmm2, %xmm1
subss %xmm1, %xmm3
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x100(%rsp)
cvtss2sd %xmm4, %xmm1
movsd %xmm1, 0x168(%rsp)
cvtss2sd %xmm3, %xmm1
movsd %xmm1, 0x160(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x158(%rsp)
xorl %ebp, %ebp
movq 0x18(%r15), %rax
movss (%rax,%rbp), %xmm0
ucomiss 0x496a1(%rip), %xmm0    # 0x550a0
jne 0xba03
jnp 0xba4a
leaq 0x60ba6(%rip), %rax     # 0x6c5b0
movl (%rbp,%rax), %ecx
cvtss2sd %xmm0, %xmm4
movq %r13, %rdi
leaq 0x4f75a(%rip), %rsi     # 0x5b176
movl %r14d, %edx
movsd 0x100(%rsp), %xmm0
movsd 0x168(%rsp), %xmm1
movsd 0x160(%rsp), %xmm2
movsd 0x158(%rsp), %xmm3
movb $0x5, %al
callq 0x3270
addq $0x4, %rbp
cmpq %rbp, %r12
jne 0xb9ef
incq %rbx
cmpq 0xb8(%rsp), %rbx
jne 0xb91e
movq 0xe0(%rsp), %rax
movq 0x148(%rsp), %r14
leaq (%rax,%r14), %rbx
addq 0xe8(%rsp), %r14
movl 0xb4(%rsp), %esi
movq 0xf8(%rsp), %rdi
callq 0x32ac9
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0x150(%rsp), %rbx
incq %rbx
cmpq $0x8, %rbx
movq 0xc8(%rsp), %rbp
movq 0xd0(%rsp), %rcx
jne 0xb825
leaq 0x8(%rcx), %rax
addl $-0x8, 0xb0(%rsp)
movq 0x130(%rsp), %rbx
addq $0x8, %rbx
addq $0x40, 0x110(%rsp)
cmpq 0xd8(%rsp), %rcx
movq %rax, %rcx
jb 0xb6e6
pushq $-0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rdi
callq 0x3340
leaq 0x4f577(%rip), %rdi     # 0x5b0a2
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rcx
callq 0x3440
movq %r13, %rdi
callq 0x3130
movq 0x604b0(%rip), %rax     # 0x6bff8
movq (%rax), %rbx
xorl %edi, %edi
callq 0x32c0
subq 0x128(%rsp), %rax
cvtsi2sd %rax, %xmm0
leaq 0x4f540(%rip), %rsi     # 0x5b0a6
movq %rbx, %rdi
movb $0x1, %al
callq 0x3270
addq $0x648, %rsp            # imm = 0x648
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq