// File: /workspace/github_cpp_makefile_star2_O3/aalto-speech[P]ftk/src/EM.cc
// Function: forward(StringSet const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<std::vector<Token, std::allocator<Token>>, std::allocator<std::vector<Token, std::allocator<Token>>>>&, std::vector<double, std::allocator<double>>&, bool)
void forward(const StringSet &vocab,
             const string &text,
             vector<vector<Token> > &search,
             vector<flt_type> &fw,
             bool utf8)
{
    int len = text.length();

    vector<unsigned int> char_positions;
    get_character_positions(text, char_positions, utf8);

    for (unsigned int cpi=0; cpi<char_positions.size(); cpi++) {

        int i = char_positions[cpi];
        if (i>0 && search[i-1].size() == 0) continue;

        if (i>0) {
            fw[i-1] = search[i-1][0].cost;
            for (unsigned int t=1; t<search[i-1].size(); t++)
                fw[i-1] = add_log_domain_probs(fw[i-1], search[i-1][t].cost);
        }

        // Iterate all factors starting from this position
        const StringSet::Node *node = &vocab.root_node;
        for (unsigned int j=i; j<text.length(); j++) {

            StringSet::Arc *arc = vocab.find_arc(text[j], node);

            if (arc == nullptr) break;
            node = arc->target_node;

            // Factor associated with this node
            if (arc->factor.length() > 0) {
                flt_type cost = arc->cost;
                if (i>0) cost += fw[i-1];

                Token tok(i-1, cost);
                search[j].push_back(tok);
            }
        }
    }

    if (search[len-1].size() == 0) return;

    fw[len-1] = search[len-1][0].cost;
    for (unsigned int j=1; j<search[len-1].size(); j++)
        fw[len-1] = add_log_domain_probs(fw[len-1], search[len-1][j].cost);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, -0x48(%rbp)
movq 0x8(%rsi), %r15
xorpd %xmm0, %xmm0
leaq -0x60(%rbp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movq %rax, -0x80(%rbp)
movq %rax, %rdi
movl %r8d, %edx
callq 0x169dd
movq %r15, -0x78(%rbp)
movq %r14, -0x38(%rbp)
movq -0x60(%rbp), %rdi
cmpq %rdi, -0x58(%rbp)
movq %rbx, -0x30(%rbp)
je 0x17092
xorl %ecx, %ecx
movapd 0xf938(%rip), %xmm4     # 0x26820
movq %rcx, -0x88(%rbp)
movl (%rdi,%rcx,4), %eax
movq %rax, -0x40(%rbp)
testl %eax, %eax
movq -0x38(%rbp), %rax
jle 0x16fc8
movq -0x40(%rbp), %rcx
leal -0x1(%rcx), %r12d
movq (%rax), %rcx
leaq (%r12,%r12,2), %r14
movq (%rcx,%r14,8), %rax
movq 0x8(%rcx,%r14,8), %rcx
subq %rax, %rcx
je 0x17071
movsd 0x8(%rax), %xmm0
movq -0x30(%rbp), %rbx
movq (%rbx), %rdx
movsd %xmm0, (%rdx,%r12,8)
cmpq $0x11, %rcx
movq -0x38(%rbp), %r15
jb 0x16fc8
movl $0x1, %ecx
movl $0x2, %r13d
shlq $0x4, %rcx
movsd 0x8(%rax,%rcx), %xmm2
movapd %xmm0, %xmm3
subsd %xmm2, %xmm3
movapd %xmm3, %xmm1
xorpd %xmm4, %xmm1
movapd %xmm1, %xmm4
cmpltsd %xmm3, %xmm4
andpd %xmm4, %xmm0
andnpd %xmm2, %xmm4
orpd %xmm0, %xmm4
movapd %xmm4, -0x70(%rbp)
minsd %xmm3, %xmm1
movapd %xmm1, %xmm0
callq 0x4660
callq 0x46e0
movapd 0xf884(%rip), %xmm4     # 0x26820
addsd -0x70(%rbp), %xmm0
movq (%rbx), %rax
movsd %xmm0, (%rax,%r12,8)
movl %r13d, %ecx
movq (%r15), %rdx
movq (%rdx,%r14,8), %rax
movq 0x8(%rdx,%r14,8), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
incl %r13d
cmpq %rcx, %rdx
ja 0x16f4e
movq -0x80(%rbp), %r15
movq -0x40(%rbp), %rax
cmpq %rax, 0x8(%r15)
jbe 0x17071
movq -0x40(%rbp), %rbx
leal -0x1(%rbx), %r14d
leal 0x1(%rbx), %r13d
movq -0x48(%rbp), %r12
movq (%r15), %rax
movsbl (%rax,%rbx), %esi
movq -0x48(%rbp), %rdi
movq %r12, %rdx
callq 0xcd82
testq %rax, %rax
movapd 0xf818(%rip), %xmm4     # 0x26820
je 0x17071
movq 0x28(%rax), %r12
cmpq $0x0, 0x10(%rax)
je 0x17061
movsd 0x30(%rax), %xmm0
movq -0x40(%rbp), %rcx
testl %ecx, %ecx
jle 0x1702f
movq -0x30(%rbp), %rax
movq (%rax), %rax
addsd -0x8(%rax,%rcx,8), %xmm0
movl %r14d, -0x98(%rbp)
movsd %xmm0, -0x90(%rbp)
leaq (%rbx,%rbx,2), %rdi
shlq $0x3, %rdi
movq -0x38(%rbp), %rax
addq (%rax), %rdi
leaq -0x98(%rbp), %rsi
callq 0x1b006
movapd 0xf7bf(%rip), %xmm4     # 0x26820
movl %r13d, %ebx
incl %r13d
cmpq %rbx, 0x8(%r15)
ja 0x16fea
movq -0x88(%rbp), %rcx
incl %ecx
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rax
subq %rdi, %rax
sarq $0x2, %rax
cmpq %rcx, %rax
ja 0x16ee8
movq -0x78(%rbp), %rax
decl %eax
movslq %eax, %rbx
movq -0x38(%rbp), %r13
movq (%r13), %rcx
leaq (%rbx,%rbx,2), %r14
movq (%rcx,%r14,8), %rax
movq 0x8(%rcx,%r14,8), %rcx
subq %rax, %rcx
je 0x1715e
movsd 0x8(%rax), %xmm0
movq -0x30(%rbp), %rdx
movq (%rdx), %rdx
movsd %xmm0, (%rdx,%rbx,8)
cmpq $0x11, %rcx
jb 0x1715e
movl $0x1, %ecx
movl $0x2, %r15d
movq -0x30(%rbp), %r12
shlq $0x4, %rcx
movsd 0x8(%rax,%rcx), %xmm2
movapd %xmm0, %xmm3
subsd %xmm2, %xmm3
movapd %xmm3, %xmm1
xorpd 0xf71f(%rip), %xmm1     # 0x26820
movapd %xmm1, %xmm4
cmpltsd %xmm3, %xmm4
andpd %xmm4, %xmm0
andnpd %xmm2, %xmm4
orpd %xmm0, %xmm4
movapd %xmm4, -0x70(%rbp)
minsd %xmm3, %xmm1
movapd %xmm1, %xmm0
callq 0x4660
callq 0x46e0
addsd -0x70(%rbp), %xmm0
movq (%r12), %rax
movsd %xmm0, (%rax,%rbx,8)
movl %r15d, %ecx
movq (%r13), %rdx
movq (%rdx,%r14,8), %rax
movq 0x8(%rdx,%r14,8), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
incl %r15d
cmpq %rcx, %rdx
ja 0x170e3
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x17168
callq 0x4350
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1717b
jmp 0x1717b
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x1718c
callq 0x4350
movq %rbx, %rdi
callq 0x4650