// File: iPapatsoris[P]Maximum-Independent-Set/src/Graph.cpp
// Function: Graph::getGoodNode(std::vector<Graph::Traversal*, std::allocator<Graph::Traversal*>>&, std::unordered_set<unsigned int, std::hash<unsigned int>, std::equal_to<unsigned int>, std::allocator<unsigned int>>&, std::vector<unsigned int, std::allocator<unsigned int>>&, unsigned int const&) const
uint32_t Graph::getGoodNode(vector<Traversal *> &frontier, unordered_set<uint32_t> &set, vector<uint32_t> &nodes, const uint32_t &size) const {
    Traversal *traversal = frontier[0];
    if (traversal->index == NONE) {
        return NONE;
    }
    while (true) {
        auto it = traversal->set.begin();
        std::advance(it, traversal->index);
        uint32_t neighbor = *it;
        if (set.find(neighbor) == set.end()) {
            frontier.push_back(new Traversal(neighbor, *this, frontier[frontier.size()-1]));
            set.insert(neighbor);
            traversal = frontier[frontier.size()-1];

            if (set.size() == size) {
                unordered_set<uint32_t> neighbors;
                gatherAllNeighbors(set, neighbors, 3);
                if (neighbors.size() == 3) {
                    return *(neighbors.begin());
                } else {
                    delete traversal;
                    frontier.pop_back();
                    set.erase(neighbor);
                    if (!advance(frontier, &traversal, *this, set)) {
                        return NONE;
                    }
                }
            }
        } else {
            if (!advance(frontier, &traversal, *this, set)) {
                return NONE;
            }
        }
    }
    return true;
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x108(%rsp)
movq %rsi, 0x100(%rsp)
movq %rdx, 0xf8(%rsp)
movq %rcx, 0xf0(%rsp)
movq %r8, 0xe8(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x100(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1a600
movq (%rax), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rax
cmpl $-0x1, 0x30(%rax)
jne 0x8f46
movl $0xffffffff, 0x114(%rsp) # imm = 0xFFFFFFFF
jmp 0x927d
jmp 0x8f48
movq 0xe0(%rsp), %rdi
callq 0x197f0
movq %rax, 0xd8(%rsp)
movq 0xe0(%rsp), %rax
movl 0x30(%rax), %esi
leaq 0xd8(%rsp), %rdi
callq 0x1a620
leaq 0xd8(%rsp), %rdi
callq 0x1a670
movl (%rax), %eax
movl %eax, 0xd4(%rsp)
movq 0xf8(%rsp), %rdi
leaq 0xd4(%rsp), %rsi
callq 0x192c0
movq %rax, 0xc8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x19250
movq %rax, 0xc0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x1a690
testb $0x1, %al
jne 0x8fdb
jmp 0x9243
movq 0x100(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x38, %edi
callq 0x21b0
movq %rax, 0x38(%rsp)
movq %rax, 0x28(%rsp)
movq 0x100(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x1a6e0
movq 0x30(%rsp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x1a600
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rdx
movq (%rax), %rcx
leaq 0xd4(%rsp), %rsi
callq 0x1a700
jmp 0x903a
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0xb8(%rsp), %rsi
callq 0x1a6b0
movq 0xf8(%rsp), %rdi
leaq 0xd4(%rsp), %rsi
callq 0x18960
movq %rax, 0x98(%rsp)
movb %dl, 0xa0(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x100(%rsp), %rdi
callq 0x1a6e0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x1a600
movq (%rax), %rax
movq %rax, 0xe0(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x191e0
movq 0xe8(%rsp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jne 0x9241
leaq 0x60(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x1a020
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq 0xf8(%rsp), %rsi
movl $0x3, 0x5c(%rsp)
leaq 0x5c(%rsp), %rcx
callq 0x1a270
jmp 0x9108
leaq 0x60(%rsp), %rdi
callq 0x191e0
cmpq $0x3, %rax
jne 0x918d
leaq 0x60(%rsp), %rdi
callq 0x19220
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x192a0
movl (%rax), %eax
movl %eax, 0x114(%rsp)
movl $0x1, 0x4c(%rsp)
jmp 0x9229
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
callq 0x2180
jmp 0x928c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x1a030
jmp 0x928c
movq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x91b4
movq 0x8(%rsp), %rdi
callq 0x1a860
movq 0x8(%rsp), %rdi
callq 0x2180
movq 0x100(%rsp), %rdi
callq 0x1a870
movq 0xf8(%rsp), %rdi
leaq 0xd4(%rsp), %rsi
callq 0x1a890
jmp 0x91d8
movq 0x40(%rsp), %rdx
movq 0x100(%rsp), %rdi
movq 0xf8(%rsp), %rcx
leaq 0xe0(%rsp), %rsi
callq 0x1a8c0
movb %al, 0x7(%rsp)
jmp 0x9200
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x921f
jmp 0x920a
movl $0xffffffff, 0x114(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x4c(%rsp)
jmp 0x9229
jmp 0x9221
movl $0x0, 0x4c(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x1a030
movl 0x4c(%rsp), %eax
testl %eax, %eax
je 0x923f
jmp 0x923d
jmp 0x927d
jmp 0x9241
jmp 0x9278
movq 0x40(%rsp), %rdx
movq 0x100(%rsp), %rdi
movq 0xf8(%rsp), %rcx
leaq 0xe0(%rsp), %rsi
callq 0x1a8c0
testb $0x1, %al
jne 0x9276
movl $0xffffffff, 0x114(%rsp) # imm = 0xFFFFFFFF
jmp 0x927d
jmp 0x9278
jmp 0x8f48
movl 0x114(%rsp), %eax
addq $0x118, %rsp            # imm = 0x118
retq
movq 0xb0(%rsp), %rdi
callq 0x2310
nopl (%rax)