// File: aalto-speech[P]ftk/src/MSFG.cc
// Function: MultiStringFactorGraph::num_paths(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
int
MultiStringFactorGraph::num_paths(const std::string &text) const
{
    if (nodes.size() == 0) return 0;
    if (string_end_nodes.find(text) == string_end_nodes.end()) return 0;
    msfg_node_idx_t end_node = string_end_nodes.at(text);
    map<msfg_node_idx_t, int> path_counts; path_counts[end_node] = 1;
    set<msfg_node_idx_t> nodes_to_process; nodes_to_process.insert(end_node);

    while(nodes_to_process.size() > 0) {

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

        const Node &node = nodes[i];
        for (auto arc = node.incoming.begin(); arc != node.incoming.end(); ++arc) {
            path_counts[(**arc).source_node] += path_counts[i];
            nodes_to_process.insert((**arc).source_node);
        }

        nodes_to_process.erase(i);
    }

    return path_counts[0];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
addq $0x20, %rdi
callq 0x30500
cmpq $0x0, %rax
jne 0x2da89
movl $0x0, -0x4(%rbp)
jmp 0x2dd70
movq -0xf8(%rbp), %rdi
addq $0x38, %rdi
movq -0x18(%rbp), %rsi
callq 0x30910
movq -0xf8(%rbp), %rdi
movq %rax, -0x20(%rbp)
addq $0x38, %rdi
callq 0x30940
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x308e0
testb $0x1, %al
jne 0x2dac8
jmp 0x2dad4
movl $0x0, -0x4(%rbp)
jmp 0x2dd70
movq -0xf8(%rbp), %rdi
addq $0x38, %rdi
movq -0x18(%rbp), %rsi
callq 0x30970
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x30a10
movq -0x108(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x30a30
movq %rax, -0x100(%rbp)
jmp 0x2db16
movq -0x100(%rbp), %rax
movl $0x1, (%rax)
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x30b10
movq -0x120(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x30b30
movb %dl, -0x111(%rbp)
movq %rax, -0x110(%rbp)
jmp 0x2db55
movb -0x111(%rbp), %al
movq -0x110(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movb %al, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x30b80
cmpq $0x0, %rax
jbe 0x2dd1f
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x130(%rbp)
leaq -0xa0(%rbp), %rsi
callq 0x30ba0
movq -0x130(%rbp), %rdi
callq 0x30bd0
movq %rax, -0x128(%rbp)
jmp 0x2dbb4
movq -0xf8(%rbp), %rdi
movq -0x128(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xb4(%rbp)
addq $0x20, %rdi
movl -0xb4(%rbp), %eax
movl %eax, %esi
callq 0x30c00
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
addq $0x20, %rdi
callq 0x30260
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
addq $0x20, %rdi
callq 0x302c0
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x30290
testb $0x1, %al
jne 0x2dc2c
jmp 0x2dd05
leaq -0x60(%rbp), %rdi
leaq -0xb4(%rbp), %rsi
callq 0x30a30
movq %rax, -0x138(%rbp)
jmp 0x2dc45
movq -0x138(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x144(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x302f0
movq (%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0x30a30
movq %rax, -0x140(%rbp)
jmp 0x2dc75
movq -0x140(%rbp), %rax
movl -0x144(%rbp), %edx
movl (%rax), %ecx
addl %edx, %ecx
movl %ecx, (%rax)
leaq -0xd0(%rbp), %rdi
callq 0x302f0
movq (%rax), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x30b30
movb %dl, -0x151(%rbp)
movq %rax, -0x150(%rbp)
jmp 0x2dcb2
movb -0x151(%rbp), %al
movq -0x150(%rbp), %rcx
movq %rcx, -0xe8(%rbp)
movb %al, -0xe0(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x30320
jmp 0x2dbf9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2dd65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x30d30
jmp 0x2dd65
leaq -0xa0(%rbp), %rdi
leaq -0xb4(%rbp), %rsi
callq 0x30c20
jmp 0x2dd1a
jmp 0x2db6f
movl $0x0, -0xec(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0xec(%rbp), %rsi
callq 0x30c50
movq %rax, -0x160(%rbp)
jmp 0x2dd42
movq -0x160(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x30d30
leaq -0x60(%rbp), %rdi
callq 0x30d50
jmp 0x2dd70
leaq -0x60(%rbp), %rdi
callq 0x30d50
jmp 0x2dd7c
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x46e0
nopw %cs:(%rax,%rax)