// File: /workspace/github_c_makefile_star2_O2/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 0x41c8
movq 0x25c6a(%rip), %rcx     # 0x63ff8
movq (%rcx), %rdi
leaq 0x11662(%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, 0x8(%rsp)
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 0x3e407
movsbq (%r15,%r13), %rbp
movl $0x3f800000, (%r14,%rbp,4) # imm = 0x3F800000
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x233e2
andl $0x0, (%r14,%rbp,4)
incq %r13
jmp 0x3e3de
movq 0x25bca(%rip), %rax     # 0x63fd8
movq (%rax), %rdi
callq 0x34a0
movl %eax, %r13d
pushq $0x1
popq %rbx
xorl %r15d, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movl $0x0, 0x10(%rsp)
movl %r13d, %r12d
cmpl $-0x1, %r13d
je 0x3e554
movq 0x25b95(%rip), %rax     # 0x63fd8
movq (%rax), %rdi
callq 0x34a0
cmpl $-0x1, %eax
je 0x3e554
movl %eax, %r13d
cmpl $0xff, %eax
jb 0x3e46a
leaq 0x1356d(%rip), %rdi     # 0x519d2
callq 0x43df
movslq %r12d, %rbp
movl $0x3f800000, (%r14,%rbp,4) # imm = 0x3F800000
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x233e2
andl $0x0, (%r14,%rbp,4)
movl %r12d, %ecx
xorl $0x2e, %ecx
movl %r13d, %edx
xorl $0xa, %edx
orl %ecx, %edx
sete %cl
testl %r15d, %r15d
je 0x3e4a1
testb %cl, %cl
je 0x3e4bd
xorl $0x3e, %r12d
movl %r13d, %eax
xorl $0x3e, %eax
xorl %r15d, %r15d
orl %r12d, %eax
sete %r15b
addl %r15d, %ebx
jmp 0x3e42f
movl 0x10(%rsp), %r15d
incl %r15d
movslq %r13d, %rcx
cvtss2sd (%rax,%rcx,4), %xmm0
callq 0x31d0
divsd 0x1346e(%rip), %xmm0    # 0x51948
cvtss2sd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, %xmm1
cvtsi2ss %r15d, %xmm0
xorps 0xdc54(%rip), %xmm1     # 0x4c150
movaps %xmm1, 0x10(%rsp)
divss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
callq 0x3030
cvtsi2ss %ebx, %xmm1
movsd %xmm0, 0x28(%rsp)
movaps 0x10(%rsp), %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3030
movaps %xmm0, %xmm1
leaq 0x134b5(%rip), %rdi     # 0x519e9
movl %r15d, 0x10(%rsp)
movl %r15d, %esi
movl %ebx, %edx
movsd 0x28(%rsp), %xmm0
movb $0x2, %al
callq 0x3160
pushq $0x1
popq %r15
jmp 0x3e42f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq