// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movq %rcx, -0x30(%rbp)
movq %rdi, -0xa0(%rbp)
movq 0x48(%rsi), %rax
cmpq 0x40(%rsi), %rax
je 0x189b9
movq %rdx, %r15
movq %rsi, %r14
movq %rdx, %rdi
callq 0x1c532
movq 0x48(%r14), %rsi
subq 0x40(%r14), %rsi
sarq $0x3, %rsi
movabsq $0x6db6db6db6db6db7, %r12 # imm = 0x6DB6DB6DB6DB6DB7
imulq %r12, %rsi
movabsq $-0x10000000000001, %rbx # imm = 0xFFEFFFFFFFFFFFFF
leaq -0x90(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rcx
callq 0x1b220
movq %r15, -0x98(%rbp)
movq 0x48(%r14), %rsi
subq 0x40(%r14), %rsi
sarq $0x3, %rsi
imulq %r12, %rsi
leaq -0x90(%rbp), %rdx
movq %rbx, (%rdx)
leaq -0xb8(%rbp), %rdi
leaq -0x70(%rbp), %rcx
callq 0x1b220
movq -0x50(%rbp), %rax
xorl %ebx, %ebx
movq %rbx, (%rax)
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
movq -0xb8(%rbp), %rcx
imulq %r12, %rax
movq %rbx, -0x8(%rcx,%rax)
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq %rbx, -0x8(%rax)
movb %bl, (%rax)
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq %rbx, -0x8(%rax)
movb %bl, (%rax)
movq 0x40(%r14), %r13
cmpq %r13, 0x48(%r14)
je 0x18935
movq %r14, -0x38(%rbp)
movq -0x50(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
ucomisd 0xe0d3(%rip), %xmm0     # 0x26800
jne 0x1875e
jp 0x1875e
incl %ebx
movq -0x38(%rbp), %r14
movq 0x40(%r14), %r13
movq 0x48(%r14), %rax
subq %r13, %rax
sarq $0x3, %rax
movabsq $0x6db6db6db6db6db7, %rcx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rcx, %rax
cmpq %rbx, %rax
ja 0x1871c
jmp 0x18935
imulq $0x38, %rbx, %rax
addq %rax, %r13
leaq -0xd8(%rbp), %r15
movq %r15, %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
callq 0x10332
leaq -0x90(%rbp), %rdi
movq %r15, %rsi
callq 0x4430
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x187a2
callq 0x4350
movq -0x88(%rbp), %rdx
movq -0x30(%rbp), %rax
cmpq 0x8(%rax), %rdx
jne 0x187d7
testq %rdx, %rdx
je 0x18731
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq -0x90(%rbp), %rdi
callq 0x43a0
testl %eax, %eax
je 0x18731
movq 0x20(%r13), %r15
cmpq 0x28(%r13), %r15
je 0x18731
movq (%r15), %rax
movzwl 0x2(%rax), %r12d
leaq -0xd8(%rbp), %r14
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movl %r12d, %edx
callq 0x10378
leaq -0x70(%rbp), %rdi
movq %r14, %rsi
callq 0x4430
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x18827
callq 0x4350
movq -0x68(%rbp), %rdx
movq -0x30(%rbp), %rax
cmpq 0x8(%rax), %rdx
jne 0x18856
testq %rdx, %rdx
je 0x188fd
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
callq 0x43a0
testl %eax, %eax
je 0x188fd
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x1b47a
movq %rax, %rdi
leaq -0x70(%rbp), %rsi
callq 0x1b4d8
movsd (%rax), %xmm0
movq (%r15), %rax
movsd %xmm0, 0x8(%rax)
movq -0x50(%rbp), %rax
movsd (%rax,%rbx,8), %xmm1
movq (%r15), %rcx
addsd 0x8(%rcx), %xmm1
movsd (%rax,%r12,8), %xmm2
ucomisd 0xdf60(%rip), %xmm2     # 0x26800
jne 0x188ac
jp 0x188ac
movsd %xmm1, (%rax,%r12,8)
jmp 0x188fd
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
movapd %xmm3, %xmm0
xorpd 0xdf60(%rip), %xmm0     # 0x26820
movapd %xmm0, %xmm4
cmpltsd %xmm3, %xmm4
andpd %xmm4, %xmm2
andnpd %xmm1, %xmm4
orpd %xmm2, %xmm4
movapd %xmm4, -0xf0(%rbp)
minsd %xmm3, %xmm0
callq 0x4660
callq 0x46e0
addsd -0xf0(%rbp), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, (%rax,%r12,8)
addq $0x8, %r15
jmp 0x187db
movq %rax, %r14
cmpl $0x1, %edx
jne 0x189e6
movq %r14, %rdi
callq 0x4160
movq (%r15), %rax
movabsq $-0x3fa7000000000000, %rcx # imm = 0xC059000000000000
movq %rcx, 0x8(%rax)
callq 0x45c0
jmp 0x18881
leaq -0x50(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
movq %r14, %rdi
movq -0x98(%rbp), %rcx
callq 0x1808e
movq -0x48(%rbp), %rax
movsd -0x8(%rax), %xmm0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
movsd %xmm0, -0x30(%rbp)
je 0x18974
callq 0x4350
movsd -0x30(%rbp), %xmm0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x1898e
callq 0x4350
movsd -0x30(%rbp), %xmm0
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x189a4
callq 0x4350
movsd -0x30(%rbp), %xmm0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x189c1
callq 0x4350
movsd -0x30(%rbp), %xmm0
jmp 0x189c1
movsd 0xde3f(%rip), %xmm0     # 0x26800
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x189e3
jmp 0x189e3
movq %rax, %r14
jmp 0x18a1e
movq %rax, %r14
jmp 0x18a2c
jmp 0x189e3
movq %rax, %r14
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x189f8
callq 0x4350
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x18a0d
callq 0x4350
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x18a1e
callq 0x4350
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x18a2c
callq 0x4350
movq %r14, %rdi
callq 0x4650