// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r15
callq 0xe717
movq 0x5f756(%rip), %rcx     # 0x69ff8
movq (%rcx), %rdi
leaq 0x4c0fe(%rip), %rsi     # 0x569aa
movl $0x0, 0x10(%rsp)
movq %rax, %rdx
xorl %eax, %eax
callq 0x3280
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2f9e4
movq %rax, %rbx
movslq 0x80(%rax), %r15
movq %r12, %rdi
callq 0x3150
movq %rax, %r13
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x3260
movq %rax, %r15
testl %r13d, %r13d
jle 0xa921
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
xorl %ebp, %ebp
movsbq (%r12,%rbp), %r14
movl $0x3f800000, (%r15,%r14,4) # imm = 0x3F800000
movq %rbx, %rdi
movq %r15, %rsi
callq 0x307ea
andl $0x0, (%r15,%r14,4)
incq %rbp
cmpq %rbp, %r13
jne 0xa8fc
movq %rbx, 0x8(%rsp)
movq 0x5f6ab(%rip), %rax     # 0x69fd8
movq (%rax), %rdi
callq 0x34b0
movl %eax, %r12d
pushq $0x1
popq %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
cmpl $-0x1, %r12d
je 0xaa63
movq 0x5f683(%rip), %rax     # 0x69fd8
movq (%rax), %rdi
callq 0x34b0
movl %eax, %ebp
cmpl $-0x1, %eax
je 0xaa4e
cmpl $0xff, %ebp
jb 0xa97c
leaq 0x4e04b(%rip), %rdi     # 0x589c2
callq 0xe956
cmpl $0x20, %ebp
ja 0xaa59
movl %ebp, %eax
movabsq $0x100000600, %rcx      # imm = 0x100000600
btq %rax, %rcx
movq 0x8(%rsp), %rdi
jae 0xa99f
incl %r13d
movl 0x10(%rsp), %ebx
incl %ebx
movslq %r12d, %r14
movl $0x3f800000, (%r15,%r14,4) # imm = 0x3F800000
movq %r15, %rsi
callq 0x307ea
andl $0x0, (%r15,%r14,4)
movslq %ebp, %rcx
cvtss2sd (%rax,%rcx,4), %xmm0
callq 0x31e0
divsd 0x4df66(%rip), %xmm0    # 0x58938
cvtss2sd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, %xmm1
cvtsi2ss %ebx, %xmm0
xorps 0x4875d(%rip), %xmm1    # 0x53150
movaps %xmm1, 0x10(%rsp)
divss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
callq 0x3030
cvtsi2ss %r13d, %xmm1
movsd %xmm0, 0x20(%rsp)
movaps 0x10(%rsp), %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3030
movaps %xmm0, %xmm2
leaq 0x4dfda(%rip), %rdi     # 0x58a0c
movl %ebx, 0x10(%rsp)
movl %ebx, %esi
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movb $0x3, %al
callq 0x3170
movl %ebp, %r12d
cmpl $-0x1, %ebp
jne 0xa944
jmp 0xaa63
movq 0x8(%rsp), %rdi
jmp 0xa99f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq