// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/rnn.c
// Function: valid_char_rnn
void valid_char_rnn(char *cfgfile, char *weightfile, char *seed)
{
    char *base = basecfg(cfgfile);
    fprintf(stderr, "%s\n", base);

    network *net = load_network(cfgfile, weightfile, 0);
    int inputs = net->inputs;

    int count = 0;
    int words = 1;
    int c;
    int len = strlen(seed);
    float *input = calloc(inputs, sizeof(float));
    int i;
    for(i = 0; i < len; ++i){
        c = seed[i];
        input[(int)c] = 1;
        network_predict(net, input);
        input[(int)c] = 0;
    }
    float sum = 0;
    c = getc(stdin);
    float log2 = log(2);
    while(c != EOF){
        int next = getc(stdin);
        if(next == EOF) break;
        if(next < 0 || next >= 255) error("Out of range character");
        ++count;
        if(next == ' ' || next == '\n' || next == '\t') ++words;
        input[c] = 1;
        float *out = network_predict(net, input);
        input[c] = 0;
        sum += log(out[next])/log2;
        c = next;
        printf("%d BPC: %4.4f   Perplexity: %4.4f    Word Perplexity: %4.4f\n", count, -sum/count, pow(2, -sum/count), pow(2, -sum/words));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
callq 0x41c8
movq 0x25a72(%rip), %rcx     # 0x63ff8
movq (%rcx), %rdi
leaq 0x1146a(%rip), %rsi     # 0x4f9fa
xorl %r13d, %r13d
movq %rax, %rdx
xorl %eax, %eax
callq 0x3270
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x22658
movq %rax, %rbx
movslq 0x80(%rax), %r14
movq %r15, %rdi
callq 0x3140
movq %rax, %r12
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x3250
movq %rax, %r14
testl %r12d, %r12d
cmovlel %r13d, %r12d
cmpq %r13, %r12
je 0x3e5fb
movsbq (%r15,%r13), %rbp
movl $0x3f800000, (%r14,%rbp,4) # imm = 0x3F800000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x233e2
andl $0x0, (%r14,%rbp,4)
incq %r13
jmp 0x3e5d4
movq 0x259d6(%rip), %rax     # 0x63fd8
movq (%rax), %rdi
callq 0x34a0
movl %eax, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
pushq $0x1
popq %rbp
movl %ebp, %r12d
cmpl $-0x1, %r15d
je 0x3e71c
movq 0x259ac(%rip), %rax     # 0x63fd8
movq (%rax), %rdi
callq 0x34a0
cmpl $-0x1, %eax
je 0x3e71c
movl %eax, %r13d
cmpl $0xff, %eax
jb 0x3e653
leaq 0x13384(%rip), %rdi     # 0x519d2
callq 0x43df
cmpl $0x20, %r13d
ja 0x3e66f
movl %r13d, %eax
movabsq $0x100000600, %rcx      # imm = 0x100000600
btq %rax, %rcx
jae 0x3e66f
incl %r12d
movslq %r15d, %r15
movl $0x3f800000, (%r14,%r15,4) # imm = 0x3F800000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x233e2
andl $0x0, (%r14,%r15,4)
movslq %r13d, %rcx
cvtss2sd (%rax,%rcx,4), %xmm0
callq 0x31d0
divsd 0x132a9(%rip), %xmm0    # 0x51948
cvtss2sd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, %xmm1
cvtsi2ss %ebp, %xmm0
xorps 0xda90(%rip), %xmm1     # 0x4c150
movaps %xmm1, 0x20(%rsp)
divss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x3030
cvtsi2ss %r12d, %xmm1
movsd %xmm0, (%rsp)
movaps 0x20(%rsp), %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3030
movaps %xmm0, %xmm2
leaq 0x1331e(%rip), %rdi     # 0x51a1c
movl %ebp, %esi
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
movb $0x3, %al
callq 0x3160
incl %ebp
movl %r13d, %r15d
jmp 0x3e61b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq