// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rdi, %r12
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 0x138da
movq %rbx, -0x40(%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 0x155c4
leaq -0x88(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1b5c8
movq $0x0, (%rax)
cmpq $0x0, -0x90(%rbp)
je 0x1aa19
leaq -0xb8(%rbp), %r15
leaq -0x2c(%rbp), %r13
movq %r12, -0x48(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x4210
movslq 0x20(%rax), %rbx
movq 0x20(%r12), %rax
movq %rbx, %rcx
shlq $0x7, %rcx
addq %rcx, %rax
addq $0x28, %rax
movq 0x10(%rax), %r14
movq %rax, -0x50(%rbp)
cmpq %rax, %r14
je 0x1a9ee
movq %r15, %r12
movq 0x20(%r14), %rax
movl (%rax), %r15d
movl %ebx, -0x2c(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x1b630
movsd (%rax), %xmm0
movq 0x20(%r14), %rax
movq 0x8(%rax), %rax
addsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x78(%rbp), %rsi
testq %rsi, %rsi
je 0x1a996
leaq -0x80(%rbp), %rdi
movq %rdi, %rax
movq %rsi, %rcx
movl 0x20(%rsi), %edx
xorl %esi, %esi
cmpl %r15d, %edx
setb %sil
movq %rcx, %rdi
cmovbq %rax, %rdi
movq 0x10(%rcx,%rsi,8), %rsi
testq %rsi, %rsi
jne 0x1a93f
leaq -0x80(%rbp), %rsi
cmpq %rsi, %rdi
je 0x1a996
cmpl %r15d, %edx
cmovbq %rax, %rcx
cmpl 0x20(%rcx), %r15d
jb 0x1a996
movl %r15d, -0x2c(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x1b630
movsd -0x38(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x1a9c7
movl %r15d, -0x2c(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x1b630
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rax)
movl %r15d, -0x2c(%rbp)
leaq -0xe8(%rbp), %rdi
movq %r13, %rsi
callq 0x1b794
movl %ebx, (%rax)
movl %r15d, -0x2c(%rbp)
movq %r12, %r15
movq %r12, %rdi
movq %r13, %rsi
callq 0x1d3a4
movq %r14, %rdi
callq 0x4410
movq %rax, %r14
cmpq -0x50(%rbp), %rax
jne 0x1a901
movl %ebx, -0x2c(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x156e0
movq %r15, %rdi
movq %rax, %rsi
callq 0x15762
cmpq $0x0, -0x90(%rbp)
movq -0x48(%rbp), %r12
jne 0x1a8cd
movq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x82a2
xorl %eax, %eax
leaq -0xe8(%rbp), %rbx
leaq -0x2c(%rbp), %r14
movl %eax, -0x2c(%rbp)
movl %eax, %esi
shlq $0x7, %rsi
addq 0x20(%r12), %rsi
movq %r15, %rdi
callq 0x7f60
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0x1aa5f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1b7fc
movl (%rax), %eax
jmp 0x1aa32
leaq -0x54(%rbp), %rsi
movl $0x0, (%rsi)
leaq -0x88(%rbp), %rdi
callq 0x1b698
movsd (%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x13f0a
leaq -0xe8(%rbp), %rdi
callq 0x1bb12
leaq -0x88(%rbp), %rdi
callq 0x1ba0a
movsd -0x38(%rbp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1aace
movq %rax, %rbx
jmp 0x1aadd
jmp 0x1aace
jmp 0x1aace
jmp 0x1aace
jmp 0x1aace
jmp 0x1aace
jmp 0x1aace
jmp 0x1aace
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x13f0a
leaq -0xe8(%rbp), %rdi
callq 0x1bb12
leaq -0x88(%rbp), %rdi
callq 0x1ba0a
movq %rbx, %rdi
callq 0x4650