// File: /workspace/github_cpp_makefile_star2_O3/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 0x18888
movq %rdx, %r15
movq %rsi, %r14
movq %rdx, %rdi
callq 0x1c43c
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 0x1b134
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 0x1b134
movq %r12, %rdx
movq -0x50(%rbp), %rax
xorl %ebx, %ebx
movq %rbx, (%rax)
movq 0x40(%r14), %r13
movq 0x48(%r14), %rax
movq %rax, %rcx
subq %r13, %rcx
imulq %rdx, %rcx
movq -0xb8(%rbp), %rdx
movq %rbx, -0x8(%rdx,%rcx)
leaq -0x80(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rbx, -0x8(%rcx)
movb %bl, (%rcx)
leaq -0x60(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rbx, -0x8(%rcx)
movb %bl, (%rcx)
cmpq %r13, %rax
je 0x18804
movq %r14, -0x38(%rbp)
movq -0x50(%rbp), %rax
movsd (%rax,%rbx,8), %xmm0
ucomisd 0xe204(%rip), %xmm0     # 0x26800
jne 0x1862d
jp 0x1862d
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 0x185eb
jmp 0x18804
imulq $0x38, %rbx, %rax
addq %rax, %r13
leaq -0xd8(%rbp), %r15
movq %r15, %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
callq 0x10242
leaq -0x90(%rbp), %rdi
movq %r15, %rsi
callq 0x4430
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x18671
callq 0x4350
movq -0x88(%rbp), %rdx
movq -0x30(%rbp), %rax
cmpq 0x8(%rax), %rdx
jne 0x186a6
testq %rdx, %rdx
je 0x18600
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq -0x90(%rbp), %rdi
callq 0x43a0
testl %eax, %eax
je 0x18600
movq 0x20(%r13), %r15
cmpq 0x28(%r13), %r15
je 0x18600
movq (%r15), %rax
movzwl 0x2(%rax), %r12d
leaq -0xd8(%rbp), %r14
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movl %r12d, %edx
callq 0x10288
leaq -0x70(%rbp), %rdi
movq %r14, %rsi
callq 0x4430
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x186f6
callq 0x4350
movq -0x68(%rbp), %rdx
movq -0x30(%rbp), %rax
cmpq 0x8(%rax), %rdx
jne 0x18725
testq %rdx, %rdx
je 0x187c4
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq -0x70(%rbp), %rdi
callq 0x43a0
testl %eax, %eax
je 0x187c4
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x1b398
movq %rax, %rdi
leaq -0x70(%rbp), %rsi
callq 0x1b3f6
movsd (%rax), %xmm1
movq (%r15), %rax
movsd %xmm1, 0x8(%rax)
movq -0x50(%rbp), %rax
addsd (%rax,%rbx,8), %xmm1
movsd (%rax,%r12,8), %xmm2
ucomisd 0xe099(%rip), %xmm2     # 0x26800
jne 0x18773
jp 0x18773
movsd %xmm1, (%rax,%r12,8)
jmp 0x187c4
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
movapd %xmm3, %xmm0
xorpd 0xe099(%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 0x186aa
movq %rax, %r14
cmpl $0x1, %edx
jne 0x188b5
movq %r14, %rdi
callq 0x4160
movq (%r15), %rax
movabsq $-0x3fa7000000000000, %rcx # imm = 0xC059000000000000
movq %rcx, 0x8(%rax)
callq 0x45c0
movq (%r15), %rax
movsd 0x8(%rax), %xmm1
jmp 0x18750
leaq -0x50(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
movq %r14, %rdi
movq -0x98(%rbp), %rcx
callq 0x17f51
movq -0x48(%rbp), %rax
movsd -0x8(%rax), %xmm0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
movsd %xmm0, -0x30(%rbp)
je 0x18843
callq 0x4350
movsd -0x30(%rbp), %xmm0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x1885d
callq 0x4350
movsd -0x30(%rbp), %xmm0
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x18873
callq 0x4350
movsd -0x30(%rbp), %xmm0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x18890
callq 0x4350
movsd -0x30(%rbp), %xmm0
jmp 0x18890
movsd 0xdf70(%rip), %xmm0     # 0x26800
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x188b2
jmp 0x188b2
movq %rax, %r14
jmp 0x188ed
movq %rax, %r14
jmp 0x188fb
jmp 0x188b2
movq %rax, %r14
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x188c7
callq 0x4350
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x188dc
callq 0x4350
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x188ed
callq 0x4350
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x188fb
callq 0x4350
movq %r14, %rdi
callq 0x4650