// File: /workspace/github_cpp_makefile_star2_O1/aalto-speech[P]ftk/src/EM.cc
// Function: backward(MultiStringFactorGraph const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<double, std::allocator<double>> const&, 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>>>>>>&, double)
flt_type
backward(const MultiStringFactorGraph &msfg,
         const string &text,
         const vector<flt_type> &fw,
         transitions_t &stats,
         flt_type text_weight)
{

    int text_end_node = msfg.string_end_nodes.at(text);
    map<int, flt_type> bw; bw[text_end_node] = 0.0;
    set<int> nodes_to_process; nodes_to_process.insert(text_end_node);

    while(nodes_to_process.size() > 0) {

        int i = *(nodes_to_process.rbegin());

        const MultiStringFactorGraph::Node &node = msfg.nodes[i];

        for (auto arc = node.incoming.begin(); arc != node.incoming.end(); ++arc) {
            int src_node = (**arc).source_node;
            if (fw[src_node] == MIN_FLOAT) continue;
            flt_type curr_cost = *(**arc).cost + fw[src_node] - fw[i] + bw[i];
            stats[msfg.nodes.at(src_node).factor][node.factor] += text_weight * exp(curr_cost);
            if (bw.find(src_node) == bw.end()) {
                bw[src_node] = curr_cost;
                nodes_to_process.insert(src_node);
            }
            else bw[src_node] = add_log_domain_probs(bw[src_node], curr_cost);
        }

        nodes_to_process.erase(i);
    }

    return fw.at(msfg.string_end_nodes.at(text));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movsd %xmm0, -0x98(%rbp)
movq %rcx, -0xa0(%rbp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r13
leaq 0x38(%rdi), %r15
movq %r15, %rdi
callq 0x139bc
movl (%rax), %eax
leaq -0x44(%rbp), %rsi
movl %eax, (%rsi)
leaq -0x100(%rbp), %r12
movl $0x0, (%r12)
xorl %eax, %eax
movq %rax, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
movq %rax, 0x20(%r12)
leaq -0x108(%rbp), %rdi
callq 0x1b7ca
movq %r15, -0x88(%rbp)
movq %r14, -0x90(%rbp)
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq -0xd0(%rbp), %rax
movl $0x0, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq -0xd8(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x1ce60
cmpq $0x0, -0xb0(%rbp)
je 0x1a2c0
leaq -0xd0(%rbp), %rdi
callq 0x4210
movslq 0x20(%rax), %rax
movl %eax, -0x30(%rbp)
movq 0x20(%r13), %rcx
shlq $0x7, %rax
movq %rcx, -0x68(%rbp)
leaq (%rcx,%rax), %r15
addq $0x28, %r15
movq 0x10(%r15), %r14
cmpq %r15, %r14
je 0x1a29d
addq %rax, -0x68(%rbp)
movq 0x20(%r14), %rax
movslq (%rax), %rdx
movl %edx, -0x2c(%rbp)
movq (%rbx), %rcx
movsd (%rcx,%rdx,8), %xmm0
movapd %xmm0, -0x40(%rbp)
ucomisd 0xc719(%rip), %xmm0     # 0x26800
jne 0x1a0ef
jnp 0x1a289
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movslq -0x30(%rbp), %rax
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, -0x80(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1b7ca
movapd -0x40(%rbp), %xmm0
addsd -0x60(%rbp), %xmm0
subsd -0x80(%rbp), %xmm0
addsd (%rax), %xmm0
movapd %xmm0, -0x40(%rbp)
callq 0x4660
movsd %xmm0, -0x60(%rbp)
movslq -0x2c(%rbp), %rsi
movq 0x20(%r13), %rax
movq 0x28(%r13), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
cmpq %rsi, %rdx
jbe 0x1a321
shlq $0x7, %rsi
addq %rsi, %rax
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x1b3fa
movq %rax, %rdi
movq -0x68(%rbp), %rsi
callq 0x1b05e
movsd -0x60(%rbp), %xmm0
mulsd -0x98(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0xf8(%rbp), %rcx
movq %r12, %rax
testq %rcx, %rcx
je 0x1a1bb
movl -0x2c(%rbp), %edx
movq %r12, %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x1a1a4
movq %r12, %rcx
cmpq %r12, %rax
je 0x1a1d0
movl -0x2c(%rbp), %ecx
cmpl 0x20(%rax), %ecx
cmovlq %r12, %rax
movq %rax, %rcx
cmpq %r12, %rcx
je 0x1a260
leaq -0x108(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1b7ca
movsd (%rax), %xmm0
movapd %xmm0, -0x60(%rbp)
movapd %xmm0, %xmm1
subsd -0x40(%rbp), %xmm1
movapd %xmm1, %xmm0
xorpd 0xc619(%rip), %xmm0     # 0x26820
movapd %xmm1, -0x80(%rbp)
minsd %xmm1, %xmm0
callq 0x4660
callq 0x46e0
movsd %xmm0, -0xa8(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1b7ca
xorpd %xmm0, %xmm0
cmpltsd -0x80(%rbp), %xmm0
movapd -0x60(%rbp), %xmm1
andpd %xmm0, %xmm1
andnpd -0x40(%rbp), %xmm0
orpd %xmm1, %xmm0
movsd -0xa8(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
jmp 0x1a289
leaq -0x108(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1b7ca
movapd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0xd8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1ce60
movq %r14, %rdi
callq 0x4410
movq %rax, %r14
cmpq %r15, %rax
jne 0x1a0c8
leaq -0xd8(%rbp), %r14
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1cf88
movq %r14, %rdi
movq %rax, %rsi
callq 0x1d004
jmp 0x1a082
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x139bc
movl (%rax), %esi
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x1a32f
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x1bb50
leaq -0x108(%rbp), %rdi
callq 0x1bba8
movsd -0x40(%rbp), %xmm0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc52e(%rip), %rdi      # 0x26856
xorl %eax, %eax
callq 0x4530
leaq 0xc520(%rip), %rdi      # 0x26856
xorl %eax, %eax
callq 0x4530
movq %rax, %rbx
jmp 0x1a357
jmp 0x1a348
jmp 0x1a348
jmp 0x1a348
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0x1bb50
leaq -0x108(%rbp), %rdi
callq 0x1bba8
movq %rbx, %rdi
callq 0x4650