// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl (%rsi), %r8d
testq %r8, %r8
je 0x33a1
movq %rdi, %r14
movq %rsi, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
xorl %r12d, %r12d
movq %r12, 0x30(%rsp)
movq (%rdi), %rax
movq 0x8(%rdi), %rdi
movq %rdi, %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r15, %rcx
cmpq %r8, %rcx
cmovbeq %r12, %r8
movq %rcx, %rdx
subq %r8, %rdx
cmpq %rax, %rdi
je 0x3029
addq $0x8, %rax
movl $0x1, %esi
cmpb $0x0, (%rax)
jne 0x3019
addl -0x4(%rax), %r12d
movl %esi, %edi
addq $0xc, %rax
incl %esi
cmpq %rdi, %rcx
ja 0x3010
movl %r12d, %r12d
movl %edx, %ebp
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0xc38e
movl $0x18, %edi
callq 0x21e0
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, %rdi
movq %r12, %rsi
callq 0xc44a
movq %rbx, 0x38(%rsp)
movl $0x38, %edi
callq 0x21e0
movq %rax, %r13
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x10(%rax)
movq $0x0, 0x30(%rax)
addq $0x30, %rax
movq %rax, (%r13)
movq $0x1, 0x8(%r13)
movl $0x3f800000, 0x20(%r13) # imm = 0x3F800000
movups %xmm0, 0x28(%r13)
movl $0x18, %edi
callq 0x21e0
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, %rdi
movq %rbp, %rsi
callq 0xc44a
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
movq %rbx, %rbp
je 0x330a
sarq $0x2, %rcx
imulq %r15, %rcx
leaq 0x20(%r14), %rdx
movq %rdx, 0x48(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x10(%rsp)
movq %r13, 0x58(%rsp)
movq %rbp, 0x50(%rsp)
leaq (%r12,%r12,2), %rbx
cmpb $0x0, 0x8(%rax,%rbx,4)
jne 0x32d9
cmpb $0x1, 0x3c(%r14)
movl %r12d, %edi
jne 0x3126
movq 0x48(%r14), %rdx
movq (%rdx), %rdx
movl (%rdx,%r12,4), %edi
leaq (%rax,%rbx,4), %rdx
movl %edi, 0xc(%rsp)
cmpl $0x0, 0x4(%rdx)
je 0x3152
decq %rcx
cmpq %r12, %rcx
movq %r12, 0x60(%rsp)
jne 0x316f
movq 0x18(%r14), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
shrq $0x2, %rax
jmp 0x317b
movq 0x28(%r14), %rsi
cmpq 0x30(%r14), %rsi
je 0x32f9
movl %edi, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%r14)
jmp 0x32d9
leal 0x1(%r12), %ecx
leaq (%rcx,%rcx,2), %rcx
movl (%rax,%rcx,4), %eax
movl (%rdx), %r13d
xorl %r12d, %r12d
cmpl %eax, %r13d
jae 0x321a
movl %eax, %r15d
leaq (,%r13,4), %rbp
incq %r13
xorl %r12d, %r12d
cmpb $0x0, 0x3c(%r14)
je 0x31b7
movq 0x18(%r14), %rax
movq 0x40(%r14), %rdi
movq (%rax), %rsi
addq %rbp, %rsi
callq 0xda16
jmp 0x31c1
movq 0x18(%r14), %rax
movq (%rax), %rax
addq %rbp, %rax
movl (%rax), %eax
movq (%r14), %rcx
leaq (%rax,%rax,2), %rax
cmpb $0x0, 0x8(%rcx,%rax,4)
jne 0x3200
movq 0x18(%r14), %rax
movq (%rax), %rdx
addq %rbp, %rdx
movq 0x38(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x31f8
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x31fd
callq 0xdeac
incl %r12d
movq (%r14), %rax
cmpl 0x4(%rax,%rbx,4), %r12d
je 0x321a
addq $0x4, %rbp
leaq 0x1(%r13), %rax
cmpq %r15, %r13
movq %rax, %r13
jb 0x319b
testl %r12d, %r12d
je 0x33b0
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
shrq $0x2, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
movl 0xc(%rsp), %ecx
movl %ecx, 0x14(%rsp)
movl %eax, 0x18(%rsp)
movq 0x58(%rsp), %r13
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
callq 0xdfc4
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
movq 0x50(%rsp), %rbp
movq 0x8(%rbp), %rsi
cmpq 0x10(%rbp), %rsi
je 0x327e
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbp)
jmp 0x328b
movq %rbp, %rdi
leaq 0xc(%rsp), %rdx
callq 0xdeac
movl 0x10(%rsp), %eax
movl %eax, 0x14(%rsp)
movl %r12d, 0x18(%rsp)
movb $0x0, 0x1c(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x32c0
movl 0x1c(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0x14(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x28(%rsp)
jmp 0x32cf
leaq 0x20(%rsp), %rdi
leaq 0x14(%rsp), %rdx
callq 0xe250
addl %r12d, 0x10(%rsp)
movq 0x60(%rsp), %r12
incl %r12d
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
imulq %r15, %rcx
cmpq %r12, %rcx
ja 0x3102
jmp 0x330a
movq 0x48(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0xdeac
jmp 0x32d9
movq %rbp, %rbx
movb $0x1, 0x3c(%r14)
movq 0x40(%r14), %rbp
testq %rbp, %rbp
je 0x332b
movq %rbp, %rdi
callq 0xcebc
movq %rbp, %rdi
callq 0x21a0
movq 0x48(%r14), %rbp
testq %rbp, %rbp
je 0x334a
movq (%rbp), %rdi
testq %rdi, %rdi
je 0x3342
callq 0x21a0
movq %rbp, %rdi
callq 0x21a0
movq %r13, 0x40(%r14)
movq %rbx, 0x48(%r14)
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0xbde6
movq 0x18(%r14), %r12
testq %r12, %r12
movq 0x38(%rsp), %rbx
je 0x3383
movq (%r12), %rdi
testq %rdi, %rdi
je 0x337b
callq 0x21a0
movq %r12, %rdi
callq 0x21a0
movq %rbx, 0x18(%r14)
movq 0x40(%rsp), %rax
movl $0x0, (%rax)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x33a1
callq 0x21a0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16c81(%rip), %rdi     # 0x1a038
leaq 0x16c84(%rip), %rsi     # 0x1a042
leaq 0x16c8b(%rip), %rcx     # 0x1a050
movl $0xc3, %edx
callq 0x2110
jmp 0x33e1
jmp 0x33e1
jmp 0x33e1
jmp 0x33e1
jmp 0x33e1
jmp 0x33e1
jmp 0x33e1
jmp 0x33e1
jmp 0x33e1
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x33f3
callq 0x21a0
movq %rbx, %rdi
callq 0x2320
nop