// File: aalto-speech[P]ftk/util/Ngram.cc
// Function: Ngram::read_arpa_read_order(std::basic_ifstream<char, std::char_traits<char>>&, std::vector<Ngram::NgramInfo, std::allocator<Ngram::NgramInfo>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, int, int&)
int
Ngram::read_arpa_read_order(ifstream &arpafile,
                            vector<NgramInfo> &order_ngrams,
                            string &line,
                            int curr_ngram_order,
                            int &linei)
{
    int ngrams_read = 0;

    while (line.length() > 0) {
        stringstream vals(line);

        NgramInfo ngram;
        vals >> ngram.prob;
        if (ngram.prob > 0.0)
            throw string("Invalid log probability");

        vector<string> curr_ngram_str;
        string tmp;
        for (int i=0; i<curr_ngram_order; i++) {
            if (vals.eof()) throw string("Invalid ARPA line");
            vals >> tmp;
            str::clean(tmp);
            curr_ngram_str.push_back(tmp);
        }
        if (curr_ngram_order == 1) {
            vocabulary.push_back(curr_ngram_str[0]);
            vocabulary_lookup[curr_ngram_str[0]] = vocabulary.size()-1;
        }

        vector<int> curr_ngram_words;
        for (auto sit = curr_ngram_str.begin(); sit != curr_ngram_str.end(); ++sit)
            curr_ngram_words.push_back(vocabulary_lookup[*sit]);
        ngram.ngram = curr_ngram_words;

        if (!vals.eof())
            vals >> ngram.backoff_prob;

        order_ngrams.push_back(ngram);
        _getline(arpafile, line, linei);
        ngrams_read++;
    }

    return ngrams_read;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x268(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x20(%rbp), %rdi
callq 0x45e0
cmpq $0x0, %rax
jbe 0x131ee
movq -0x20(%rbp), %rax
movq %rax, -0x270(%rbp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x13950
movq -0x270(%rbp), %rsi
movl %eax, %edx
leaq -0x1c0(%rbp), %rdi
callq 0x4630
leaq -0x1e8(%rbp), %rdi
callq 0x13cd0
jmp 0x12d05
leaq -0x1d0(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x4350
jmp 0x12d1a
movsd -0x1d0(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x12e0b
movb $0x1, -0x1f6(%rbp)
movl $0x20, %edi
callq 0x41e0
movq %rax, -0x280(%rbp)
movq %rax, -0x288(%rbp)
leaq -0x1f5(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x46f0
movq -0x280(%rbp), %rdi
movq -0x278(%rbp), %rdx
leaq 0x53754(%rip), %rsi     # 0x664ca
callq 0x4550
jmp 0x12d7d
movq -0x288(%rbp), %rdi
movb $0x0, -0x1f6(%rbp)
leaq 0x80fbe(%rip), %rsi     # 0x93d50
movq 0x81207(%rip), %rdx     # 0x93fa0
callq 0x46b0
jmp 0x13206
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f0(%rbp)
movl %eax, -0x1f4(%rbp)
jmp 0x131e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f0(%rbp)
movl %eax, -0x1f4(%rbp)
jmp 0x131d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f0(%rbp)
movl %eax, -0x1f4(%rbp)
leaq -0x1f5(%rbp), %rdi
callq 0x4420
testb $0x1, -0x1f6(%rbp)
jne 0x12dfa
jmp 0x12e06
movq -0x288(%rbp), %rdi
callq 0x42f0
jmp 0x131d4
leaq -0x210(%rbp), %rdi
callq 0xa160
leaq -0x230(%rbp), %rdi
callq 0x4560
movl $0x0, -0x234(%rbp)
movl -0x234(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x12f85
movq -0x1c0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x1c0(%rbp,%rax), %rdi
callq 0x4740
movb %al, -0x289(%rbp)
jmp 0x12e5c
movb -0x289(%rbp), %al
testb $0x1, %al
jne 0x12e6b
jmp 0x12f30
movb $0x1, -0x236(%rbp)
movl $0x20, %edi
callq 0x41e0
movq %rax, -0x2a0(%rbp)
movq %rax, -0x2a8(%rbp)
leaq -0x235(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x46f0
movq -0x2a0(%rbp), %rdi
movq -0x298(%rbp), %rdx
leaq 0x53630(%rip), %rsi     # 0x664e2
callq 0x4550
jmp 0x12eb9
movq -0x2a8(%rbp), %rdi
movb $0x0, -0x236(%rbp)
leaq 0x80e82(%rip), %rsi     # 0x93d50
movq 0x810cb(%rip), %rdx     # 0x93fa0
callq 0x46b0
jmp 0x13206
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f0(%rbp)
movl %eax, -0x1f4(%rbp)
jmp 0x131bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f0(%rbp)
movl %eax, -0x1f4(%rbp)
leaq -0x235(%rbp), %rdi
callq 0x4420
testb $0x1, -0x236(%rbp)
jne 0x12f1f
jmp 0x12f2b
movq -0x2a8(%rbp), %rdi
callq 0x42f0
jmp 0x131bc
leaq -0x1c0(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x44b0
jmp 0x12f45
leaq 0x535a8(%rip), %rsi     # 0x664f4
leaq -0x230(%rbp), %rdi
callq 0x13d10
jmp 0x12f5a
leaq -0x210(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0xabb0
jmp 0x12f6f
jmp 0x12f71
movl -0x234(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x234(%rbp)
jmp 0x12e2d
cmpl $0x1, -0x24(%rbp)
jne 0x13026
movq -0x268(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x2b0(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x210(%rbp), %rdi
callq 0x5f90
movq -0x2b0(%rbp), %rdi
movq %rax, %rsi
callq 0xabb0
jmp 0x12fc2
movq -0x268(%rbp), %rdi
addq $0x30, %rdi
callq 0x5f70
movq %rax, %rcx
movq -0x268(%rbp), %rax
decl %ecx
movl %ecx, -0x2c4(%rbp)
addq $0x48, %rax
movq %rax, -0x2c0(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x210(%rbp), %rdi
callq 0x5f90
movq -0x2c0(%rbp), %rdi
movq %rax, %rsi
callq 0xa7c0
movq %rax, -0x2b8(%rbp)
jmp 0x13017
movq -0x2b8(%rbp), %rax
movl -0x2c4(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x250(%rbp), %rdi
callq 0x13df0
leaq -0x210(%rbp), %rdi
callq 0xb2f0
movq %rax, -0x258(%rbp)
leaq -0x210(%rbp), %rdi
callq 0xb320
movq %rax, -0x260(%rbp)
leaq -0x258(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x11960
testb $0x1, %al
jne 0x13074
jmp 0x130f5
movq -0x268(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x2d8(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x119d0
movq -0x2d8(%rbp), %rdi
movq %rax, %rsi
callq 0xa7c0
movq %rax, -0x2d0(%rbp)
jmp 0x130aa
movq -0x2d0(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x13e10
jmp 0x130bf
jmp 0x130c1
leaq -0x258(%rbp), %rdi
callq 0x117f0
jmp 0x13045
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f0(%rbp)
movl %eax, -0x1f4(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x14140
jmp 0x131bc
leaq -0x1e8(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x13e80
jmp 0x1310a
movq -0x1c0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x1c0(%rbp,%rax), %rdi
callq 0x4740
movb %al, -0x2d9(%rbp)
jmp 0x1312a
movb -0x2d9(%rbp), %al
testb $0x1, %al
jne 0x1314d
jmp 0x13136
leaq -0x1c8(%rbp), %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x4350
jmp 0x1314b
jmp 0x1314d
movq -0x18(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x140d0
jmp 0x1315f
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x121d0
jmp 0x13172
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x14140
leaq -0x230(%rbp), %rdi
callq 0x4828
leaq -0x210(%rbp), %rdi
callq 0x6970
leaq -0x1e8(%rbp), %rdi
callq 0x141a0
leaq -0x1c0(%rbp), %rdi
callq 0x4310
jmp 0x12cb5
leaq -0x230(%rbp), %rdi
callq 0x4828
leaq -0x210(%rbp), %rdi
callq 0x6970
leaq -0x1e8(%rbp), %rdi
callq 0x141a0
leaq -0x1c0(%rbp), %rdi
callq 0x4310
jmp 0x131fa
movl -0x34(%rbp), %eax
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
movq -0x1f0(%rbp), %rdi
callq 0x46e0
nopw %cs:(%rax,%rax)