// File: /workspace/github_c_makefile_star2_O1/SimpleDoger[P]Darknet_CPU_Only/classifier.c
// Function: validate_classifier_single
void validate_classifier_single(char *datacfg, char *filename, char *weightfile)
{
    int i, j;
    network *net = load_network(filename, weightfile, 0);
    set_batch_network(net, 1);
    srand(time(0));

    list *options = read_data_cfg(datacfg);

    char *label_list = option_find_str(options, "labels", "data/labels.list");
    char *leaf_list = option_find_str(options, "leaves", 0);
    if(leaf_list) change_leaves(net->hierarchy, leaf_list);
    char *valid_list = option_find_str(options, "valid", "data/train.list");
    int classes = option_find_int(options, "classes", 2);
    int topk = option_find_int(options, "top", 1);

    char **labels = get_labels(label_list);
    list *plist = get_paths(valid_list);

    char **paths = (char **)list_to_array(plist);
    int m = plist->size;
    free_list(plist);

    float avg_acc = 0;
    float avg_topk = 0;
    int *indexes = calloc(topk, sizeof(int));

    for(i = 0; i < m; ++i){
        int class = -1;
        char *path = paths[i];
        for(j = 0; j < classes; ++j){
            if(strstr(path, labels[j])){
                class = j;
                break;
            }
        }
        image im = load_image_color(paths[i], 0, 0);
        image crop = center_crop_image(im, net->w, net->h);
        //grayscale_image_3c(crop);
        //show_image(im, "orig");
        //show_image(crop, "cropped");
        //cvWaitKey(0);
        float *pred = network_predict(net, crop.data);
        if(net->hierarchy) hierarchy_predictions(pred, net->outputs, net->hierarchy, 1, 1);

        free_image(im);
        free_image(crop);
        top_k(pred, classes, topk, indexes);

        if(indexes[0] == class) avg_acc += 1;
        for(j = 0; j < topk; ++j){
            if(indexes[j] == class) avg_topk += 1;
        }

        printf("%s, %d, %f, %f, \n", paths[i], class, pred[0], pred[1]);
        printf("%d: top 1: %f, top %d: %f\n", i, avg_acc/(i+1), topk, avg_topk/(i+1));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %r14
movq %rsi, %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x2f9e4
movq %rax, %rbx
movq %rax, %rdi
movl $0x1, %esi
callq 0x302d4
xorl %edi, %edi
callq 0x32d0
movl %eax, %edi
callq 0x3230
movq %r14, %rdi
callq 0x34b9c
movq %rax, %r14
leaq 0xc239(%rip), %rsi      # 0x56956
leaq 0xe42f(%rip), %rdx      # 0x58b53
movq %rax, %rdi
callq 0x34d5b
movq %rax, %r15
leaq 0xe49e(%rip), %rsi      # 0x58bd4
movq %r14, %rdi
xorl %edx, %edx
callq 0x34d5b
testq %rax, %rax
je 0x4a754
movq 0xd0(%rbx), %rdi
movq %rax, %rsi
callq 0x8248
leaq 0xb831(%rip), %rsi      # 0x55f8c
leaq 0xe3be(%rip), %rdx      # 0x58b20
movq %r14, %rdi
callq 0x34d5b
movq %rax, %r12
leaq 0xca27(%rip), %rsi      # 0x5719b
movq %r14, %rdi
movl $0x2, %edx
callq 0x34d9f
movl %eax, 0x2c(%rsp)
leaq 0xe6e8(%rip), %rsi      # 0x58e74
movq %r14, %rdi
movl $0x1, %edx
callq 0x34d9f
movl %eax, %ebp
movq %r15, %rdi
callq 0x2b6d3
movq %rax, 0x50(%rsp)
movq %r12, %rdi
callq 0x296f8
movq %rax, %r14
movq %rax, %rdi
callq 0x10fa0
movq %rax, 0x40(%rsp)
movslq (%r14), %r15
movq %r14, %rdi
callq 0x10f56
movl %ebp, 0x28(%rsp)
movslq %ebp, %rdi
movl $0x4, %esi
callq 0x3260
movq %r15, 0x48(%rsp)
testq %r15, %r15
jle 0x4aa0f
movq %rax, %r13
movq %rbx, %r15
movl 0x2c(%rsp), %ebx
movl 0x28(%rsp), %ebp
xorps %xmm1, %xmm1
movq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movq %r15, 0x38(%rsp)
movss %xmm1, 0x24(%rsp)
movss %xmm0, 0x20(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x0, 0x2c(%rsp)
jle 0x4a85e
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %r14
xorl %r15d, %r15d
movq 0x50(%rsp), %rax
movq (%rax,%r15,8), %rsi
movq %r14, %rdi
callq 0x34c0
testq %rax, %rax
jne 0x4a856
incq %r15
cmpq %r15, %rbx
jne 0x4a836
jmp 0x4a859
movl %r15d, %r12d
movq 0x38(%rsp), %r15
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x58(%rsp), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x160b6
movl 0x90(%r15), %edx
movl 0x94(%r15), %esi
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x70(%rsp), %rdi
callq 0x18163
movq 0x80(%rsp), %rsi
movq %r15, %rdi
callq 0x307ea
movq %rax, %r14
movq 0xd0(%r15), %rdx
testq %rdx, %rdx
je 0x4a8de
movl 0x84(%r15), %esi
movq %r14, %rdi
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x3cc56
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
movq %r14, %rdi
movl 0x2c(%rsp), %esi
movl 0x28(%rsp), %edx
movq %r13, %rcx
callq 0xe8e2
movss 0x24(%rsp), %xmm1
movaps %xmm1, %xmm2
movss 0x86d3(%rip), %xmm0     # 0x53008
addss %xmm0, %xmm2
cmpl %r12d, (%r13)
je 0x4a942
movaps %xmm1, %xmm2
cmpl $0x0, 0x28(%rsp)
movss 0x20(%rsp), %xmm1
movss %xmm2, 0x24(%rsp)
jle 0x4a975
xorl %eax, %eax
movaps %xmm1, %xmm2
addss %xmm0, %xmm2
cmpl %r12d, (%r13,%rax,4)
je 0x4a968
movaps %xmm1, %xmm2
incq %rax
movaps %xmm2, %xmm1
cmpq %rax, %rbp
jne 0x4a95a
jmp 0x4a978
movaps %xmm1, %xmm2
movss %xmm2, 0x20(%rsp)
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %r15
movq (%rax,%r15,8), %rsi
xorps %xmm0, %xmm0
cvtss2sd (%r14), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x4(%r14), %xmm1
leaq 0xe237(%rip), %rdi      # 0x58bdb
movl %r12d, %edx
movb $0x2, %al
callq 0x3170
leaq 0x1(%r15), %r14
xorps %xmm1, %xmm1
cvtsi2ss %r14d, %xmm1
movss 0x24(%rsp), %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movss 0x20(%rsp), %xmm2
divss %xmm1, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
leaq 0xe1d9(%rip), %rdi      # 0x58bb9
movl %r15d, %esi
movl 0x28(%rsp), %edx
movb $0x2, %al
callq 0x3170
movq %r14, 0x30(%rsp)
movss 0x24(%rsp), %xmm1
movss 0x20(%rsp), %xmm0
cmpq 0x48(%rsp), %r14
movq 0x38(%rsp), %r15
jne 0x4a80c
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq