// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/classifier.c
// Function: test_classifier
void test_classifier(char *datacfg, char *cfgfile, char *weightfile, int target_layer)
{
    int curr = 0;
    network *net = load_network(cfgfile, weightfile, 0);
    srand(time(0));

    list *options = read_data_cfg(datacfg);

    char *test_list = option_find_str(options, "test", "data/test.list");
    int classes = option_find_int(options, "classes", 2);

    list *plist = get_paths(test_list);

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

    clock_t time;

    data val, buffer;

    load_args args = {0};
    args.w = net->w;
    args.h = net->h;
    args.paths = paths;
    args.classes = classes;
    args.n = net->batch;
    args.m = 0;
    args.labels = 0;
    args.d = &buffer;
    args.type = OLD_CLASSIFICATION_DATA;

    pthread_t load_thread = load_data_in_thread(args);
    for(curr = net->batch; curr < m; curr += net->batch){
        time=clock();

        pthread_join(load_thread, 0);
        val = buffer;

        if(curr < m){
            args.paths = paths + curr;
            if (curr + net->batch > m) args.n = m - curr;
            load_thread = load_data_in_thread(args);
        }
        fprintf(stderr, "Loaded: %d images in %lf seconds\n", val.X.rows, sec(clock()-time));

        time=clock();
        matrix pred = network_predict_data(net, val);

        int i, j;
        if (target_layer >= 0){
            //layer l = net->layers[target_layer];
        }

        for(i = 0; i < pred.rows; ++i){
            printf("%s", paths[curr-net->batch+i]);
            for(j = 0; j < pred.cols; ++j){
                printf("\t%g", pred.vals[i][j]);
            }
            printf("\n");
        }

        free_matrix(pred);

        fprintf(stderr, "%lf seconds, %d images, %d total\n", sec(clock()-time), val.X.rows, curr);
        free_data(val);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %r14
movq %rsi, %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x316bc
movq %rax, %rbx
xorl %edi, %edi
callq 0x32c0
movl %eax, %edi
callq 0x3220
movq %r14, %rdi
callq 0x36cb4
movq %rax, %r14
leaq 0xd6db(%rip), %rsi      # 0x5b255
leaq 0xd1f2(%rip), %rdx      # 0x5ad73
movq %rax, %rdi
callq 0x36e77
movq %rax, %r15
leaq 0xb708(%rip), %rsi      # 0x5929b
movq %r14, %rdi
movl $0x2, %edx
callq 0x36eed
movl %eax, %ebp
movq %r15, %rdi
callq 0x2af38
movq %rax, %r15
movq %rax, %rdi
callq 0x11928
movq %rax, %r14
movl (%r15), %r13d
movq %r15, %rdi
callq 0x118de
leaq 0x160(%rsp), %r15
movl $0xa8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x31c0
movq 0x90(%rbx), %rax
movq %rax, 0x28(%r15)
movq %r14, 0xc0(%rsp)
movq %r14, 0x8(%r15)
movl %ebp, 0x50(%r15)
movl 0x4(%rbx), %eax
movl %eax, 0x18(%r15)
movq $0x0, 0x20(%r15)
leaq 0x120(%rsp), %rax
movq %rax, 0x80(%r15)
movl $0x9, 0x98(%r15)
movl $0x15, %ecx
movq %rsp, %rdi
movq %r15, %rsi
movq %rbx, %r15
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movl 0x4(%rbx), %ebx
cmpl %r13d, %ebx
jge 0x4dec6
movq %rax, %rbp
movq 0x1e3ae(%rip), %r14     # 0x6bff8
leaq 0xd157(%rip), %r12      # 0x5ada8
movl %r13d, 0xb4(%rsp)
callq 0x3120
movq %rax, 0xa8(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
callq 0x3470
movups 0x120(%rsp), %xmm0
movups 0x130(%rsp), %xmm1
movups 0x140(%rsp), %xmm2
movups 0x150(%rsp), %xmm3
movaps %xmm3, 0x110(%rsp)
movaps %xmm2, 0x100(%rsp)
movaps %xmm1, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movslq %ebx, %rax
movq 0xc0(%rsp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, 0x168(%rsp)
addl 0x4(%r15), %eax
cmpl %r13d, %eax
jle 0x4dcdc
movl %r13d, %eax
subl %ebx, %eax
movl %eax, 0x178(%rsp)
movl $0x15, %ecx
movq %rsp, %rdi
leaq 0x160(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2f8eb
movq %rax, 0xd0(%rsp)
movq (%r14), %r13
movl 0xe8(%rsp), %ebp
callq 0x3120
subq 0xa8(%rsp), %rax
movq %rax, %rdi
callq 0xf0bf
cvtss2sd %xmm0, %xmm0
movq %r13, %rdi
leaq 0xcfac(%rip), %rsi      # 0x5acd5
movl %ebp, %edx
movb $0x1, %al
callq 0x3270
callq 0x3120
movq %rax, 0xc8(%rsp)
movaps 0xe0(%rsp), %xmm0
movaps 0xf0(%rsp), %xmm1
movaps 0x100(%rsp), %xmm2
movaps 0x110(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0x32f01
movq %rdx, %r13
movq %rax, 0xb8(%rsp)
testl %eax, %eax
jle 0x4de24
movq 0xb8(%rsp), %rax
movq %rax, %rbp
shrq $0x20, %rbp
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0xa8(%rsp)
xorl %r14d, %r14d
movq %rbx, 0xd8(%rsp)
leal (%rbx,%r14), %eax
movq %r15, %rbx
subl 0x4(%r15), %eax
cltq
movq 0xc0(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
leaq 0xaca7(%rip), %rdi      # 0x58a7b
xorl %eax, %eax
callq 0x3160
testl %ebp, %ebp
jle 0x4de02
xorl %r15d, %r15d
movq (%r13,%r14,8), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r15,4), %xmm0
movq %r12, %rdi
movb $0x1, %al
callq 0x3160
incq %r15
cmpq %r15, %rbp
jne 0x4dde2
movl $0xa, %edi
callq 0x3060
incq %r14
cmpq 0xa8(%rsp), %r14
movq %rbx, %r15
movq 0xd8(%rsp), %rbx
jne 0x4ddb4
movq 0xb8(%rsp), %rdi
movq %r13, %rsi
callq 0x30ee4
movq 0x1e1bd(%rip), %r14     # 0x6bff8
movq (%r14), %r13
callq 0x3120
subq 0xc8(%rsp), %rax
movq %rax, %rdi
callq 0xf0bf
cvtss2sd %xmm0, %xmm0
movl 0xe8(%rsp), %edx
movq %r13, %rdi
leaq 0xcf1e(%rip), %rsi      # 0x5ad86
movl %ebx, %ecx
movb $0x1, %al
callq 0x3270
movaps 0xe0(%rsp), %xmm0
movaps 0xf0(%rsp), %xmm1
movaps 0x100(%rsp), %xmm2
movaps 0x110(%rsp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x2d296
addl 0x4(%r15), %ebx
movl 0xb4(%rsp), %r13d
cmpl %r13d, %ebx
movq 0xd0(%rsp), %rbp
jl 0x4dc59
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq