// File: iPapatsoris[P]Maximum-Independent-Set/src/Graph.cpp
// Function: Graph::getEffectiveNodeOrOptimalFunnel(unsigned int&, unsigned int&, unsigned int&) const
bool Graph::getEffectiveNodeOrOptimalFunnel(uint32_t &effectiveNode, uint32_t &nodeV, uint32_t &nodeA) const {
    effectiveNode = nodeV = nodeA = NONE;
    uint32_t measure = getEffectiveNodeMeasure();
    vector<Funnel> funnels;
    Funnel fourFunnel;
    if (getFunnels(funnels, &measure, &effectiveNode, &fourFunnel)) {
        if (effectiveNode != NONE) {
            return true;
        } else {
            nodeV = fourFunnel.v;
            nodeA = fourFunnel.a;
            return true;
        }
    } else {
        for (uint32_t i = 0 ; i < 3 ; i++) {
            for (auto &funnel: funnels) {
                bool optimal = false;
                if (!i && getNodeDegree(funnel.a) >= 4 || i == 1 && isInTriangle(funnel.a)) {
                    optimal = true;
                }
                else if (i == 2) {
                    unordered_set<uint32_t> nodes;
                    nodes.insert(funnel.v);
                    nodes.insert(funnel.a);
                    unordered_set<uint32_t> neighbors;
                    gatherAllNeighbors(nodes, neighbors);
                    for (auto neighbor: neighbors) {
                        if (getNodeDegree(neighbor) >= 4) {
                            optimal = true;
                            break;
                        }
                    }
                } else if (i == 3) {
                    Graph newGraph = *this;
                    vector<uint32_t> neighborsA;
                    gatherNeighbors(funnel.a, neighborsA);
                    neighborsA.push_back(funnel.a);
                    ReduceInfo dummy;
                    newGraph.remove(neighborsA, dummy);
                    optimal = newGraph.isFineInstance();
                }
                if (optimal) {
                    nodeV = fourFunnel.v;
                    nodeA = fourFunnel.a;
                    return true;
                }
            }
        }
    }
}

