// File: iPapatsoris[P]Maximum-Independent-Set/src/Graph.cpp
// Function: Graph::rebuildFromNodes(std::unordered_set<unsigned int, std::hash<unsigned int>, std::equal_to<unsigned int>, std::allocator<unsigned int>>&)
void Graph::rebuildFromNodes(unordered_set<uint32_t> &nodes) {
    zeroDegreeNodes.clear();
    if (!nodes.size()) {
        nodeIndex.clear();
        edgeBuffer->clear();
        if (mapping) {
            idToPos->clear();
            posToId->clear();
        }
        return;
    }
    vector<NodeInfo> nodeIndex;
    nodeIndex.reserve(nodes.size());
    vector<uint32_t> *edgeBuffer = new vector<uint32_t>();
    unordered_map<uint32_t, uint32_t> *idToPos = new unordered_map<uint32_t, uint32_t>();
    vector<uint32_t> *posToId = new vector<uint32_t>();
    posToId->reserve(nodes.size());
    uint32_t offset = 0;

    for (auto node: nodes) {
        uint32_t edges = 0;
        uint32_t pos = (!mapping ? node : this->idToPos->at(node));
        uint32_t nextNodeOffset = (pos == this->nodeIndex.size()-1 ? this->edgeBuffer->size() : this->nodeIndex[pos+1].offset);
        /* Don't add neighbors that are marked as removed or are outside of nodes struct */
        for (uint32_t i = this->nodeIndex[pos].offset ; i < nextNodeOffset ; i++) {
            uint32_t nPos = (!this->mapping ? (*this->edgeBuffer)[i] : this->idToPos->at((*this->edgeBuffer)[i]));
            if (!this->nodeIndex[nPos].removed || nodes.find((*this->edgeBuffer)[i]) != nodes.end()) {
                edgeBuffer->push_back((*this->edgeBuffer)[i]);
                edges++;
            }
            if (edges == this->nodeIndex[pos].edges) {
                break;
            }
        }
        if (!edges) {
            zeroDegreeNodes.push_back(node);
        } else {
            idToPos->insert({node, nodeIndex.size()});
            posToId->push_back(node);
            nodeIndex.push_back(Graph::NodeInfo(offset, edges));
            offset += edges;
        }
    }
    this->mapping = true;
    if (this->idToPos != NULL) {
        delete this->idToPos;
    }
    if (this->posToId != NULL) {
        delete this->posToId;
    }
    this->idToPos = idToPos;
    this->posToId = posToId;
    this->nodeIndex = nodeIndex;
    delete this->edgeBuffer;
    this->edgeBuffer = edgeBuffer;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x180(%rsp)
movq %rsi, 0x178(%rsp)
movq 0x180(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
addq $0x20, %rdi
callq 0x191c0
movq 0x178(%rsp), %rdi
callq 0x191e0
cmpq $0x0, %rax
jne 0x3b36
movq 0xb8(%rsp), %rdi
callq 0x191f0
movq 0xb8(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x191c0
movq 0xb8(%rsp), %rax
testb $0x1, 0x3c(%rax)
je 0x3b31
movq 0xb8(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0x19210
movq 0xb8(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0x191c0
jmp 0x41ca
leaq 0x160(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x17e50
movq 0x178(%rsp), %rdi
callq 0x191e0
movq 0xb0(%rsp), %rdi
movq %rax, %rsi
callq 0x18e20
jmp 0x3b6a
movl $0x18, %edi
callq 0x21b0
movq %rax, 0xa8(%rsp)
jmp 0x3b7e
movq 0xa8(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x17e60
movq 0xa8(%rsp), %rax
movq %rax, 0x148(%rsp)
movl $0x38, %edi
callq 0x21b0
movq %rax, 0xa0(%rsp)
jmp 0x3bbd
movq 0xa0(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
movq $0x0, 0x30(%rdi)
callq 0x19040
movq 0xa0(%rsp), %rax
movq %rax, 0x140(%rsp)
movl $0x18, %edi
callq 0x21b0
movq %rax, 0x98(%rsp)
jmp 0x3c04
movq 0x98(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x17e60
movq 0x98(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x138(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x178(%rsp), %rdi
callq 0x191e0
movq 0x90(%rsp), %rdi
movq %rax, %rsi
callq 0x18f30
jmp 0x3c5e
movl $0x0, 0x134(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x128(%rsp), %rdi
callq 0x19220
movq %rax, 0x120(%rsp)
movq 0x128(%rsp), %rdi
callq 0x19250
movq %rax, 0x118(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x19280
testb $0x1, %al
jne 0x3cc1
jmp 0x40d6
leaq 0x120(%rsp), %rdi
callq 0x192a0
movq %rax, %rcx
movq 0xb8(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x114(%rsp)
movl $0x0, 0x110(%rsp)
testb $0x1, 0x3c(%rax)
jne 0x3d03
movl 0x114(%rsp), %eax
movl %eax, 0x8c(%rsp)
jmp 0x3d37
movq 0xb8(%rsp), %rax
movq 0x40(%rax), %rdi
leaq 0x114(%rsp), %rsi
callq 0x188b0
movq %rax, 0x80(%rsp)
jmp 0x3d26
movq 0x80(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x8c(%rsp)
movq 0xb8(%rsp), %rdi
movl 0x8c(%rsp), %eax
movl %eax, 0x10c(%rsp)
movl 0x10c(%rsp), %eax
movq %rax, 0x78(%rsp)
callq 0x18830
movq %rax, %rcx
movq 0x78(%rsp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x3d87
movq 0xb8(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x188e0
movq %rax, 0x70(%rsp)
jmp 0x3da9
movq 0xb8(%rsp), %rdi
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x19050
movl (%rax), %eax
movq %rax, 0x70(%rsp)
movq 0xb8(%rsp), %rdi
movq 0x70(%rsp), %rax
movl %eax, 0x108(%rsp)
movl 0x10c(%rsp), %eax
movl %eax, %esi
callq 0x19050
movl (%rax), %eax
movl %eax, 0x104(%rsp)
movl 0x104(%rsp), %eax
cmpl 0x108(%rsp), %eax
jae 0x3fc0
movq 0xb8(%rsp), %rax
testb $0x1, 0x3c(%rax)
jne 0x3e18
movq 0xb8(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x104(%rsp), %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x6c(%rsp)
jmp 0x3e5a
movq 0xb8(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x40(%rax), %rax
movq %rax, 0x58(%rsp)
movl 0x104(%rsp), %eax
movl %eax, %esi
callq 0x18900
movq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x188b0
movq %rax, 0x60(%rsp)
jmp 0x3e4f
movq 0x60(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x6c(%rsp)
movq 0xb8(%rsp), %rdi
movl 0x6c(%rsp), %eax
movl %eax, 0x100(%rsp)
movl 0x100(%rsp), %eax
movl %eax, %esi
callq 0x19050
movq %rax, %rcx
movb $0x1, %al
testb $0x1, 0x8(%rcx)
movb %al, 0x57(%rsp)
je 0x3f00
movq 0xb8(%rsp), %rax
movq 0x178(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq 0x18(%rax), %rdi
movl 0x104(%rsp), %eax
movl %eax, %esi
callq 0x18900
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x192c0
movq %rax, 0x48(%rsp)
jmp 0x3ec5
movq 0x48(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0x178(%rsp), %rdi
callq 0x19250
movq %rax, 0xf0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x19280
movb %al, 0x57(%rsp)
movb 0x57(%rsp), %al
testb $0x1, %al
jne 0x3f0a
jmp 0x3f79
movq 0xb8(%rsp), %rax
movq 0x148(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movq 0x18(%rax), %rdi
movl 0x104(%rsp), %eax
movl %eax, %esi
callq 0x18900
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x19070
jmp 0x3f40
movl 0x110(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x110(%rsp)
jmp 0x3f79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x18580
jmp 0x41d2
movq 0xb8(%rsp), %rdi
movl 0x110(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x10c(%rsp), %eax
movl %eax, %esi
callq 0x19050
movq %rax, %rcx
movl 0x34(%rsp), %eax
cmpl 0x4(%rcx), %eax
jne 0x3fa8
jmp 0x3fc0
jmp 0x3faa
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x3dd4
cmpl $0x0, 0x110(%rsp)
jne 0x3fea
movq 0xb8(%rsp), %rdi
addq $0x20, %rdi
leaq 0x114(%rsp), %rsi
callq 0x19070
jmp 0x3fe5
jmp 0x40c2
movq 0x140(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x18830
movq %rax, 0xe0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0x114(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x19130
jmp 0x402b
movq 0x28(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x190e0
movb %dl, 0x1f(%rsp)
movq %rax, 0x20(%rsp)
jmp 0x4048
movb 0x1f(%rsp), %al
movq 0x20(%rsp), %rcx
movq %rcx, 0xd0(%rsp)
movb %al, 0xd8(%rsp)
movq 0x138(%rsp), %rdi
leaq 0x114(%rsp), %rsi
callq 0x19070
jmp 0x4077
leaq 0xc4(%rsp), %rdi
leaq 0x134(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x19190
jmp 0x4096
leaq 0x160(%rsp), %rdi
leaq 0xc4(%rsp), %rsi
callq 0x19160
jmp 0x40ad
movl 0x110(%rsp), %eax
addl 0x134(%rsp), %eax
movl %eax, 0x134(%rsp)
jmp 0x40c4
leaq 0x120(%rsp), %rdi
callq 0x192f0
jmp 0x3ca3
movq 0xb8(%rsp), %rax
movb $0x1, 0x3c(%rax)
cmpq $0x0, 0x40(%rax)
je 0x4116
movq 0xb8(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x4114
movq 0x10(%rsp), %rdi
callq 0x185e0
movq 0x10(%rsp), %rdi
callq 0x2180
jmp 0x4116
movq 0xb8(%rsp), %rax
cmpq $0x0, 0x48(%rax)
je 0x4152
movq 0xb8(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x4150
movq 0x8(%rsp), %rdi
callq 0x18520
movq 0x8(%rsp), %rdi
callq 0x2180
jmp 0x4152
movq 0xb8(%rsp), %rdi
movq 0x140(%rsp), %rax
movq %rax, 0x40(%rdi)
movq 0x138(%rsp), %rax
movq %rax, 0x48(%rdi)
leaq 0x160(%rsp), %rsi
callq 0x17e70
jmp 0x4181
movq 0xb8(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x41a9
movq (%rsp), %rdi
callq 0x18520
movq (%rsp), %rdi
callq 0x2180
movq 0xb8(%rsp), %rax
movq 0x148(%rsp), %rcx
movq %rcx, 0x18(%rax)
leaq 0x160(%rsp), %rdi
callq 0x18580
addq $0x188, %rsp            # imm = 0x188
retq
movq 0x158(%rsp), %rdi
callq 0x2310
nop