// File: /workspace/github_cpp_makefile_star2_O2/aalto-speech[P]ftk/src/EM.cc
// Function: posterior_decode(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, double>>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, double>>>>>> const&, FactorGraph&, 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>>>>&, bool)
flt_type posterior_decode(const transitions_t &transitions,
                          FactorGraph &text,
                          vector<string> &path,
                          bool reverse)
{
    if (text.nodes.size() == 0) return MIN_FLOAT;
    path.clear();

    transitions_t stats;
    vector<flt_type> fw(text.nodes.size(), MIN_FLOAT);
    vector<flt_type> bw(text.nodes.size(), MIN_FLOAT);
    fw[0] = 0.0; bw[text.nodes.size()-1] = 0.0;

    forward(transitions, text, fw);
    backward(text, fw, bw, stats);

    // Initialize node scores
    vector<flt_type> costs(text.nodes.size(), MIN_FLOAT);
    vector<int> source_nodes(text.nodes.size());
    costs[0] = 0.0; source_nodes[0] = -1;

    // Traverse paths
    for (unsigned int i=0; i<text.nodes.size(); i++) {

        FactorGraph::Node &node = text.nodes[i];
        for (auto arc = node.outgoing.begin(); arc != node.outgoing.end(); ++arc) {

            int tgt_node = (**arc).target_node;
            flt_type curr_cost = costs[tgt_node];
            flt_type new_cost = costs[i] + bw[tgt_node];
            if (new_cost > curr_cost) {
                costs[tgt_node] = new_cost;
                source_nodes[tgt_node] = i;
            }
        }
    }

    // Find best path
    int node = text.nodes.size()-1;
    path.push_back(text.get_factor(node));
    while (true) {
        node = source_nodes[node];
        if (node == -1) break;
        path.push_back(text.get_factor(node));
    }
    if (reverse) std::reverse(path.begin(), path.end());

    return costs.back();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %ecx, -0x30(%rbp)
movq 0x48(%rsi), %rax
cmpq 0x40(%rsi), %rax
je 0x172b1
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, %rdi
callq 0x7532
leaq -0xd8(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
pushq $0x38
popq %r13
cqto
idivq %r13
movabsq $-0x10000000000001, %r14 # imm = 0xFFEFFFFFFFFFFFFF
leaq -0x68(%rbp), %rdx
movq %r14, (%rdx)
leaq -0xb0(%rbp), %rdi
leaq -0x48(%rbp), %rcx
movq %rax, %rsi
callq 0x18ee6
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
cqto
idivq %r13
leaq -0x68(%rbp), %rdx
movq %r14, (%rdx)
leaq -0x48(%rbp), %rdi
leaq -0x98(%rbp), %rcx
movq %rax, %rsi
callq 0x18ee6
leaq -0xb0(%rbp), %rcx
movq (%rcx), %rax
andq $0x0, (%rax)
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
movq -0x48(%rbp), %rsi
pushq $0x7
popq %rdi
cqto
idivq %rdi
andq $0x0, -0x8(%rsi,%rax)
movq %r12, %rdi
movq %r15, %rsi
movq %rcx, %rdx
callq 0x16453
leaq -0xb0(%rbp), %rsi
leaq -0x48(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
movq %r15, %rdi
callq 0x165fe
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
cqto
idivq %r13
leaq -0x68(%rbp), %rdx
movq %r14, (%rdx)
leaq -0x98(%rbp), %rdi
leaq -0x80(%rbp), %rcx
movq %rax, %rsi
callq 0x18ee6
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
cqto
idivq %r13
leaq -0x80(%rbp), %rdi
leaq -0x68(%rbp), %rdx
movq %rax, %rsi
callq 0xe8ca
movq -0x98(%rbp), %rcx
andq $0x0, (%rcx)
movq -0x80(%rbp), %rsi
orl $-0x1, (%rsi)
movq 0x40(%r15), %rdi
movq 0x48(%r15), %rax
subq %rdi, %rax
cqto
idivq %r13
xorl %edx, %edx
movl %edx, %r8d
cmpq %r8, %rax
jbe 0x171fa
imulq $0x38, %r8, %r10
movq 0x20(%rdi,%r10), %r9
movq 0x28(%rdi,%r10), %r10
movq -0x48(%rbp), %r11
cmpq %r10, %r9
je 0x171f6
movq (%r9), %r14
movzwl 0x2(%r14), %r14d
leal (,%r14,8), %r12d
movsd (%rcx,%r8,8), %xmm0
addsd (%r11,%r12), %xmm0
ucomisd (%rcx,%r12), %xmm0
jbe 0x171f0
movsd %xmm0, (%rcx,%r14,8)
movl %edx, (%rsi,%r14,4)
addq $0x8, %r9
jmp 0x171bd
incl %edx
jmp 0x171a3
leal -0x1(%rax), %r12d
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0xea5a
leaq -0x68(%rbp), %rsi
movq %rbx, %rdi
callq 0x7570
leaq -0x68(%rbp), %r13
movq %r13, %rdi
callq 0x46b8
movslq %r12d, %rax
movq -0x80(%rbp), %rcx
movl (%rcx,%rax,4), %r12d
cmpl $-0x1, %r12d
je 0x17251
movq %r13, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0xea5a
movq %rbx, %rdi
movq %r13, %rsi
callq 0x7570
jmp 0x1721d
cmpb $0x0, -0x30(%rbp)
je 0x17263
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x1423d
leaq -0x98(%rbp), %rbx
movq 0x8(%rbx), %rax
movsd -0x8(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xa2cc
movq %rbx, %rdi
callq 0x1a10a
leaq -0x48(%rbp), %rdi
callq 0x1a10a
leaq -0xb0(%rbp), %rdi
callq 0x1a10a
leaq -0xe0(%rbp), %rdi
callq 0x19564
movsd -0x30(%rbp), %xmm0
jmp 0x172b9
movsd 0xc4d7(%rip), %xmm0     # 0x23790
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x172e7
jmp 0x172ec
jmp 0x172e7
movq %rax, %rbx
jmp 0x17301
jmp 0x172e2
movq %rax, %rbx
jmp 0x17316
movq %rax, %rbx
jmp 0x17322
movq %rax, %rbx
jmp 0x1730d
movq %rax, %rbx
jmp 0x172f8
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x46b8
leaq -0x80(%rbp), %rdi
callq 0xa2cc
leaq -0x98(%rbp), %rdi
callq 0x1a10a
leaq -0x48(%rbp), %rdi
callq 0x1a10a
leaq -0xb0(%rbp), %rdi
callq 0x1a10a
leaq -0xe0(%rbp), %rdi
callq 0x19564
movq %rbx, %rdi
callq 0x45f0