// File: /workspace/github_cpp_makefile_star2_O3/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 %rdx, -0x58(%rbp)
movq (%rsi), %rdx
movq 0x8(%rsi), %rax
movq %rdx, -0x60(%rbp)
subq %rdx, %rax
je 0xafbd
movq %rdi, %r15
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rdx
movq %rdx, -0x78(%rbp)
movq 0x78(%rdi), %rdx
movq 0x90(%rdi), %rax
movq %rax, -0x70(%rbp)
movq 0xa8(%rdi), %rax
movq %rax, -0x68(%rbp)
xorl %eax, %eax
movq %rcx, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
movl (%r15), %r12d
movq %rax, -0x80(%rbp)
leaq (%rax,%rax,4), %rcx
movq -0x60(%rbp), %rax
movq (%rax,%rcx,8), %rbx
movq %rcx, -0x30(%rbp)
movq 0x8(%rax,%rcx,8), %r13
movq %r13, -0x38(%rbp)
subq %rbx, %r13
sarq $0x2, %r13
movq %r13, -0x40(%rbp)
decq %r13
je 0xaeb7
movl $0x1, %r14d
xorl %eax, %eax
movl (%rbx,%rax,4), %edx
movq %r15, %rdi
movl %r12d, %esi
callq 0x9f1c
cmpl $-0x1, %eax
je 0xafcc
movl %eax, %r12d
movl %r14d, %eax
incl %r14d
cmpq %rax, %r13
ja 0xae92
movq -0x38(%rbp), %r14
movl -0x4(%r14), %edx
movq %r15, %rdi
movl %r12d, %esi
callq 0x9f1c
cmpl $-0x1, %eax
jne 0xb00c
movslq %r12d, %rax
leaq (%rax,%rax,4), %rax
movq -0x48(%rbp), %rdi
leaq (%rdi,%rax,4), %rax
cmpl $-0x1, 0xc(%rax)
movq -0x50(%rbp), %rsi
movl (%rsi), %ecx
jne 0xaef1
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rdx
movq -0x30(%rbp), %r8
leaq (%rdx,%r8,8), %rdx
movl %ecx, 0x10(%rax)
movl -0x4(%r14), %eax
movslq (%rsi), %rcx
movq -0x70(%rbp), %r8
movl %eax, (%r8,%rcx,4)
movq -0x58(%rbp), %rax
movslq (%rax), %rax
movslq (%rsi), %rcx
movq -0x68(%rbp), %rsi
movl %eax, (%rsi,%rcx,4)
xorps %xmm0, %xmm0
cvtsd2ss 0x18(%rdx), %xmm0
leaq (%rax,%rax,4), %rax
movss %xmm0, (%rdi,%rax,4)
xorps %xmm0, %xmm0
cvtsd2ss 0x20(%rdx), %xmm0
movss %xmm0, 0x4(%rdi,%rax,4)
movl (%r15), %edx
cmpq $0x2, -0x40(%rbp)
movq %rax, -0x38(%rbp)
jb 0xaf93
movl $0x1, %r13d
movl $0x2, %r12d
movl %edx, -0x30(%rbp)
movl %r12d, %r14d
movq %r13, %rcx
movl %edx, %eax
movl (%rbx,%rcx,4), %edx
movq %r15, %rdi
movl %eax, %esi
callq 0x9f1c
cmpl $-0x1, %eax
je 0xaf84
movl %r14d, %ecx
incl %r14d
cmpq %rcx, -0x40(%rbp)
ja 0xaf64
jmp 0xaf95
incq %r13
incl %r12d
cmpq -0x40(%rbp), %r13
movl -0x30(%rbp), %edx
jne 0xaf5c
movl %edx, %eax
movq -0x48(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl %eax, 0x8(%rdx,%rcx,4)
movq -0x50(%rbp), %rcx
incl (%rcx)
movq -0x58(%rbp), %rax
incl (%rax)
movq -0x80(%rbp), %rax
incl %eax
cmpq %rax, -0x78(%rbp)
ja 0xae5a
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)
leaq 0x1b5b1(%rip), %rsi     # 0x26598
leaq 0x1b5c4(%rip), %rdx     # 0x265b2
movq %rbx, %rdi
callq 0x5fac
leaq 0x28d53(%rip), %rsi     # 0x33d50
movq 0x28f9c(%rip), %rdx     # 0x33fa0
movq %rbx, %rdi
callq 0x4610
movl $0x20, %edi
callq 0x4190
movq %rax, %rbx
addq $0x10, %rax
movq %rax, (%rbx)
leaq 0x1b58c(%rip), %rsi     # 0x265b3
leaq 0x1b59e(%rip), %rdx     # 0x265cc
movq %rbx, %rdi
callq 0x5fac
jmp 0xaff6
jmp 0xb03a
movq %rax, %r14
movq %rbx, %rdi
callq 0x42b0
movq %r14, %rdi
callq 0x4650