// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x20(%rdi), %rax
cmpq %rax, 0x28(%rdi)
je 0x2f8c
movq %rax, 0x28(%rbx)
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0x324a
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
callq 0xa06c
pushq $0x18
popq %rdi
callq 0x2190
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rax, 0x18(%rsp)
andq $0x0, 0x10(%rax)
pushq $0x38
popq %rdi
callq 0x2190
movq %rax, %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rax)
addq $0x30, %rax
movq %rax, (%r12)
movq $0x1, 0x8(%r12)
movups %xmm0, 0x10(%r12)
movl $0x3f800000, 0x20(%r12) # imm = 0x3F800000
movups %xmm0, 0x28(%r12)
pushq $0x18
popq %rdi
callq 0x2190
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0x18(%r14), %rsi
movq %rax, %rdi
callq 0xa11c
movq %r15, 0x20(%rsp)
leaq 0x20(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0x10(%r14), %r15
xorl %r13d, %r13d
movq %r14, 0x60(%rsp)
movq %r12, 0x28(%rsp)
movq (%r15), %r15
testq %r15, %r15
je 0x31cc
movl 0x8(%r15), %eax
movl %eax, 0x4(%rsp)
cmpb $0x1, 0x3c(%rbx)
jne 0x3069
movq 0x40(%rbx), %rdi
leaq 0x4(%rsp), %rsi
callq 0xb880
movl (%rax), %eax
movl %eax, %esi
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
subq %rcx, %rax
cqto
pushq $0xc
popq %rdi
idivq %rdi
decq %rax
cmpq %rsi, %rax
movq %r15, 0x58(%rsp)
movl %r13d, 0x8(%rsp)
jne 0x30a0
movq 0x18(%rbx), %rdx
movq 0x8(%rdx), %rax
subq (%rdx), %rax
shrq $0x2, %rax
jmp 0x30aa
leal 0x1(%rsi), %eax
imulq $0xc, %rax, %rax
movl (%rcx,%rax), %eax
imulq $0xc, %rsi, %r12
movl (%rcx,%r12), %r15d
movl %eax, %r13d
leaq (,%r15,4), %r14
decq %r15
xorl %ebp, %ebp
incq %r15
cmpq %r13, %r15
jae 0x313c
cmpb $0x0, 0x3c(%rbx)
je 0x30ec
movq 0x18(%rbx), %rax
movq 0x40(%rbx), %rdi
movq (%rax), %rsi
addq %r14, %rsi
callq 0xb880
movq (%rbx), %rcx
movq 0x18(%rbx), %rdx
jmp 0x30f6
movq 0x18(%rbx), %rdx
movq (%rdx), %rax
addq %r14, %rax
movl (%rax), %eax
imulq $0xc, %rax, %rax
cmpb $0x1, 0x8(%rcx,%rax)
jne 0x311c
movq (%rdx), %rsi
addq %r14, %rsi
movq 0x60(%rsp), %rdi
callq 0xc35a
testq %rax, %rax
je 0x312e
movq 0x18(%rbx), %rdx
movq 0x18(%rsp), %rdi
movq (%rdx), %rsi
addq %r14, %rsi
callq 0xa1ac
incl %ebp
addq $0x4, %r14
movq (%rbx), %rcx
cmpl 0x4(%rcx,%r12), %ebp
jne 0x30c2
testl %ebp, %ebp
movq 0x58(%rsp), %r15
je 0x31ae
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
cqto
pushq $0xc
popq %rcx
idivq %rcx
movl 0x4(%rsp), %ecx
movl %ecx, 0xc(%rsp)
movl %eax, 0x10(%rsp)
movq 0x28(%rsp), %r12
movq %r12, %rdi
leaq 0xc(%rsp), %rsi
callq 0xbfd8
movl 0x8(%rsp), %r13d
movq 0x20(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0xa1ac
movl %r13d, 0xc(%rsp)
movl %ebp, 0x10(%rsp)
movb $0x0, 0x14(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0xc224
addl %ebp, %r13d
jmp 0x303f
movq 0x50(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0xa1ac
movq 0x28(%rsp), %r12
movl 0x8(%rsp), %r13d
jmp 0x303f
movb $0x1, 0x3c(%rbx)
movq 0x40(%rbx), %r15
testq %r15, %r15
movq 0x20(%rsp), %r14
je 0x31ee
movq %r15, %rdi
callq 0xac1a
movq %r15, %rdi
callq 0x2160
movq 0x48(%rbx), %r15
testq %r15, %r15
je 0x3207
movq %r15, %rdi
callq 0xb872
movq %r15, %rdi
callq 0x2160
movq %r12, 0x40(%rbx)
movq %r14, 0x48(%rbx)
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x9b18
movq 0x18(%rbx), %r15
testq %r15, %r15
je 0x322d
movq %r15, %rdi
callq 0xb872
movq %r15, %rdi
callq 0x2160
movq 0x18(%rsp), %rax
movq %rax, 0x18(%rbx)
leaq 0x30(%rsp), %rdi
callq 0xb864
jmp 0x3288
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x3257
movq %rax, 0x8(%rbx)
movq 0x18(%rbx), %rax
movq (%rax), %rcx
cmpq %rcx, 0x8(%rax)
je 0x3268
movq %rcx, 0x8(%rax)
cmpb $0x1, 0x3c(%rbx)
jne 0x3288
movq 0x40(%rbx), %rdi
callq 0xaae8
movq 0x48(%rbx), %rax
movq (%rax), %rcx
cmpq %rcx, 0x8(%rax)
je 0x3288
movq %rcx, 0x8(%rax)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x32ab
jmp 0x32ab
jmp 0x32ab
jmp 0x32ab
jmp 0x32ab
jmp 0x32ab
jmp 0x32ab
jmp 0x32ab
jmp 0x32ab
jmp 0x32ab
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xb864
movq %rbx, %rdi
callq 0x22c0