// File: /workspace/github_cpp_makefile_star2_O2/iPapatsoris[P]Maximum-Independent-Set/src/Alg.cpp
// Function: Alg::run()
void Alg::run() {
    uint32_t searchNodes = 1;
    uint32_t minCompletedSearchNode = NONE;
    bool down = true;
    uint32_t i = 0;
    while(true) {
        if (down) {
            if (searchTree[i]->theta == 5 && !searchTree[i]->hasCut && searchTree[i]->handleCuts()) {
                ;
            } else {
                searchTree[i]->reductions->run(searchTree[i]->theta);
                //cout << "search node " << searchNodes ;
                searchTree[i]->branchingRule.choose(searchTree[i]->graph, *(searchTree[i]->reductions), searchTree[i]->theta, searchTree[i]);
            }
        } else if (searchTree[i]->rightChild == NONE) {
            down = true;
            assert(searchTree[i]->branchingRule.type != BranchingRule::Type::DONE);
        }
        if (down && searchTree[i]->branchingRule.type == BranchingRule::Type::DONE) {
            searchTree[i]->id = searchNodeID++;
            searchTree[i]->finalMis = new vector<uint32_t>();
            searchTree[i]->mis.unfoldHypernodes(searchTree[i]->graph.zeroDegreeNodes, *searchTree[i]->finalMis);
            i = searchTree[i]->parent;
            if (i == NONE) {
                break;
            }
            down = false;
            continue;
        }
        uint32_t *nextChild;
        if (searchTree[i]->leftChild == NONE) {
            nextChild = &searchTree[i]->leftChild;
        } else if (searchTree[i]->rightChild == NONE) {
            nextChild = &searchTree[i]->rightChild;
        } else if (searchTree[i]->hasCut && !searchTree[i]->cutIsDone) {
            chooseCutBranch(searchTree[i]);
            nextChild = &searchTree[i]->rightChild;
            down = true;
        } else {
            if (i < minCompletedSearchNode) {
                minCompletedSearchNode = i;
                cout << i << endl;
            }
            SearchNode *parent = searchTree[i];
            if (parent->hasCut) {
                assert(parent->cutIsDone);
                concatMis(parent);
                //cout << "concating mis" << endl;
            } else {
                chooseMaxMis(parent);
            }
            i = parent->parent;
            if (searchTree.size() == 1) {
                break;
            }
            continue;
        }
        SearchNode *searchNode = new SearchNode(*searchTree[i], i);
        searchNodes++;
        searchTree.push_back(searchNode);
        *nextChild = searchTree.size() - 1;
        if (nextChild == &searchTree[i]->leftChild) {
            branchLeft(searchTree[i]->branchingRule, searchNode, searchTree[i]->mis);
        }
        else if (nextChild == &searchTree[i]->rightChild) {
            branchRight(searchTree[i]->branchingRule, searchNode, searchTree[i]->mis);
        }
        else {
            assert(false);
        }
        i = *nextChild;
    }
    cout << searchNodes << " search nodes\n";
    searchTree[0]->graph.collectZeroDegreeNodes();
    //cout << "Final id " << searchTree[0]->id;
    Mis::print(*searchTree[0]->finalMis);
    delete searchTree[0]->finalMis;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x4(%rsp), %rax
andl $0x0, (%rax)
pushq $0x1
popq %rax
movl %eax, 0xc(%rsp)
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
movb $0x1, %r14b
xorl %r12d, %r12d
pushq $0x18
popq %r13
movl %r12d, %ebp
movq (%rbx), %r15
movq (%r15,%rbp,8), %rsi
testb $0x1, %r14b
je 0x11c17
cmpl $0x5, 0x4(%rsi)
jne 0x11b6d
cmpb $0x0, 0x128(%rsi)
jne 0x11b6d
movq %rsi, %rdi
callq 0x11e90
movq (%rbx), %r15
testb %al, %al
jne 0x11b9f
movq (%r15,%rbp,8), %rsi
movq 0x108(%rsi), %rdi
addq $0x4, %rsi
callq 0xdf4c
movq (%rbx), %rax
movq (%rax,%rbp,8), %r8
leaq 0x8(%r8), %rdi
leaq 0x30(%r8), %rsi
movq 0x108(%r8), %rdx
leaq 0x4(%r8), %rcx
callq 0x123f4
movq (%rbx), %r15
movq (%r15,%rbp,8), %rax
cmpl $0xb, 0x8(%rax)
jne 0x11c2d
movl 0x105ed(%rip), %ecx     # 0x221a0
leal 0x1(%rcx), %edx
movl %edx, 0x105e4(%rip)     # 0x221a0
movl %ecx, (%rax)
movq %r13, %rdi
callq 0x2190
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq (%r15,%rbp,8), %rcx
movq %rax, 0x120(%rcx)
movq (%r15,%rbp,8), %rsi
leaq 0x80(%rsi), %rdi
movq 0x120(%rsi), %rdx
addq $0x50, %rsi
callq 0x14b5a
movq (%rbx), %rax
movq (%rax,%rbp,8), %rax
movl 0x110(%rax), %r12d
xorl %r14d, %r14d
cmpl $-0x1, %r12d
jne 0x11b37
jmp 0x11dbd
cmpl $-0x1, 0x118(%rsi)
jne 0x11c2d
movb $0x1, %r14b
cmpl $0xb, 0x8(%rsi)
je 0x11e47
movl %r12d, 0x4(%rsp)
movq (%r15,%rbp,8), %r13
cmpl $-0x1, 0x114(%r13)
je 0x11cec
cmpl $-0x1, 0x118(%r13)
je 0x11d14
movb 0x128(%r13), %al
cmpb $0x1, %al
jne 0x11c6b
cmpb $0x0, 0x199(%r13)
je 0x11cf5
cmpl 0x8(%rsp), %r12d
jae 0x11c9c
movq 0x10357(%rip), %rdi     # 0x21fd0
movq %rbp, %rsi
callq 0x2110
movq %rax, %rdi
callq 0x20a0
movq (%rbx), %rax
movq (%rax,%rbp,8), %r13
movb 0x128(%r13), %al
movl %r12d, 0x8(%rsp)
testb $0x1, %al
je 0x11cbb
cmpb $0x0, 0x199(%r13)
je 0x11e64
movq %rbx, %rdi
movq %r13, %rsi
callq 0x128d8
jmp 0x11cc6
movq %rbx, %rdi
movq %r13, %rsi
callq 0x12a48
movl 0x110(%r13), %r12d
movl %r12d, 0x4(%rsp)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cmpq $0x8, %rax
pushq $0x18
popq %r13
jne 0x11b37
jmp 0x11dbd
addq $0x114, %r13            # imm = 0x114
jmp 0x11d1b
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1280c
movq (%rbx), %r15
movq (%r15,%rbp,8), %r13
movl $0x118, %eax            # imm = 0x118
addq %rax, %r13
movb $0x1, %r14b
jmp 0x11d1b
addq $0x118, %r13            # imm = 0x118
movl $0x1a0, %edi            # imm = 0x1A0
callq 0x2190
movq %rax, %r12
movq (%r15,%rbp,8), %rsi
movq %rax, %rdi
leaq 0x4(%rsp), %rdx
callq 0x11850
movq %r12, 0x10(%rsp)
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0x12316
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
decl %ecx
movl %ecx, (%r13)
movq (%rax,%rbp,8), %rcx
leaq 0x114(%rcx), %rax
cmpq %rax, %r13
je 0x11d96
leaq 0x118(%rcx), %rax
cmpq %rax, %r13
jne 0x11e2e
leaq 0x8(%rcx), %rsi
movq 0x10(%rsp), %rdx
subq $-0x80, %rcx
movq %rbx, %rdi
callq 0x12e7a
jmp 0x11dab
leaq 0x8(%rcx), %rsi
movq 0x10(%rsp), %rdx
subq $-0x80, %rcx
movq %rbx, %rdi
callq 0x12b52
incl 0xc(%rsp)
movl (%r13), %r12d
movl %r12d, 0x4(%rsp)
jmp 0x11b33
movl 0xc(%rsp), %esi
movq 0x10208(%rip), %rdi     # 0x21fd0
callq 0x2110
leaq 0x5cd2(%rip), %rsi      # 0x17aa6
movq %rax, %rdi
callq 0x2170
movq (%rbx), %rax
movq (%rax), %rdi
addq $0x30, %rdi
callq 0x608e
movq (%rbx), %rax
movq (%rax), %rax
movq 0x120(%rax), %rdi
callq 0x14cce
movq (%rbx), %rax
movq (%rax), %rax
movq 0x120(%rax), %rbx
testq %rbx, %rbx
je 0x11e17
movq %rbx, %rdi
callq 0xb872
movq %rbx, %rdi
callq 0x2160
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5ab3(%rip), %rdi      # 0x178e8
leaq 0x5c3c(%rip), %rsi      # 0x17a78
leaq 0x5c41(%rip), %rcx      # 0x17a84
pushq $0x6f
jmp 0x11e5e
leaq 0x5beb(%rip), %rdi      # 0x17a39
leaq 0x5c23(%rip), %rsi      # 0x17a78
leaq 0x5c28(%rip), %rcx      # 0x17a84
pushq $0x3b
popq %rdx
callq 0x2100
leaq 0x5c29(%rip), %rdi      # 0x17a94
leaq 0x5c06(%rip), %rsi      # 0x17a78
leaq 0x5c0b(%rip), %rcx      # 0x17a84
pushq $0x58
jmp 0x11e5e
movq %rax, %rbx
movq %r12, %rdi
callq 0x2160
movq %rbx, %rdi
callq 0x22c0