// File: /workspace/github_cpp_makefile_star2_O1/aalto-speech[P]ftk/src/FactorGraph.cc
// Function: FactorGraph::prune_and_create_arcs(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::prune_and_create_arcs(vector<unordered_set<fg_node_idx_t> > &incoming)
{
    // Find all possible node start positions
    unordered_set<int> possible_node_starts;
    possible_node_starts.insert(text.size());
    for (int i=incoming.size()-1; i>= 0; i--) {
        if (possible_node_starts.find(i) == possible_node_starts.end()) continue;
        for (auto it = incoming[i].cbegin(); it != incoming[i].cend(); ++it)
            possible_node_starts.insert(*it);
    }

    // Prune non-reachable nodes
    for (auto it = nodes.begin(); it != nodes.end(); ) {
        if (possible_node_starts.find(it->start_pos) == possible_node_starts.end() ||
            possible_node_starts.find(it->start_pos+it->len) == possible_node_starts.end())
            it = nodes.erase(it);
        else
            ++it;
    }

    // Add end node
    nodes.push_back(Node(text.size(),0));

    // Collect nodes by start position
    vector<vector<unsigned int> > nodes_by_start_pos(text.size()+1);
    for (unsigned int i=1; i<nodes.size(); i++)
        nodes_by_start_pos[nodes[i].start_pos].push_back(i);

    // Set arcs
    for (unsigned int i=0; i<nodes.size()-1; i++) {
        unsigned int end_pos = nodes[i].start_pos + nodes[i].len;
        for (unsigned int j=0; j<nodes_by_start_pos[end_pos].size(); j++) {
            unsigned int nodei = nodes_by_start_pos[end_pos][j];
            Arc *arc = new Arc(i, nodei, 0.0);
            arcs.push_back(arc);
            nodes[i].outgoing.push_back(arc);
            nodes[nodei].incoming.push_back(arc);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
leaq -0x90(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movq %rdi, -0x40(%rbp)
movl 0x8(%rdi), %eax
leaq -0x30(%rbp), %rsi
movl %eax, (%rsi)
leaq -0xc0(%rbp), %r15
leaq -0x88(%rbp), %rdx
movq %r15, (%rdx)
movq %r15, %rdi
callq 0x10dd6
movq 0x8(%rbx), %rax
movq %rbx, -0x38(%rbp)
subq (%rbx), %rax
shrq $0x3, %rax
imull $0xb6db6db7, %eax, %eax # imm = 0xB6DB6DB7
decl %eax
js 0xf02a
movl %eax, %r12d
leaq -0x30(%rbp), %r13
leaq -0x88(%rbp), %r14
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdi
movq %r12, %rax
xorl %edx, %edx
divq %rdi
movq %rdx, %rcx
movq (%rsi,%rdx,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0xefd8
movq (%rdx), %r8
movl 0x8(%r8), %esi
movq %rdx, %rax
cmpq %rsi, %r12
je 0xefd8
movq %r8, %r9
movq (%r8), %r8
testq %r8, %r8
je 0xefd6
movslq 0x8(%r8), %rsi
movq %rsi, %rax
xorl %edx, %edx
divq %rdi
movl $0x0, %eax
cmpq %rcx, %rdx
jne 0xefd8
movl %esi, %edx
movq %r9, %rax
cmpq %rdx, %r12
jne 0xefa9
jmp 0xefd8
xorl %eax, %eax
testq %rax, %rax
je 0xf019
cmpq $0x0, (%rax)
je 0xf019
movq -0x38(%rbp), %rax
movq (%rax), %rax
imulq $0x38, %r12, %rcx
movq 0x10(%rax,%rcx), %rbx
testq %rbx, %rbx
je 0xf019
movzwl 0x8(%rbx), %eax
movl %eax, -0x30(%rbp)
movq %r15, -0x88(%rbp)
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x10dd6
movq (%rbx), %rbx
jmp 0xeff3
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
jg 0xef73
movq -0x40(%rbp), %r14
leaq 0x40(%r14), %rax
movq %rax, -0x38(%rbp)
movq 0x40(%r14), %rsi
cmpq 0x48(%r14), %rsi
je 0xf133
movzwl (%rsi), %ecx
movq -0xc0(%rbp), %r10
movq -0xb8(%rbp), %r9
movq %rcx, %rax
xorl %edx, %edx
divq %r9
movq %rdx, %rdi
movl %edi, %eax
movq (%r10,%rax,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0xf0a9
movq (%rdx), %r11
movq %rdx, %rax
cmpl %ecx, 0x8(%r11)
je 0xf0a9
movq %r11, %rbx
movq (%r11), %r11
testq %r11, %r11
je 0xf0a7
movslq 0x8(%r11), %r8
movq %r8, %rax
xorl %edx, %edx
divq %r9
movl $0x0, %eax
cmpq %rdi, %rdx
jne 0xf0a9
movq %rbx, %rax
cmpl %ecx, %r8d
jne 0xf07c
jmp 0xf0a9
xorl %eax, %eax
testq %rax, %rax
je 0xf122
cmpq $0x0, (%rax)
je 0xf122
movzbl 0x2(%rsi), %edi
addl %ecx, %edi
movq %rdi, %rax
xorl %edx, %edx
divq %r9
movq %rdx, %rcx
movl %ecx, %eax
movq (%r10,%rax,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0xf10e
movq (%rdx), %r10
movq %rdx, %rax
cmpl 0x8(%r10), %edi
je 0xf10e
movq %r10, %r11
movq (%r10), %r10
testq %r10, %r10
je 0xf10c
movslq 0x8(%r10), %r8
movq %r8, %rax
xorl %edx, %edx
divq %r9
movl $0x0, %eax
cmpq %rcx, %rdx
jne 0xf10e
movq %r11, %rax
cmpl %r8d, %edi
jne 0xf0e1
jmp 0xf10e
xorl %eax, %eax
testq %rax, %rax
je 0xf122
cmpq $0x0, (%rax)
je 0xf122
addq $0x38, %rsi
jmp 0xf03a
movq -0x38(%rbp), %rdi
callq 0x110a6
movq %rax, %rsi
jmp 0xf03a
movzwl 0x8(%r14), %eax
leaq -0x88(%rbp), %rsi
movw %ax, (%rsi)
movb $0x0, 0x2(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsi)
movups %xmm0, 0x18(%rsi)
movups %xmm0, 0x28(%rsi)
movq -0x38(%rbp), %rdi
callq 0x10650
leaq -0x88(%rbp), %rdi
callq 0xff90
movq 0x8(%r14), %rsi
incq %rsi
leaq -0x88(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0xffd6
movl $0x1, -0x30(%rbp)
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $0x6db6db6db6db6db7, %rbx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rbx, %rcx
cmpq $0x2, %rcx
jb 0xf210
movl $0x1, %edx
movl $0x1, %ecx
leaq -0x30(%rbp), %r15
imulq $0x38, %rcx, %rcx
movzwl (%rax,%rcx), %eax
movq -0x88(%rbp), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf1e6
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0xf1ee
movq %r15, %rdx
callq 0x1057c
movl -0x30(%rbp), %ecx
incl %ecx
movl %ecx, -0x30(%rbp)
movq 0x40(%r14), %rax
movq 0x48(%r14), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
imulq %rbx, %rsi
movl %ecx, %edx
cmpq %rcx, %rsi
ja 0xf1b9
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
cmpq $0x38, %rcx
je 0xf374
leaq 0x58(%r14), %rcx
movq %rcx, -0x48(%rbp)
xorl %r13d, %r13d
imulq $0x38, %r13, %rdx
movzwl (%rax,%rdx), %ecx
movq %rdx, -0x50(%rbp)
movzbl 0x2(%rax,%rdx), %eax
leaq (%rcx,%rcx,2), %r12
shlq $0x3, %r12
movq -0x88(%rbp), %rcx
addq %r12, %rcx
leaq (%rax,%rax,2), %r14
movq (%rcx,%r14,8), %rax
cmpq %rax, 0x8(%rcx,%r14,8)
je 0xf344
movl $0x1, %ebx
xorl %ecx, %ecx
movl (%rax,%rcx,4), %r15d
movl $0x10, %edi
callq 0x4390
movw %r13w, (%rax)
movw %r15w, 0x2(%rax)
movq $0x0, 0x8(%rax)
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rcx
movq 0x60(%rcx), %rsi
cmpq 0x68(%rcx), %rsi
je 0xf2a8
movq %rax, (%rsi)
addq $0x8, 0x60(%rcx)
jmp 0xf2b5
movq -0x48(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x1125c
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x50(%rbp), %rcx
leaq (%rax,%rcx), %rdi
addq $0x20, %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf2e0
movq -0x30(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xf2e9
leaq -0x30(%rbp), %rdx
callq 0x1125c
movq -0x38(%rbp), %rax
movq (%rax), %rax
imulq $0x38, %r15, %rcx
leaq (%rax,%rcx), %rdi
addq $0x8, %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xf314
movq -0x30(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0xf31d
leaq -0x30(%rbp), %rdx
callq 0x1125c
movl %ebx, %ecx
movq -0x88(%rbp), %rdx
addq %r12, %rdx
movq (%rdx,%r14,8), %rax
movq 0x8(%rdx,%r14,8), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %ebx
cmpq %rcx, %rdx
ja 0xf26d
incl %r13d
movq -0x40(%rbp), %rcx
movq 0x40(%rcx), %rax
movq 0x48(%rcx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $0x6db6db6db6db6db7, %rdx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rdx, %rcx
decq %rcx
cmpq %r13, %rcx
ja 0xf230
leaq -0x88(%rbp), %rdi
callq 0x10068
leaq -0xc0(%rbp), %rdi
callq 0x10506
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf3b7
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0xff90
jmp 0xf3cb
jmp 0xf3b7
jmp 0xf3bc
jmp 0xf3b7
movq %rax, %rbx
jmp 0xf3cb
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x10068
leaq -0xc0(%rbp), %rdi
callq 0x10506
movq %rbx, %rdi
callq 0x4650
nop