// File: iPapatsoris[P]Maximum-Independent-Set/src/Graph.cpp
// Function: Graph::getOptimalDegree5Node() const
uint32_t Graph::getOptimalDegree5Node() const {
    uint32_t node = NONE;
    vector<uint32_t> nodes;
    for (uint32_t pos = 0 ; pos < nodeIndex.size() ; pos++) {
        if (nodeIndex[pos].removed || nodeIndex[pos].edges != 5) {
            continue;
        }
        uint32_t node = (!mapping ? pos : posToId->at(pos));
        nodes.push_back(node);
        if (getNumberOfDegreeNeighbors(node, 3, 1) >= 1) {
            //cout << "Branching on optimal degree-5 node: at least 1 degree 3 neighbor " << node << "\n";
            return node;
        }
    }
    for (auto node: nodes) {
        if (nodeIsEffective(node)) {
            //cout << "Branching on optimal degree-5 node: effective node " << node << "\n";
            return node;
        }
        std::unordered_set<uint32_t> extendedGrandchildren;
        GraphTraversal graphTraversal(*this, node);
        getExtendedGrandchildren(graphTraversal, extendedGrandchildren, NULL, true);
        if (extendedGrandchildren.size()) {
            //cout << "Branching on optimal degree-5 node: extended grandchildren " << node << "\n";
            return node;
        }
    }
    return node;
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0xffffffff, 0xd4(%rsp) # imm = 0xFFFFFFFF
leaq 0xb8(%rsp), %rdi
callq 0x17e60
movl $0x0, 0xb4(%rsp)
movq 0x28(%rsp), %rdi
movl 0xb4(%rsp), %eax
movq %rax, 0x20(%rsp)
callq 0x18830
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x8806
movq 0x28(%rsp), %rdi
movl 0xb4(%rsp), %eax
movl %eax, %esi
callq 0x18850
testb $0x1, 0x8(%rax)
jne 0x8708
movq 0x28(%rsp), %rdi
movl 0xb4(%rsp), %eax
movl %eax, %esi
callq 0x18850
cmpl $0x5, 0x4(%rax)
je 0x870d
jmp 0x87f0
movq 0x28(%rsp), %rax
testb $0x1, 0x3c(%rax)
jne 0x8725
movl 0xb4(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x874e
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rdi
movl 0xb4(%rsp), %eax
movl %eax, %esi
callq 0x18870
movq %rax, 0x10(%rsp)
jmp 0x8743
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x19070
jmp 0x8770
movq 0x28(%rsp), %rdi
movl $0x3, 0xa0(%rsp)
movl $0x1, 0x9c(%rsp)
leaq 0xb0(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
leaq 0x9c(%rsp), %rcx
callq 0x2d40
movl %eax, 0xc(%rsp)
jmp 0x87ae
movl 0xc(%rsp), %eax
cmpl $0x1, %eax
jb 0x87ee
movl 0xb0(%rsp), %eax
movl %eax, 0xe4(%rsp)
movl $0x1, 0x98(%rsp)
jmp 0x8985
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
jmp 0x89a1
jmp 0x87f0
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x86af
leaq 0xb8(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rdi
callq 0x19b50
movq %rax, 0x88(%rsp)
movq 0x90(%rsp), %rdi
callq 0x1a0e0
movq %rax, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x1a110
testb $0x1, %al
jne 0x885e
jmp 0x896c
leaq 0x88(%rsp), %rdi
callq 0x1a150
movq 0x28(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x7c(%rsp)
leaq 0x7c(%rsp), %rsi
callq 0x89c0
movl %eax, 0x8(%rsp)
jmp 0x8886
movl 0x8(%rsp), %eax
cmpl $0x0, %eax
je 0x88aa
movl 0x7c(%rsp), %eax
movl %eax, 0xe4(%rsp)
movl $0x1, 0x98(%rsp)
jmp 0x8985
leaq 0x40(%rsp), %rdi
callq 0x1a020
movq 0x28(%rsp), %rsi
leaq 0x38(%rsp), %rdi
leaq 0x7c(%rsp), %rdx
callq 0x2a70
jmp 0x88ca
movq 0x28(%rsp), %rdi
movb $0x1, 0x37(%rsp)
xorl %eax, %eax
movl %eax, %ecx
leaq 0x38(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x37(%rsp), %r8
callq 0x4f80
jmp 0x88ee
leaq 0x40(%rsp), %rdi
callq 0x191e0
cmpq $0x0, %rax
je 0x8936
movl 0x7c(%rsp), %eax
movl %eax, 0xe4(%rsp)
movl $0x1, 0x98(%rsp)
jmp 0x8941
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x1a030
jmp 0x89a1
movl $0x0, 0x98(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x1a030
movl 0x98(%rsp), %eax
testl %eax, %eax
jne 0x8985
jmp 0x8958
jmp 0x895a
leaq 0x88(%rsp), %rdi
callq 0x1a160
jmp 0x8840
movl 0xd4(%rsp), %eax
movl %eax, 0xe4(%rsp)
movl $0x1, 0x98(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x18520
movl 0xe4(%rsp), %eax
addq $0xe8, %rsp
retq
leaq 0xb8(%rsp), %rdi
callq 0x18520
movq 0xa8(%rsp), %rdi
callq 0x2310
nopl (%rax,%rax)