// File: /workspace/github_cpp_makefile_star2_O1/aalto-speech[P]ftk/util/Ngram.cc
// Function: Ngram::read_arpa_insert_order_to_tree(std::vector<Ngram::NgramInfo, std::allocator<Ngram::NgramInfo>>&, int&, int&, int)
void
Ngram::read_arpa_insert_order_to_tree(std::vector<NgramInfo> &order_ngrams,
                                      int &curr_node_idx,
                                      int &curr_arc_idx,
                                      int curr_order)
{
    for (unsigned int ni=0; ni<order_ngrams.size(); ni++) {

        int node_idx_traversal = root_node;
        for (unsigned int i=0; i<order_ngrams[ni].ngram.size()-1; i++) {
            node_idx_traversal = find_node(node_idx_traversal, order_ngrams[ni].ngram[i]);
            if (node_idx_traversal == -1) throw string("Missing lower order n-gram");
        }
        int tmp = find_node(node_idx_traversal, order_ngrams[ni].ngram.back());
        if (tmp != -1)
            throw string("Duplicate n-gram in model");

        if (nodes[node_idx_traversal].first_arc == -1)
            nodes[node_idx_traversal].first_arc = curr_arc_idx;
        nodes[node_idx_traversal].last_arc = curr_arc_idx;

        arc_words[curr_arc_idx] = order_ngrams[ni].ngram.back();
        arc_target_nodes[curr_arc_idx] = curr_node_idx;
        nodes[curr_node_idx].prob = order_ngrams[ni].prob;
        nodes[curr_node_idx].backoff_prob = order_ngrams[ni].backoff_prob;

        int ctxt_start = 1;
        while (true) {
            int bo_traversal = root_node;
            unsigned int i = ctxt_start;
            for (; i<order_ngrams[ni].ngram.size(); i++) {
                int tmp = find_node(bo_traversal, order_ngrams[ni].ngram[i]);
                if (tmp == -1) break;
                bo_traversal = tmp;
            }
            if (i >= order_ngrams[ni].ngram.size()) {
                nodes[curr_node_idx].backoff_node = bo_traversal;
                break;
            }
            else ctxt_start++;
        }

        curr_arc_idx++;
        curr_node_idx++;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, -0x48(%rbp)
movq %rdx, -0x50(%rbp)
movq %rdi, -0x30(%rbp)
movq (%rsi), %rcx
movq 0x8(%rsi), %rax
movq %rcx, -0x58(%rbp)
subq %rcx, %rax
je 0xb092
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rcx
movq %rcx, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rcx
movq %rcx, -0x60(%rbp)
movq 0x90(%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0xa8(%rax), %rax
movq %rax, -0x68(%rbp)
xorl %ecx, %ecx
movq -0x30(%rbp), %rax
movl (%rax), %r12d
movq %rcx, -0x80(%rbp)
leaq (%rcx,%rcx,4), %rcx
movq -0x58(%rbp), %rax
movq (%rax,%rcx,8), %r14
movq %rcx, -0x40(%rbp)
movq 0x8(%rax,%rcx,8), %rbx
movq %rbx, -0x38(%rbp)
subq %r14, %rbx
sarq $0x2, %rbx
movq %rbx, %r15
decq %r15
je 0xaf45
movl $0x1, %r13d
xorl %eax, %eax
movl (%r14,%rax,4), %edx
movq -0x30(%rbp), %rdi
movl %r12d, %esi
callq 0x9f9c
cmpl $-0x1, %eax
je 0xb0a1
movl %eax, %r12d
movl %r13d, %eax
incl %r13d
cmpq %rax, %r15
ja 0xaf1e
movq -0x38(%rbp), %r15
movl -0x4(%r15), %edx
movq -0x30(%rbp), %rdi
movl %r12d, %esi
callq 0x9f9c
cmpl $-0x1, %eax
jne 0xb0e9
movslq %r12d, %rax
leaq (%rax,%rax,4), %rax
movq -0x60(%rbp), %r8
leaq (%r8,%rax,4), %rax
cmpl $-0x1, 0xc(%rax)
jne 0xaf80
movq -0x48(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, 0xc(%rax)
movq -0x58(%rbp), %rcx
movq -0x40(%rbp), %rdx
leaq (%rcx,%rdx,8), %rcx
movq -0x48(%rbp), %rsi
movl (%rsi), %edx
movl %edx, 0x10(%rax)
movl -0x4(%r15), %eax
movslq (%rsi), %rdx
movq -0x70(%rbp), %rdi
movl %eax, (%rdi,%rdx,4)
movq -0x50(%rbp), %rdi
movl (%rdi), %eax
movslq (%rsi), %rdx
movq -0x68(%rbp), %rsi
movl %eax, (%rsi,%rdx,4)
cvtsd2ss 0x18(%rcx), %xmm0
movslq (%rdi), %rax
leaq (%rax,%rax,4), %rax
movss %xmm0, (%r8,%rax,4)
xorps %xmm0, %xmm0
cvtsd2ss 0x20(%rcx), %xmm0
movss %xmm0, 0x4(%r8,%rax,4)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movl $0x1, %eax
movq %rax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpq %rax, %rbx
seta %r12b
jbe 0xb044
movl (%r14,%rax,4), %edx
movq -0x30(%rbp), %rdi
movl -0x40(%rbp), %r15d
movl %r15d, %esi
callq 0x9f9c
movl %eax, %r13d
cmpl $-0x1, %eax
cmovel %r15d, %r13d
je 0xb048
movq -0x38(%rbp), %rax
leal 0x1(%rax), %ecx
movl %ecx, %r15d
cmpq %r15, %rbx
seta %r12b
jbe 0xb048
movl (%r14,%r15,4), %edx
movq -0x30(%rbp), %rdi
movl %r13d, %esi
callq 0x9f9c
leal 0x1(%r15), %ecx
cmpl $-0x1, %eax
cmovnel %eax, %r13d
jne 0xb019
jmp 0xb048
movl -0x40(%rbp), %r13d
testb %r12b, %r12b
je 0xb059
movq -0x38(%rbp), %rax
incl %eax
movq %rax, -0x38(%rbp)
jmp 0xb06d
movq -0x50(%rbp), %rax
movslq (%rax), %rax
leaq (%rax,%rax,4), %rax
movq -0x60(%rbp), %rcx
movl %r13d, 0x8(%rcx,%rax,4)
testb %r12b, %r12b
jne 0xafe6
movq -0x48(%rbp), %rax
incl (%rax)
movq -0x50(%rbp), %rax
incl (%rax)
movq -0x80(%rbp), %rcx
incl %ecx
cmpq %rcx, -0x78(%rbp)
ja 0xaee3
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x4190
movq %rax, %rbx
addq $0x10, %rax
movq %rax, (%rbx)
movb $0x1, %r15b
leaq 0x1b4d9(%rip), %rsi     # 0x26598
leaq 0x1b4ec(%rip), %rdx     # 0x265b2
movq %rbx, %rdi
callq 0x5fa4
xorl %r15d, %r15d
leaq 0x28c78(%rip), %rsi     # 0x33d50
movq 0x28ec1(%rip), %rdx     # 0x33fa0
movq %rbx, %rdi
callq 0x4610
jmp 0xb12f
movl $0x20, %edi
callq 0x4190
movq %rax, %rbx
addq $0x10, %rax
movq %rax, (%rbx)
movb $0x1, %r15b
leaq 0x1b4ac(%rip), %rsi     # 0x265b3
leaq 0x1b4be(%rip), %rdx     # 0x265cc
movq %rbx, %rdi
callq 0x5fa4
xorl %r15d, %r15d
leaq 0x28c30(%rip), %rsi     # 0x33d50
movq 0x28e79(%rip), %rdx     # 0x33fa0
movq %rbx, %rdi
callq 0x4610
jmp 0xb131
movq %rax, %r14
testb %r15b, %r15b
je 0xb141
movq %rbx, %rdi
callq 0x42b0
movq %r14, %rdi
callq 0x4650