// File: iPapatsoris[P]Maximum-Independent-Set/src/Graph.cpp
// Function: Graph::get4Cycle(std::vector<unsigned int, std::allocator<unsigned int>>&) const
bool Graph::get4Cycle(vector<uint32_t> &optimalCycle) const {
    optimalCycle.clear();
    uint32_t maxDegree3NodesCount = NONE;
    GraphTraversal graphTraversal(*this);
    while (graphTraversal.curNode != NONE) {
        if (getNodeDegree(graphTraversal.curNode) == 4) {
            vector<uint32_t> neighbors;
            gatherNeighbors(graphTraversal.curNode, neighbors);
            uint32_t b, d;
            for (uint32_t i = 0 ; i < 6 ; i++) {
                switch (i) {
                    case 0:
                        b = neighbors[0];
                        d = neighbors[1];
                        break;
                    case 1:
                        b = neighbors[0];
                        d = neighbors[2];
                        break;
                    case 2:
                        b = neighbors[0];
                        d = neighbors[3];
                        break;
                    case 3:
                        b = neighbors[1];
                        d = neighbors[2];
                        break;
                    case 4:
                        b = neighbors[1];
                        d = neighbors[3];
                        break;
                    case 5:
                        b = neighbors[2];
                        d = neighbors[3];
                        break;
                    default:
                        assert(false);
                }
                vector<uint32_t> commonNeighbors;
                getCommonNeighbors(b, d, commonNeighbors);
                for (auto c: commonNeighbors) {
                    if (c == graphTraversal.curNode) {
                        continue;
                    }
                    uint32_t degree3NodesCount = 0;
                    if (getNodeDegree(b) == 3) {
                        degree3NodesCount++;
                    }
                    if (getNodeDegree(c) == 3) {
                        degree3NodesCount++;
                    }
                    if (getNodeDegree(d) == 3) {
                        degree3NodesCount++;
                    }
                    if (maxDegree3NodesCount == NONE || degree3NodesCount > maxDegree3NodesCount) {
                        maxDegree3NodesCount = degree3NodesCount;
                        optimalCycle.clear();
                        optimalCycle.push_back(graphTraversal.curNode);
                        optimalCycle.push_back(b);
                        optimalCycle.push_back(c);
                        optimalCycle.push_back(d);
                        if (maxDegree3NodesCount == 3) {
                            return true;
                        }
                    }
                }
            }
        }
        getNextNode(graphTraversal);
    }
    return maxDegree3NodesCount != NONE;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movq %rsi, 0xc0(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x191c0
movq 0x28(%rsp), %rsi
movl $0xffffffff, 0xbc(%rsp) # imm = 0xFFFFFFFF
leaq 0xb4(%rsp), %rdi
callq 0x2a40
cmpl $-0x1, 0xb4(%rsp)
je 0x6277
movq 0x28(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
callq 0x1a040
cmpl $0x4, %eax
jne 0x6260
leaq 0x98(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x17e60
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rdx
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
leaq 0xb4(%rsp), %rsi
leaq 0x94(%rsp), %r8
callq 0x19c30
jmp 0x5e49
movl $0x0, 0x78(%rsp)
cmpl $0x6, 0x78(%rsp)
jae 0x622e
movl 0x78(%rsp), %eax
movq %rax, 0x18(%rsp)
subq $0x5, %rax
ja 0x5fe4
movq 0x18(%rsp), %rax
leaq 0x40189(%rip), %rcx     # 0x46004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
jmp 0x6251
leaq 0x98(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x80(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x7c(%rsp)
jmp 0x6003
leaq 0x98(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x80(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x2, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x7c(%rsp)
jmp 0x6003
leaq 0x98(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x80(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x3, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x7c(%rsp)
jmp 0x6003
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x80(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x2, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x7c(%rsp)
jmp 0x6003
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x80(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x3, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x7c(%rsp)
jmp 0x6003
leaq 0x98(%rsp), %rdi
movl $0x2, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x80(%rsp)
leaq 0x98(%rsp), %rdi
movl $0x3, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x7c(%rsp)
jmp 0x6003
leaq 0x4019b(%rip), %rdi     # 0x46186
leaq 0x40048(%rip), %rsi     # 0x4603a
movl $0x227, %edx            # imm = 0x227
leaq 0x4018e(%rip), %rcx     # 0x4618c
callq 0x2110
leaq 0x60(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x17e60
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rcx
movl $0x0, 0x5c(%rsp)
leaq 0x80(%rsp), %rsi
leaq 0x7c(%rsp), %rdx
leaq 0x5c(%rsp), %r8
callq 0x62b0
jmp 0x603d
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
callq 0x19b50
movq %rax, 0x48(%rsp)
movq 0x50(%rsp), %rdi
callq 0x1a0e0
movq %rax, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1a110
testb $0x1, %al
jne 0x607d
jmp 0x6200
leaq 0x48(%rsp), %rdi
callq 0x1a150
movl (%rax), %eax
movl %eax, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0xb4(%rsp), %eax
jne 0x60c2
jmp 0x61f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x18520
jmp 0x6251
movq 0x28(%rsp), %rdi
movl $0x0, 0x38(%rsp)
leaq 0x80(%rsp), %rsi
callq 0x1a040
movl %eax, 0xc(%rsp)
jmp 0x60e2
movl 0xc(%rsp), %eax
cmpl $0x3, %eax
jne 0x60f6
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
callq 0x1a040
movl %eax, 0x8(%rsp)
jmp 0x610b
movl 0x8(%rsp), %eax
cmpl $0x3, %eax
jne 0x611f
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x7c(%rsp), %rsi
callq 0x1a040
movl %eax, 0x4(%rsp)
jmp 0x6134
movl 0x4(%rsp), %eax
cmpl $0x3, %eax
jne 0x6148
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
cmpl $-0x1, 0xbc(%rsp)
je 0x6163
movl 0x38(%rsp), %eax
cmpl 0xbc(%rsp), %eax
jbe 0x61ef
movl 0x38(%rsp), %eax
movl %eax, 0xbc(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x191c0
movq 0xc0(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
callq 0x19070
jmp 0x6192
movq 0xc0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x19070
jmp 0x61a9
movq 0xc0(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
callq 0x19070
jmp 0x61bd
movq 0xc0(%rsp), %rdi
leaq 0x7c(%rsp), %rsi
callq 0x19070
jmp 0x61d1
cmpl $0x3, 0xbc(%rsp)
jne 0x61ed
movb $0x1, 0xd7(%rsp)
movl $0x1, 0x34(%rsp)
jmp 0x6208
jmp 0x61ef
jmp 0x61f1
leaq 0x48(%rsp), %rdi
callq 0x1a160
jmp 0x6065
movl $0x0, 0x34(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x18520
movl 0x34(%rsp), %eax
testl %eax, %eax
jne 0x6236
jmp 0x621c
jmp 0x621e
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
jmp 0x5e51
movl $0x0, 0x34(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x18520
movl 0x34(%rsp), %eax
testl %eax, %eax
je 0x624f
jmp 0x624d
jmp 0x628b
jmp 0x6260
leaq 0x98(%rsp), %rdi
callq 0x18520
jmp 0x629c
movq 0x28(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
callq 0x185f0
jmp 0x5dde
cmpl $-0x1, 0xbc(%rsp)
setne %al
andb $0x1, %al
movb %al, 0xd7(%rsp)
movb 0xd7(%rsp), %al
andb $0x1, %al
addq $0xd8, %rsp
retq
movq 0x88(%rsp), %rdi
callq 0x2310
nopl (%rax)