// File: 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:
subq $0x348, %rsp            # imm = 0x348
movq %rdi, 0x338(%rsp)
movq 0x338(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq (%rax), %rsi
leaq 0x330(%rsp), %rdi
callq 0x2a40
cmpl $-0x1, 0x330(%rsp)
je 0x314a2
movq 0xf0(%rsp), %rax
movb $0x1, 0x32f(%rsp)
movq (%rax), %rdi
leaq 0x330(%rsp), %rsi
callq 0x1a040
cmpl $0x3, %eax
jb 0x31485
leaq 0x310(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
callq 0x17e60
movq 0xf0(%rsp), %rax
movq 0xe8(%rsp), %rdx
movq (%rax), %rdi
movl $0xffffffff, 0x30c(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
leaq 0x330(%rsp), %rsi
leaq 0x30c(%rsp), %r8
callq 0x19c30
jmp 0x30914
testb $0x1, 0x32f(%rsp)
je 0x3144d
movl $0x0, 0x2f0(%rsp)
movl 0x2f0(%rsp), %eax
movq %rax, 0xe0(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0xe0(%rsp), %rax
cmpq %rcx, %rax
jae 0x3144b
movl 0x2f0(%rsp), %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
callq 0x18900
movq %rax, %rcx
movq 0xf0(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x2f8(%rsp)
movq (%rax), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0x1a040
movl %eax, 0xdc(%rsp)
jmp 0x309a0
movl 0xdc(%rsp), %eax
cmpl $0x3, %eax
jae 0x309ca
jmp 0x31435
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
jmp 0x31476
movl 0x2f0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2ec(%rsp)
movl 0x2ec(%rsp), %eax
movq %rax, 0xd0(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0xd0(%rsp), %rax
cmpq %rcx, %rax
jae 0x31433
movl 0x2ec(%rsp), %eax
movl %eax, %esi
leaq 0x310(%rsp), %rdi
callq 0x18900
movq %rax, %rcx
movq 0xf0(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x2f4(%rsp)
movq (%rax), %rdi
leaq 0x2f4(%rsp), %rsi
callq 0x1a040
movl %eax, 0xcc(%rsp)
jmp 0x30a4e
movl 0xcc(%rsp), %eax
cmpl $0x3, %eax
jae 0x30a5f
jmp 0x3140e
leaq 0x2d0(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0x17e60
movq 0xf0(%rsp), %rax
movq 0xc0(%rsp), %rcx
movq (%rax), %rdi
movl $0x0, 0x2cc(%rsp)
leaq 0x2f8(%rsp), %rsi
leaq 0x2f4(%rsp), %rdx
leaq 0x2cc(%rsp), %r8
callq 0x62b0
jmp 0x30ab1
leaq 0x2d0(%rsp), %rax
movq %rax, 0x2c0(%rsp)
movq 0x2c0(%rsp), %rdi
callq 0x19b50
movq %rax, 0x2b8(%rsp)
movq 0x2c0(%rsp), %rdi
callq 0x1a0e0
movq %rax, 0x2b0(%rsp)
leaq 0x2b8(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x1a110
testb $0x1, %al
jne 0x30b09
jmp 0x313e7
leaq 0x2b8(%rsp), %rdi
callq 0x1a150
movl (%rax), %eax
movl %eax, 0x2ac(%rsp)
movl 0x2ac(%rsp), %eax
cmpl 0x330(%rsp), %eax
je 0x30b5c
movq 0xf0(%rsp), %rax
movq (%rax), %rdi
leaq 0x2ac(%rsp), %rsi
callq 0x1a040
movl %eax, 0xbc(%rsp)
jmp 0x30b50
movl 0xbc(%rsp), %eax
cmpl $0x3, %eax
jae 0x30b7a
jmp 0x313d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
jmp 0x31424
movq 0xf0(%rsp), %rax
movq (%rax), %rdi
leaq 0x330(%rsp), %rsi
leaq 0x2ac(%rsp), %rdx
callq 0x18920
movb %al, 0xbb(%rsp)
jmp 0x30ba3
movb 0xbb(%rsp), %al
testb $0x1, %al
jne 0x313d3
jmp 0x30bb4
movq 0xf0(%rsp), %rax
movq (%rax), %rdi
leaq 0x2f8(%rsp), %rsi
leaq 0x2f4(%rsp), %rdx
callq 0x18920
movb %al, 0xba(%rsp)
jmp 0x30bdd
movb 0xba(%rsp), %al
testb $0x1, %al
jne 0x313d3
jmp 0x30bee
leaq 0x278(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x193a0
leaq 0x248(%rsp), %rdi
callq 0x193a0
movq 0xf0(%rsp), %rax
movq 0xb0(%rsp), %rdx
movq (%rax), %rdi
movl $0xffffffff, 0x244(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
leaq 0x330(%rsp), %rsi
leaq 0x244(%rsp), %r8
callq 0x1d720
jmp 0x30c49
movq 0xf0(%rsp), %rax
movq (%rax), %rdi
movl $0xffffffff, 0x240(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
leaq 0x2ac(%rsp), %rsi
leaq 0x278(%rsp), %rdx
leaq 0x240(%rsp), %r8
callq 0x1d720
jmp 0x30c82
movq 0xf0(%rsp), %rax
movq (%rax), %rdi
movl $0xffffffff, 0x23c(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
leaq 0x2f8(%rsp), %rsi
leaq 0x248(%rsp), %rdx
leaq 0x23c(%rsp), %r8
callq 0x1d720
jmp 0x30cbb
movq 0xf0(%rsp), %rax
movq (%rax), %rdi
movl $0xffffffff, 0x238(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
leaq 0x2f4(%rsp), %rsi
leaq 0x248(%rsp), %rdx
leaq 0x238(%rsp), %r8
callq 0x1d720
jmp 0x30cf4
leaq 0x278(%rsp), %rdi
callq 0x19770
cmpq $0x4, %rax
ja 0x31383
leaq 0x248(%rsp), %rdi
callq 0x19770
cmpq $0x4, %rax
ja 0x31383
leaq 0x278(%rsp), %rax
movq %rax, 0x230(%rsp)
movq 0x230(%rsp), %rdi
callq 0x197f0
movq %rax, 0x228(%rsp)
movq 0x230(%rsp), %rdi
callq 0x19820
movq %rax, 0x220(%rsp)
leaq 0x228(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x1d6a0
testb $0x1, %al
jne 0x30d7a
jmp 0x30e26
leaq 0x228(%rsp), %rdi
callq 0x1a670
movl (%rax), %eax
movl %eax, 0x21c(%rsp)
leaq 0x248(%rsp), %rdi
leaq 0x21c(%rsp), %rsi
callq 0x33010
movq %rax, 0xa8(%rsp)
jmp 0x30daf
movq 0xa8(%rsp), %rax
movq %rax, 0x210(%rsp)
leaq 0x248(%rsp), %rdi
callq 0x19820
movq %rax, 0x208(%rsp)
leaq 0x210(%rsp), %rdi
leaq 0x208(%rsp), %rsi
callq 0x1d6a0
testb $0x1, %al
jne 0x30def
jmp 0x30e12
movb $0x0, 0x32f(%rsp)
jmp 0x30e26
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
jmp 0x313b7
jmp 0x30e14
leaq 0x228(%rsp), %rdi
callq 0x1d6c0
jmp 0x30d5c
testb $0x1, 0x32f(%rsp)
je 0x31381
movq 0xf0(%rsp), %rdx
movq (%rdx), %rdi
addq $0x10, %rdx
movb $0x0, 0x207(%rsp)
movb $0x0, 0x206(%rsp)
xorl %eax, %eax
movl %eax, %r8d
leaq 0x278(%rsp), %rsi
leaq 0x207(%rsp), %rcx
leaq 0x206(%rsp), %r9
callq 0x33050
jmp 0x30e77
movq 0xf0(%rsp), %rdx
movq (%rdx), %rdi
addq $0x10, %rdx
movb $0x0, 0x205(%rsp)
movb $0x0, 0x204(%rsp)
xorl %eax, %eax
movl %eax, %r8d
leaq 0x248(%rsp), %rsi
leaq 0x205(%rsp), %rcx
leaq 0x204(%rsp), %r9
callq 0x33050
jmp 0x30eba
movq 0xf0(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x33420
movq %rax, 0xa0(%rsp)
jmp 0x30ed5
movq 0xa0(%rsp), %rax
movq %rax, 0x1f8(%rsp)
leaq 0x278(%rsp), %rax
movq %rax, 0x1f0(%rsp)
movq 0x1f0(%rsp), %rdi
callq 0x197f0
movq %rax, 0x1e8(%rsp)
movq 0x1f0(%rsp), %rdi
callq 0x19820
movq %rax, 0x1e0(%rsp)
leaq 0x1e8(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x1d6a0
testb $0x1, %al
jne 0x30f3d
jmp 0x31137
leaq 0x1e8(%rsp), %rdi
callq 0x1a670
movl (%rax), %eax
movl %eax, 0x1dc(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x1d4(%rsp), %rdi
leaq 0x1dc(%rsp), %rsi
leaq 0x2f8(%rsp), %rdx
callq 0x1b1e0
jmp 0x30f82
movq 0x98(%rsp), %rdi
leaq 0x1d4(%rsp), %rsi
callq 0x190e0
movb %dl, 0x8f(%rsp)
movq %rax, 0x90(%rsp)
jmp 0x30fa8
movb 0x8f(%rsp), %al
movq 0x90(%rsp), %rcx
movq %rcx, 0x1c0(%rsp)
movb %al, 0x1c8(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x1b8(%rsp), %rdi
leaq 0x1dc(%rsp), %rsi
leaq 0x2f4(%rsp), %rdx
callq 0x1b1e0
jmp 0x30ff5
movq 0x80(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x190e0
movb %dl, 0x77(%rsp)
movq %rax, 0x78(%rsp)
jmp 0x31015
movq 0xf0(%rsp), %rax
movb 0x77(%rsp), %cl
movq 0x78(%rsp), %rdx
movq %rdx, 0x1a8(%rsp)
movb %cl, 0x1b0(%rsp)
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movl 0x1dc(%rsp), %eax
movl %eax, 0x5c(%rsp)
leaq 0x248(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x197f0
movq 0x60(%rsp), %rdi
movq %rax, 0x188(%rsp)
callq 0x19820
movq %rax, 0x180(%rsp)
leaq 0x17f(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x18d80
movq 0x68(%rsp), %rcx
movq 0x188(%rsp), %rsi
movq 0x180(%rsp), %rdx
leaq 0x190(%rsp), %rdi
callq 0x33430
jmp 0x310aa
movl 0x5c(%rsp), %esi
movq 0x50(%rsp), %rdi
leaq 0x190(%rsp), %rdx
callq 0x9840
jmp 0x310c2
leaq 0x190(%rsp), %rdi
callq 0x18520
leaq 0x17f(%rsp), %rdi
callq 0x18e10
leaq 0x1e8(%rsp), %rdi
callq 0x1d6c0
jmp 0x30f1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
jmp 0x31125
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x18520
leaq 0x17f(%rsp), %rdi
callq 0x18e10
jmp 0x313b7
leaq 0x248(%rsp), %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rdi
callq 0x197f0
movq %rax, 0x168(%rsp)
movq 0x170(%rsp), %rdi
callq 0x19820
movq %rax, 0x160(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x1d6a0
testb $0x1, %al
jne 0x3118f
jmp 0x3136c
leaq 0x168(%rsp), %rdi
callq 0x1a670
movl (%rax), %eax
movl %eax, 0x15c(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x154(%rsp), %rdi
leaq 0x15c(%rsp), %rsi
leaq 0x330(%rsp), %rdx
callq 0x1b1e0
jmp 0x311d1
movq 0x48(%rsp), %rdi
leaq 0x154(%rsp), %rsi
callq 0x190e0
movb %dl, 0x3f(%rsp)
movq %rax, 0x40(%rsp)
jmp 0x311ee
movb 0x3f(%rsp), %al
movq 0x40(%rsp), %rcx
movq %rcx, 0x140(%rsp)
movb %al, 0x148(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x138(%rsp), %rdi
leaq 0x15c(%rsp), %rsi
leaq 0x2ac(%rsp), %rdx
callq 0x1b1e0
jmp 0x31232
movq 0x30(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x190e0
movb %dl, 0x27(%rsp)
movq %rax, 0x28(%rsp)
jmp 0x3124f
movq 0xf0(%rsp), %rax
movb 0x27(%rsp), %cl
movq 0x28(%rsp), %rdx
movq %rdx, 0x128(%rsp)
movb %cl, 0x130(%rsp)
movq (%rax), %rax
movq %rax, (%rsp)
movl 0x15c(%rsp), %eax
movl %eax, 0xc(%rsp)
leaq 0x278(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x197f0
movq 0x10(%rsp), %rdi
movq %rax, 0x108(%rsp)
callq 0x19820
movq %rax, 0x100(%rsp)
leaq 0xff(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x18d80
movq 0x18(%rsp), %rcx
movq 0x108(%rsp), %rsi
movq 0x100(%rsp), %rdx
leaq 0x110(%rsp), %rdi
callq 0x33430
jmp 0x312e3
movl 0xc(%rsp), %esi
movq (%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0x9840
jmp 0x312fa
leaq 0x110(%rsp), %rdi
callq 0x18520
leaq 0xff(%rsp), %rdi
callq 0x18e10
leaq 0x168(%rsp), %rdi
callq 0x1d6c0
jmp 0x31171
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
jmp 0x3135d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x300(%rsp)
movl %eax, 0x2fc(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x18520
leaq 0xff(%rsp), %rdi
callq 0x18e10
jmp 0x313b7
movb $0x1, 0x347(%rsp)
movl $0x1, 0xf8(%rsp)
jmp 0x3138e
jmp 0x31383
movl $0x0, 0xf8(%rsp)
leaq 0x248(%rsp), %rdi
callq 0x19880
leaq 0x278(%rsp), %rdi
callq 0x19880
movl 0xf8(%rsp), %eax
testl %eax, %eax
jne 0x313f2
jmp 0x313b5
jmp 0x313d3
leaq 0x248(%rsp), %rdi
callq 0x19880
leaq 0x278(%rsp), %rdi
callq 0x19880
jmp 0x31424
jmp 0x313d5
leaq 0x2b8(%rsp), %rdi
callq 0x1a160
jmp 0x30aeb
movl $0x0, 0xf8(%rsp)
leaq 0x2d0(%rsp), %rdi
callq 0x18520
movl 0xf8(%rsp), %eax
testl %eax, %eax
jne 0x31458
jmp 0x3140c
jmp 0x3140e
movl 0x2ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2ec(%rsp)
jmp 0x309db
leaq 0x2d0(%rsp), %rdi
callq 0x18520
jmp 0x31476
jmp 0x31435
movl 0x2f0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2f0(%rsp)
jmp 0x3092d
jmp 0x3144d
movl $0x0, 0xf8(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x18520
movl 0xf8(%rsp), %eax
testl %eax, %eax
je 0x31474
jmp 0x31472
jmp 0x314aa
jmp 0x31485
leaq 0x310(%rsp), %rdi
callq 0x18520
jmp 0x314bb
movq 0xf0(%rsp), %rax
movq (%rax), %rdi
leaq 0x330(%rsp), %rsi
callq 0x185f0
jmp 0x3088f
movb $0x0, 0x347(%rsp)
movb 0x347(%rsp), %al
andb $0x1, %al
addq $0x348, %rsp            # imm = 0x348
retq
movq 0x300(%rsp), %rdi
callq 0x2310
nopl (%rax,%rax)