// File: /workspace/github_cpp_makefile_star2_O3/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 0x7536
leaq -0x298(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x21f0b(%rip), %rsi     # 0x27030
leaq 0x21f36(%rip), %rdx     # 0x27062
leaq -0x2a8(%rbp), %rdi
callq 0x6442
leaq -0x360(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x759c
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 0x6442
leaq -0x178(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x22322(%rip), %rdx     # 0x274a7
leaq -0x188(%rbp), %rdi
movq %rdx, %rsi
callq 0x6442
leaq -0x158(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x22301(%rip), %rdx     # 0x274a7
leaq -0x168(%rbp), %rdi
movq %rdx, %rsi
callq 0x6442
leaq -0x138(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x21ea2(%rip), %rsi     # 0x27069
leaq 0x21eba(%rip), %rdx     # 0x27088
leaq -0x148(%rbp), %rdi
callq 0x6442
leaq -0x288(%rbp), %rdx
leaq -0x188(%rbp), %rcx
leaq -0x168(%rbp), %r8
leaq -0x148(%rbp), %r9
movq %r15, %rdi
movl $0x38, %esi
callq 0x75b4
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 0x6442
leaq -0xf8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x2226a(%rip), %rdx     # 0x274a7
leaq -0x108(%rbp), %rdi
movq %rdx, %rsi
callq 0x6442
leaq -0xd8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x22249(%rip), %rdx     # 0x274a7
leaq -0xe8(%rbp), %rdi
movq %rdx, %rsi
callq 0x6442
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x21e0a(%rip), %rsi     # 0x27089
leaq 0x21e0f(%rip), %rdx     # 0x27095
leaq -0xc8(%rbp), %rdi
callq 0x6442
leaq -0x128(%rbp), %rdx
leaq -0x108(%rbp), %rcx
leaq -0xe8(%rbp), %r8
leaq -0xc8(%rbp), %r9
movq %r15, %rdi
movl $0x68, %esi
callq 0x75b4
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 0x7fdc
movq -0x2c8(%rbp), %rax
movq -0x2c0(%rbp), %rcx
subq %rax, %rcx
cmpq $0x60, %rcx
je 0x53d0
movq 0x2fc13(%rip), %rax     # 0x34fc8
movq (%rax), %rsi
leaq -0x360(%rbp), %rdi
movl $0x1, %edx
callq 0x857e
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 0x63a4
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 0x63a4
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 0x63a4
leaq -0x218(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x21c0e(%rip), %rsi     # 0x27063
leaq 0x21c0c(%rip), %rdx     # 0x27068
leaq -0x228(%rbp), %rdi
callq 0x6442
leaq -0x360(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x8096
movb 0x4a(%rax), %bl
movq -0x228(%rbp), %rdi
cmpq %r14, %rdi
je 0x548f
callq 0x4360
leaq -0x458(%rbp), %rdi
callq 0x5cbe
leaq -0x1f8(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x1c8(%rbp), %rsi
movq -0x1c0(%rbp), %rdx
addq %rsi, %rdx
leaq -0x208(%rbp), %rdi
callq 0x63a4
leaq -0x458(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0xa97e
movq -0x208(%rbp), %rdi
cmpq %r14, %rdi
je 0x54e7
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 0x575c
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 0x5782
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 0x21a7e(%rip), %xmm0    # 0x27004
movss %xmm0, -0x38(%rbp)
leaq -0x1e8(%rbp), %r14
leaq -0x5e0(%rbp), %r15
leaq -0x1a8(%rbp), %r12
movzbl %bl, %eax
movl %eax, -0x3c(%rbp)
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 0x57b0
movq %r15, %rdi
movq %r14, %rsi
movl $0x18, %edx
callq 0x4590
movq %r15, %rdi
leaq -0xa4(%rbp), %rsi
callq 0x4700
movq %r15, %rdi
movq %r12, %rsi
callq 0x4460
movl $0x0, -0x2c(%rbp)
movl -0x458(%rbp), %r15d
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
movq %r12, %rdi
leaq -0x80(%rbp), %rsi
movl -0x3c(%rbp), %edx
callq 0x5af3
movl $0x1, %r14d
leal -0x1(%r14), %ecx
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
decq %rdx
cmpq %rcx, %rdx
jbe 0x5698
movl (%rax,%rcx,4), %edx
movl %r14d, %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 0x5dfe
movl (%rax), %ebx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x567b
callq 0x4360
incl %r14d
leaq -0x458(%rbp), %rdi
movl %r15d, %esi
movl %ebx, %edx
leaq -0x2c(%rbp), %rcx
callq 0xa7f4
movl %eax, %r15d
jmp 0x5627
xorps %xmm0, %xmm0
cvtss2sd -0x2c(%rbp), %xmm0
mulsd 0x21960(%rip), %xmm0    # 0x27008
cvtsd2ss %xmm0, %xmm1
movss %xmm1, -0x2c(%rbp)
xorps %xmm0, %xmm0
cvtss2sd -0x38(%rbp), %xmm0
cvtss2sd %xmm1, %xmm1
callq 0x5c6a
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 0x63a4
movss -0x2c(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
leaq -0xa0(%rbp), %rdi
movq %r13, %rsi
callq 0x6834
leaq -0x1e8(%rbp), %r14
leaq -0x5e0(%rbp), %r15
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5721
callq 0x4360
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x572f
callq 0x4360
xorps %xmm0, %xmm0
cvtsd2ss -0x38(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
movq %r15, %rdi
movq 0x2f84a(%rip), %rsi     # 0x34f90
callq 0x42d0
leaq -0x560(%rbp), %rdi
callq 0x4120
jmp 0x55aa
movq 0x2f885(%rip), %rdi     # 0x34fe8
leaq 0x2192c(%rip), %rsi     # 0x27096
movl $0x2c, %edx
callq 0x4410
movq 0x2f86d(%rip), %rdi     # 0x34fe8
callq 0x4190
jmp 0x57a6
movq 0x2f85f(%rip), %rdi     # 0x34fe8
leaq 0x21933(%rip), %rsi     # 0x270c3
movl $0x2d, %edx
callq 0x4410
movq 0x2f847(%rip), %rdi     # 0x34fe8
callq 0x4190
movl $0x1, %edi
callq 0x4430
movq -0xa0(%rbp), %r12
cmpq -0x98(%rbp), %r12
jne 0x57df
leaq -0x9e8(%rbp), %rdi
callq 0x40b0
leaq -0x7e0(%rbp), %rdi
callq 0x44d0
xorl %edi, %edi
callq 0x4430
leaq -0x7e0(%rbp), %rbx
leaq 0x21cb9(%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 0x57ed
jmp 0x57c0
jmp 0x584c
jmp 0x584c
jmp 0x5858
jmp 0x586f
jmp 0x586f
jmp 0x584c
movq %rax, %rbx
jmp 0x589f
movq %rax, %rbx
jmp 0x5880
jmp 0x586f
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5872
callq 0x4360
jmp 0x5872
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x5880
callq 0x4360
movq 0x2f709(%rip), %rsi     # 0x34f90
leaq -0x5e0(%rbp), %rdi
callq 0x42d0
leaq -0x560(%rbp), %rdi
callq 0x4120
leaq -0xa0(%rbp), %rdi
callq 0x5e7e
movq -0x1a8(%rbp), %rdi
leaq -0x198(%rbp), %rax
cmpq %rax, %rdi
je 0x58c3
callq 0x4360
movq -0x1e8(%rbp), %rdi
leaq -0x1d8(%rbp), %rax
cmpq %rax, %rdi
je 0x58e0
callq 0x4360
jmp 0x58e0
movq %rax, %rbx
leaq -0x7e0(%rbp), %rdi
callq 0x4520
jmp 0x58f3
jmp 0x58f0
movq %rax, %rbx
leaq -0x9e8(%rbp), %rdi
callq 0x40d0
jmp 0x591c
jmp 0x5919
movq %rax, %rbx
movq -0x208(%rbp), %rdi
cmpq %r14, %rdi
je 0x591c
callq 0x4360
jmp 0x591c
movq %rax, %rbx
leaq -0x458(%rbp), %rdi
callq 0x5ed6
jmp 0x5945
jmp 0x5942
movq %rax, %rbx
movq -0x228(%rbp), %rdi
cmpq %r14, %rdi
je 0x5945
callq 0x4360
jmp 0x5945
movq %rax, %rbx
movq -0x248(%rbp), %rdi
leaq -0x238(%rbp), %rax
cmpq %rax, %rdi
je 0x5962
callq 0x4360
jmp 0x5962
movq %rax, %rbx
movq -0x268(%rbp), %rdi
leaq -0x258(%rbp), %rax
cmpq %rax, %rdi
je 0x597f
callq 0x4360
jmp 0x597f
movq %rax, %rbx
movq -0x1c8(%rbp), %rdi
leaq -0x1b8(%rbp), %rax
cmpq %rax, %rdi
jne 0x5a99
jmp 0x5aa3
jmp 0x5aa0
jmp 0x5aa0
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x59c5
callq 0x4360
jmp 0x59c5
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x59e2
callq 0x4360
jmp 0x59e2
movq %rax, %rbx
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x59ff
callq 0x4360
jmp 0x59ff
movq %rax, %rbx
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x5a1e
callq 0x4360
jmp 0x5a1e
jmp 0x5a1b
movq %rax, %rbx
movq -0x148(%rbp), %rdi
leaq -0x138(%rbp), %rax
cmpq %rax, %rdi
je 0x5a3b
callq 0x4360
jmp 0x5a3b
movq %rax, %rbx
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
cmpq %rax, %rdi
je 0x5a58
callq 0x4360
jmp 0x5a58
movq %rax, %rbx
movq -0x188(%rbp), %rdi
leaq -0x178(%rbp), %rax
cmpq %rax, %rdi
je 0x5a75
callq 0x4360
jmp 0x5a75
movq %rax, %rbx
movq -0x288(%rbp), %rdi
cmpq %r13, %rdi
je 0x5a8d
callq 0x4360
jmp 0x5a8d
jmp 0x5a8a
movq %rax, %rbx
movq -0x2a8(%rbp), %rdi
cmpq %r12, %rdi
je 0x5aa3
callq 0x4360
jmp 0x5aa3
movq %rax, %rbx
leaq -0x2c8(%rbp), %rdi
callq 0x5f48
leaq -0x2f8(%rbp), %rdi
callq 0x6006
leaq -0x328(%rbp), %rdi
callq 0x62da
leaq -0x340(%rbp), %r14
movq %r14, %rdi
callq 0x62a6
movq -0x20(%r14), %rdi
leaq -0x350(%rbp), %rax
cmpq %rax, %rdi
je 0x5aeb
callq 0x4360
movq %rbx, %rdi
callq 0x4650