// File: /workspace/github_c_makefile_star2_O3/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 0xef02
movq 0x60f98(%rip), %rcx     # 0x6bff8
movq (%rcx), %rdi
leaq 0x4da40(%rip), %rsi     # 0x58aaa
movq %rax, %rdx
xorl %eax, %eax
callq 0x3270
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x316bc
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
jle 0xb0d8
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movsbq (%r15,%r13), %rbp
movl $0x3f800000, (%r14,%rbp,4) # imm = 0x3F800000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32690
andl $0x0, (%r14,%rbp,4)
incq %r13
cmpq %r13, %r12
jne 0xb0b3
movq 0x60ef9(%rip), %rax     # 0x6bfd8
movq (%rax), %rdi
callq 0x34a0
cmpl $-0x1, %eax
je 0xb20b
movl %eax, %ebp
movq 0x60edf(%rip), %rax     # 0x6bfd8
movq (%rax), %rdi
callq 0x34a0
cmpl $-0x1, %eax
je 0xb20b
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
pushq $0x1
popq %r15
movl %r15d, %r12d
movl %ebp, %r13d
movl %eax, %ebp
cmpl $0xff, %eax
jb 0xb131
leaq 0x4f9e6(%rip), %rdi     # 0x5ab12
callq 0xf141
cmpl $0x20, %ebp
ja 0xb14b
movl %ebp, %eax
movabsq $0x100000600, %rcx      # imm = 0x100000600
btq %rax, %rcx
jae 0xb14b
incl %r12d
movslq %r13d, %r13
movl $0x3f800000, (%r14,%r13,4) # imm = 0x3F800000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32690
andl $0x0, (%r14,%r13,4)
movslq %ebp, %rcx
cvtss2sd (%rax,%rcx,4), %xmm0
callq 0x31d0
divsd 0x4f90d(%rip), %xmm0    # 0x5aa88
cvtss2sd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, %xmm1
cvtsi2ss %r15d, %xmm0
xorps 0x49ef3(%rip), %xmm1    # 0x55090
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 0x4f981(%rip), %rdi     # 0x5ab5c
movl %r15d, %esi
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
movb $0x3, %al
callq 0x3160
movq 0x60de1(%rip), %rax     # 0x6bfd8
movq (%rax), %rdi
callq 0x34a0
incl %r15d
cmpl $-0x1, %eax
jne 0xb119
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq