// File: /workspace/github_cpp_makefile_star2_O1/aalto-speech[P]ftk/src/strscore.cc
// Function: main
int main(int argc, char* argv[]) {

    conf::Config config;
    config("usage: strscore [OPTION...] ARPAFILE INPUT OUTPUT\n")
    ('8', "utf-8", "", "", "Utf-8 character encoding in use")
    ('h', "help", "", "", "display help");
    config.default_parse(argc, argv);
    if (config.arguments.size() != 3) config.print_help(stderr, 1);

    string arpafname = config.arguments[0];
    string infname = config.arguments[1];
    string outfname = config.arguments[2];
    bool utf8_encoding = config["utf-8"].specified;

    Ngram lm;
    lm.read_arpa(arpafname);

    ifstream infile(infname);
    if (!infile) {
        cerr << "Something went wrong opening the input file." << endl;
        exit(1);
    }

    ofstream outfile(outfname);
    if (!outfile) {
        cerr << "Something went wrong opening the output file." << endl;
        exit(1);
    }

    float count;
    string line, lstr;
    vector<pair<string, float> > scores;
    float normalizer = SMALL_LP;
    while (getline(infile, line)) {
        stringstream ss(line);
        ss >> count;
        ss >> lstr;

        float total_prob = 0.0;
        int node_id = lm.root_node;

        vector<unsigned int> char_positions;
        get_character_positions(lstr, char_positions, utf8_encoding);
        for (unsigned int i=0; i<char_positions.size()-1; i++) {
            unsigned int start_pos = char_positions[i];
            unsigned int end_pos = char_positions[i+1];
            int sym = lm.vocabulary_lookup[lstr.substr(start_pos, end_pos-start_pos)];
            node_id = lm.score(node_id, sym, total_prob);
        }

        total_prob *= log(10.0); // Convert from log10 (ARPA default) to ln
        normalizer = add_log_domain_probs(normalizer, total_prob);
        scores.push_back(make_pair(lstr, total_prob));
    }

    for (auto it=scores.begin(); it != scores.end(); ++it)
        outfile << it->second-normalizer << "\t" << it->first << endl;

    infile.close();
    outfile.close();

    exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x9c8, %rsp            # imm = 0x9C8
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x360(%rbp), %rdi
callq 0x750e
leaq -0x298(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x21f0b(%rip), %rsi     # 0x27030
leaq 0x21f36(%rip), %rdx     # 0x27062
leaq -0x2a8(%rbp), %rdi
callq 0x6414
leaq -0x360(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x7574
movq %rax, %r15
leaq -0x278(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x21f03(%rip), %rsi     # 0x27063
leaq 0x21f01(%rip), %rdx     # 0x27068
leaq -0x288(%rbp), %rdi
callq 0x6414
leaq -0x178(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x22322(%rip), %rdx     # 0x274a7
leaq -0x188(%rbp), %rdi
movq %rdx, %rsi
callq 0x6414
leaq -0x158(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x22301(%rip), %rdx     # 0x274a7
leaq -0x168(%rbp), %rdi
movq %rdx, %rsi
callq 0x6414
leaq -0x138(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x21ea2(%rip), %rsi     # 0x27069
leaq 0x21eba(%rip), %rdx     # 0x27088
leaq -0x148(%rbp), %rdi
callq 0x6414
leaq -0x288(%rbp), %rdx
leaq -0x188(%rbp), %rcx
leaq -0x168(%rbp), %r8
leaq -0x148(%rbp), %r9
movq %r15, %rdi
movl $0x38, %esi
callq 0x758c
movq %rax, %r15
leaq -0x118(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x21e79(%rip), %rsi     # 0x27091
leaq 0x21e76(%rip), %rdx     # 0x27095
leaq -0x128(%rbp), %rdi
callq 0x6414
leaq -0xf8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x2226a(%rip), %rdx     # 0x274a7
leaq -0x108(%rbp), %rdi
movq %rdx, %rsi
callq 0x6414
leaq -0xd8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x22249(%rip), %rdx     # 0x274a7
leaq -0xe8(%rbp), %rdi
movq %rdx, %rsi
callq 0x6414
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x21e0a(%rip), %rsi     # 0x27089
leaq 0x21e0f(%rip), %rdx     # 0x27095
leaq -0xc8(%rbp), %rdi
callq 0x6414
leaq -0x128(%rbp), %rdx
leaq -0x108(%rbp), %rcx
leaq -0xe8(%rbp), %r8
leaq -0xc8(%rbp), %r9
movq %r15, %rdi
movl $0x68, %esi
callq 0x758c
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x52d3
callq 0x4360
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x52eb
callq 0x4360
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x5303
callq 0x4360
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x531b
callq 0x4360
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0x5333
callq 0x4360
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
cmpq %rax, %rdi
je 0x534b
callq 0x4360
movq -0x188(%rbp), %rdi
leaq -0x178(%rbp), %rax
cmpq %rax, %rdi
je 0x5363
callq 0x4360
movq -0x288(%rbp), %rdi
cmpq %r13, %rdi
je 0x5374
callq 0x4360
movq -0x2a8(%rbp), %rdi
cmpq %r12, %rdi
je 0x5385
callq 0x4360
leaq -0x360(%rbp), %rdi
movl %r14d, %esi
movq %rbx, %rdx
callq 0x7fda
movq -0x2c0(%rbp), %rax
subq -0x2c8(%rbp), %rax
cmpq $0x60, %rax
je 0x53c6
movq 0x2fc16(%rip), %rax     # 0x34fc8
movq (%rax), %rsi
leaq -0x360(%rbp), %rdi
movl $0x1, %edx
callq 0x857c
movq -0x2c8(%rbp), %rax
leaq -0x1b8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x1c8(%rbp), %rdi
callq 0x637a
movq -0x2c8(%rbp), %rax
leaq -0x258(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0x268(%rbp), %rdi
callq 0x637a
movq -0x2c8(%rbp), %rax
leaq -0x238(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq -0x248(%rbp), %rdi
callq 0x637a
leaq -0x218(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x21c11(%rip), %rsi     # 0x27063
leaq 0x21c0f(%rip), %rdx     # 0x27068
leaq -0x228(%rbp), %rdi
callq 0x6414
leaq -0x360(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x8094
movb 0x4a(%rax), %bl
movq -0x228(%rbp), %rdi
cmpq %r14, %rdi
je 0x548c
callq 0x4360
leaq -0x458(%rbp), %rdi
callq 0x5ca8
leaq -0x1f8(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x1c8(%rbp), %rsi
movq -0x1c0(%rbp), %rdx
addq %rsi, %rdx
leaq -0x208(%rbp), %rdi
callq 0x637a
leaq -0x458(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0xa9da
movq -0x208(%rbp), %rdi
cmpq %r14, %rdi
je 0x54e4
callq 0x4360
leaq -0x9e8(%rbp), %rdi
leaq -0x268(%rbp), %rsi
movl $0x8, %edx
callq 0x45b0
movq -0x9e8(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x9c8(%rbp,%rax)
jne 0x575a
leaq -0x7e0(%rbp), %rdi
leaq -0x248(%rbp), %rsi
movl $0x10, %edx
callq 0x46c0
movq -0x7e0(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x5, -0x7c0(%rbp,%rax)
jne 0x5780
leaq -0x1d8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x198(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xa0(%rbp), %rcx
movq %rax, 0x10(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rcx)
movss 0x21a81(%rip), %xmm0    # 0x27004
movss %xmm0, -0x38(%rbp)
leaq -0x1e8(%rbp), %r14
leaq -0x5e0(%rbp), %rax
leaq -0x1a8(%rbp), %r12
movzbl %bl, %ecx
movl %ecx, -0x3c(%rbp)
movq %rax, %rbx
leaq -0x68(%rbp), %r13
leaq -0x9e8(%rbp), %rdi
movq %r14, %rsi
callq 0x40a0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x57ae
movq %rbx, %rdi
movq %r14, %rsi
movl $0x18, %edx
callq 0x4590
movq %rbx, %rdi
leaq -0xa4(%rbp), %rsi
callq 0x4700
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4460
movl $0x0, -0x2c(%rbp)
movl -0x458(%rbp), %r14d
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
movq %r12, %rdi
leaq -0x80(%rbp), %rsi
movl -0x3c(%rbp), %edx
callq 0x5af1
movl $0x1, %ebx
leal -0x1(%rbx), %ecx
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
decq %rdx
cmpq %rcx, %rdx
jbe 0x5696
movl (%rax,%rcx,4), %edx
movl %ebx, %ecx
movl (%rax,%rcx,4), %ecx
subl %edx, %ecx
movq %r13, %rdi
movq %r12, %rsi
callq 0x43c0
leaq -0x410(%rbp), %rdi
movq %r13, %rsi
callq 0x5de8
movl (%rax), %r15d
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5679
callq 0x4360
incl %ebx
leaq -0x458(%rbp), %rdi
movl %r14d, %esi
movl %r15d, %edx
leaq -0x2c(%rbp), %rcx
callq 0xa850
movl %eax, %r14d
jmp 0x5626
xorps %xmm0, %xmm0
cvtss2sd -0x2c(%rbp), %xmm0
mulsd 0x21962(%rip), %xmm0    # 0x27008
cvtsd2ss %xmm0, %xmm1
movss %xmm1, -0x2c(%rbp)
xorps %xmm0, %xmm0
cvtss2sd -0x38(%rbp), %xmm0
cvtss2sd %xmm1, %xmm1
callq 0x5c55
movsd %xmm0, -0x38(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x1a8(%rbp), %rsi
movq -0x1a0(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x637a
movss -0x2c(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
leaq -0xa0(%rbp), %rdi
movq %r13, %rsi
callq 0x680c
leaq -0x1e8(%rbp), %r14
leaq -0x5e0(%rbp), %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x571f
callq 0x4360
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x572d
callq 0x4360
xorps %xmm0, %xmm0
cvtsd2ss -0x38(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
movq %rbx, %rdi
movq 0x2f84c(%rip), %rsi     # 0x34f90
callq 0x42d0
leaq -0x560(%rbp), %rdi
callq 0x4120
jmp 0x55aa
movq 0x2f887(%rip), %rdi     # 0x34fe8
leaq 0x2192e(%rip), %rsi     # 0x27096
movl $0x2c, %edx
callq 0x4410
movq 0x2f86f(%rip), %rdi     # 0x34fe8
callq 0x4190
jmp 0x57a4
movq 0x2f861(%rip), %rdi     # 0x34fe8
leaq 0x21935(%rip), %rsi     # 0x270c3
movl $0x2d, %edx
callq 0x4410
movq 0x2f849(%rip), %rdi     # 0x34fe8
callq 0x4190
movl $0x1, %edi
callq 0x4430
movq -0xa0(%rbp), %r12
cmpq -0x98(%rbp), %r12
jne 0x57dd
leaq -0x9e8(%rbp), %rdi
callq 0x40b0
leaq -0x7e0(%rbp), %rdi
callq 0x44d0
xorl %edi, %edi
callq 0x4430
leaq -0x7e0(%rbp), %rbx
leaq 0x21cbb(%rip), %r14     # 0x274a6
movss 0x20(%r12), %xmm0
subss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq %rbx, %rdi
callq 0x45a0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x4410
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x4410
movq %rax, %rdi
callq 0x4190
addq $0x28, %r12
cmpq -0x98(%rbp), %r12
jne 0x57eb
jmp 0x57be
jmp 0x584a
jmp 0x584a
jmp 0x5856
jmp 0x586d
jmp 0x586d
jmp 0x584a
movq %rax, %rbx
jmp 0x589d
movq %rax, %rbx
jmp 0x587e
jmp 0x586d
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5870
callq 0x4360
jmp 0x5870
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x587e
callq 0x4360
movq 0x2f70b(%rip), %rsi     # 0x34f90
leaq -0x5e0(%rbp), %rdi
callq 0x42d0
leaq -0x560(%rbp), %rdi
callq 0x4120
leaq -0xa0(%rbp), %rdi
callq 0x5e68
movq -0x1a8(%rbp), %rdi
leaq -0x198(%rbp), %rax
cmpq %rax, %rdi
je 0x58c1
callq 0x4360
movq -0x1e8(%rbp), %rdi
leaq -0x1d8(%rbp), %rax
cmpq %rax, %rdi
je 0x58de
callq 0x4360
jmp 0x58de
movq %rax, %rbx
leaq -0x7e0(%rbp), %rdi
callq 0x4520
jmp 0x58f1
jmp 0x58ee
movq %rax, %rbx
leaq -0x9e8(%rbp), %rdi
callq 0x40d0
jmp 0x591a
jmp 0x5917
movq %rax, %rbx
movq -0x208(%rbp), %rdi
cmpq %r14, %rdi
je 0x591a
callq 0x4360
jmp 0x591a
movq %rax, %rbx
leaq -0x458(%rbp), %rdi
callq 0x5eb6
jmp 0x5943
jmp 0x5940
movq %rax, %rbx
movq -0x228(%rbp), %rdi
cmpq %r14, %rdi
je 0x5943
callq 0x4360
jmp 0x5943
movq %rax, %rbx
movq -0x248(%rbp), %rdi
leaq -0x238(%rbp), %rax
cmpq %rax, %rdi
je 0x5960
callq 0x4360
jmp 0x5960
movq %rax, %rbx
movq -0x268(%rbp), %rdi
leaq -0x258(%rbp), %rax
cmpq %rax, %rdi
je 0x597d
callq 0x4360
jmp 0x597d
movq %rax, %rbx
movq -0x1c8(%rbp), %rdi
leaq -0x1b8(%rbp), %rax
cmpq %rax, %rdi
jne 0x5a97
jmp 0x5aa1
jmp 0x5a9e
jmp 0x5a9e
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x59c3
callq 0x4360
jmp 0x59c3
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x59e0
callq 0x4360
jmp 0x59e0
movq %rax, %rbx
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x59fd
callq 0x4360
jmp 0x59fd
movq %rax, %rbx
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x5a1c
callq 0x4360
jmp 0x5a1c
jmp 0x5a19
movq %rax, %rbx
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0x5a39
callq 0x4360
jmp 0x5a39
movq %rax, %rbx
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
cmpq %rax, %rdi
je 0x5a56
callq 0x4360
jmp 0x5a56
movq %rax, %rbx
movq -0x188(%rbp), %rdi
leaq -0x178(%rbp), %rax
cmpq %rax, %rdi
je 0x5a73
callq 0x4360
jmp 0x5a73
movq %rax, %rbx
movq -0x288(%rbp), %rdi
cmpq %r13, %rdi
je 0x5a8b
callq 0x4360
jmp 0x5a8b
jmp 0x5a88
movq %rax, %rbx
movq -0x2a8(%rbp), %rdi
cmpq %r12, %rdi
je 0x5aa1
callq 0x4360
jmp 0x5aa1
movq %rax, %rbx
leaq -0x2c8(%rbp), %rdi
callq 0x5f28
leaq -0x2f8(%rbp), %rdi
callq 0x5fdc
leaq -0x328(%rbp), %rdi
callq 0x62b0
leaq -0x340(%rbp), %r14
movq %r14, %rdi
callq 0x627c
movq -0x20(%r14), %rdi
leaq -0x350(%rbp), %rax
cmpq %rax, %rdi
je 0x5ae9
callq 0x4360
movq %rbx, %rdi
callq 0x4650