// File: /workspace/github_c_makefile_star2_O2/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 $0x658, %rsp            # imm = 0x658
xorl %r12d, %r12d
xorl %edx, %edx
callq 0x22658
movq %rax, %r13
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x22f00
movq 0x20b61(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
cvtss2sd 0x34(%r13), %xmm0
cvtss2sd 0x38(%r13), %xmm1
cvtss2sd 0x3c(%r13), %xmm2
leaq 0xda1d(%rip), %rsi      # 0x50ed0
movb $0x3, %al
callq 0x3270
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
leaq 0xea65(%rip), %rdi      # 0x51f34
callq 0x1c8c8
movq %rax, %rbx
movq %rax, %rdi
callq 0x72f5
movq %rax, 0xc8(%rsp)
movq 0x20(%r13), %rax
movslq (%r13), %rcx
imulq $0x4a0, %rcx, %rcx      # imm = 0x4A0
movl -0x41c(%rax,%rcx), %edx
movl %edx, 0xb4(%rsp)
movl -0x40c(%rax,%rcx), %edx
movl %edx, 0xe0(%rsp)
movl -0x3a4(%rax,%rcx), %eax
movl %eax, 0xb8(%rsp)
leaq 0xea23(%rip), %rdx      # 0x51f4a
leaq 0xe9fd(%rip), %rcx      # 0x51f2b
leaq 0x250(%rsp), %r14
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
xorl %eax, %eax
callq 0x3180
leaq 0xec9b(%rip), %rsi      # 0x521e7
movq %r14, %rdi
callq 0x3390
movq %rax, %r15
leaq 0xea01(%rip), %rdi      # 0x51f5f
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x3440
movslq (%rbx), %rax
movq %rax, 0xc0(%rsp)
pushq $0x8
popq %r14
pushq $0x18
popq %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0x100(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0x120(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, 0xd0(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3250
movq %rax, %rbp
movq %r14, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0xd8(%rsp)
leaq 0x1a8(%rsp), %rbx
movl $0xa8, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31c0
movq %r13, 0x138(%rsp)
movq 0x90(%r13), %rax
movq %rax, 0x28(%rbx)
movl $0x4, 0x98(%rbx)
pushq $0x15
popq %r14
movq 0xd0(%rsp), %r13
movq %rbp, 0x108(%rsp)
cmpq $0x8, %r12
je 0x43674
movq 0xc8(%rsp), %rax
movq (%rax,%r12,8), %rax
movq %rax, 0x1b8(%rsp)
movq %r13, 0x230(%rsp)
movq %rbp, 0x238(%rsp)
movq %r14, %rcx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x20b03
movq 0xd8(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
addq $0x18, %rbp
addq $0x18, %r13
jmp 0x43620
xorl %edi, %edi
callq 0x32c0
movq %rax, 0x128(%rsp)
movl 0xb4(%rsp), %eax
movl 0xe0(%rsp), %ecx
imull %ecx, %eax
imull %ecx, %eax
movl 0xb8(%rsp), %ecx
testl %ecx, %ecx
movl $0x0, %ebp
cmovgl %ecx, %ebp
testl %eax, %eax
movl $0x0, %ecx
movl %eax, 0xb4(%rsp)
cmovgl %eax, %ecx
movq %rcx, 0x160(%rsp)
movq 0xc0(%rsp), %rax
addl $0x8, %eax
cltq
movq %rax, 0x130(%rsp)
movq 0xc8(%rsp), %rax
addq $0x40, %rax
movq %rax, 0xf8(%rsp)
shlq $0x2, %rbp
movq $0x0, 0x118(%rsp)
pushq $0x8
popq %rdx
cmpq 0x130(%rsp), %rdx
movq 0x100(%rsp), %r12
jge 0x43af7
movq 0x208de(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
leaq 0xdd2d(%rip), %rsi      # 0x51451
movq %rdx, 0x110(%rsp)
xorl %eax, %eax
callq 0x3270
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpq $0x7, %r14
ja 0x437ac
movq 0x118(%rsp), %rax
addq %r14, %rax
cmpq 0xc0(%rsp), %rax
jge 0x437ac
movq 0xd8(%rsp), %rax
movq (%rax,%r14,8), %rdi
xorl %esi, %esi
callq 0x3470
movq 0xd0(%rsp), %rcx
movq 0x10(%rcx,%rbx), %rax
movq %rax, 0x10(%r12,%rbx)
movups (%rcx,%rbx), %xmm0
movups %xmm0, (%r12,%rbx)
movq 0x108(%rsp), %rdx
movq 0x10(%rdx,%rbx), %rax
movq 0x120(%rsp), %rcx
movq %rax, 0x10(%rcx,%rbx)
movups (%rdx,%rbx), %xmm0
movups %xmm0, (%rcx,%rbx)
incq %r14
addq $0x18, %rbx
jmp 0x43738
movq 0xd0(%rsp), %rbx
movq 0x108(%rsp), %r14
xorl %r12d, %r12d
cmpq $0x8, %r12
movq 0x110(%rsp), %rdx
je 0x4382e
leaq (%rdx,%r12), %rax
cmpq 0xc0(%rsp), %rax
jge 0x4382e
movq 0xf8(%rsp), %rax
movq (%rax,%r12,8), %rax
movq %rax, 0x1b8(%rsp)
movq %rbx, 0x230(%rsp)
movq %r14, 0x238(%rsp)
pushq $0x15
popq %rcx
movq %rsp, %rdi
leaq 0x1a8(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x20b03
movq 0xd8(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
addq $0x18, %r14
addq $0x18, %rbx
jmp 0x437bf
xorl %ebx, %ebx
cmpq $0x8, %rbx
je 0x43adc
leaq (%rbx,%rdx), %rax
addq $-0x8, %rax
cmpq 0xc0(%rsp), %rax
jge 0x43adc
movq %rbx, %rax
orq %rdx, %rax
movq 0xc8(%rsp), %rcx
movq -0x40(%rcx,%rax,8), %rdi
callq 0x43454
movl %eax, %r14d
movq %rbx, 0x150(%rsp)
imulq $0x18, %rbx, %rbx
movq 0x120(%rsp), %rax
leaq (%rax,%rbx), %rcx
movq %rcx, 0x148(%rsp)
movq 0x10(%rax,%rbx), %rsi
movq 0x138(%rsp), %r12
movq %r12, %rdi
callq 0x233e2
movq 0x100(%rsp), %rax
leaq (%rax,%rbx), %rcx
movq %rcx, 0x140(%rsp)
andl $0x0, 0xbc(%rsp)
movq (%rax,%rbx), %rsi
movq %rsi, %xmm0
movdqa %xmm0, 0xe0(%rsp)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %edx
xorps %xmm1, %xmm1
movq %r12, %rdi
movss 0xbcc3(%rip), %xmm0     # 0x4f5a8
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0xbc(%rsp), %r9
callq 0x2379c
movq %rax, %r13
movq %rax, %rdi
movl 0xb4(%rsp), %esi
movl 0xb8(%rsp), %edx
movss 0x8921(%rip), %xmm0     # 0x4c234
callq 0x2b219
cvtdq2ps 0xe0(%rsp), %xmm0
movaps %xmm0, 0x190(%rsp)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movaps %xmm0, 0x180(%rsp)
xorl %ebx, %ebx
movq %r13, 0x158(%rsp)
cmpq 0x160(%rsp), %rbx
je 0x43a7b
imulq $0x30, %rbx, %r12
cvtps2pd (%r13,%r12), %xmm0
cvtps2pd 0x8(%r13,%r12), %xmm2
mulpd 0x893c(%rip), %xmm2     # 0x4c2a0
movapd %xmm2, %xmm1
addpd %xmm0, %xmm1
cvtpd2ps %xmm1, %xmm4
movaps 0x190(%rsp), %xmm3
movaps %xmm3, %xmm1
cmpltps %xmm4, %xmm1
unpcklps %xmm1, %xmm1            # xmm1 = xmm1[0,0,1,1]
movmskpd %xmm1, %eax
movaps %xmm3, %xmm1
testb $0x1, %al
jne 0x43990
movaps %xmm4, %xmm1
movaps 0x180(%rsp), %xmm3
testb $0x2, %al
jne 0x439a3
shufps $0x55, %xmm4, %xmm4     # xmm4 = xmm4[1,1,1,1]
movaps %xmm4, %xmm3
subpd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm2
movhlps %xmm0, %xmm0            # xmm0 = xmm0[1,1]
cvtsd2ss %xmm0, %xmm0
addq %r13, %r12
xorps %xmm4, %xmm4
maxss %xmm2, %xmm4
xorps %xmm2, %xmm2
maxss %xmm0, %xmm2
subss %xmm4, %xmm1
subss %xmm2, %xmm3
cvtss2sd %xmm4, %xmm0
movsd %xmm0, 0xe0(%rsp)
cvtss2sd %xmm2, %xmm0
movsd %xmm0, 0x178(%rsp)
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x170(%rsp)
cvtss2sd %xmm3, %xmm0
movsd %xmm0, 0x168(%rsp)
xorl %r13d, %r13d
cmpq %r13, %rbp
je 0x43a6b
movq 0x18(%r12), %rax
movss (%rax,%r13), %xmm0
ucomiss 0x865f(%rip), %xmm0     # 0x4c078
jne 0x43a1d
jnp 0x43a65
leaq 0x20b9c(%rip), %rax     # 0x645c0
movl (%r13,%rax), %ecx
cvtss2sd %xmm0, %xmm4
movq %r15, %rdi
leaq 0xe5ff(%rip), %rsi      # 0x52036
movl %r14d, %edx
movsd 0xe0(%rsp), %xmm0
movsd 0x178(%rsp), %xmm1
movsd 0x170(%rsp), %xmm2
movsd 0x168(%rsp), %xmm3
movb $0x5, %al
callq 0x3270
addq $0x4, %r13
jmp 0x43a02
incq %rbx
movq 0x158(%rsp), %r13
jmp 0x4393e
movl 0xbc(%rsp), %esi
movq %r13, %rdi
callq 0x237fe
movq 0x140(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x148(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x150(%rsp), %rbx
incq %rbx
movq 0x110(%rsp), %rdx
jmp 0x43830
addq $0x8, %rdx
addq $0x8, 0x118(%rsp)
addq $0x40, 0xf8(%rsp)
jmp 0x436fd
pushq $-0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x3340
leaq 0xe456(%rip), %rdi      # 0x51f62
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x3440
movq %r15, %rdi
callq 0x3130
movq 0x204cf(%rip), %rax     # 0x63ff8
movq (%rax), %rbx
xorl %edi, %edi
callq 0x32c0
subq 0x128(%rsp), %rax
cvtsi2sd %rax, %xmm0
leaq 0xe41f(%rip), %rsi      # 0x51f66
movq %rbx, %rdi
movb $0x1, %al
callq 0x3270
addq $0x658, %rsp            # imm = 0x658
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq