// File: /workspace/github_cpp_makefile_star2_O3/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 $0xd8, %rsp
movsd %xmm0, -0x90(%rbp)
movq %rcx, -0x98(%rbp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r13
leaq 0x38(%rdi), %r15
movq %r15, %rdi
callq 0x138da
movl (%rax), %eax
leaq -0x44(%rbp), %rsi
movl %eax, (%rsi)
leaq -0xc0(%rbp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0xc8(%rbp), %rdi
callq 0x1b6e2
movq %r15, -0x78(%rbp)
movq %r14, -0x80(%rbp)
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq -0xf0(%rbp), %rax
movl $0x0, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq -0xf8(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x1cd4c
cmpq $0x0, -0xd0(%rbp)
je 0x1a1ec
leaq -0xf0(%rbp), %rdi
callq 0x4210
movslq 0x20(%rax), %rax
movl %eax, -0x30(%rbp)
movq 0x20(%r13), %r15
shlq $0x7, %rax
leaq (%r15,%rax), %r12
addq $0x28, %r12
movq 0x10(%r12), %r14
cmpq %r12, %r14
je 0x1a1c9
addq %rax, %r15
movq 0x20(%r14), %rax
movslq (%rax), %rdx
movl %edx, -0x2c(%rbp)
movq (%rbx), %rcx
movsd (%rcx,%rdx,8), %xmm0
movapd %xmm0, -0x40(%rbp)
ucomisd 0xc7f9(%rip), %xmm0     # 0x26800
jne 0x1a00f
jnp 0x1a126
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movslq -0x30(%rbp), %rax
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1b6e2
movapd -0x40(%rbp), %xmm0
addsd -0x60(%rbp), %xmm0
subsd -0x70(%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 0x1a247
shlq $0x7, %rsi
addq %rsi, %rax
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x1b318
movq %rax, %rdi
movq %r15, %rsi
callq 0x1af86
movsd -0x60(%rbp), %xmm0
mulsd -0x90(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x1a0fd
movl -0x2c(%rbp), %eax
leaq -0xc0(%rbp), %r8
movq %r8, %rcx
movq %rdi, %rdx
movl 0x20(%rdi), %esi
xorl %edi, %edi
cmpl %eax, %esi
setl %dil
movq %rdx, %r8
cmovlq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x1a0c4
leaq -0xc0(%rbp), %rdi
cmpq %rdi, %r8
je 0x1a0fd
cmpl %eax, %esi
cmovlq %rcx, %rdx
cmpl 0x20(%rdx), %eax
jge 0x1a13f
leaq -0xc8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1b6e2
movapd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0xf8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1cd4c
movq %r14, %rdi
callq 0x4410
movq %rax, %r14
cmpq %r12, %rax
jne 0x19fe8
jmp 0x1a1c9
leaq -0xc8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1b6e2
movsd (%rax), %xmm0
movapd %xmm0, -0x60(%rbp)
movapd %xmm0, %xmm1
subsd -0x40(%rbp), %xmm1
movapd %xmm1, %xmm0
xorpd 0xc6b3(%rip), %xmm0     # 0x26820
movapd %xmm1, -0x70(%rbp)
minsd %xmm1, %xmm0
callq 0x4660
callq 0x46e0
movsd %xmm0, -0x88(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1b6e2
xorpd %xmm0, %xmm0
cmpltsd -0x70(%rbp), %xmm0
movapd -0x60(%rbp), %xmm1
andpd %xmm0, %xmm1
andnpd -0x40(%rbp), %xmm0
orpd %xmm1, %xmm0
movsd -0x88(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
jmp 0x1a126
leaq -0xf8(%rbp), %r14
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1ce68
movq %r14, %rdi
movq %rax, %rsi
callq 0x1ceea
jmp 0x19fa6
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x138da
movl (%rax), %esi
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x1a255
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x1ba62
leaq -0xc8(%rbp), %rdi
callq 0x1baba
movsd -0x40(%rbp), %xmm0
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc608(%rip), %rdi      # 0x26856
xorl %eax, %eax
callq 0x4530
leaq 0xc5fa(%rip), %rdi      # 0x26856
xorl %eax, %eax
callq 0x4530
movq %rax, %rbx
jmp 0x1a27d
jmp 0x1a26e
jmp 0x1a26e
jmp 0x1a26e
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
callq 0x1ba62
leaq -0xc8(%rbp), %rdi
callq 0x1baba
movq %rbx, %rdi
callq 0x4650