// File: iPapatsoris[P]Maximum-Independent-Set/src/Graph.cpp
// Function: Graph::contractToSingleNode(std::vector<unsigned int, std::allocator<unsigned int>> const&, std::vector<unsigned int, std::allocator<unsigned int>> const&, ReduceInfo&)
uint32_t Graph::contractToSingleNode(const vector<uint32_t> &nodes, const vector<uint32_t> &neighbors, ReduceInfo &reduceInfo) {
    uint32_t newNode = nextUnusedId;
    assert(++nextUnusedId != 0);
    assert(!mapping || mapping && idToPos->find(newNode) == idToPos->end());
    set<uint32_t> newNeighbors;
    for (auto it = neighbors.begin() ; it != neighbors.end() ; it++) {
        GraphTraversal graphTraversal(*this, *it);
        while (graphTraversal.curEdgeOffset != NONE) {
            uint32_t neighbor = (*edgeBuffer)[graphTraversal.curEdgeOffset];
            if (find(nodes.begin(), nodes.end(), neighbor) == nodes.end() && find(neighbors.begin(), neighbors.end(), neighbor) == neighbors.end()) {
                if (newNeighbors.insert(neighbor).second) {
                    replaceNeighbor(neighbor, *it, newNode);
                    uint32_t pos = (!mapping ? neighbor : idToPos->at(neighbor));
                    nodeIndex[pos].edges++;
                }
            }
            getNextEdge(graphTraversal);
        }
    }
    reduceInfo.nodesRemoved--;
    if (!newNeighbors.size()) {
        zeroDegreeNodes.push_back(newNode);
    } else {
        uint32_t offset = edgeBuffer->size();
        edgeBuffer->reserve(edgeBuffer->size() + newNeighbors.size());
        copy(newNeighbors.begin(), newNeighbors.end(), back_inserter(*edgeBuffer));
        nodeIndex.push_back(NodeInfo(offset, newNeighbors.size()));
        if (mapping) {
            idToPos->insert({newNode, nodeIndex.size() - 1});
            posToId->push_back(newNode);
        }
    }
    return newNode;
}

// Assembly:
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, 0x1e0(%rsp)
movq %rsi, 0x1d8(%rsp)
movq %rdx, 0x1d0(%rsp)
movq %rcx, 0x1c8(%rsp)
movq 0x1e0(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movl 0x38(%rcx), %eax
movl %eax, 0x1c4(%rsp)
movl 0x38(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x38(%rcx)
cmpl $0x0, %eax
je 0x4231
jmp 0x4250
leaq 0x41e32(%rip), %rdi     # 0x4606a
leaq 0x41dfb(%rip), %rsi     # 0x4603a
movl $0x115, %edx            # imm = 0x115
leaq 0x41e33(%rip), %rcx     # 0x4607e
callq 0x2110
movq 0x88(%rsp), %rcx
movb $0x1, %al
testb $0x1, 0x3c(%rcx)
movb %al, 0x87(%rsp)
je 0x42e5
movq 0x88(%rsp), %rcx
xorl %eax, %eax
testb $0x1, 0x3c(%rcx)
movb %al, 0x86(%rsp)
je 0x42d7
movq 0x88(%rsp), %rax
movq 0x40(%rax), %rdi
leaq 0x1c4(%rsp), %rsi
callq 0x19340
movq %rax, %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0x1b8(%rsp)
movq 0x40(%rax), %rdi
callq 0x19370
movq %rax, 0x1b0(%rsp)
leaq 0x1b8(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x19320
movb %al, 0x86(%rsp)
movb 0x86(%rsp), %al
movb %al, 0x87(%rsp)
movb 0x87(%rsp), %al
testb $0x1, %al
jne 0x42f2
jmp 0x42f4
jmp 0x4313
leaq 0x41dea(%rip), %rdi     # 0x460e5
leaq 0x41d38(%rip), %rsi     # 0x4603a
movl $0x116, %edx            # imm = 0x116
leaq 0x41d70(%rip), %rcx     # 0x4607e
callq 0x2110
leaq 0x180(%rsp), %rdi
callq 0x193a0
movq 0x1d0(%rsp), %rdi
callq 0x193b0
movq %rax, 0x178(%rsp)
movq 0x1d0(%rsp), %rdi
callq 0x19420
movq %rax, 0x170(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x193e0
testb $0x1, %al
jne 0x4368
jmp 0x4656
leaq 0x178(%rsp), %rdi
callq 0x19450
movq 0x88(%rsp), %rsi
movq %rax, %rdx
leaq 0x168(%rsp), %rdi
callq 0x2a70
jmp 0x438f
jmp 0x4391
cmpl $-0x1, 0x16c(%rsp)
je 0x4638
movq 0x88(%rsp), %rax
movq 0x18(%rax), %rdi
movl 0x16c(%rsp), %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x158(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x193b0
movq %rax, 0x148(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x19420
movq %rax, 0x140(%rsp)
movq 0x148(%rsp), %rdi
movq 0x140(%rsp), %rsi
leaq 0x158(%rsp), %rdx
callq 0x194a0
movq %rax, 0x78(%rsp)
jmp 0x4410
movq 0x78(%rsp), %rax
movq %rax, 0x150(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x19420
movq %rax, 0x138(%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x19460
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x77(%rsp)
jne 0x4459
jmp 0x44e2
movq 0x1d0(%rsp), %rdi
callq 0x193b0
movq %rax, 0x128(%rsp)
movq 0x1d0(%rsp), %rdi
callq 0x19420
movq %rax, 0x120(%rsp)
movq 0x128(%rsp), %rdi
movq 0x120(%rsp), %rsi
leaq 0x158(%rsp), %rdx
callq 0x194a0
movq %rax, 0x68(%rsp)
jmp 0x44a7
movq 0x68(%rsp), %rax
movq %rax, 0x130(%rsp)
movq 0x1d0(%rsp), %rdi
callq 0x19420
movq %rax, 0x118(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x19460
movb %al, 0x77(%rsp)
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x44ef
jmp 0x461c
leaq 0x180(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x19500
movb %dl, 0x5f(%rsp)
movq %rax, 0x60(%rsp)
jmp 0x450f
movb 0x5f(%rsp), %al
movq 0x60(%rsp), %rcx
movq %rcx, 0xf8(%rsp)
movb %al, 0x100(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x108(%rsp)
movb 0x100(%rsp), %al
movb %al, 0x110(%rsp)
testb $0x1, 0x110(%rsp)
je 0x461a
leaq 0x178(%rsp), %rdi
callq 0x19450
movq 0x88(%rsp), %rdi
movq %rax, %rdx
leaq 0x158(%rsp), %rsi
leaq 0x1c4(%rsp), %rcx
callq 0x48a0
jmp 0x4582
movq 0x88(%rsp), %rax
testb $0x1, 0x3c(%rax)
jne 0x459d
movl 0x158(%rsp), %eax
movl %eax, 0x58(%rsp)
jmp 0x45c8
movq 0x88(%rsp), %rax
movq 0x40(%rax), %rdi
leaq 0x158(%rsp), %rsi
callq 0x188b0
movq %rax, 0x50(%rsp)
jmp 0x45bd
movq 0x50(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x58(%rsp)
movq 0x88(%rsp), %rdi
movl 0x58(%rsp), %eax
movl %eax, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
movl %eax, %esi
callq 0x19050
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
jmp 0x461a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x160(%rsp)
movl %eax, 0x15c(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x19880
jmp 0x4892
jmp 0x461c
movq 0x88(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x19560
jmp 0x4633
jmp 0x4391
jmp 0x463a
leaq 0x178(%rsp), %rdi
xorl %esi, %esi
callq 0x19730
movq %rax, 0xe8(%rsp)
jmp 0x4335
movq 0x1c8(%rsp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
leaq 0x180(%rsp), %rdi
callq 0x19770
cmpq $0x0, %rax
jne 0x4698
movq 0x88(%rsp), %rdi
addq $0x20, %rdi
leaq 0x1c4(%rsp), %rsi
callq 0x19070
jmp 0x4693
jmp 0x486e
movq 0x88(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0x88(%rsp), %rax
movl %ecx, 0xe4(%rsp)
movq 0x18(%rax), %rdi
movq %rdi, 0x48(%rsp)
callq 0x188e0
movq %rax, 0x40(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x19770
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdi
addq %rax, %rsi
callq 0x18f30
jmp 0x46ef
leaq 0x180(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x197f0
movq 0x30(%rsp), %rdi
movq %rax, 0xd8(%rsp)
callq 0x19820
movq %rax, %rcx
movq 0x88(%rsp), %rax
movq %rcx, 0xd0(%rsp)
movq 0x18(%rax), %rdi
callq 0x19850
movq %rax, 0x38(%rsp)
jmp 0x4736
movq 0x38(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0xd8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
callq 0x19780
movq %rax, 0x28(%rsp)
jmp 0x4767
movq 0x88(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, 0xc0(%rsp)
movq %rax, 0x20(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x19770
movl %eax, 0xb0(%rsp)
leaq 0xb4(%rsp), %rdi
leaq 0xe4(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
callq 0x19190
jmp 0x47b4
movq 0x20(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
callq 0x19160
jmp 0x47c8
movq 0x88(%rsp), %rax
testb $0x1, 0x3c(%rax)
je 0x486c
movq 0x88(%rsp), %rdi
movq 0x40(%rdi), %rax
movq %rax, 0x18(%rsp)
callq 0x18830
decq %rax
movq %rax, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x1c4(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x19130
jmp 0x481a
movq 0x18(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x190e0
movb %dl, 0xf(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x4837
movq 0x88(%rsp), %rax
movb 0xf(%rsp), %cl
movq 0x10(%rsp), %rdx
movq %rdx, 0x90(%rsp)
movb %cl, 0x98(%rsp)
movq 0x48(%rax), %rdi
leaq 0x1c4(%rsp), %rsi
callq 0x19070
jmp 0x486a
jmp 0x486c
jmp 0x486e
movl 0x1c4(%rsp), %eax
movl %eax, 0x8(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x19880
movl 0x8(%rsp), %eax
addq $0x1e8, %rsp            # imm = 0x1E8
retq
movq 0x160(%rsp), %rdi
callq 0x2310
nop