// File: /workspace/github_c_makefile_star2_O1/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 0xe717
movq 0x5f952(%rip), %rcx     # 0x69ff8
movq (%rcx), %rdi
leaq 0x4c2fa(%rip), %rsi     # 0x569aa
movq %rax, %rdx
xorl %eax, %eax
callq 0x3280
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2f9e4
movq %rax, %rbp
movslq 0x80(%rax), %r14
movq %r15, %rdi
callq 0x3150
movq %rax, %r12
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x3260
movq %rax, %r14
testl %r12d, %r12d
jle 0xa71e
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movsbq (%r15,%r13), %rbx
movl $0x3f800000, (%r14,%rbx,4) # imm = 0x3F800000
movq %rbp, %rdi
movq %r14, %rsi
callq 0x307ea
andl $0x0, (%r14,%rbx,4)
incq %r13
cmpq %r13, %r12
jne 0xa6f9
movq %rbp, 0x18(%rsp)
movq 0x5f8ae(%rip), %rax     # 0x69fd8
movq (%rax), %rdi
callq 0x34b0
movl %eax, %r12d
pushq $0x1
popq %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movl %eax, 0xc(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpl $-0x1, %r12d
je 0xa870
movq 0x5f87e(%rip), %rax     # 0x69fd8
movq (%rax), %rdi
callq 0x34b0
movl %eax, %r15d
cmpl $-0x1, %eax
je 0xa866
cmpl $0xff, %r15d
jb 0xa783
leaq 0x4e244(%rip), %rdi     # 0x589c2
callq 0xe956
movslq %r12d, %rbx
movl $0x3f800000, (%r14,%rbx,4) # imm = 0x3F800000
movq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x307ea
andl $0x0, (%r14,%rbx,4)
movl %r12d, %ecx
xorl $0x2e, %ecx
movl %r15d, %edx
xorl $0xa, %edx
orl %ecx, %edx
je 0xa84c
testl %ebp, %ebp
je 0xa84c
incl %r13d
movslq %r15d, %rcx
cvtss2sd (%rax,%rcx,4), %xmm0
callq 0x31e0
divsd 0x4e164(%rip), %xmm0    # 0x58938
cvtss2sd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, %xmm1
cvtsi2ss %r13d, %xmm0
xorps 0x4895a(%rip), %xmm1    # 0x53150
movaps %xmm1, 0x30(%rsp)
divss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
callq 0x3030
movl 0xc(%rsp), %ebx
cvtsi2ss %ebx, %xmm1
movsd %xmm0, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3030
movaps %xmm0, %xmm1
leaq 0x4e1a7(%rip), %rdi     # 0x589d9
movl %r13d, %esi
movl %ebx, %edx
movsd 0x10(%rsp), %xmm0
movb $0x2, %al
callq 0x3170
movl %r15d, %r12d
pushq $0x1
popq %rbp
jmp 0xa866
xorl $0x3e, %r12d
movl %r15d, %eax
xorl $0x3e, %eax
xorl %ebp, %ebp
orl %r12d, %eax
sete %bpl
addl %ebp, 0xc(%rsp)
movl %r15d, %r12d
cmpl $-0x1, %r15d
jne 0xa749
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq