// File: /workspace/github_cpp_makefile_star2_O1/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 0x341e
movq %rax, 0x28(%rbx)
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0x37bf
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
callq 0xc38e
movl $0x18, %edi
callq 0x21e0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rax)
movl $0x38, %edi
callq 0x21e0
movq %rax, %r12
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x10(%rax)
movq $0x0, 0x30(%rax)
addq $0x30, %rax
movq %rax, (%r12)
movq $0x1, 0x8(%r12)
movl $0x3f800000, 0x20(%r12) # imm = 0x3F800000
movups %xmm0, 0x28(%r12)
movl $0x18, %edi
callq 0x21e0
movq %rax, %rbp
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq 0x18(%r14), %rsi
movq %rax, %rdi
callq 0xc44a
movq 0x10(%r14), %r15
testq %r15, %r15
je 0x3732
leaq 0x20(%rbx), %rax
movq %rax, 0x58(%rsp)
movq $0x0, 0x10(%rsp)
movq %r14, 0x60(%rsp)
movq %r12, 0x48(%rsp)
movq %rbp, 0x40(%rsp)
movl 0x8(%r15), %eax
movl %eax, (%rsp)
cmpb $0x1, 0x3c(%rbx)
movq %rsp, %rax
jne 0x3514
movq 0x40(%rbx), %rdi
movq %rsp, %rsi
callq 0xda16
movl (%rax), %eax
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
decq %rdx
cmpq %rax, %rdx
movq %r15, 0x50(%rsp)
jne 0x3550
movq 0x18(%rbx), %rsi
movq 0x8(%rsi), %rdx
subq (%rsi), %rdx
shrq $0x2, %rdx
jmp 0x355a
leal 0x1(%rax), %edx
leaq (%rdx,%rdx,2), %rdx
movl (%rcx,%rdx,4), %edx
leaq (%rax,%rax,2), %rbp
movl (%rcx,%rbp,4), %r12d
xorl %r13d, %r13d
cmpl %edx, %r12d
jae 0x3637
movl %edx, %r15d
leaq (,%r12,4), %r14
incq %r12
xorl %r13d, %r13d
cmpb $0x0, 0x3c(%rbx)
je 0x359a
movq 0x18(%rbx), %rax
movq 0x40(%rbx), %rdi
movq (%rax), %rsi
addq %r14, %rsi
callq 0xda16
jmp 0x35a4
movq 0x18(%rbx), %rax
movq (%rax), %rax
addq %r14, %rax
movl (%rax), %eax
movq (%rbx), %rcx
leaq (%rax,%rax,2), %rax
cmpb $0x1, 0x8(%rcx,%rax,4)
jne 0x35e9
movq 0x18(%rbx), %rax
movq (%rax), %rcx
movl (%rcx,%r14), %r8d
addq %r14, %rcx
movq %r8, %rax
xorl %edx, %edx
movq 0x60(%rsp), %rdi
divq 0x8(%rdi)
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
callq 0xdaee
testq %rax, %rax
je 0x3618
cmpq $0x0, (%rax)
je 0x3618
movq 0x18(%rbx), %rax
movq (%rax), %rdx
addq %r14, %rdx
movq 0x18(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x3610
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x3615
callq 0xdeac
incl %r13d
movq (%rbx), %rax
cmpl 0x4(%rax,%rbp,4), %r13d
je 0x3637
addq $0x4, %r14
leaq 0x1(%r12), %rax
cmpq %r15, %r12
movq %rax, %r12
jb 0x357f
testl %r13d, %r13d
je 0x3690
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
shrq $0x2, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
movl (%rsp), %ecx
movl %ecx, 0x4(%rsp)
movl %eax, 0x8(%rsp)
movq 0x48(%rsp), %r12
movq %r12, %rdi
leaq 0x4(%rsp), %rsi
callq 0xdfc4
movq 0x40(%rsp), %rbp
movq 0x50(%rsp), %r15
movq 0x8(%rbp), %rsi
cmpq 0x10(%rbp), %rsi
je 0x36b8
movl (%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbp)
jmp 0x36c3
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
movq 0x48(%rsp), %r12
movq 0x40(%rsp), %rbp
movq 0x50(%rsp), %r15
je 0x3723
movl (%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rbx)
jmp 0x3715
movq %rbp, %rdi
movq %rsp, %rdx
callq 0xdeac
movq 0x10(%rsp), %rax
movl %eax, 0x4(%rsp)
movl %r13d, 0x8(%rsp)
movb $0x0, 0xc(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x36f9
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0x4(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x28(%rsp)
jmp 0x3708
leaq 0x20(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0xe250
movq 0x10(%rsp), %rax
addl %r13d, %eax
movq %rax, 0x10(%rsp)
movq (%r15), %r15
testq %r15, %r15
jne 0x34f8
jmp 0x3732
movq 0x58(%rsp), %rdi
movq %rsp, %rdx
callq 0xdeac
jmp 0x3715
movb $0x1, 0x3c(%rbx)
movq 0x40(%rbx), %r15
testq %r15, %r15
je 0x374f
movq %r15, %rdi
callq 0xcebc
movq %r15, %rdi
callq 0x21a0
movq 0x48(%rbx), %r15
testq %r15, %r15
je 0x376d
movq (%r15), %rdi
testq %rdi, %rdi
je 0x3765
callq 0x21a0
movq %r15, %rdi
callq 0x21a0
movq %r12, 0x40(%rbx)
movq %rbp, 0x48(%rbx)
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xbde6
movq 0x18(%rbx), %r15
testq %r15, %r15
movq 0x18(%rsp), %rax
je 0x37aa
movq (%r15), %rdi
testq %rdi, %rdi
je 0x379d
callq 0x21a0
movq %r15, %rdi
callq 0x21a0
movq 0x18(%rsp), %rax
movq %rax, 0x18(%rbx)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x37fd
callq 0x21a0
jmp 0x37fd
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x37cc
movq %rax, 0x8(%rbx)
movq 0x18(%rbx), %rax
movq (%rax), %rcx
cmpq %rcx, 0x8(%rax)
je 0x37dd
movq %rcx, 0x8(%rax)
cmpb $0x1, 0x3c(%rbx)
jne 0x37fd
movq 0x40(%rbx), %rdi
callq 0xce5c
movq 0x48(%rbx), %rax
movq (%rax), %rcx
cmpq %rcx, 0x8(%rax)
je 0x37fd
movq %rcx, 0x8(%rax)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3820
jmp 0x3820
jmp 0x3820
jmp 0x3820
jmp 0x3820
jmp 0x3820
jmp 0x3820
jmp 0x3820
jmp 0x3820
jmp 0x3820
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3832
callq 0x21a0
movq %rbx, %rdi
callq 0x2320