// File: aalto-speech[P]ftk/src/FactorGraph.cc
// Function: FactorGraph::create_nodes(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, StringSet const&, std::vector<std::unordered_set<unsigned short, std::hash<unsigned short>, std::equal_to<unsigned short>, std::allocator<unsigned short>>, std::allocator<std::unordered_set<unsigned short, std::hash<unsigned short>, std::equal_to<unsigned short>, std::allocator<unsigned short>>>>&)
void
FactorGraph::create_nodes(const string &text,
                          const StringSet &vocab,
                          vector<unordered_set<fg_node_idx_t> > &incoming)
{
    nodes.push_back(Node(0,0));

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

    for (unsigned int i=0; i<char_positions.size()-1; i++) {

        unsigned int start_pos = char_positions[i];
        if (incoming[start_pos].size() == 0) continue;

        const StringSet::Node *node = &vocab.root_node;
        for (unsigned int j=start_pos; j<text.length(); j++) {

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

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

            // String associated with this node
            if (arc->factor.length() > 0) {
                nodes.push_back(Node(start_pos, j+1-start_pos));
                incoming[j+1].insert(start_pos);
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x108(%rbp)
addq $0x40, %rax
movq %rax, -0x100(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
xorl %edx, %edx
movl %edx, %esi
callq 0x233d0
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x233a0
jmp 0x215ea
leaq -0x58(%rbp), %rdi
callq 0x23420
leaq -0x80(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x23470
movq -0x108(%rbp), %rax
movq -0x110(%rbp), %rsi
movq -0x10(%rbp), %rdi
movzbl 0x70(%rax), %edx
andl $0x1, %edx
callq 0x21130
jmp 0x21623
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
movq %rax, -0x118(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x23490
movq %rax, %rcx
movq -0x118(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x21878
movl -0x84(%rbp), %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x234b0
movl (%rax), %eax
movl %eax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
movl -0x88(%rbp), %eax
movl %eax, %esi
callq 0x234d0
movq %rax, %rdi
callq 0x234f0
cmpq $0x0, %rax
jne 0x216c2
jmp 0x21864
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x23420
jmp 0x21893
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2188a
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movq %rax, -0x120(%rbp)
movq -0x10(%rbp), %rdi
callq 0x45e0
movq %rax, %rcx
movq -0x120(%rbp), %rax
cmpq %rcx, %rax
jae 0x21862
movq -0x18(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x10(%rbp), %rdi
movl -0x94(%rbp), %eax
movl %eax, %esi
callq 0x4430
movq -0x130(%rbp), %rdi
movsbl (%rax), %esi
movq -0x90(%rbp), %rdx
callq 0x1a730
movq %rax, -0x128(%rbp)
jmp 0x2173d
movq -0x128(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
jne 0x2175a
jmp 0x21862
movq -0xa0(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0xa0(%rbp), %rdi
addq $0x8, %rdi
callq 0x45e0
cmpq $0x0, %rax
jbe 0x2184c
movq -0x108(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x138(%rbp)
movl -0x88(%rbp), %esi
movl -0x94(%rbp), %edx
subl %esi, %edx
incl %edx
leaq -0xd8(%rbp), %rdi
callq 0x233d0
jmp 0x217b6
movq -0x138(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x233a0
jmp 0x217cb
leaq -0xd8(%rbp), %rdi
callq 0x23420
movq -0x20(%rbp), %rdi
movl -0x94(%rbp), %eax
incl %eax
movl %eax, %esi
callq 0x234d0
movq %rax, %rdi
movw -0x88(%rbp), %ax
movw %ax, -0xda(%rbp)
leaq -0xda(%rbp), %rsi
callq 0x23510
movb %dl, -0x141(%rbp)
movq %rax, -0x140(%rbp)
jmp 0x21816
movb -0x141(%rbp), %al
movq -0x140(%rbp), %rcx
movq %rcx, -0xf0(%rbp)
movb %al, -0xe8(%rbp)
jmp 0x2184c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x23420
jmp 0x2188a
jmp 0x2184e
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x216d9
jmp 0x21864
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x2162d
leaq -0x80(%rbp), %rdi
callq 0x23550
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
leaq -0x80(%rbp), %rdi
callq 0x23550
movq -0x60(%rbp), %rdi
callq 0x46e0
nopl (%rax)