// File: /workspace/github_cpp_makefile_star2_O1/iPapatsoris[P]Maximum-Independent-Set/src/Reductions.cpp
// Function: Reductions::removeDesks()
bool Reductions::removeDesks() {
    Graph::GraphTraversal graphTraversal(graph);
    while (graphTraversal.curNode != NONE) {
        bool valid = true;
        if (graph.getNodeDegree(graphTraversal.curNode) >= 3) {
            vector<uint32_t> neighbors;
            graph.gatherNeighbors(graphTraversal.curNode, neighbors);
            if (valid) {
                uint32_t b, d;
                for (uint32_t i = 0 ; i < neighbors.size() ; i++) {
                    b = neighbors[i];
                    if (graph.getNodeDegree(b) < 3) {
                        continue;
                    }
                    for (uint32_t j = i+1 ; j < neighbors.size() ; j++) {
                        d = neighbors[j];
                        if (graph.getNodeDegree(d) < 3) {
                            continue;
                        }
                        vector<uint32_t> commonNeighbors;
                        graph.getCommonNeighbors(b, d, commonNeighbors);
                        for (auto c: commonNeighbors) {
                            if (c == graphTraversal.curNode || graph.getNodeDegree(c) < 3) {
                                continue;
                            }
                            if (!graph.edgeExists(graphTraversal.curNode, c) && !graph.edgeExists(b, d)) {
                                set<uint32_t> neighborsAC;
                                set<uint32_t> neighborsBD;
                                graph.gatherNeighbors(graphTraversal.curNode, neighborsAC);
                                graph.gatherNeighbors(c, neighborsAC);
                                graph.gatherNeighbors(b, neighborsBD);
                                graph.gatherNeighbors(d, neighborsBD);
                                if (neighborsAC.size() <= 4 && neighborsBD.size() <= 4) {
                                    for (auto n: neighborsAC) {
                                        if (neighborsBD.find(n) != neighborsBD.end()) {
                                            valid = false;
                                            break;
                                        }
                                    }
                                    if (valid) {
                                        //cout << "reducing desk " << graphTraversal.curNode << "-" << b << "-" << c << "-" << d << "\n";
                                        graph.remove(neighborsAC, reduceInfo);
                                        graph.remove(neighborsBD, reduceInfo);
                                        std::unordered_map<uint32_t, uint32_t> &subsequentNodes = mis.getSubsequentNodes();
                                        for (auto neighborAC: neighborsAC) {
                                            subsequentNodes.insert({neighborAC, b});
                                            subsequentNodes.insert({neighborAC, d});
                                            graph.addEdges(neighborAC, vector<uint32_t>(neighborsBD.begin(), neighborsBD.end()));
                                        }
                                        for (auto neighborBD: neighborsBD) {
                                            subsequentNodes.insert({neighborBD, graphTraversal.curNode});
                                            subsequentNodes.insert({neighborBD, c});
                                            graph.addEdges(neighborBD, vector<uint32_t>(neighborsAC.begin(), neighborsAC.end()));
                                        }
                                        return true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        graph.getNextNode(graphTraversal);
    }
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %r15
movq (%rdi), %rsi
leaq 0x14(%rsp), %r14
movq %r14, %rdi
callq 0x29d8
cmpl $-0x1, (%r14)
setne 0x5(%rsp)
je 0x117a0
leaq 0xa0(%rsp), %r12
leaq 0x10(%r15), %rbx
leaq 0x14(%rsp), %rsi
leaq 0x60(%rsp), %rbp
movq %r15, 0x38(%rsp)
movq %rbx, 0xf0(%rsp)
movq (%r15), %rdi
callq 0xc98e
cmpl $0x3, %eax
leaq 0x14(%rsp), %rsi
jb 0x11782
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq (%r15), %rdi
movl $0xffffffff, 0x60(%rsp) # imm = 0xFFFFFFFF
leaq 0x40(%rsp), %rdx
xorl %ecx, %ecx
movq %rbp, %r8
callq 0xc714
movq 0x40(%rsp), %rax
cmpq %rax, 0x48(%rsp)
setne 0x6(%rsp)
je 0x11767
xorl %edx, %edx
movb $0x1, %cl
movl %ecx, 0x1c(%rsp)
movq %rdx, 0x90(%rsp)
movl (%rax,%rdx,4), %eax
movl %eax, 0xc(%rsp)
movq (%r15), %rdi
leaq 0xc(%rsp), %rsi
callq 0xc98e
cmpl $0x3, %eax
jae 0x11252
movq 0x90(%rsp), %rdx
jmp 0x11746
movq 0x90(%rsp), %rax
leal 0x1(%rax), %ebx
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
seta %r13b
jbe 0x11738
movl (%rax,%rbx,4), %eax
movl %eax, 0x8(%rsp)
movq (%r15), %rdi
leaq 0x8(%rsp), %rsi
callq 0xc98e
cmpl $0x3, %eax
jb 0x11731
xorps %xmm0, %xmm0
movaps %xmm0, 0xd0(%rsp)
movq $0x0, 0xe0(%rsp)
movq (%r15), %rdi
movl $0x0, 0x60(%rsp)
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0xd0(%rsp), %rcx
movq %rbp, %r8
callq 0x4bae
movq %rbp, %r14
movb %r13b, 0x7(%rsp)
movq %rbx, 0x100(%rsp)
movq 0xd0(%rsp), %rbx
movq 0xd8(%rsp), %rbp
movl $0xa, %ecx
cmpq %rbp, %rbx
je 0x116fd
movl (%rbx), %eax
movl %eax, 0x10(%rsp)
movl $0xb, %r13d
cmpl 0x14(%rsp), %eax
je 0x1135c
movq (%r15), %rdi
leaq 0x10(%rsp), %rsi
callq 0xc98e
cmpl $0x3, %eax
jb 0x11357
movq (%r15), %rdi
leaq 0x14(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0xc5e2
xorl %r13d, %r13d
cmpl $-0x1, %eax
jne 0x11357
movq (%r15), %rdi
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0xc5e2
cmpl $-0x1, %eax
je 0x11371
movl $0xa, %ecx
cmpl $0xb, %r13d
je 0x1136b
testl %r13d, %r13d
jne 0x116fa
addq $0x4, %rbx
jmp 0x112f9
movq %rbp, 0xf8(%rsp)
xorl %ecx, %ecx
movl %ecx, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
leaq 0x68(%rsp), %rax
movq %rax, 0x78(%rsp)
movq %rax, 0x80(%rsp)
movq %rcx, 0x88(%rsp)
movl %ecx, 0xa0(%rsp)
movq %rcx, 0xa8(%rsp)
movq %r12, 0xb0(%rsp)
movq %r12, 0xb8(%rsp)
movq %rcx, 0xc0(%rsp)
movq (%r15), %rdi
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
leaq 0x14(%rsp), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
leaq 0x20(%rsp), %r13
movq %r13, %r8
callq 0xd05a
movq (%r15), %rdi
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
movq %r13, %r8
callq 0xd05a
movq (%r15), %rdi
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
leaq 0xc(%rsp), %rsi
leaq 0x98(%rsp), %rbp
movq %rbp, %rdx
xorl %ecx, %ecx
movq %r13, %r8
callq 0xd05a
movq (%r15), %rdi
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
leaq 0x8(%rsp), %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
movq %r13, %r8
callq 0xd05a
xorl %r13d, %r13d
cmpq $0x4, 0x88(%rsp)
ja 0x116cb
cmpq $0x4, 0xc0(%rsp)
ja 0x116cb
movq 0x78(%rsp), %rax
leaq 0x68(%rsp), %rcx
cmpq %rcx, %rax
je 0x114e2
movq 0xa8(%rsp), %r14
movl 0x20(%rax), %ecx
movq %r12, %rdx
testq %r14, %r14
je 0x114a6
movq %r14, %rsi
movq %r12, %rdx
xorl %edi, %edi
cmpl %ecx, 0x20(%rsi)
setb %dil
cmovaeq %rsi, %rdx
movq 0x10(%rsi,%rdi,8), %rsi
testq %rsi, %rsi
jne 0x1148f
movq %r12, %rsi
cmpq %r12, %rdx
je 0x114b8
cmpl 0x20(%rdx), %ecx
cmovbq %r12, %rdx
movq %rdx, %rsi
movl 0x1c(%rsp), %edx
movzbl %dl, %edx
cmpq %r12, %rsi
movl $0x0, %ecx
cmovnel %ecx, %edx
movl %edx, 0x1c(%rsp)
jne 0x114e2
movq %rax, %rdi
callq 0x2210
leaq 0x68(%rsp), %rcx
cmpq %rcx, %rax
jne 0x1147e
testb $0x1, 0x1c(%rsp)
je 0x116cb
movq (%r15), %rdi
xorl %r14d, %r14d
movb %r14b, 0x20(%rsp)
movb %r14b, 0x4(%rsp)
leaq 0x60(%rsp), %rsi
movq 0xf0(%rsp), %rbp
movq %rbp, %rdx
leaq 0x20(%rsp), %r13
movq %r13, %rcx
xorl %r8d, %r8d
leaq 0x4(%rsp), %r12
movq %r12, %r9
callq 0x12a88
movq (%r15), %rdi
movb %r14b, 0x20(%rsp)
movb %r14b, 0x4(%rsp)
leaq 0x98(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
movq %r12, %r9
callq 0x12a88
movq %r12, %rbp
movq 0x8(%r15), %r15
addq $0x50, %r15
movq 0x78(%rsp), %r14
leaq 0x68(%rsp), %rax
cmpq %rax, %r14
movq %r15, 0xc8(%rsp)
je 0x11606
movl 0x20(%r14), %r12d
movl %r12d, 0x20(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x24(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0xdfc4
movl %r12d, 0x20(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x24(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0xdfc4
movq 0x38(%rsp), %rax
movq (%rax), %r15
movq 0xb0(%rsp), %rsi
movq %r13, %rdi
leaq 0xa0(%rsp), %rdx
movq %rbp, %rcx
callq 0x12cba
movq %r15, %rdi
movl %r12d, %esi
movq %r13, %rdx
callq 0x6cde
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x115e5
callq 0x21a0
movq %r14, %rdi
callq 0x2210
movq %rax, %r14
leaq 0x68(%rsp), %rax
cmpq %rax, %r14
movq 0xc8(%rsp), %r15
jne 0x11571
movq 0xb0(%rsp), %r14
movl $0x1, %r13d
leaq 0xa0(%rsp), %rax
cmpq %rax, %r14
je 0x116be
movl 0x20(%r14), %r12d
movl %r12d, 0x20(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x24(%rsp)
movq %r15, %rdi
leaq 0x20(%rsp), %rbp
movq %rbp, %rsi
callq 0xdfc4
movl %r12d, 0x20(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x24(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0xdfc4
movq 0x38(%rsp), %rax
movq (%rax), %r15
movq 0x78(%rsp), %rsi
movq %rbp, %rdi
leaq 0x68(%rsp), %rdx
leaq 0x4(%rsp), %rcx
callq 0x12cba
movq %r15, %rdi
movl %r12d, %esi
movq %rbp, %rdx
callq 0x6cde
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1169a
callq 0x21a0
movq %r14, %rdi
callq 0x2210
movq %rax, %r14
leaq 0xa0(%rsp), %rax
cmpq %rax, %r14
movq 0xc8(%rsp), %r15
jne 0x11625
movq 0x38(%rsp), %r15
leaq 0xa0(%rsp), %r12
leaq 0x60(%rsp), %rbp
leaq 0x98(%rsp), %rdi
callq 0xcfae
movq %rbp, %r14
movq %rbp, %rdi
callq 0xcfae
movl $0xa, %ecx
movq 0xf8(%rsp), %rbp
jmp 0x1135c
movl %r13d, %ecx
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
movq 0x100(%rsp), %rbx
movb 0x7(%rsp), %r13b
je 0x11720
movl %ecx, %ebp
callq 0x21a0
movl %ebp, %ecx
cmpl $0xa, %ecx
je 0x1172e
testl %ecx, %ecx
movq %r14, %rbp
je 0x11731
jmp 0x11738
movq %r14, %rbp
incl %ebx
jmp 0x1125d
testb $0x1, %r13b
movq 0x90(%rsp), %rdx
jne 0x11767
incl %edx
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rdx, %rcx
seta 0x6(%rsp)
ja 0x11224
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x11776
callq 0x21a0
testb $0x1, 0x6(%rsp)
leaq 0x14(%rsp), %rsi
jne 0x117a0
movq (%r15), %rdi
movq %rsi, %r14
callq 0xc034
movq %r14, %rsi
cmpl $-0x1, 0x14(%rsp)
setne 0x5(%rsp)
jne 0x111c6
movb 0x5(%rsp), %al
andb $0x1, %al
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x117ca
jmp 0x117db
jmp 0x117db
jmp 0x117ca
jmp 0x117db
jmp 0x117db
jmp 0x117db
jmp 0x117db
jmp 0x1180b
movq %rax, %rbx
jmp 0x11820
jmp 0x117db
jmp 0x117db
jmp 0x117db
jmp 0x117db
jmp 0x117db
jmp 0x117f7
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0xcfae
leaq 0x60(%rsp), %rdi
callq 0xcfae
jmp 0x1180e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x117de
callq 0x21a0
jmp 0x117de
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x11820
callq 0x21a0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1182f
callq 0x21a0
movq %rbx, %rdi
callq 0x2320
nop