// File: /workspace/github_c_makefile_star2_O3/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 0x316bc
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movl $0x1, %esi
callq 0x320a7
movl $0x21e88e, %edi         # imm = 0x21E88E
callq 0x3220
movq %r14, %rdi
callq 0x36cb4
movq %rax, %r14
leaq 0xc307(%rip), %rsi      # 0x597e9
movq %rax, %rdi
xorl %edx, %edx
callq 0x36e77
movq %rax, %r15
testq %rax, %rax
jne 0x4d50d
leaq 0xb55b(%rip), %rsi      # 0x58a56
leaq 0xd7c2(%rip), %rdx      # 0x5acc4
movq %r14, %rdi
callq 0x36e77
movq %rax, %r15
testl %ebx, %ebx
jne 0x4d527
leaq 0xdab4(%rip), %rsi      # 0x5afcc
movq %r14, %rdi
movl $0x1, %edx
callq 0x36eed
movl %eax, %ebx
movq %r15, %rdi
callq 0x2d26c
movq %rax, %r15
movslq %ebx, %rbx
movl $0x4, %esi
movq %rbx, %rdi
callq 0x3250
movq %rax, %r12
movl %ebx, %r13d
leaq 0x70(%rsp), %r14
leaq 0xd812(%rip), %rbx      # 0x5ad66
movq %rbp, 0x30(%rsp)
testq %rbp, %rbp
jne 0x4d711
leaq 0xcbd9(%rip), %rdi      # 0x5a142
xorl %eax, %eax
callq 0x3160
movq 0x1ea59(%rip), %rax     # 0x6bfd0
movq (%rax), %rdi
callq 0x3310
movq 0x1ea52(%rip), %rax     # 0x6bfd8
movq (%rax), %rdx
movq %r14, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x3230
testq %rax, %rax
je 0x4d726
movq %rax, %r14
movq %rax, %rdi
leaq 0xd0b5(%rip), %rsi      # 0x5a661
callq 0x33b0
leaq 0x40(%rsp), %rdi
movq %r14, 0x20(%rsp)
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x16ac9
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 0x19916
movq 0x68(%rsp), %r14
callq 0x3120
movq %rax, 0x38(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x32690
movq %rax, %r14
movq 0xd0(%rbp), %rdx
testq %rdx, %rdx
je 0x4d637
movl 0x84(%rbp), %esi
movq %r14, %rdi
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x3eeda
movl 0x84(%rbp), %esi
movq %r14, %rdi
movl %r13d, %edx
movq %r12, %rcx
callq 0xf0cd
movq 0x1e9a6(%rip), %rax     # 0x6bff8
movq (%rax), %rbp
callq 0x3120
subq 0x38(%rsp), %rax
movq %rax, %rdi
callq 0xf0bf
cvtss2sd %xmm0, %xmm0
movq %rbp, %rdi
leaq 0xcaa7(%rip), %rsi      # 0x5a11c
movq 0x20(%rsp), %rdx
movb $0x1, %al
callq 0x3270
testl %r13d, %r13d
movss 0x7be8(%rip), %xmm1     # 0x55274
jle 0x4d6c0
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 0x3160
movss 0x7bbc(%rip), %xmm1     # 0x55274
incq %rbp
cmpq %rbp, %r13
jne 0x4d690
movq 0x68(%rsp), %rax
cmpq 0x50(%rsp), %rax
je 0x4d6e4
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x58(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x1657b
movq 0x30(%rsp), %rbp
testq %rbp, %rbp
movq 0x20(%rsp), %r14
je 0x4d559
jmp 0x4d726
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3080
jmp 0x4d5b1
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq