// File: iPapatsoris[P]Maximum-Independent-Set/src/Reductions.cpp
// Function: Reductions::findMis(std::vector<unsigned int, std::allocator<unsigned int>> const&)
void Reductions::findMis(const vector<uint32_t> &cc) {
    vector<uint32_t> independentSet;
    vector<uint32_t> maximumIndependentSet;
    vector<uint32_t> frontier; // cc array indexes
    vector<unordered_set<uint32_t> > removedNodes;
    frontier.push_back(0);
    removedNodes.push_back(unordered_set<uint32_t>());
    while (frontier.size()) {
        uint32_t node = cc[frontier.back()];
        Graph::GraphTraversal graphTraversal(graph, node);
        while (graphTraversal.curEdgeOffset != NONE) {
            removedNodes.back().insert((*graph.edgeBuffer)[graphTraversal.curEdgeOffset]);
            graph.getNextEdge(graphTraversal);
        }
        uint32_t newNode = NONE;
        uint32_t newIndex;
        bool found = false;
        for (newIndex = frontier.back()+1 ; newIndex < cc.size() ; newIndex++) {
            if (cc.size() - newIndex + frontier.size() <= maximumIndependentSet.size()) {
                break;
            }
            newNode = cc[newIndex];
            if (removedNodes.back().find(newNode) == removedNodes.back().end()) {
                found = true;
                break;
            }
        }
        if (found) {
            frontier.push_back(newIndex);
            removedNodes.push_back(removedNodes.back());
        } else {
            if (frontier.size() > maximumIndependentSet.size()) {
                maximumIndependentSet = frontier;
            }
            while (frontier.size()) {
                newIndex = frontier.back() + 1;
                frontier.pop_back();
                removedNodes.pop_back();
                found = false;
                for (; newIndex < cc.size() ; newIndex++) {
                    if (cc.size() - newIndex + frontier.size() <= maximumIndependentSet.size()) {
                        break;
                    }
                    newNode = cc[newIndex];
                    if (!removedNodes.size() || removedNodes.size() && removedNodes.back().find(newNode) == removedNodes.back().end()) {
                        found = true;
                        break;
                    }
                }
                if (found) {
                    frontier.push_back(newIndex);
                    removedNodes.push_back((removedNodes.size() ? removedNodes.back() : unordered_set<uint32_t>()));
                    break;
                }
            }
        }
    }
    vector<uint32_t> &mis = this->mis.getMis();
    for (auto &i: maximumIndependentSet) {
        mis.push_back(cc[i]);
    }
}

