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

    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;

    string source_node_str, target_node_str;

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

        if (fw[i] == MIN_FLOAT) continue;

        FactorGraph::Node &node = text.nodes[i];
        source_node_str = text.get_factor(node);
        if (source_node_str == block) continue;

        for (auto arc = node.outgoing.begin(); arc != node.outgoing.end(); ++arc) {

            int tgt_node = (**arc).target_node;
            target_node_str = text.get_factor(tgt_node);
            if (target_node_str == block) continue;
            try {
                (**arc).cost = transitions.at(source_node_str).at(target_node_str);
            }
            catch (std::out_of_range &oor) {
                (**arc).cost = SMALL_LP;
            }

            flt_type cost = fw[i] + (**arc).cost;
            if (fw[tgt_node] == MIN_FLOAT) fw[tgt_node] = cost;
            else fw[tgt_node] = add_log_domain_probs(fw[tgt_node], cost);
        }
    }

    backward(text, fw, bw, stats);

    return fw.back();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, -0x40(%rbp)
movq %rdi, -0x68(%rbp)
movq 0x48(%rsi), %rax
cmpq 0x40(%rsi), %rax
je 0x16d96
movq %rdx, %r14
movq %rsi, %r15
movq %rdx, %rdi
callq 0x1a3dc
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
pushq $0x38
popq %r12
cqto
idivq %r12
movabsq $-0x10000000000001, %rbx # imm = 0xFFEFFFFFFFFFFFFF
leaq -0xa8(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x58(%rbp), %rdi
leaq -0x88(%rbp), %rcx
movq %rax, %rsi
callq 0x18ee6
movq %r14, -0x60(%rbp)
movq 0x48(%r15), %rax
subq 0x40(%r15), %rax
cqto
idivq %r12
leaq -0xa8(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0xc0(%rbp), %rdi
leaq -0x88(%rbp), %rcx
movq %rax, %rsi
callq 0x18ee6
movq -0x58(%rbp), %rax
andq $0x0, (%rax)
movq 0x40(%r15), %r13
movq 0x48(%r15), %rcx
movq %rcx, %rax
subq %r13, %rax
movq -0xc0(%rbp), %rsi
pushq $0x7
popq %rdi
cqto
idivq %rdi
andq $0x0, -0x8(%rsi,%rax)
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x78(%rbp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
xorl %esi, %esi
movb %sil, (%rax)
movb %sil, (%rdx)
movq %r15, -0x30(%rbp)
movl %esi, %esi
subq %r13, %rcx
movq %rcx, %rax
cqto
idivq %r12
cmpq %rsi, %rax
jbe 0x16d3a
movq -0x58(%rbp), %rax
movq %rsi, -0x38(%rbp)
movsd (%rax,%rsi,8), %xmm0
ucomisd 0xcbba(%rip), %xmm0     # 0x23790
jne 0x16bda
jnp 0x16c22
imulq $0x38, -0x38(%rbp), %rax
addq %rax, %r13
leaq -0xe0(%rbp), %r15
movq %r15, %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
callq 0xea24
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x43d0
movq %r15, %rdi
callq 0x46b8
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
callq 0x10328
testb %al, %al
je 0x16c3d
movq -0x38(%rbp), %rsi
incl %esi
movq -0x30(%rbp), %r15
movq 0x40(%r15), %r13
movq 0x48(%r15), %rcx
pushq $0x38
popq %r12
jmp 0x16bab
movq 0x20(%r13), %r12
cmpq 0x28(%r13), %r12
je 0x16c22
movq %r13, %r14
movq (%r12), %rax
movzwl 0x2(%rax), %r15d
leaq -0xe0(%rbp), %rbx
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
movl %r15d, %edx
callq 0xea5a
leaq -0x88(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x43d0
movq %rbx, %rdi
callq 0x46b8
movq %r13, %rdi
movq -0x40(%rbp), %rsi
callq 0x10328
testb %al, %al
movq %r14, %r13
jne 0x16cf8
movq -0x68(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x190b2
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x19102
movsd (%rax), %xmm1
movq (%r12), %rax
movsd %xmm1, 0x8(%rax)
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm1
movsd (%rax,%r15,8), %xmm0
ucomisd 0xcab3(%rip), %xmm0     # 0x23790
jne 0x16ce9
jp 0x16ce9
movsd %xmm1, (%rax,%r15,8)
jmp 0x16cf8
callq 0x15a53
movq -0x58(%rbp), %rax
movsd %xmm0, (%rax,%r15,8)
addq $0x8, %r12
jmp 0x16c41
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x16dc3
movq %rbx, %rdi
callq 0x4150
movq (%r12), %rax
movabsq $-0x3fa7000000000000, %rcx # imm = 0xC059000000000000
movq %rcx, 0x8(%rax)
callq 0x4560
movq (%r12), %rax
movsd 0x8(%rax), %xmm1
movq %r14, %r13
jmp 0x16cc2
leaq -0x58(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
movq %r15, %rdi
movq -0x60(%rbp), %rcx
callq 0x165fe
leaq -0x58(%rbp), %rbx
movq 0x8(%rbx), %rax
movsd -0x8(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x46b8
leaq -0xa8(%rbp), %rdi
callq 0x46b8
leaq -0xc0(%rbp), %rdi
callq 0x1a10a
movq %rbx, %rdi
callq 0x1a10a
movsd -0x30(%rbp), %xmm0
jmp 0x16d9e
movsd 0xc9f2(%rip), %xmm0     # 0x23790
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16dc0
jmp 0x16dc0
movq %rax, %rbx
jmp 0x16de7
movq %rax, %rbx
jmp 0x16df0
jmp 0x16dc0
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x46b8
leaq -0xa8(%rbp), %rdi
callq 0x46b8
leaq -0xc0(%rbp), %rdi
callq 0x1a10a
leaq -0x58(%rbp), %rdi
callq 0x1a10a
movq %rbx, %rdi
callq 0x45f0