// File: iPapatsoris[P]Maximum-Independent-Set/src/Graph.cpp
// Function: Graph::getGoodFunnelTheta5(unsigned int&, unsigned int&) const
bool Graph::getGoodFunnelTheta5(uint32_t &node1, uint32_t &node2) const {
    GraphTraversal graphTraversal(*this);
    while (graphTraversal.curNode != NONE) {
        uint32_t nodeV = graphTraversal.curNode;
        uint32_t vDegree = getNodeDegree(nodeV);
        if (vDegree == 3) {
            //cout << "nodeV " << nodeV << endl;
            vector<uint32_t> neighborsV;
            gatherNeighbors(nodeV, neighborsV);
            for (uint32_t i = 0 ; i < neighborsV.size() ; i++) {
                uint32_t nodeA = neighborsV[i];
                uint32_t nodeB, nodeC;
                if (i == 0) {
                    nodeB = neighborsV[1];
                    nodeC = neighborsV[2];
                } else if (i == 1) {
                    nodeB = neighborsV[0];
                    nodeC = neighborsV[2];
                } else if (i == 2) {
                    nodeB = neighborsV[0];
                    nodeC = neighborsV[1];
                } else {
                    nodeB = neighborsV[0];
                    nodeC = neighborsV[1];
                }
                if (edgeExists(nodeB, nodeC))  {
                    vector<uint32_t> neighborsA;
                    gatherNeighbors(nodeA, neighborsA);
                    for (auto neighborA: neighborsA) {
                        if (neighborA != nodeV && getNodeDegree(neighborA) == 5) {
                            vector<uint32_t> commonNeighbors;
                            getCommonNeighbors(neighborA, nodeV, commonNeighbors, 3);
                            if (commonNeighbors.size() >= 3) {
                                node1 = nodeA;
                                node2 = nodeV;
                                //cout << "branching on theta-5 good funnel " << node1 << "-" << node2 << "\n";
                                return true;
                            }
                        }
                    }
                }
            }
        }
        getNextNode(graphTraversal);
    }
    return false;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
movq 0xf8(%rsp), %rsi
movq %rsi, 0x30(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x2a40
cmpl $-0x1, 0xe0(%rsp)
je 0x843c
movq 0x30(%rsp), %rdi
movl 0xe0(%rsp), %eax
movl %eax, 0xdc(%rsp)
leaq 0xdc(%rsp), %rsi
callq 0x1a040
movl %eax, 0xd8(%rsp)
cmpl $0x3, 0xd8(%rsp)
jne 0x8425
leaq 0xc0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x17e60
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rdx
movl $0xffffffff, 0xbc(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
leaq 0xdc(%rsp), %rsi
leaq 0xbc(%rsp), %r8
callq 0x19c30
jmp 0x806e
movl $0x0, 0xa8(%rsp)
movl 0xa8(%rsp), %eax
movq %rax, 0x20(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x83f3
movl 0xa8(%rsp), %eax
movl %eax, %esi
leaq 0xc0(%rsp), %rdi
callq 0x18900
movl (%rax), %eax
movl %eax, 0xa4(%rsp)
cmpl $0x0, 0xa8(%rsp)
jne 0x8120
leaq 0xc0(%rsp), %rdi
movl $0x1, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0xa0(%rsp)
leaq 0xc0(%rsp), %rdi
movl $0x2, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x9c(%rsp)
jmp 0x81db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x8416
cmpl $0x1, 0xa8(%rsp)
jne 0x8161
leaq 0xc0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0xa0(%rsp)
leaq 0xc0(%rsp), %rdi
movl $0x2, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x9c(%rsp)
jmp 0x81d9
cmpl $0x2, 0xa8(%rsp)
jne 0x81a2
leaq 0xc0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0xa0(%rsp)
leaq 0xc0(%rsp), %rdi
movl $0x1, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x9c(%rsp)
jmp 0x81d7
leaq 0xc0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0xa0(%rsp)
leaq 0xc0(%rsp), %rdi
movl $0x1, %esi
callq 0x18900
movl (%rax), %eax
movl %eax, 0x9c(%rsp)
jmp 0x81d9
jmp 0x81db
movq 0x30(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x9c(%rsp), %rdx
callq 0x18920
movb %al, 0x1f(%rsp)
jmp 0x81fb
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x8208
jmp 0x83db
leaq 0x80(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x17e60
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rdx
movl $0xffffffff, 0x7c(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
leaq 0xa4(%rsp), %rsi
leaq 0x7c(%rsp), %r8
callq 0x19c30
jmp 0x8244
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
callq 0x19b50
movq %rax, 0x68(%rsp)
movq 0x70(%rsp), %rdi
callq 0x1a0e0
movq %rax, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x1a110
testb $0x1, %al
jne 0x8287
jmp 0x83ab
leaq 0x68(%rsp), %rdi
callq 0x1a150
movl (%rax), %eax
movl %eax, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0xdc(%rsp), %eax
je 0x839a
movq 0x30(%rsp), %rdi
leaq 0x5c(%rsp), %rsi
callq 0x1a040
movl %eax, 0xc(%rsp)
jmp 0x82bd
movl 0xc(%rsp), %eax
cmpl $0x5, %eax
jne 0x839a
leaq 0x40(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x17e60
movq 0x30(%rsp), %rdi
movq (%rsp), %rcx
movl $0x3, 0x3c(%rsp)
leaq 0x5c(%rsp), %rsi
leaq 0xdc(%rsp), %rdx
leaq 0x3c(%rsp), %r8
callq 0x62b0
jmp 0x8302
leaq 0x40(%rsp), %rdi
callq 0x188e0
cmpq $0x3, %rax
jb 0x837c
movl 0xa4(%rsp), %ecx
movq 0xf0(%rsp), %rax
movl %ecx, (%rax)
movl 0xdc(%rsp), %ecx
movq 0xe8(%rsp), %rax
movl %ecx, (%rax)
movb $0x1, 0x107(%rsp)
movl $0x1, 0x38(%rsp)
jmp 0x8384
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x83cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x18520
jmp 0x83cc
movl $0x0, 0x38(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x18520
movl 0x38(%rsp), %eax
testl %eax, %eax
jne 0x83b3
jmp 0x8398
jmp 0x839a
jmp 0x839c
leaq 0x68(%rsp), %rdi
callq 0x1a160
jmp 0x826f
movl $0x0, 0x38(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x18520
movl 0x38(%rsp), %eax
testl %eax, %eax
jne 0x83fb
jmp 0x83ca
jmp 0x83db
leaq 0x80(%rsp), %rdi
callq 0x18520
jmp 0x8416
jmp 0x83dd
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0x8079
movl $0x0, 0x38(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x18520
movl 0x38(%rsp), %eax
testl %eax, %eax
je 0x8414
jmp 0x8412
jmp 0x8444
jmp 0x8425
leaq 0xc0(%rsp), %rdi
callq 0x18520
jmp 0x8455
movq 0x30(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x185f0
jmp 0x7fe9
movb $0x0, 0x107(%rsp)
movb 0x107(%rsp), %al
andb $0x1, %al
addq $0x108, %rsp            # imm = 0x108
retq
movq 0xb0(%rsp), %rdi
callq 0x2310
nopw %cs:(%rax,%rax)