// File: iPapatsoris[P]Maximum-Independent-Set/src/Alg.hpp
// Function: Alg::BranchingRule::choose(Graph const&, Reductions&, unsigned int&, Alg::SearchNode*)
void choose(const Graph &graph, Reductions &reductions, uint32_t &theta, SearchNode *searchNode) {
            uint32_t maxDegree = 0;
            uint32_t maxDegreeNode = NONE;
            graph.getMaxNodeDegree(maxDegreeNode, maxDegree);
            bool run = true;
            while (run) {
                //std::cout << "theta " << theta << " max degree " << maxDegree << "\n";
                run = false;
                switch (theta) {
                    case 8:
                    case 7:
                    case 6:
                        if (maxDegree > theta) {
                            type = Type::MAX_DEGREE;
                        } else if (maxDegree == theta) {
                            graph.getOptimalShortEdge(theta, node1, node2, container);
                            if (node1 != NONE) {
                                type = Type::SHORT_EDGE;
                                //std::cout << "optimal short edge " << node1 << " " << node2 << " with size " << container.size() << "\n";
                            } else {
                                type = Type::OPTNODE;
                                getOptimalNode(graph, theta);
                            }
                        } else {
                            theta = maxDegree;
                            if (theta < 3) {
                                theta = 3;
                            } else if (theta == 5 && searchNode->handleCuts()) {
                                return;
                            }
                            if (graph.nodeIndex.size()) {
                                reductions.run(theta);
                                graph.getMaxNodeDegree(maxDegreeNode, maxDegree);
                                run = true;
                            } else {
                                type = Type::DONE;
                            }
                        }
                        break;
                    case 5:
                        if (!maxDegree) {
                            type = Type::DONE;
                        } else if (maxDegree >= 6) {
                            type = Type::MAX_DEGREE;
                        } else if (graph.getGoodFunnelTheta5(node1, node2)) {
                            type = Type::GOOD_FUNNEL;
                        } else if (graph.getGoodPair(node1, node2, container)) {
                            type = Type::GOOD_PAIR;
                        } else if (maxDegree >= 5) {
                            node1 = graph.getOptimalDegree5Node();
                            type = Type::OPTNODE;
                        } else if (maxDegree < theta) {
                            theta = maxDegree;
                            if (theta < 3) {
                                theta = 3;
                            }
                            if (graph.nodeIndex.size()) {
                                reductions.run(theta);
                                graph.getMaxNodeDegree(maxDegreeNode, maxDegree);
                                run = true;
                            } else {
                                type = Type::DONE;
                            }
                        }
                        break;
                    case 4: {
                        type = Type::MAX_DEGREE;
                        if (maxDegree >= 5) {
                            uint32_t goodNode = graph.getGoodNode(reductions.getCCToNodes());
                            if (goodNode != NONE) {
                                maxDegreeNode = goodNode;
                            }
                        } else if (graph.getGoodFunnel(node1, node2)) {
                            type = Type::GOOD_FUNNEL;
                        } else if (graph.get4Cycle(container)) {
                            type = Type::FOUR_CYCLE;
                            //std::cout << "branching on optimal cycle " << container[0] << "-" << container[1] << "-" << container[2] << "-" << container[3] << "\n";
                        } else if (maxDegree == theta) {
                            node1 = graph.getOptimalDegree4Node();
                            assert(node1 != NONE);
                            type = Type::OPT4NODE;
                        }
                        else if (maxDegree < theta) {
                            theta = 3;
                            if (graph.nodeIndex.size()) {
                                reductions.run(theta);
                                graph.getMaxNodeDegree(maxDegreeNode, maxDegree);
                                run = true;
                            } else {
                                type = Type::DONE;
                            }
                        } else {
                            assert(false);
                        }
                        break;
                    }
                    case 3:
                        if (!maxDegree) {
                            type = Type::DONE;
                        }
                        else {
                            uint32_t effectiveNode = NONE;
                            uint32_t nodeV = NONE;
                            uint32_t nodeA = NONE;
                            graph.getEffectiveNodeOrOptimalFunnel(effectiveNode, nodeV, nodeA);
                            if (effectiveNode != NONE) {
                                node1 = effectiveNode;
                                type = Type::EFFECTIVE_NODE;
                            } else if (nodeV != NONE && nodeA != NONE) {
                                node1 = nodeA;
                                node2 = nodeV;
                                type = Type::GOOD_FUNNEL;
                            } else if (graph.get4CycleTheta3(container)) {
                                type = Type::FOUR_CYCLE;
                            }
                            else {
                                node1 = graph.getOptimalNodeTheta3(maxDegreeNode, maxDegree);
                                type = Type::MAX_DEGREE;
                            }
                        }
                        break;
                    case 0:
                        break;
                    default:
                        assert(false);
                }
            }
            if (type == Type::MAX_DEGREE) {
                node1 = maxDegreeNode;
            }
        }

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0xffffffff, 0x48(%rsp) # imm = 0xFFFFFFFF
movq 0x68(%rsp), %rdi
movl $0xffffffff, 0x44(%rsp) # imm = 0xFFFFFFFF
leaq 0x48(%rsp), %rsi
leaq 0x4c(%rsp), %rdx
leaq 0x44(%rsp), %rcx
callq 0x2aa0
movb $0x1, 0x43(%rsp)
testb $0x1, 0x43(%rsp)
je 0x3a9df
movb $0x0, 0x43(%rsp)
movq 0x58(%rsp), %rax
movl (%rax), %eax
movq %rax, 0x10(%rsp)
subq $0x8, %rax
ja 0x3a9bb
movq 0x10(%rsp), %rax
leaq 0xc519(%rip), %rcx      # 0x469e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x4c(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl (%rcx), %eax
jbe 0x3a4f5
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
jmp 0x3a5f8
movl 0x4c(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x3a55f
movq 0x18(%rsp), %r8
movq 0x68(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq %r8, %rdx
addq $0x4, %rdx
movq %r8, %rcx
addq $0x8, %rcx
addq $0x10, %r8
callq 0x92a0
movq 0x18(%rsp), %rax
cmpl $-0x1, 0x4(%rax)
je 0x3a540
movq 0x18(%rsp), %rax
movl $0x1, (%rax)
jmp 0x3a55a
movq 0x18(%rsp), %rdi
movl $0x2, (%rdi)
movq 0x68(%rsp), %rsi
movq 0x58(%rsp), %rdx
callq 0x3e9c0
jmp 0x3a5f6
movl 0x4c(%rsp), %ecx
movq 0x58(%rsp), %rax
movl %ecx, (%rax)
movq 0x58(%rsp), %rax
cmpl $0x3, (%rax)
jae 0x3a581
movq 0x58(%rsp), %rax
movl $0x3, (%rax)
jmp 0x3a5a2
movq 0x58(%rsp), %rax
cmpl $0x5, (%rax)
jne 0x3a5a0
movq 0x50(%rsp), %rdi
callq 0x39850
testb $0x1, %al
jne 0x3a59b
jmp 0x3a5a0
jmp 0x3a9f5
jmp 0x3a5a2
movq 0x68(%rsp), %rdi
callq 0x18830
cmpq $0x0, %rax
je 0x3a5e9
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x2e4f0
movq 0x68(%rsp), %rdi
movl $0xffffffff, 0x3c(%rsp) # imm = 0xFFFFFFFF
leaq 0x48(%rsp), %rsi
leaq 0x4c(%rsp), %rdx
leaq 0x3c(%rsp), %rcx
callq 0x2aa0
movb $0x1, 0x43(%rsp)
jmp 0x3a5f4
movq 0x18(%rsp), %rax
movl $0xb, (%rax)
jmp 0x3a5f6
jmp 0x3a5f8
jmp 0x3a9da
cmpl $0x0, 0x4c(%rsp)
jne 0x3a614
movq 0x18(%rsp), %rax
movl $0xb, (%rax)
jmp 0x3a743
cmpl $0x6, 0x4c(%rsp)
jb 0x3a62b
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
jmp 0x3a741
movq 0x18(%rsp), %rdx
movq 0x68(%rsp), %rdi
movq %rdx, %rsi
addq $0x4, %rsi
addq $0x8, %rdx
callq 0x7fb0
testb $0x1, %al
jne 0x3a64b
jmp 0x3a65b
movq 0x18(%rsp), %rax
movl $0x3, (%rax)
jmp 0x3a73f
movq 0x18(%rsp), %rcx
movq 0x68(%rsp), %rdi
movq %rcx, %rsi
addq $0x4, %rsi
movq %rcx, %rdx
addq $0x8, %rdx
addq $0x10, %rcx
callq 0x8470
testb $0x1, %al
jne 0x3a682
jmp 0x3a692
movq 0x18(%rsp), %rax
movl $0x4, (%rax)
jmp 0x3a73d
cmpl $0x5, 0x4c(%rsp)
jb 0x3a6b8
movq 0x68(%rsp), %rdi
callq 0x8670
movl %eax, %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x4(%rax)
movl $0x2, (%rax)
jmp 0x3a73b
movl 0x4c(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl (%rcx), %eax
jae 0x3a739
movl 0x4c(%rsp), %ecx
movq 0x58(%rsp), %rax
movl %ecx, (%rax)
movq 0x58(%rsp), %rax
cmpl $0x3, (%rax)
jae 0x3a6e5
movq 0x58(%rsp), %rax
movl $0x3, (%rax)
movq 0x68(%rsp), %rdi
callq 0x18830
cmpq $0x0, %rax
je 0x3a72c
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x2e4f0
movq 0x68(%rsp), %rdi
movl $0xffffffff, 0x38(%rsp) # imm = 0xFFFFFFFF
leaq 0x48(%rsp), %rsi
leaq 0x4c(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0x2aa0
movb $0x1, 0x43(%rsp)
jmp 0x3a737
movq 0x18(%rsp), %rax
movl $0xb, (%rax)
jmp 0x3a739
jmp 0x3a73b
jmp 0x3a73d
jmp 0x3a73f
jmp 0x3a741
jmp 0x3a743
jmp 0x3a9da
movq 0x18(%rsp), %rax
movl $0x0, (%rax)
cmpl $0x5, 0x4c(%rsp)
jb 0x3a793
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rdi
callq 0x3f070
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x8ec0
movl %eax, 0x34(%rsp)
cmpl $-0x1, 0x34(%rsp)
je 0x3a78e
movl 0x34(%rsp), %eax
movl %eax, 0x48(%rsp)
jmp 0x3a8d7
movq 0x18(%rsp), %rdx
movq 0x68(%rsp), %rdi
movq %rdx, %rsi
addq $0x4, %rsi
addq $0x8, %rdx
callq 0x7d80
testb $0x1, %al
jne 0x3a7b3
jmp 0x3a7c3
movq 0x18(%rsp), %rax
movl $0x3, (%rax)
jmp 0x3a8d5
movq 0x18(%rsp), %rsi
movq 0x68(%rsp), %rdi
addq $0x10, %rsi
callq 0x5d90
testb $0x1, %al
jne 0x3a7dc
jmp 0x3a7ec
movq 0x18(%rsp), %rax
movl $0x5, (%rax)
jmp 0x3a8d3
movl 0x4c(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x3a844
movq 0x68(%rsp), %rdi
callq 0x5190
movl %eax, %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x4(%rax)
cmpl $-0x1, 0x4(%rax)
je 0x3a815
jmp 0x3a834
leaq 0xc2e3(%rip), %rdi      # 0x46aff
leaq 0xc2ea(%rip), %rsi      # 0x46b0d
movl $0x78, %edx
leaq 0xc2ea(%rip), %rcx      # 0x46b19
callq 0x2110
movq 0x18(%rsp), %rax
movl $0x6, (%rax)
jmp 0x3a8d1
movl 0x4c(%rsp), %eax
movq 0x58(%rsp), %rcx
cmpl (%rcx), %eax
jae 0x3a8b0
movq 0x58(%rsp), %rax
movl $0x3, (%rax)
movq 0x68(%rsp), %rdi
callq 0x18830
cmpq $0x0, %rax
je 0x3a8a3
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x2e4f0
movq 0x68(%rsp), %rdi
movl $0xffffffff, 0x30(%rsp) # imm = 0xFFFFFFFF
leaq 0x48(%rsp), %rsi
leaq 0x4c(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x2aa0
movb $0x1, 0x43(%rsp)
jmp 0x3a8ae
movq 0x18(%rsp), %rax
movl $0xb, (%rax)
jmp 0x3a8cf
leaq 0xb8cf(%rip), %rdi      # 0x46186
leaq 0xc24f(%rip), %rsi      # 0x46b0d
movl $0x85, %edx
leaq 0xc24f(%rip), %rcx      # 0x46b19
callq 0x2110
jmp 0x3a8d1
jmp 0x3a8d3
jmp 0x3a8d5
jmp 0x3a8d7
jmp 0x3a9da
cmpl $0x0, 0x4c(%rsp)
jne 0x3a8f3
movq 0x18(%rsp), %rax
movl $0xb, (%rax)
jmp 0x3a9b7
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
movq 0x68(%rsp), %rdi
leaq 0x2c(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0x24(%rsp), %rcx
callq 0x6ad0
cmpl $-0x1, 0x2c(%rsp)
je 0x3a93f
movq 0x18(%rsp), %rax
movl 0x2c(%rsp), %ecx
movl %ecx, 0x4(%rax)
movl $0x7, (%rax)
jmp 0x3a9b5
cmpl $-0x1, 0x28(%rsp)
je 0x3a968
cmpl $-0x1, 0x24(%rsp)
je 0x3a968
movq 0x18(%rsp), %rax
movl 0x24(%rsp), %ecx
movl %ecx, 0x4(%rax)
movl 0x28(%rsp), %ecx
movl %ecx, 0x8(%rax)
movl $0x3, (%rax)
jmp 0x3a9b3
movq 0x18(%rsp), %rsi
movq 0x68(%rsp), %rdi
addq $0x10, %rsi
callq 0x6530
testb $0x1, %al
jne 0x3a981
jmp 0x3a98e
movq 0x18(%rsp), %rax
movl $0x5, (%rax)
jmp 0x3a9b1
movq 0x68(%rsp), %rdi
movl 0x48(%rsp), %esi
leaq 0x4c(%rsp), %rdx
callq 0x5060
movl %eax, %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x4(%rax)
movl $0x0, (%rax)
jmp 0x3a9b3
jmp 0x3a9b5
jmp 0x3a9b7
jmp 0x3a9da
jmp 0x3a9da
leaq 0xb7c4(%rip), %rdi      # 0x46186
leaq 0xc144(%rip), %rsi      # 0x46b0d
movl $0xa5, %edx
leaq 0xc144(%rip), %rcx      # 0x46b19
callq 0x2110
jmp 0x3a49d
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x3a9f5
movq 0x18(%rsp), %rax
movl 0x48(%rsp), %ecx
movl %ecx, 0x4(%rax)
addq $0x78, %rsp
retq
nopw (%rax,%rax)