// File: /workspace/github_cpp_makefile_star2_O3/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 0x18eba
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
movq %rdx, %rdi
callq 0x82a2
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 -0x98(%rbp), %rcx
callq 0x1b134
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 -0x80(%rbp), %rcx
callq 0x1b134
leaq -0xb0(%rbp), %rdx
movq (%rdx), %rax
xorl %ecx, %ecx
movq %rcx, (%rax)
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
movq -0x98(%rbp), %rsi
imulq %r13, %rax
movq %rcx, -0x8(%rsi,%rax)
movq %r12, %rdi
movq %r15, %rsi
callq 0x17d10
leaq -0xb0(%rbp), %rsi
leaq -0x98(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
movq %r15, %rdi
callq 0x17f51
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 -0x68(%rbp), %rcx
callq 0x1b134
movq 0x48(%r15), %rsi
subq 0x40(%r15), %rsi
sarq $0x3, %rsi
imulq %r13, %rsi
leaq -0x68(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x100b0
movq -0x80(%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 0x18d92
movq -0x98(%rbp), %rsi
xorl %edi, %edi
imulq $0x38, %rdi, %r9
movq 0x20(%rdx,%r9), %r8
movq 0x28(%rdx,%r9), %r9
cmpq %r9, %r8
je 0x18d87
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 0x18d81
movsd %xmm0, (%rax,%r10,8)
movl %edi, (%rcx,%r10,4)
addq $0x8, %r8
jmp 0x18d4f
incq %rdi
movl %edi, %r8d
cmpq %r8, %r12
ja 0x18d41
decl %r12d
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x10288
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x82e8
leaq -0x40(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x18dc2
callq 0x4350
movslq %r12d, %rax
movq -0x68(%rbp), %rdi
movl (%rdi,%rax,4), %r12d
cmpl $-0x1, %r12d
je 0x18e0f
leaq -0x50(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x10288
movq %rbx, %rdi
movq %r13, %rsi
callq 0x82e8
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x18dfe
callq 0x4350
movslq %r12d, %rax
movq -0x68(%rbp), %rdi
movl (%rdi,%rax,4), %r12d
cmpl $-0x1, %r12d
jne 0x18dd7
cmpb $0x0, -0x30(%rbp)
je 0x18e64
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 0x18e64
movq %r14, %rdi
movq %rbx, %rsi
callq 0x42a0
addq $0x20, %r14
addq $-0x20, %rbx
cmpq %rbx, %r14
jb 0x18e33
movq -0x68(%rbp), %rdi
movq -0x78(%rbp), %rax
movsd -0x8(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
testq %rdi, %rdi
jne 0x18e72
jmp 0x18e77
movq -0x78(%rbp), %rax
movsd -0x8(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x4350
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x18e85
callq 0x4350
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x18e96
callq 0x4350
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x18ea7
callq 0x4350
leaq -0xe0(%rbp), %rdi
callq 0x1b8ec
movsd -0x30(%rbp), %xmm0
jmp 0x18ec2
movsd 0xd93e(%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 0x18f0f
jmp 0x18f14
jmp 0x18efe
movq %rax, %rbx
jmp 0x18f22
jmp 0x18ef9
movq %rax, %rbx
jmp 0x18f41
movq %rax, %rbx
jmp 0x18f52
movq %rax, %rbx
jmp 0x18f30
movq %rax, %rbx
jmp 0x18f14
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x18f14
callq 0x4350
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x18f22
callq 0x4350
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x18f30
callq 0x4350
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x18f41
callq 0x4350
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x18f52
callq 0x4350
leaq -0xe0(%rbp), %rdi
callq 0x1b8ec
movq %rbx, %rdi
callq 0x4650