// File: iPapatsoris[P]Maximum-Independent-Set/src/Graph.cpp
// Function: Graph::rebuild(ReduceInfo&)
void Graph::rebuild(ReduceInfo &reduceInfo) {
    if (!reduceInfo.nodesRemoved) {
        return;
    }
    vector<NodeInfo> nodeIndex;
    uint32_t newNodes = (this->nodeIndex.size() > reduceInfo.nodesRemoved ? this->nodeIndex.size() - reduceInfo.nodesRemoved : this->nodeIndex.size());
    uint32_t newEdges = this->getTotalEdges();
    nodeIndex.reserve(newNodes);
    vector<uint32_t> *edgeBuffer = new vector<uint32_t>();
    edgeBuffer->reserve(newEdges);
    unordered_map<uint32_t, uint32_t> *idToPos = new unordered_map<uint32_t, uint32_t>();
    vector<uint32_t> *posToId = new vector<uint32_t>();
    posToId->reserve(newNodes);
    uint32_t offset = 0;

    for (uint32_t pos = 0 ; pos < this->nodeIndex.size() ; pos++) {
        if (this->nodeIndex[pos].removed) {
            continue;
        }
        uint32_t node = (!mapping ? pos : (*this->posToId)[pos]);
        if (!this->nodeIndex[pos].edges) {
            //cout << "Found node " << node << " with no edges at rebuilding\n";
            zeroDegreeNodes.push_back(node);
            continue;
        }
        uint32_t edges = 0;
        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 */
        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) {
                edgeBuffer->push_back((*this->edgeBuffer)[i]);
                edges++;
            }
            if (edges == this->nodeIndex[pos].edges) {
                break;
            }
        }
        assert(edges > 0);
        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;
    reduceInfo.nodesRemoved = 0;
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x140(%rsp)
movq %rsi, 0x138(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x138(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x3409
jmp 0x3a8b
leaq 0x120(%rsp), %rdi
callq 0x17e50
movq 0x98(%rsp), %rdi
callq 0x18830
movq 0x138(%rsp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jbe 0x3456
movq 0x98(%rsp), %rdi
callq 0x18830
movq 0x138(%rsp), %rcx
movl (%rcx), %ecx
subq %rcx, %rax
movq %rax, 0x90(%rsp)
jmp 0x346b
movq 0x98(%rsp), %rdi
callq 0x18830
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rax
movl %eax, 0x11c(%rsp)
callq 0x2cb0
movl %eax, 0x118(%rsp)
movl 0x11c(%rsp), %eax
movl %eax, %esi
leaq 0x120(%rsp), %rdi
callq 0x18e20
jmp 0x34a6
movl $0x18, %edi
callq 0x21b0
movq %rax, 0x88(%rsp)
jmp 0x34ba
movq 0x88(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x17e60
movq 0x88(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rdi
movl 0x118(%rsp), %eax
movl %eax, %esi
callq 0x18f30
jmp 0x34fd
movl $0x38, %edi
callq 0x21b0
movq %rax, 0x80(%rsp)
jmp 0x3511
movq 0x80(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
movq $0x0, 0x30(%rdi)
callq 0x19040
movq 0x80(%rsp), %rax
movq %rax, 0xf8(%rsp)
movl $0x18, %edi
callq 0x21b0
movq %rax, 0x78(%rsp)
jmp 0x3555
movq 0x78(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0x17e60
movq 0x78(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rdi
movl 0x11c(%rsp), %eax
movl %eax, %esi
callq 0x18f30
jmp 0x3592
movl $0x0, 0xec(%rsp)
movl $0x0, 0xe8(%rsp)
movq 0x98(%rsp), %rdi
movl 0xe8(%rsp), %eax
movq %rax, 0x70(%rsp)
callq 0x18830
movq %rax, %rcx
movq 0x70(%rsp), %rax
cmpq %rcx, %rax
jae 0x3989
movq 0x98(%rsp), %rdi
movl 0xe8(%rsp), %eax
movl %eax, %esi
callq 0x19050
testb $0x1, 0x8(%rax)
je 0x3619
jmp 0x3973
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x110(%rsp)
movl %eax, 0x10c(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x18580
jmp 0x3a93
movq 0x98(%rsp), %rax
testb $0x1, 0x3c(%rax)
jne 0x3634
movl 0xe8(%rsp), %eax
movl %eax, 0x6c(%rsp)
jmp 0x3654
movq 0x98(%rsp), %rax
movq 0x48(%rax), %rdi
movl 0xe8(%rsp), %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x6c(%rsp)
movq 0x98(%rsp), %rdi
movl 0x6c(%rsp), %eax
movl %eax, 0xe4(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, %esi
callq 0x19050
cmpl $0x0, 0x4(%rax)
jne 0x369b
movq 0x98(%rsp), %rdi
addq $0x20, %rdi
leaq 0xe4(%rsp), %rsi
callq 0x19070
jmp 0x3696
jmp 0x3973
movq 0x98(%rsp), %rdi
movl $0x0, 0xe0(%rsp)
movl 0xe8(%rsp), %eax
movq %rax, 0x60(%rsp)
callq 0x18830
movq %rax, %rcx
movq 0x60(%rsp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x36e8
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x188e0
movq %rax, 0x58(%rsp)
jmp 0x370a
movq 0x98(%rsp), %rdi
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x19050
movl (%rax), %eax
movq %rax, 0x58(%rsp)
movq 0x98(%rsp), %rdi
movq 0x58(%rsp), %rax
movl %eax, 0xdc(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, %esi
callq 0x19050
movl (%rax), %eax
movl %eax, 0xd8(%rsp)
movl 0xd8(%rsp), %eax
cmpl 0xdc(%rsp), %eax
jae 0x3870
movq 0x98(%rsp), %rax
testb $0x1, 0x3c(%rax)
jne 0x3779
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0xd8(%rsp), %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x54(%rsp)
jmp 0x37bb
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x40(%rax), %rax
movq %rax, 0x40(%rsp)
movl 0xd8(%rsp), %eax
movl %eax, %esi
callq 0x18900
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x188b0
movq %rax, 0x48(%rsp)
jmp 0x37b0
movq 0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x54(%rsp)
movq 0x98(%rsp), %rdi
movl 0x54(%rsp), %eax
movl %eax, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
movl %eax, %esi
callq 0x19050
testb $0x1, 0x8(%rax)
jne 0x3829
movq 0x98(%rsp), %rax
movq 0x100(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movq 0x18(%rax), %rdi
movl 0xd8(%rsp), %eax
movl %eax, %esi
callq 0x18900
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x19070
jmp 0x3818
movl 0xe0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe0(%rsp)
movq 0x98(%rsp), %rdi
movl 0xe0(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, %esi
callq 0x19050
movq %rax, %rcx
movl 0x34(%rsp), %eax
cmpl 0x4(%rcx), %eax
jne 0x3858
jmp 0x3870
jmp 0x385a
movl 0xd8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd8(%rsp)
jmp 0x3735
cmpl $0x0, 0xe0(%rsp)
jbe 0x387c
jmp 0x389b
leaq 0x427ad(%rip), %rdi     # 0x46030
leaq 0x427b0(%rip), %rsi     # 0x4603a
movl $0xc3, %edx
leaq 0x427b2(%rip), %rcx     # 0x46048
callq 0x2110
movq 0xf8(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x18830
movq %rax, 0xc0(%rsp)
leaq 0xcc(%rsp), %rdi
leaq 0xe4(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x19130
jmp 0x38dc
movq 0x28(%rsp), %rdi
leaq 0xcc(%rsp), %rsi
callq 0x190e0
movb %dl, 0x1f(%rsp)
movq %rax, 0x20(%rsp)
jmp 0x38f9
movb 0x1f(%rsp), %al
movq 0x20(%rsp), %rcx
movq %rcx, 0xb0(%rsp)
movb %al, 0xb8(%rsp)
movq 0xf0(%rsp), %rdi
leaq 0xe4(%rsp), %rsi
callq 0x19070
jmp 0x3928
leaq 0xa4(%rsp), %rdi
leaq 0xec(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x19190
jmp 0x3947
leaq 0x120(%rsp), %rdi
leaq 0xa4(%rsp), %rsi
callq 0x19160
jmp 0x395e
movl 0xe0(%rsp), %eax
addl 0xec(%rsp), %eax
movl %eax, 0xec(%rsp)
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe8(%rsp)
jmp 0x35a8
movq 0x98(%rsp), %rax
movb $0x1, 0x3c(%rax)
cmpq $0x0, 0x40(%rax)
je 0x39c9
movq 0x98(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x39c7
movq 0x10(%rsp), %rdi
callq 0x185e0
movq 0x10(%rsp), %rdi
callq 0x2180
jmp 0x39c9
movq 0x98(%rsp), %rax
cmpq $0x0, 0x48(%rax)
je 0x3a05
movq 0x98(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x3a03
movq 0x8(%rsp), %rdi
callq 0x18520
movq 0x8(%rsp), %rdi
callq 0x2180
jmp 0x3a05
movq 0x98(%rsp), %rdi
movq 0xf8(%rsp), %rax
movq %rax, 0x40(%rdi)
movq 0xf0(%rsp), %rax
movq %rax, 0x48(%rdi)
leaq 0x120(%rsp), %rsi
callq 0x17e70
jmp 0x3a34
movq 0x98(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x3a5c
movq (%rsp), %rdi
callq 0x18520
movq (%rsp), %rdi
callq 0x2180
movq 0x98(%rsp), %rax
movq 0x100(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq 0x138(%rsp), %rax
movl $0x0, (%rax)
leaq 0x120(%rsp), %rdi
callq 0x18580
addq $0x148, %rsp            # imm = 0x148
retq
movq 0x110(%rsp), %rdi
callq 0x2310