// File: /workspace/github_c_makefile_star2_O1/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, %ebx
movq %rcx, %rbp
movq %rdi, %r14
movq %rsi, %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x2f9e4
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movl $0x1, %esi
callq 0x302d4
movl $0x21e88e, %edi         # imm = 0x21E88E
callq 0x3230
movq %r14, %rdi
callq 0x34b9c
movq %rax, %r14
leaq 0xc4dc(%rip), %rsi      # 0x576e9
movq %rax, %rdi
xorl %edx, %edx
callq 0x34d5b
movq %rax, %r15
testq %rax, %rax
jne 0x4b238
leaq 0xb730(%rip), %rsi      # 0x56956
leaq 0xd926(%rip), %rdx      # 0x58b53
movq %r14, %rdi
callq 0x34d5b
movq %rax, %r15
testl %ebx, %ebx
jne 0x4b252
leaq 0xdc31(%rip), %rsi      # 0x58e74
movq %r14, %rdi
movl $0x1, %edx
callq 0x34d9f
movl %eax, %ebx
movq %r15, %rdi
callq 0x2b6d3
movq %rax, %r15
movslq %ebx, %rbx
movl $0x4, %esi
movq %rbx, %rdi
callq 0x3260
movq %rax, %r12
movl %ebx, %r13d
leaq 0x70(%rsp), %r14
leaq 0xd976(%rip), %rbx      # 0x58bf5
movq %rbp, 0x30(%rsp)
testq %rbp, %rbp
jne 0x4b43c
leaq 0xcd76(%rip), %rdi      # 0x5800a
xorl %eax, %eax
callq 0x3170
movq 0x1ed2e(%rip), %rax     # 0x69fd0
movq (%rax), %rdi
callq 0x3320
movq 0x1ed27(%rip), %rax     # 0x69fd8
movq (%rax), %rdx
movq %r14, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x3240
testq %rax, %rax
je 0x4b451
movq %rax, %r14
movq %rax, %rdi
leaq 0xd232(%rip), %rsi      # 0x58509
callq 0x33c0
leaq 0x40(%rsp), %rdi
movq %r14, 0x20(%rsp)
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x160b6
movq 0x28(%rsp), %rbp
movl 0x90(%rbp), %edx
movl 0x94(%rbp), %esi
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x58(%rsp), %rdi
callq 0x1905c
movq 0x68(%rsp), %r14
callq 0x3130
movq %rax, 0x38(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x307ea
movq %rax, %r14
movq 0xd0(%rbp), %rdx
testq %rdx, %rdx
je 0x4b362
movl 0x84(%rbp), %esi
movq %r14, %rdi
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x3cc56
movl 0x84(%rbp), %esi
movq %r14, %rdi
movl %r13d, %edx
movq %r12, %rcx
callq 0xe8e2
movq 0x1ec7b(%rip), %rax     # 0x69ff8
movq (%rax), %rbp
callq 0x3130
subq 0x38(%rsp), %rax
movq %rax, %rdi
callq 0xe8d4
cvtss2sd %xmm0, %xmm0
movq %rbp, %rdi
leaq 0xcc44(%rip), %rsi      # 0x57fe4
movq 0x20(%rsp), %rdx
movb $0x1, %al
callq 0x3280
testl %r13d, %r13d
movss 0x7e8d(%rip), %xmm1     # 0x53244
jle 0x4b3eb
xorl %ebp, %ebp
movslq (%r12,%rbp,4), %rax
movss (%r14,%rax,4), %xmm0
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movq (%r15,%rax,8), %rsi
movq %rbx, %rdi
movb $0x1, %al
callq 0x3170
movss 0x7e61(%rip), %xmm1     # 0x53244
incq %rbp
cmpq %rbp, %r13
jne 0x4b3bb
movq 0x68(%rsp), %rax
cmpq 0x50(%rsp), %rax
je 0x4b40f
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x15b37
movq 0x30(%rsp), %rbp
testq %rbp, %rbp
movq 0x20(%rsp), %r14
je 0x4b284
jmp 0x4b451
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3080
jmp 0x4b2dc
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq