// File: /workspace/github_cpp_makefile_star2_O1/aalto-speech[P]ftk/src/EM.cc
// Function: viterbi(MultiStringFactorGraph const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
flt_type
viterbi(const MultiStringFactorGraph &msfg,
        const string &text,
        vector<string> &best_path)
{
    map<msfg_node_idx_t, flt_type> scores;
    map<msfg_node_idx_t, msfg_node_idx_t> sources;
    unsigned int text_end_node = msfg.string_end_nodes.at(text);
    set<unsigned int> nodes_to_process; nodes_to_process.insert(text_end_node);
    scores[text_end_node] = 0.0;

    while(nodes_to_process.size() > 0) {

        int i = *(nodes_to_process.rbegin());

        const MultiStringFactorGraph::Node &node = msfg.nodes[i];

        for (auto arc = node.incoming.begin(); arc != node.incoming.end(); ++arc) {
            int src_node = (**arc).source_node;
            flt_type cost = scores[i] + *(**arc).cost;
            if (scores.find(src_node) == scores.end() || (cost > scores[src_node])) {
                scores[src_node] = cost;
                sources[src_node] = i;
            }
            nodes_to_process.insert(src_node);
        }

        nodes_to_process.erase(i);
    }

    best_path.clear();

    msfg_node_idx_t curr_node = 0;
    while (true) {
        best_path.push_back(msfg.nodes[curr_node].factor);
        if (curr_node == text_end_node) break;
        curr_node = sources[curr_node];
    }

    return scores.at(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, %r14
movq %rdi, %r15
leaq -0x80(%rbp), %rcx
xorl %eax, %eax
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0xe0(%rbp), %rcx
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
addq $0x38, %rdi
callq 0x139bc
movq %r15, -0x40(%rbp)
movq %r14, -0x48(%rbp)
movl (%rax), %eax
leaq -0x30(%rbp), %rsi
movl %eax, (%rsi)
leaq -0xb0(%rbp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0xb8(%rbp), %rdi
callq 0x156ce
leaq -0x88(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1b6aa
movq $0x0, (%rax)
cmpq $0x0, -0x90(%rbp)
je 0x1aaef
leaq -0xb8(%rbp), %rbx
leaq -0x2c(%rbp), %r13
leaq -0xb0(%rbp), %rdi
callq 0x4210
movslq 0x20(%rax), %r12
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq %r12, %rcx
shlq $0x7, %rcx
addq %rcx, %rax
addq $0x28, %rax
movq 0x10(%rax), %r14
movq %rax, -0x50(%rbp)
cmpq %rax, %r14
je 0x1aac7
movq 0x20(%r14), %rax
movl (%rax), %r15d
movl %r12d, -0x2c(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x1b712
movq -0x78(%rbp), %rdx
leaq -0x80(%rbp), %rdi
movq %rdi, %rcx
testq %rdx, %rdx
je 0x1aa26
movq %rdi, %rcx
xorl %esi, %esi
cmpl %r15d, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x1aa0e
movq %rdi, %rdx
cmpq %rdi, %rcx
je 0x1aa39
cmpl 0x20(%rcx), %r15d
cmovbq %rdi, %rcx
movq %rcx, %rdx
movsd (%rax), %xmm0
movq 0x20(%r14), %rax
movq 0x8(%rax), %rax
addsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
cmpq %rdi, %rdx
je 0x1aa71
movl %r15d, -0x2c(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x1b712
movsd -0x38(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x1aaa3
movl %r15d, -0x2c(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x1b712
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rax)
movl %r15d, -0x2c(%rbp)
leaq -0xe8(%rbp), %rdi
movq %r13, %rsi
callq 0x1b882
movl %r12d, (%rax)
movl %r15d, -0x2c(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1d4d6
movq %r14, %rdi
callq 0x4410
movq %rax, %r14
cmpq -0x50(%rbp), %rax
jne 0x1a9e1
movl %r12d, -0x2c(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x157f6
movq %rbx, %rdi
movq %rax, %rsi
callq 0x15872
cmpq $0x0, -0x90(%rbp)
jne 0x1a9aa
movq -0x48(%rbp), %r15
movq %r15, %rdi
callq 0x82e8
xorl %eax, %eax
leaq -0xe8(%rbp), %rbx
leaq -0x2c(%rbp), %r14
movq -0x40(%rbp), %r12
movl %eax, -0x2c(%rbp)
movl %eax, %esi
shlq $0x7, %rsi
addq 0x20(%r12), %rsi
movq %r15, %rdi
callq 0x7f8c
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0x1ab39
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1b8ea
movl (%rax), %eax
jmp 0x1ab0c
leaq -0x54(%rbp), %rsi
movl $0x0, (%rsi)
leaq -0x88(%rbp), %rdi
callq 0x1b77a
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x13fe2
leaq -0xe8(%rbp), %rdi
callq 0x1bc00
leaq -0x88(%rbp), %rdi
callq 0x1baf8
movsd -0x38(%rbp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1aba8
movq %rax, %rbx
jmp 0x1abb7
jmp 0x1aba8
jmp 0x1aba8
jmp 0x1aba8
jmp 0x1aba8
jmp 0x1aba8
jmp 0x1aba8
jmp 0x1aba8
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x13fe2
leaq -0xe8(%rbp), %rdi
callq 0x1bc00
leaq -0x88(%rbp), %rdi
callq 0x1baf8
movq %rbx, %rdi
callq 0x4650