// File: /workspace/github_cpp_makefile_star2_O1/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 0x18fd7
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, %rdi
callq 0x82e8
leaq -0xd8(%rbp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq 0x48(%r15), %rsi
subq 0x40(%r15), %rsi
sarq $0x3, %rsi
movabsq $0x6db6db6db6db6db7, %r13 # imm = 0x6DB6DB6DB6DB6DB7
imulq %r13, %rsi
movabsq $-0x10000000000001, %r14 # imm = 0xFFEFFFFFFFFFFFFF
leaq -0x50(%rbp), %rdx
movq %r14, (%rdx)
leaq -0xb0(%rbp), %rdi
leaq -0x80(%rbp), %rcx
callq 0x1b220
movq 0x48(%r15), %rsi
subq 0x40(%r15), %rsi
sarq $0x3, %rsi
imulq %r13, %rsi
leaq -0x50(%rbp), %rdx
movq %r14, (%rdx)
leaq -0x80(%rbp), %rdi
leaq -0x98(%rbp), %rcx
callq 0x1b220
leaq -0xb0(%rbp), %rdx
movq (%rdx), %rax
xorl %ecx, %ecx
movq %rcx, (%rax)
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
movq -0x80(%rbp), %rsi
imulq %r13, %rax
movq %rcx, -0x8(%rsi,%rax)
movq %r12, %rdi
movq %r15, %rsi
callq 0x17e65
leaq -0xb0(%rbp), %rsi
leaq -0x80(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
movq %r15, %rdi
callq 0x1808e
movq 0x48(%r15), %rsi
subq 0x40(%r15), %rsi
sarq $0x3, %rsi
imulq %r13, %rsi
leaq -0x50(%rbp), %rdx
movq %r14, (%rdx)
leaq -0x98(%rbp), %rdi
leaq -0x68(%rbp), %rcx
callq 0x1b220
movq 0x48(%r15), %rsi
subq 0x40(%r15), %rsi
sarq $0x3, %rsi
imulq %r13, %rsi
leaq -0x68(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x101a2
movq -0x98(%rbp), %rax
movq $0x0, (%rax)
movq -0x68(%rbp), %rcx
movl $0xffffffff, (%rcx)     # imm = 0xFFFFFFFF
movq 0x40(%r15), %rdx
movq 0x48(%r15), %rsi
movq %rsi, %r12
subq %rdx, %r12
sarq $0x3, %r12
imulq %r13, %r12
cmpq %rdx, %rsi
je 0x18ebc
movq -0x80(%rbp), %rsi
xorl %edi, %edi
imulq $0x38, %rdi, %r9
movq 0x20(%rdx,%r9), %r8
movq 0x28(%rdx,%r9), %r9
cmpq %r9, %r8
je 0x18eb1
movq (%r8), %r10
movzwl 0x2(%r10), %r10d
leal (,%r10,8), %r11d
movsd (%rax,%rdi,8), %xmm0
addsd (%rsi,%r11), %xmm0
ucomisd (%rax,%r11), %xmm0
jbe 0x18eab
movsd %xmm0, (%rax,%r10,8)
movl %edi, (%rcx,%r10,4)
addq $0x8, %r8
jmp 0x18e79
incq %rdi
movl %edi, %r8d
cmpq %r8, %r12
ja 0x18e6b
decl %r12d
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x10378
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x832e
leaq -0x40(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x18eec
callq 0x4350
movslq %r12d, %rax
movq -0x68(%rbp), %rcx
movl (%rcx,%rax,4), %r12d
cmpl $-0x1, %r12d
je 0x18f39
leaq -0x50(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x10378
movq %rbx, %rdi
movq %r13, %rsi
callq 0x832e
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x18f28
callq 0x4350
movslq %r12d, %rax
movq -0x68(%rbp), %rcx
movl (%rcx,%rax,4), %r12d
cmpl $-0x1, %r12d
jne 0x18f01
cmpb $0x0, -0x30(%rbp)
je 0x18f75
movq (%rbx), %r14
movq 0x8(%rbx), %rbx
cmpq %rbx, %r14
setne %al
addq $-0x20, %rbx
cmpq %r14, %rbx
seta %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x18f75
movq %r14, %rdi
movq %rbx, %rsi
callq 0x42a0
addq $0x20, %r14
addq $-0x20, %rbx
cmpq %rbx, %r14
jb 0x18f5d
movq -0x90(%rbp), %rax
movsd -0x8(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x18f94
callq 0x4350
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x18fa5
callq 0x4350
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x18fb3
callq 0x4350
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x18fc4
callq 0x4350
leaq -0xe0(%rbp), %rdi
callq 0x1b9da
movsd -0x30(%rbp), %xmm0
jmp 0x18fdf
movsd 0xd821(%rip), %xmm0     # 0x26800
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x1902c
jmp 0x19031
jmp 0x1901b
movq %rax, %rbx
jmp 0x1903f
jmp 0x19016
movq %rax, %rbx
jmp 0x1905e
movq %rax, %rbx
jmp 0x1906f
movq %rax, %rbx
jmp 0x19050
movq %rax, %rbx
jmp 0x19031
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x19031
callq 0x4350
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x1903f
callq 0x4350
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x19050
callq 0x4350
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x1905e
callq 0x4350
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x1906f
callq 0x4350
leaq -0xe0(%rbp), %rdi
callq 0x1b9da
movq %rbx, %rdi
callq 0x4650