// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/classifier.c
// Function: try_classifier
void try_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename, int layer_num)
{
    network *net = load_network(cfgfile, weightfile, 0);
    set_batch_network(net, 1);
    srand(2222222);

    list *options = read_data_cfg(datacfg);

    char *name_list = option_find_str(options, "names", 0);
    if(!name_list) name_list = option_find_str(options, "labels", "data/labels.list");
    int top = option_find_int(options, "top", 1);

    int i = 0;
    char **names = get_labels(name_list);
    clock_t time;
    int *indexes = calloc(top, sizeof(int));
    char buff[256];
    char *input = buff;
    while(1){
        if(filename){
            strncpy(input, filename, 256);
        }else{
            printf("Enter Image Path: ");
            fflush(stdout);
            input = fgets(input, 256, stdin);
            if(!input) return;
            strtok(input, "\n");
        }
        image orig = load_image_color(input, 0, 0);
        image r = resize_min(orig, 256);
        image im = crop_image(r, (r.w - 224 - 1)/2 + 1, (r.h - 224 - 1)/2 + 1, 224, 224);
        float mean[] = {0.48263312050943, 0.45230225481413, 0.40099074308742};
        float std[] = {0.22590347483426, 0.22120921437787, 0.22103996251583};
        float var[3];
        var[0] = std[0]*std[0];
        var[1] = std[1]*std[1];
        var[2] = std[2]*std[2];

        normalize_cpu(im.data, mean, var, 1, 3, im.w*im.h);

        float *X = im.data;
        time=clock();
        float *predictions = network_predict(net, X);

        layer l = net->layers[layer_num];
        for(i = 0; i < l.c; ++i){
            if(l.rolling_mean) printf("%f %f %f\n", l.rolling_mean[i], l.rolling_variance[i], l.scales[i]);
        }
        for(i = 0; i < l.outputs; ++i){
            printf("%f\n", l.output[i]);
        }
        /*

           printf("\n\nWeights\n");
           for(i = 0; i < l.n*l.size*l.size*l.c; ++i){
           printf("%f\n", l.filters[i]);
           }

           printf("\n\nBiases\n");
           for(i = 0; i < l.n; ++i){
           printf("%f\n", l.biases[i]);
           }
         */

        top_predictions(net, top, indexes);
        printf("%s: Predicted in %f seconds.\n", input, sec(clock()-time));
        for(i = 0; i < top; ++i){
            int index = indexes[i];
            printf("%s: %f\n", names[index], predictions[index]);
        }
        free_image(im);
        if (filename) break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movl %r8d, %ebx
movq %rcx, %r12
movq %rdi, %r14
xorl %r13d, %r13d
movq %rsi, %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x22658
movq %rax, %rbp
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x22f00
movl $0x21e88e, %edi         # imm = 0x21E88E
callq 0x3220
movq %r14, %rdi
callq 0x29598
movq %rax, %r14
leaq 0xeaa6(%rip), %rsi      # 0x50739
movq %rax, %rdi
xorl %edx, %edx
callq 0x29737
movq %rax, %r15
testq %rax, %rax
jne 0x41cbe
leaq 0xdcfa(%rip), %rsi      # 0x4f9a6
leaq 0xfed1(%rip), %rdx      # 0x51b84
movq %r14, %rdi
callq 0x29737
movq %rax, %r15
leaq 0x101c7(%rip), %rsi     # 0x51e8c
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x2977d
movl %eax, %r14d
movq %r15, %rdi
callq 0x1e673
movq %rax, 0x60(%rsp)
movl %r14d, 0x24(%rsp)
movslq %r14d, %r14
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x3250
movq %rax, 0x30(%rsp)
movslq %ebx, %rax
testl %r14d, %r14d
cmovlel %r13d, %r14d
movq %r14, 0x58(%rsp)
leaq 0xe0(%rsp), %rbx
imulq $0x4a0, %rax, %rax      # imm = 0x4A0
movq %rax, 0x50(%rsp)
movq %r12, 0x70(%rsp)
movq %rbp, 0x68(%rsp)
testq %r12, %r12
je 0x41d3c
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3080
jmp 0x41d8b
leaq 0xf2ff(%rip), %rdi      # 0x51042
xorl %eax, %eax
callq 0x3160
movq 0x2227f(%rip), %rax     # 0x63fd0
movq (%rax), %rdi
callq 0x3310
movq 0x22278(%rip), %rax     # 0x63fd8
movq (%rax), %rdx
movq %rbx, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x3230
testq %rax, %rax
je 0x41ffb
movq %rax, %rbx
movq %rax, %rdi
leaq 0xf793(%rip), %rsi      # 0x51519
callq 0x33b0
leaq 0xc8(%rsp), %rdi
movq %rbx, 0x28(%rsp)
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbf36
movq 0xd8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xc8(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xb0(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0xe96d
movl 0xb0(%rsp), %eax
movl $0xffffff1f, %ecx       # imm = 0xFFFFFF1F
addl %ecx, %eax
cltd
pushq $0x2
popq %rdi
idivl %edi
leal 0x1(%rax), %esi
movl 0xb4(%rsp), %eax
addl %ecx, %eax
cltd
idivl %edi
leal 0x1(%rax), %edx
movq 0xc0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xb0(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x38(%rsp), %rdi
movl $0xe0, %ecx
movl $0xe0, %r8d
callq 0xdba7
movabsq $0x3ee794293ef71bb0, %rax # imm = 0x3EE794293EF71BB0
movq %rax, 0xa0(%rsp)
movl $0x3ecd4ea9, 0xa8(%rsp) # imm = 0x3ECD4EA9
movsd 0xfd18(%rip), %xmm0     # 0x51b60
movsd %xmm0, 0x90(%rsp)
movl $0x3d482006, 0x98(%rsp) # imm = 0x3D482006
movq 0x48(%rsp), %rdi
movl 0x3c(%rsp), %r9d
imull 0x38(%rsp), %r9d
leaq 0xa0(%rsp), %rsi
leaq 0x90(%rsp), %rdx
pushq $0x1
popq %rcx
pushq $0x3
popq %r8
callq 0x1b21e
movq 0x48(%rsp), %r15
callq 0x3120
movq %rax, 0x78(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x233e2
movq %rax, 0x88(%rsp)
movq 0x20(%rbp), %rax
movq 0x50(%rsp), %rcx
movl 0x58(%rax,%rcx), %ebx
movl 0x74(%rax,%rcx), %r12d
movq 0x240(%rax,%rcx), %rdx
movq %rdx, 0x80(%rsp)
movq 0x268(%rax,%rcx), %r14
movq 0x2b0(%rax,%rcx), %rbp
movq 0x2b8(%rax,%rcx), %r15
testl %r12d, %r12d
cmovlel %r13d, %r12d
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x41f26
testq %rbp, %rbp
je 0x41f21
cvtss2sd (%rbp,%r13,4), %xmm0
cvtss2sd (%r15,%r13,4), %xmm1
movq 0x80(%rsp), %rax
cvtss2sd (%rax,%r13,4), %xmm2
leaq 0xeac8(%rip), %rdi      # 0x509e2
movb $0x3, %al
callq 0x3160
incq %r13
jmp 0x41eee
testl %ebx, %ebx
movl $0x0, %r13d
cmovlel %r13d, %ebx
xorl %r15d, %r15d
movq 0x70(%rsp), %r12
movq 0x68(%rsp), %rbp
cmpq %r15, %rbx
je 0x41f5d
cvtss2sd (%r14,%r15,4), %xmm0
leaq 0xf977(%rip), %rdi      # 0x518c8
movb $0x1, %al
callq 0x3160
incq %r15
jmp 0x41f3f
movq %rbp, %rdi
movl 0x24(%rsp), %esi
movq 0x30(%rsp), %rdx
callq 0x233cb
callq 0x3120
subq 0x78(%rsp), %rax
movq %rax, %rdi
callq 0x437c
cvtss2sd %xmm0, %xmm0
leaq 0xf091(%rip), %rdi      # 0x5101c
movq 0x28(%rsp), %rsi
movb $0x1, %al
callq 0x3160
xorl %ebx, %ebx
movq 0x60(%rsp), %r14
movq 0x58(%rsp), %r15
cmpq %rbx, %r15
je 0x41fd5
movq 0x30(%rsp), %rax
movslq (%rax,%rbx,4), %rax
movq (%r14,%rax,8), %rsi
movq 0x88(%rsp), %rcx
cvtss2sd (%rcx,%rax,4), %xmm0
leaq 0xfc55(%rip), %rdi      # 0x51c1e
movb $0x1, %al
callq 0x3160
incq %rbx
jmp 0x41fa3
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
testq %r12, %r12
movq 0x28(%rsp), %rbx
je 0x41d25
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq