// File: /workspace/github_cpp_makefile_star2_O2/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
leaq -0xb0(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0xe0(%rbp), %rax
andl $0x0, (%rax)
movq %rdx, %rbx
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rdi, -0x48(%rbp)
addq $0x38, %rdi
callq 0x11d8e
movq %rbx, -0x50(%rbp)
movl (%rax), %eax
leaq -0x34(%rbp), %rsi
movl %eax, (%rsi)
leaq -0x80(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x88(%rbp), %rdi
callq 0x13e38
leaq -0xb8(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x19294
andq $0x0, (%rax)
leaq -0x2c(%rbp), %r13
leaq -0xb8(%rbp), %r15
cmpq $0x0, -0x60(%rbp)
je 0x188fe
leaq -0x80(%rbp), %rdi
callq 0x4210
movslq 0x20(%rax), %rbx
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq %rbx, %rcx
shlq $0x7, %rcx
addq %rcx, %rax
addq $0x28, %rax
movq %rax, -0x58(%rbp)
movq 0x10(%rax), %r14
cmpq -0x58(%rbp), %r14
je 0x188e7
movq 0x20(%r14), %rax
movl (%rax), %r12d
movl %ebx, -0x2c(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x192e6
movsd (%rax), %xmm0
movq 0x20(%r14), %rax
movq 0x8(%rax), %rax
addsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movl %r12d, -0x2c(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x1ae0e
leaq -0xb0(%rbp), %rcx
cmpq %rcx, %rax
je 0x18897
movl %r12d, -0x30(%rbp)
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x192e6
movsd -0x40(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x188c4
movl %r12d, -0x2c(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x192e6
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
movl %r12d, -0x2c(%rbp)
leaq -0xe8(%rbp), %rdi
movq %r13, %rsi
callq 0x19460
movl %ebx, (%rax)
movl %r12d, -0x2c(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x1b84a
movq %r14, %rdi
callq 0x43b0
movq %rax, %r14
jmp 0x1882d
movl %ebx, -0x2c(%rbp)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x13fc8
jmp 0x187f7
movq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x7532
xorl %eax, %eax
leaq -0xe8(%rbp), %rbx
leaq -0x2c(%rbp), %r14
movl %eax, -0x2c(%rbp)
movl %eax, %esi
shlq $0x7, %rsi
movq -0x48(%rbp), %rax
addq 0x20(%rax), %rsi
movq %r15, %rdi
callq 0x719e
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x18947
movq %rbx, %rdi
movq %r14, %rsi
callq 0x194b2
movl (%rax), %eax
jmp 0x18917
leaq -0x30(%rbp), %rsi
andl $0x0, (%rsi)
leaq -0xb8(%rbp), %rdi
callq 0x19338
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x1230e
leaq -0xe8(%rbp), %rdi
callq 0x19756
leaq -0xb8(%rbp), %rdi
callq 0x19654
movsd -0x40(%rbp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x189b5
movq %rax, %rbx
jmp 0x189c4
jmp 0x189b5
jmp 0x189b5
jmp 0x189b5
jmp 0x189b5
jmp 0x189b5
jmp 0x189b5
jmp 0x189b5
jmp 0x189b5
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x1230e
leaq -0xe8(%rbp), %rdi
callq 0x19756
leaq -0xb8(%rbp), %rdi
callq 0x19654
movq %rbx, %rdi
callq 0x45f0