// Assembly:
subq $0x238, %rsp            # imm = 0x238
movq %rdi, 0x228(%rsp)
movq %rsi, 0x220(%rsp)
movq %rdx, 0x218(%rsp)
movq %rcx, 0x210(%rsp)
movq 0x228(%rsp), %rdi
movq %rdi, 0x60(%rsp)
movq 0x210(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x218(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x220(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0xffffffff, 0x208(%rsp) # imm = 0xFFFFFFFF
leaq 0x208(%rsp), %rsi
callq 0x6a40
movl %eax, 0x20c(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x1a180
leaq 0x1dc(%rsp), %rdi
callq 0x1a190
jmp 0x6b69
movq 0x60(%rsp), %rdi
movq 0x220(%rsp), %rcx
leaq 0x1f0(%rsp), %rsi
leaq 0x20c(%rsp), %rdx
leaq 0x1dc(%rsp), %r8
callq 0x70c0
movb %al, 0x5f(%rsp)
jmp 0x6b99
movb 0x5f(%rsp), %al
testb $0x1, %al
jne 0x6ba3
jmp 0x6c1b
movq 0x220(%rsp), %rax
cmpl $-0x1, (%rax)
je 0x6be1
movb $0x1, 0x237(%rsp)
movl $0x1, 0x1c8(%rsp)
jmp 0x707e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
jmp 0x709c
movl 0x1ec(%rsp), %ecx
movq 0x218(%rsp), %rax
movl %ecx, (%rax)
movl 0x1dc(%rsp), %ecx
movq 0x210(%rsp), %rax
movl %ecx, (%rax)
movb $0x1, 0x237(%rsp)
movl $0x1, 0x1c8(%rsp)
jmp 0x707e
movl $0x0, 0x1c4(%rsp)
cmpl $0x3, 0x1c4(%rsp)
jae 0x707a
leaq 0x1f0(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x1a1c0
movq %rax, 0x1b0(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x1a1f0
movq %rax, 0x1a8(%rsp)
leaq 0x1b0(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x1a220
testb $0x1, %al
jne 0x6c8c
jmp 0x7062
leaq 0x1b0(%rsp), %rdi
callq 0x1a260
movq %rax, 0x1a0(%rsp)
movb $0x0, 0x19f(%rsp)
cmpl $0x0, 0x1c4(%rsp)
jne 0x6cd4
movq 0x60(%rsp), %rdi
movq 0x1a0(%rsp), %rsi
callq 0x1a040
movl %eax, 0x58(%rsp)
jmp 0x6ccb
movl 0x58(%rsp), %eax
cmpl $0x4, %eax
jae 0x6d00
cmpl $0x1, 0x1c4(%rsp)
jne 0x6d0d
movq 0x60(%rsp), %rdi
movq 0x1a0(%rsp), %rsi
callq 0x7bc0
movb %al, 0x57(%rsp)
jmp 0x6cf6
movb 0x57(%rsp), %al
testb $0x1, %al
jne 0x6d00
jmp 0x6d0d
movb $0x1, 0x19f(%rsp)
jmp 0x700d
cmpl $0x2, 0x1c4(%rsp)
jne 0x6ef3
leaq 0x160(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x1a020
movq 0x38(%rsp), %rdi
movq 0x1a0(%rsp), %rsi
addq $0x10, %rsi
callq 0x18960
movb %dl, 0x47(%rsp)
movq %rax, 0x48(%rsp)
jmp 0x6d4e
movb 0x47(%rsp), %al
movq 0x48(%rsp), %rcx
movq %rcx, 0x150(%rsp)
movb %al, 0x158(%rsp)
movq 0x1a0(%rsp), %rsi
leaq 0x160(%rsp), %rdi
callq 0x18960
movb %dl, 0x2f(%rsp)
movq %rax, 0x30(%rsp)
jmp 0x6d86
movb 0x2f(%rsp), %al
movq 0x30(%rsp), %rcx
movq %rcx, 0x140(%rsp)
movb %al, 0x148(%rsp)
leaq 0x108(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x1a020
movq 0x60(%rsp), %rdi
movq 0x20(%rsp), %rdx
movl $0xffffffff, 0x104(%rsp) # imm = 0xFFFFFFFF
leaq 0x160(%rsp), %rsi
leaq 0x104(%rsp), %rcx
callq 0x1a270
jmp 0x6ddc
leaq 0x108(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x19220
movq %rax, 0xf0(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x19250
movq %rax, 0xe8(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x19280
testb $0x1, %al
jne 0x6e34
jmp 0x6ec2
leaq 0xf0(%rsp), %rdi
callq 0x192a0
movq 0x60(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0xe4(%rsp)
leaq 0xe4(%rsp), %rsi
callq 0x1a040
movl %eax, 0x1c(%rsp)
jmp 0x6e62
movl 0x1c(%rsp), %eax
cmpl $0x4, %eax
jb 0x6eae
movb $0x1, 0x19f(%rsp)
jmp 0x6ec2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
jmp 0x6ee1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x1a030
jmp 0x6ee1
jmp 0x6eb0
leaq 0xf0(%rsp), %rdi
callq 0x192f0
jmp 0x6e16
leaq 0x108(%rsp), %rdi
callq 0x1a030
leaq 0x160(%rsp), %rdi
callq 0x1a030
jmp 0x700b
leaq 0x160(%rsp), %rdi
callq 0x1a030
jmp 0x709c
cmpl $0x3, 0x1c4(%rsp)
jne 0x7009
movq 0x60(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x2660
jmp 0x6f15
leaq 0x78(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x17e60
movq 0x60(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq 0x1a0(%rsp), %rsi
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
leaq 0x74(%rsp), %r8
callq 0x19c30
jmp 0x6f4e
movq 0x1a0(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x19070
jmp 0x6f62
leaq 0x70(%rsp), %rdi
callq 0x1a320
jmp 0x6f6e
movb $0x0, 0x6f(%rsp)
movb $0x0, 0x6e(%rsp)
xorl %eax, %eax
movl %eax, %r8d
leaq 0x90(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x6f(%rsp), %rcx
leaq 0x6e(%rsp), %r9
callq 0x189b0
jmp 0x6fa0
leaq 0x90(%rsp), %rdi
callq 0x7d00
movb %al, 0xf(%rsp)
jmp 0x6fb3
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0x19f(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x18520
leaq 0x90(%rsp), %rdi
callq 0x2990
jmp 0x7009
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x18520
leaq 0x90(%rsp), %rdi
callq 0x2990
jmp 0x709c
jmp 0x700b
jmp 0x700d
testb $0x1, 0x19f(%rsp)
je 0x704e
movl 0x1ec(%rsp), %ecx
movq 0x218(%rsp), %rax
movl %ecx, (%rax)
movl 0x1dc(%rsp), %ecx
movq 0x210(%rsp), %rax
movl %ecx, (%rax)
movb $0x1, 0x237(%rsp)
movl $0x1, 0x1c8(%rsp)
jmp 0x707e
jmp 0x7050
leaq 0x1b0(%rsp), %rdi
callq 0x1a340
jmp 0x6c6e
jmp 0x7064
movl 0x1c4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c4(%rsp)
jmp 0x6c26
jmp 0x707c
ud2
leaq 0x1f0(%rsp), %rdi
callq 0x1a360
movb 0x237(%rsp), %al
andb $0x1, %al
addq $0x238, %rsp            # imm = 0x238
retq
leaq 0x1f0(%rsp), %rdi
callq 0x1a360
movq 0x1d0(%rsp), %rdi
callq 0x2310
nopw %cs:(%rax,%rax)