// Assembly:
subq $0x218, %rsp            # imm = 0x218
movq %rdi, 0x210(%rsp)
movq %rsi, 0x208(%rsp)
movq 0x210(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x17e60
leaq 0x1d8(%rsp), %rdi
callq 0x17e60
leaq 0x1c0(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x17e60
leaq 0x1a8(%rsp), %rdi
callq 0x337d0
movq 0x98(%rsp), %rdi
movl $0x0, 0x1a4(%rsp)
leaq 0x1a4(%rsp), %rsi
callq 0x1b870
jmp 0x318f5
xorps %xmm0, %xmm0
movaps %xmm0, 0x170(%rsp)
movaps %xmm0, 0x160(%rsp)
movaps %xmm0, 0x150(%rsp)
movq $0x0, 0x180(%rsp)
leaq 0x150(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x1a020
movq 0x88(%rsp), %rsi
leaq 0x1a8(%rsp), %rdi
callq 0x337e0
jmp 0x31948
leaq 0x150(%rsp), %rdi
callq 0x1a030
leaq 0x1c0(%rsp), %rdi
callq 0x188e0
cmpq $0x0, %rax
je 0x31f1a
movq 0x208(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x1ad00
movq 0x80(%rsp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x1b780
movq %rax, %rcx
movq 0x90(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0x14c(%rsp)
movq (%rax), %rsi
leaq 0x144(%rsp), %rdi
leaq 0x14c(%rsp), %rdx
callq 0x2a70
jmp 0x319c8
jmp 0x319ca
cmpl $-0x1, 0x148(%rsp)
je 0x31a98
leaq 0x1a8(%rsp), %rdi
callq 0x33810
movq %rax, %rcx
movq 0x90(%rsp), %rax
movq %rcx, 0x68(%rsp)
movq (%rax), %rax
movq 0x18(%rax), %rdi
movl 0x148(%rsp), %eax
movl %eax, %esi
callq 0x18900
movq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0x18960
movb %dl, 0x77(%rsp)
movq %rax, 0x78(%rsp)
jmp 0x31a22
movq 0x90(%rsp), %rax
movb 0x77(%rsp), %cl
movq 0x78(%rsp), %rdx
movq %rdx, 0x130(%rsp)
movb %cl, 0x138(%rsp)
movq (%rax), %rdi
leaq 0x144(%rsp), %rsi
callq 0x19560
jmp 0x31a54
jmp 0x319ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x32029
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x1a030
jmp 0x32029
movl $0xffffffff, 0x12c(%rsp) # imm = 0xFFFFFFFF
movb $0x0, 0x127(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x1ad00
movl (%rax), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
movl 0x128(%rsp), %eax
movq %rax, 0x60(%rsp)
movq 0x208(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0x60(%rsp), %rax
cmpq %rcx, %rax
jae 0x31bf0
movq 0x208(%rsp), %rdi
callq 0x188e0
movl 0x128(%rsp), %ecx
subq %rcx, %rax
movq %rax, 0x50(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0x50(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x58(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0x58(%rsp), %rax
cmpq %rcx, %rax
ja 0x31b46
jmp 0x31bf0
movq 0x208(%rsp), %rdi
movl 0x128(%rsp), %eax
movl %eax, %esi
callq 0x1b780
movl (%rax), %eax
movl %eax, 0x12c(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x33810
movq %rax, %rdi
leaq 0x12c(%rsp), %rsi
callq 0x192c0
movq %rax, 0x48(%rsp)
jmp 0x31b89
movq 0x48(%rsp), %rax
movq %rax, 0x118(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x33810
movq %rax, %rdi
callq 0x19250
movq %rax, 0x110(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x1a690
testb $0x1, %al
jne 0x31bce
jmp 0x31bd8
movb $0x1, 0x127(%rsp)
jmp 0x31bf0
jmp 0x31bda
movl 0x128(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
jmp 0x31ac4
testb $0x1, 0x127(%rsp)
je 0x31c37
leaq 0x1c0(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x19070
jmp 0x31c11
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x33810
movq 0x40(%rsp), %rdi
movq %rax, %rsi
callq 0x33850
jmp 0x31c32
jmp 0x31f15
leaq 0x1c0(%rsp), %rdi
callq 0x188e0
movq %rax, 0x38(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jbe 0x31c7c
leaq 0x1d8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x18130
jmp 0x31c7a
jmp 0x31c7c
jmp 0x31c7e
leaq 0x1c0(%rsp), %rdi
callq 0x188e0
cmpq $0x0, %rax
je 0x31f13
leaq 0x1c0(%rsp), %rdi
callq 0x1ad00
movl (%rax), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x1ad40
leaq 0x1a8(%rsp), %rdi
callq 0x338c0
movb $0x0, 0x127(%rsp)
movl 0x128(%rsp), %eax
movq %rax, 0x30(%rsp)
movq 0x208(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0x30(%rsp), %rax
cmpq %rcx, %rax
jae 0x31e48
movq 0x208(%rsp), %rdi
callq 0x188e0
movl 0x128(%rsp), %ecx
subq %rcx, %rax
movq %rax, 0x20(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0x20(%rsp), %rax
addq %rcx, %rax
movq %rax, 0x28(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0x188e0
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
ja 0x31d52
jmp 0x31e48
movq 0x208(%rsp), %rdi
movl 0x128(%rsp), %eax
movl %eax, %esi
callq 0x1b780
movl (%rax), %eax
movl %eax, 0x12c(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x338e0
movq %rax, %rcx
movb $0x1, %al
cmpq $0x0, %rcx
movb %al, 0x1f(%rsp)
je 0x31e1c
leaq 0x1a8(%rsp), %rdi
callq 0x338e0
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, 0x1e(%rsp)
je 0x31e14
leaq 0x1a8(%rsp), %rdi
callq 0x33810
movq %rax, %rdi
leaq 0x12c(%rsp), %rsi
callq 0x192c0
movq %rax, 0x10(%rsp)
jmp 0x31dd1
movq 0x10(%rsp), %rax
movq %rax, 0x108(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x33810
movq %rax, %rdi
callq 0x19250
movq %rax, 0x100(%rsp)
leaq 0x108(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x1a690
movb %al, 0x1e(%rsp)
movb 0x1e(%rsp), %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x31e26
jmp 0x31e30
movb $0x1, 0x127(%rsp)
jmp 0x31e48
jmp 0x31e32
movl 0x128(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
jmp 0x31cd0
testb $0x1, 0x127(%rsp)
je 0x31f0e
leaq 0x1c0(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x19070
jmp 0x31e6d
leaq 0x1a8(%rsp), %rdi
callq 0x338e0
cmpq $0x0, %rax
je 0x31ea1
leaq 0x1a8(%rsp), %rdi
callq 0x33810
movq %rax, %rsi
leaq 0xc8(%rsp), %rdi
callq 0x33900
jmp 0x31e9f
jmp 0x31ec2
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x20e0
leaq 0xc8(%rsp), %rdi
callq 0x1a020
leaq 0x1a8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x337e0
jmp 0x31ed9
leaq 0xc8(%rsp), %rdi
callq 0x1a030
jmp 0x31f13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x1a030
jmp 0x32029
jmp 0x31c7e
jmp 0x31f15
jmp 0x31955
movq 0x90(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x33930
movq %rax, 0x8(%rsp)
jmp 0x31f32
movq 0x8(%rsp), %rax
movq %rax, 0xc0(%rsp)
leaq 0x1d8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x19b50
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x1a0e0
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x1a110
testb $0x1, %al
jne 0x31f94
jmp 0x31fed
leaq 0xb0(%rsp), %rdi
callq 0x1a150
movq %rax, 0xa0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, (%rsp)
movq 0x208(%rsp), %rdi
movq 0xa0(%rsp), %rax
movl (%rax), %eax
movl %eax, %esi
callq 0x1b780
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x19070
jmp 0x31fdc
jmp 0x31fde
leaq 0xb0(%rsp), %rdi
callq 0x1a160
jmp 0x31f79
leaq 0x1a8(%rsp), %rdi
callq 0x33940
leaq 0x1c0(%rsp), %rdi
callq 0x18520
leaq 0x1d8(%rsp), %rdi
callq 0x18520
leaq 0x1f0(%rsp), %rdi
callq 0x18520
addq $0x218, %rsp            # imm = 0x218
retq
leaq 0x1a8(%rsp), %rdi
callq 0x33940
leaq 0x1c0(%rsp), %rdi
callq 0x18520
leaq 0x1d8(%rsp), %rdi
callq 0x18520
leaq 0x1f0(%rsp), %rdi
callq 0x18520
movq 0x198(%rsp), %rdi
callq 0x2310
nopw (%rax,%rax)