// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x98(%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)
movl 0x8(%rdi), %eax
leaq -0x80(%rbp), %rsi
movl %eax, (%rsi)
leaq -0xc8(%rbp), %rdi
callq 0xf5fc
movq 0x8(%r14), %rax
subq (%r14), %rax
pushq $0x38
popq %rcx
cqto
idivq %rcx
leaq -0xc8(%rbp), %r15
leaq -0x80(%rbp), %r12
leaq -0x30(%rbp), %r13
movq %rbx, -0x40(%rbp)
decl %eax
movl %eax, -0x80(%rbp)
js 0xdc3b
movq %r15, %rdi
movq %r12, %rsi
callq 0xf992
movq %rax, %rcx
movl -0x80(%rbp), %eax
testq %rcx, %rcx
je 0xdbe8
cltq
movq (%r14), %rcx
imulq $0x38, %rax, %rax
leaq (%rcx,%rax), %rbx
addq $0x10, %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
je 0xdc32
movzwl 0x8(%rbx), %eax
movl %eax, -0x30(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0xf5fc
jmp 0xdc16
movl -0x80(%rbp), %eax
movq -0x40(%rbp), %rbx
jmp 0xdbe8
leaq 0x40(%rbx), %rax
movq %rax, -0x38(%rbp)
movq 0x40(%rbx), %r13
leaq -0xc8(%rbp), %r15
leaq -0x80(%rbp), %r12
leaq -0x30(%rbp), %r14
cmpq 0x48(%rbx), %r13
je 0xdcaa
movzwl (%r13), %eax
movl %eax, -0x80(%rbp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xf992
testq %rax, %rax
je 0xdc99
movzwl (%r13), %eax
movzbl 0x2(%r13), %ecx
addl %eax, %ecx
movl %ecx, -0x30(%rbp)
movq %r15, %rdi
movq %r14, %rsi
callq 0xf992
testq %rax, %rax
je 0xdc99
addq $0x38, %r13
jmp 0xdc56
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0xe73e
movq %rax, %r13
jmp 0xdc56
movzwl 0x8(%rbx), %eax
leaq -0x80(%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 0xeddc
leaq -0x80(%rbp), %rdi
callq 0xe6fe
movq 0x8(%rbx), %rsi
incq %rsi
leaq -0x80(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0xe748
pushq $0x1
popq %rax
leaq -0x30(%rbp), %r15
movl %eax, -0x30(%rbp)
movl %eax, %edi
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rcx
movq %rcx, %rax
subq %rsi, %rax
cqto
pushq $0x38
popq %r8
idivq %r8
cmpq %rdi, %rax
jbe 0xdd35
imulq $0x38, %rdi, %rax
movzwl (%rsi,%rax), %eax
imulq $0x18, %rax, %rdi
addq -0x80(%rbp), %rdi
movq %r15, %rsi
callq 0xe79a
movl -0x30(%rbp), %eax
incl %eax
jmp 0xdcf5
leaq 0x58(%rbx), %rax
movq %rax, -0x88(%rbp)
xorl %edi, %edi
leaq -0x30(%rbp), %r13
movl %edi, %edi
subq %rsi, %rcx
movq %rcx, %rax
cqto
pushq $0x38
popq %rcx
idivq %rcx
decq %rax
cmpq %rdi, %rax
jbe 0xde2c
movq %rdi, -0x48(%rbp)
imulq $0x38, %rdi, %rcx
movzwl (%rsi,%rcx), %eax
movq %rcx, -0x90(%rbp)
movzbl 0x2(%rsi,%rcx), %ecx
xorl %r15d, %r15d
imulq $0x18, %rax, %r14
imulq $0x18, %rcx, %rbx
movl %r15d, %r15d
movq -0x80(%rbp), %rcx
addq %r14, %rcx
movq (%rbx,%rcx), %rax
movq 0x8(%rbx,%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r15, %rcx
jbe 0xde15
movl (%rax,%r15,4), %r12d
pushq $0x10
popq %rdi
callq 0x4350
movq -0x48(%rbp), %rcx
movw %cx, (%rax)
movw %r12w, 0x2(%rax)
andq $0x0, 0x8(%rax)
movq %rax, -0x30(%rbp)
movq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0xe7c0
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x90(%rbp), %rcx
leaq (%rax,%rcx), %rdi
addq $0x20, %rdi
movq %r13, %rsi
callq 0xe7c0
movq -0x38(%rbp), %rax
movq (%rax), %rax
imulq $0x38, %r12, %rcx
leaq (%rax,%rcx), %rdi
addq $0x8, %rdi
movq %r13, %rsi
callq 0xe7c0
incl %r15d
jmp 0xdd85
movq -0x48(%rbp), %rdi
incl %edi
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rcx
jmp 0xdd46
leaq -0x80(%rbp), %rdi
callq 0xe7e4
leaq -0xc8(%rbp), %rdi
callq 0xec16
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xde6f
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0xe6fe
jmp 0xde80
jmp 0xde6f
jmp 0xde6f
jmp 0xde6f
jmp 0xde74
jmp 0xde6f
jmp 0xde6f
movq %rax, %rbx
jmp 0xde80
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0xe7e4
leaq -0xc8(%rbp), %rdi
callq 0xec16
movq %rbx, %rdi
callq 0x45f0