// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/rnn.c
// Function: valid_tactic_rnn
void valid_tactic_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);
    int in = 0;
    while(c != EOF){
        int next = getc(stdin);
        if(next == EOF) break;
        if(next < 0 || next >= 255) error("Out of range character");

        input[c] = 1;
        float *out = network_predict(net, input);
        input[c] = 0;

        if(c == '.' && next == '\n') in = 0;
        if(!in) {
            if(c == '>' && next == '>'){
                in = 1;
                ++words;
            }
            c = next;
            continue;
        }
        ++count;
        sum += log(out[next])/log2;
        c = next;
        printf("%d %d Perplexity: %4.4f    Word Perplexity: %4.4f\n", count, words, 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, %r15
movq %rsi, %rbx
movq %rdi, %r14
callq 0xef02
movq 0x611a5(%rip), %rcx     # 0x6bff8
movq (%rcx), %rdi
leaq 0x4dc4d(%rip), %rsi     # 0x58aaa
movq %rax, %rdx
xorl %eax, %eax
callq 0x3270
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x316bc
movq %rax, %rbp
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 0xaeca
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %ebx, %ebx
movsbq (%r15,%rbx), %r13
movl $0x3f800000, (%r14,%r13,4) # imm = 0x3F800000
movq %rbp, %rdi
movq %r14, %rsi
callq 0x32690
andl $0x0, (%r14,%r13,4)
incq %rbx
cmpq %rbx, %r12
jne 0xaea5
movq 0x61107(%rip), %rax     # 0x6bfd8
movq (%rax), %rdi
callq 0x34a0
cmpl $-0x1, %eax
je 0xb02e
movl %eax, %r15d
movq 0x610ec(%rip), %rax     # 0x6bfd8
movq (%rax), %rdi
callq 0x34a0
cmpl $-0x1, %eax
je 0xb02e
pushq $0x1
popq %rcx
xorl %ebx, %ebx
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movl %ecx, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movq %rbp, %r13
movl %eax, %r12d
cmpl $0xff, %eax
jb 0xaf2f
leaq 0x4fbe8(%rip), %rdi     # 0x5ab12
callq 0xf141
movslq %r15d, %rbp
movl $0x3f800000, (%r14,%rbp,4) # imm = 0x3F800000
movq %r13, %rdi
movq %r14, %rsi
callq 0x32690
andl $0x0, (%r14,%rbp,4)
xorl $0x2e, %ebp
movl %r12d, %ecx
xorl $0xa, %ecx
orl %ebp, %ecx
sete %cl
testl %ebx, %ebx
je 0xaffa
testb %cl, %cl
jne 0xaffa
movl 0x10(%rsp), %ebp
incl %ebp
movslq %r12d, %rcx
cvtss2sd (%rax,%rcx,4), %xmm0
callq 0x31d0
divsd 0x4fb05(%rip), %xmm0    # 0x5aa88
cvtss2sd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, %xmm1
cvtsi2ss %ebp, %xmm0
xorps 0x4a0ec(%rip), %xmm1    # 0x55090
movaps %xmm1, 0x10(%rsp)
divss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
callq 0x3030
movl 0xc(%rsp), %ebx
cvtsi2ss %ebx, %xmm1
movsd %xmm0, 0x28(%rsp)
movaps 0x10(%rsp), %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3030
movaps %xmm0, %xmm1
leaq 0x4fb49(%rip), %rdi     # 0x5ab29
movl %ebp, 0x10(%rsp)
movl %ebp, %esi
movl %ebx, %edx
movsd 0x28(%rsp), %xmm0
movb $0x2, %al
callq 0x3160
pushq $0x1
popq %rbx
jmp 0xb010
xorl $0x3e, %r15d
movl %r12d, %eax
xorl $0x3e, %eax
xorl %ebx, %ebx
orl %r15d, %eax
sete %bl
addl %ebx, 0xc(%rsp)
movq 0x60fc1(%rip), %rax     # 0x6bfd8
movq (%rax), %rdi
callq 0x34a0
movl %r12d, %r15d
cmpl $-0x1, %eax
movq %r13, %rbp
jne 0xaf16
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq