// File: /workspace/github_c_makefile_star2_O3/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 $0x1d8, %rsp            # imm = 0x1D8
movl %r8d, %ebx
movq %rcx, %r12
movq %rdi, %r14
movq %rsi, %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x316bc
movq %rax, %r13
movq %rax, %rdi
movl $0x1, %esi
callq 0x320a7
movl $0x21e88e, %edi         # imm = 0x21E88E
callq 0x3220
movq %r14, %rdi
callq 0x36cb4
movq %rax, %r14
leaq 0xc6eb(%rip), %rsi      # 0x597e9
movq %rax, %rdi
xorl %edx, %edx
callq 0x36e77
movq %rax, %r15
testq %rax, %rax
jne 0x4d129
leaq 0xb93f(%rip), %rsi      # 0x58a56
leaq 0xdba6(%rip), %rdx      # 0x5acc4
movq %r14, %rdi
callq 0x36e77
movq %rax, %r15
leaq 0xde9c(%rip), %rsi      # 0x5afcc
movq %r14, %rdi
movl $0x1, %edx
callq 0x36eed
movl %eax, %ebp
movq %r15, %rdi
callq 0x2d26c
movq %rax, 0x58(%rsp)
movslq %ebp, %r14
movl $0x4, %esi
movq %r14, %rdi
callq 0x3250
movq %rax, 0x50(%rsp)
movslq %ebx, %rax
movl %r14d, %ecx
movq %rcx, 0x48(%rsp)
leaq 0xd0(%rsp), %rbx
imulq $0x4a0, %rax, %rax      # imm = 0x4A0
movq %rax, 0x18(%rsp)
movq %r12, 0x60(%rsp)
movq %r12, %rsi
movq %r13, 0x20(%rsp)
testq %rsi, %rsi
je 0x4d1a1
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
callq 0x3080
jmp 0x4d1f0
leaq 0xcf9a(%rip), %rdi      # 0x5a142
xorl %eax, %eax
callq 0x3160
movq 0x1ee1a(%rip), %rax     # 0x6bfd0
movq (%rax), %rdi
callq 0x3310
movq 0x1ee13(%rip), %rax     # 0x6bfd8
movq (%rax), %rdx
movq %rbx, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x3230
testq %rax, %rax
je 0x4d47b
movq %rax, %rbx
movq %rax, %rdi
leaq 0xd476(%rip), %rsi      # 0x5a661
callq 0x33b0
leaq 0xb8(%rsp), %rdi
movq %rbx, 0x28(%rsp)
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x16ac9
movq 0xc8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xb8(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa0(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x19bb8
movl 0xa0(%rsp), %eax
movl 0xa4(%rsp), %ecx
movl %eax, %edx
movl $0xffffff1f, %edi       # imm = 0xFFFFFF1F
addl %edi, %edx
shrl $0x1f, %edx
leal (%rax,%rdx), %esi
addl $0xffffff1f, %esi       # imm = 0xFFFFFF1F
sarl %esi
incl %esi
movl %ecx, %eax
addl %edi, %eax
shrl $0x1f, %eax
leal (%rcx,%rax), %edx
addl $0xffffff1f, %edx       # imm = 0xFFFFFF1F
sarl %edx
incl %edx
movq 0xb0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xa0(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x30(%rsp), %rdi
movl $0xe0, %ecx
movl $0xe0, %r8d
callq 0x18a89
movabsq $0x3ee794293ef71bb0, %rax # imm = 0x3EE794293EF71BB0
movq %rax, 0x90(%rsp)
movl $0x3ecd4ea9, 0x98(%rsp) # imm = 0x3ECD4EA9
movsd 0xd9de(%rip), %xmm0     # 0x5aca0
movsd %xmm0, 0x80(%rsp)
movl $0x3d482006, 0x88(%rsp) # imm = 0x3D482006
movq 0x40(%rsp), %rdi
movl 0x34(%rsp), %r9d
imull 0x30(%rsp), %r9d
leaq 0x90(%rsp), %rsi
leaq 0x80(%rsp), %rdx
movl $0x1, %ecx
movl $0x3, %r8d
callq 0x29a4f
movq 0x40(%rsp), %rbx
callq 0x3120
movq %rax, 0x68(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x32690
movq %rax, 0x70(%rsp)
movq 0x20(%r13), %rax
movq 0x18(%rsp), %rcx
movl 0x58(%rax,%rcx), %r14d
movslq 0x74(%rax,%rcx), %r15
movq 0x268(%rax,%rcx), %rbp
testq %r15, %r15
jle 0x4d3a6
movq 0x18(%rsp), %rcx
movq 0x240(%rax,%rcx), %rdx
movq %rdx, 0x78(%rsp)
movq 0x2b0(%rax,%rcx), %r13
movq 0x2b8(%rax,%rcx), %rbx
xorl %r12d, %r12d
testq %r13, %r13
je 0x4d39e
xorps %xmm0, %xmm0
cvtss2sd (%r13,%r12,4), %xmm0
xorps %xmm1, %xmm1
cvtss2sd (%rbx,%r12,4), %xmm1
movq 0x78(%rsp), %rax
xorps %xmm2, %xmm2
cvtss2sd (%rax,%r12,4), %xmm2
leaq 0xc71b(%rip), %rdi      # 0x59ab2
movb $0x3, %al
callq 0x3160
incq %r12
cmpq %r12, %r15
jne 0x4d36a
testl %r14d, %r14d
movq 0x58(%rsp), %r15
leaq 0xd65b(%rip), %r12      # 0x5aa10
jle 0x4d3d4
xorl %ebx, %ebx
xorps %xmm0, %xmm0
cvtss2sd (%rbp,%rbx,4), %xmm0
movq %r12, %rdi
movb $0x1, %al
callq 0x3160
incq %rbx
cmpq %rbx, %r14
jne 0x4d3b9
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rbp
movl %ebp, %esi
movq 0x50(%rsp), %r14
movq %r14, %rdx
callq 0x32679
callq 0x3120
subq 0x68(%rsp), %rax
movq %rax, %rdi
callq 0xf0bf
cvtss2sd %xmm0, %xmm0
leaq 0xcd12(%rip), %rdi      # 0x5a11c
movq 0x28(%rsp), %rsi
movb $0x1, %al
callq 0x3160
testl %ebp, %ebp
leaq 0xd93f(%rip), %r13      # 0x5ad5e
movq 0x70(%rsp), %r12
jle 0x4d44b
xorl %ebx, %ebx
movslq (%r14,%rbx,4), %rax
movq (%r15,%rax,8), %rsi
xorps %xmm0, %xmm0
cvtss2sd (%r12,%rax,4), %xmm0
movq %r13, %rdi
movb $0x1, %al
callq 0x3160
incq %rbx
cmpq %rbx, %rbp
jne 0x4d428
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0x60(%rsp), %rsi
testq %rsi, %rsi
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %r13
je 0x4d18d
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq