// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/classifier.c
// Function: predict_classifier
void predict_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename, int top)
{
    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");
    if(top == 0) 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 im = load_image_color(input, 0, 0);
        image r = letterbox_image(im, net->w, net->h);
        //image r = resize_min(im, 320);
        //printf("%d %d\n", r.w, r.h);
        //resize_network(net, r.w, r.h);
        //printf("%d %d\n", r.w, r.h);

        float *X = r.data;
        time=clock();
        float *predictions = network_predict(net, X);
        if(net->hierarchy) hierarchy_predictions(predictions, net->outputs, net->hierarchy, 1, 1);
        top_k(predictions, net->outputs, top, indexes);
        fprintf(stderr, "%s: Predicted in %f seconds.\n", input, sec(clock()-time));
        for(i = 0; i < top; ++i){
            int index = indexes[i];
            //if(net->hierarchy) printf("%d, %s: %f, parent: %s \n",index, names[index], predictions[index], (net->hierarchy->parent[index] >= 0) ? names[net->hierarchy->parent[index]] : "Root");
            //else printf("%s: %f\n",names[index], predictions[index]);
            printf("%5.2f%%: %s\n", predictions[index]*100, names[index]);
        }
        if(r.data != im.data) free_image(r);
        free_image(im);
        if (filename) break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl %r8d, %r12d
movq %rcx, %rbp
movq %rdi, %rbx
movq %rsi, %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x22658
pushq $0x1
popq %rsi
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x22f00
movl $0x21e88e, %edi         # imm = 0x21E88E
callq 0x3220
movq %rbx, %rdi
callq 0x29598
movq %rax, %rbx
leaq 0xe6d9(%rip), %rsi      # 0x50739
movq %rax, %rdi
xorl %edx, %edx
callq 0x29737
movq %rax, %r14
testq %rax, %rax
jne 0x4208b
leaq 0xd92d(%rip), %rsi      # 0x4f9a6
leaq 0xfb04(%rip), %rdx      # 0x51b84
movq %rbx, %rdi
callq 0x29737
movq %rax, %r14
testl %r12d, %r12d
jne 0x420a5
leaq 0xfdf5(%rip), %rsi      # 0x51e8c
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x2977d
movl %eax, %r12d
movq %r14, %rdi
callq 0x1e673
movq %rax, %r15
movslq %r12d, %rbx
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x3250
movl %r12d, %ecx
movq %rax, %r12
testl %ebx, %ebx
movl $0x0, %r13d
movl %ecx, 0x24(%rsp)
cmovgl %ecx, %r13d
leaq 0x70(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0xfb41(%rip), %rbx      # 0x51c26
movq %rbp, 0x30(%rsp)
movq 0x28(%rsp), %r14
testq %rbp, %rbp
jne 0x42296
leaq 0xef43(%rip), %rdi      # 0x51042
xorl %eax, %eax
callq 0x3160
movq 0x21ec3(%rip), %rax     # 0x63fd0
movq (%rax), %rdi
callq 0x3310
movq 0x21ebc(%rip), %rax     # 0x63fd8
movq (%rax), %rdx
movq 0x18(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x3230
testq %rax, %rax
je 0x422b0
movq %rax, %rbp
movq %rax, %rdi
leaq 0xf3d5(%rip), %rsi      # 0x51519
callq 0x33b0
leaq 0x40(%rsp), %rdi
movq %rbp, 0x18(%rsp)
movq %rbp, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbf36
movl 0x90(%r14), %edx
movl 0x94(%r14), %esi
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x58(%rsp), %rdi
callq 0xe7d0
movq 0x68(%rsp), %rbp
callq 0x3120
movq %rax, 0x38(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x233e2
movq %rax, %rbp
movq 0xd0(%r14), %rdx
testq %rdx, %rdx
je 0x421c8
movl 0x84(%r14), %esi
movq %rbp, %rdi
pushq $0x1
popq %rcx
movl %ecx, %r8d
callq 0x324ad
movl 0x84(%r14), %esi
movq %rbp, %rdi
movl 0x24(%rsp), %edx
movq %r12, %rcx
callq 0x438a
movq 0x21e13(%rip), %rax     # 0x63ff8
movq (%rax), %r14
callq 0x3120
subq 0x38(%rsp), %rax
movq %rax, %rdi
callq 0x437c
cvtss2sd %xmm0, %xmm0
movq %r14, %rdi
leaq 0xee14(%rip), %rsi      # 0x5101c
movq 0x18(%rsp), %rdx
movb $0x1, %al
callq 0x3270
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x42245
movslq (%r12,%r14,4), %rax
movss (%rbp,%rax,4), %xmm0
mulss 0xa016(%rip), %xmm0     # 0x4c244
cvtss2sd %xmm0, %xmm0
movq (%r15,%rax,8), %rsi
movq %rbx, %rdi
movb $0x1, %al
callq 0x3160
incq %r14
jmp 0x42217
movq 0x68(%rsp), %rax
cmpq 0x50(%rsp), %rax
je 0x42269
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xba88
movq 0x30(%rsp), %rbp
testq %rbp, %rbp
movq 0x28(%rsp), %r14
je 0x420ef
jmp 0x422b0
movl $0x100, %edx            # imm = 0x100
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
movq %rdi, %rbp
callq 0x3080
jmp 0x42149
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq