// File: iPapatsoris[P]Maximum-Independent-Set/src/ControlUnit.cpp
// Function: ControlUnit::checkIndependentSet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) const
void ControlUnit::checkIndependentSet(const string &misInputFile) const {
    /* Build mis from input file */
    vector<uint32_t> mis;
    FILE *f;
    f = fopen(misInputFile.c_str(), "r");
    if (f == NULL) {
        cerr << "Error in opening MIS input file " << misInputFile << endl;
        exit(EXIT_FAILURE);
    }
    char buf[MAXLINE];
    if (fgets(buf, MAXLINE, f) == NULL) {
        cerr << "Error in parsing MIS input file " << misInputFile << endl;
        exit(EXIT_FAILURE);
    }
    while(fgets(buf, MAXLINE, f) != NULL) {
        uint32_t node = 0;
        for (uint32_t i = 0; buf[i] != ' ' && buf[i] != '\t' && buf[i] != '\n' ; i++) {
            node = node * 10 + (buf[i] - '0');
        }
        mis.push_back(node);
    }
    uint32_t node1, node2;
    unordered_set<uint32_t> set;
    for (auto node: mis) {
        if (!set.insert(node).second) {
            cout << "NOT a set! Node " << node << " exists more than once" << endl;
        }
    }

    bool independentSet = alg.getSearchTree()[0]->getGraph().isIndependentSet(mis, &node1, &node2);
    if (independentSet) {
        cout << "Valid independent set\n";
    } else {
        cout << "NOT an independent set!\nConflict between nodes " << node1 << " and " << node2 << endl;
    }
    fclose(f);
}

// Assembly:
subq $0x588, %rsp            # imm = 0x588
movq %rdi, 0x580(%rsp)
movq %rsi, 0x578(%rsp)
movq 0x580(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0x560(%rsp), %rdi
callq 0x17e60
movq 0x578(%rsp), %rdi
callq 0x20b0
movq %rax, %rdi
leaq 0x1909(%rip), %rsi      # 0x465c4
callq 0x2200
movq %rax, 0xa8(%rsp)
jmp 0x44cca
movq 0xa8(%rsp), %rax
movq %rax, 0x558(%rsp)
cmpq $0x0, 0x558(%rsp)
jne 0x44d5a
movq 0x19304(%rip), %rdi     # 0x5dff0
leaq 0x23cb(%rip), %rsi      # 0x470be
callq 0x2190
movq %rax, 0x98(%rsp)
jmp 0x44d02
movq 0x98(%rsp), %rdi
movq 0x578(%rsp), %rsi
callq 0x2170
movq %rax, 0x90(%rsp)
jmp 0x44d21
movq 0x90(%rsp), %rdi
movq 0x19288(%rip), %rsi     # 0x5dfb8
callq 0x21d0
jmp 0x44d37
movl $0x1, %edi
callq 0x2210
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x550(%rsp)
movl %eax, 0x54c(%rsp)
jmp 0x45181
movq 0x558(%rsp), %rdx
leaq 0x140(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x22e0
movq %rax, 0x88(%rsp)
jmp 0x44d7e
movq 0x88(%rsp), %rax
cmpq $0x0, %rax
jne 0x44de2
movq 0x1925d(%rip), %rdi     # 0x5dff0
leaq 0x2345(%rip), %rsi      # 0x470df
callq 0x2190
movq %rax, 0x80(%rsp)
jmp 0x44da9
movq 0x80(%rsp), %rdi
movq 0x578(%rsp), %rsi
callq 0x2170
movq %rax, 0x78(%rsp)
jmp 0x44dc5
movq 0x78(%rsp), %rdi
movq 0x191e7(%rip), %rsi     # 0x5dfb8
callq 0x21d0
jmp 0x44dd8
movl $0x1, %edi
callq 0x2210
jmp 0x44de4
movq 0x558(%rsp), %rdx
leaq 0x140(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x22e0
movq %rax, 0x70(%rsp)
jmp 0x44e05
movq 0x70(%rsp), %rax
cmpq $0x0, %rax
je 0x44ed6
movl $0x0, 0x13c(%rsp)
movl $0x0, 0x138(%rsp)
movl 0x138(%rsp), %eax
movsbl 0x140(%rsp,%rax), %ecx
xorl %eax, %eax
cmpl $0x20, %ecx
movb %al, 0x6f(%rsp)
je 0x44e77
movl 0x138(%rsp), %eax
movsbl 0x140(%rsp,%rax), %ecx
xorl %eax, %eax
cmpl $0x9, %ecx
movb %al, 0x6f(%rsp)
je 0x44e77
movl 0x138(%rsp), %eax
movsbl 0x140(%rsp,%rax), %eax
cmpl $0xa, %eax
setne %al
movb %al, 0x6f(%rsp)
movb 0x6f(%rsp), %al
testb $0x1, %al
jne 0x44e81
jmp 0x44eba
imull $0xa, 0x13c(%rsp), %eax
movl 0x138(%rsp), %ecx
movsbl 0x140(%rsp,%rcx), %ecx
subl $0x30, %ecx
addl %ecx, %eax
movl %eax, 0x13c(%rsp)
movl 0x138(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x138(%rsp)
jmp 0x44e2a
leaq 0x560(%rsp), %rdi
leaq 0x13c(%rsp), %rsi
callq 0x19070
jmp 0x44ed1
jmp 0x44de4
leaq 0xf8(%rsp), %rdi
callq 0x1a020
leaq 0x560(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x19b50
movq %rax, 0xe8(%rsp)
movq 0xf0(%rsp), %rdi
callq 0x1a0e0
movq %rax, 0xe0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x1a110
testb $0x1, %al
jne 0x44f3b
jmp 0x45052
leaq 0xe8(%rsp), %rdi
callq 0x1a150
movl (%rax), %eax
movl %eax, 0xdc(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xdc(%rsp), %rsi
callq 0x18960
movb %dl, 0x5f(%rsp)
movq %rax, 0x60(%rsp)
jmp 0x44f71
movb 0x5f(%rsp), %al
movq 0x60(%rsp), %rcx
movq %rcx, 0xb8(%rsp)
movb %al, 0xc0(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0xc8(%rsp)
movb 0xc0(%rsp), %al
movb %al, 0xd0(%rsp)
movb 0xd0(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x44fb9
jmp 0x4503e
movq 0x19010(%rip), %rdi     # 0x5dfd0
leaq 0x2139(%rip), %rsi      # 0x47100
callq 0x2190
movq %rax, 0x50(%rsp)
jmp 0x44fd3
movq 0x50(%rsp), %rdi
movl 0xdc(%rsp), %esi
callq 0x2230
movq %rax, 0x48(%rsp)
jmp 0x44feb
movq 0x48(%rsp), %rdi
leaq 0x211a(%rip), %rsi      # 0x47111
callq 0x2190
movq %rax, 0x40(%rsp)
jmp 0x45003
movq 0x40(%rsp), %rdi
movq 0x18fa9(%rip), %rsi     # 0x5dfb8
callq 0x21d0
jmp 0x45016
jmp 0x4503e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x550(%rsp)
movl %eax, 0x54c(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x1a030
jmp 0x45181
jmp 0x45040
leaq 0xe8(%rsp), %rdi
callq 0x1a160
jmp 0x44f1d
movq 0xa0(%rsp), %rdi
callq 0x451e0
movq %rax, 0x38(%rsp)
jmp 0x45066
movq 0x38(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x451f0
movq (%rax), %rdi
callq 0x45210
movq %rax, 0x30(%rsp)
jmp 0x45083
movq 0x30(%rsp), %rdi
leaq 0x560(%rsp), %rsi
leaq 0x134(%rsp), %rdx
leaq 0x130(%rsp), %rcx
callq 0x339f0
movb %al, 0x2f(%rsp)
jmp 0x450ab
movb 0x2f(%rsp), %al
andb $0x1, %al
movb %al, 0xb7(%rsp)
testb $0x1, 0xb7(%rsp)
je 0x450d9
movq 0x18f07(%rip), %rdi     # 0x5dfd0
leaq 0x2058(%rip), %rsi      # 0x47128
callq 0x2190
jmp 0x450d7
jmp 0x45150
movq 0x18ef0(%rip), %rdi     # 0x5dfd0
leaq 0x2058(%rip), %rsi      # 0x4713f
callq 0x2190
movq %rax, 0x20(%rsp)
jmp 0x450f3
movq 0x20(%rsp), %rdi
movl 0x134(%rsp), %esi
callq 0x2230
movq %rax, 0x18(%rsp)
jmp 0x4510b
movq 0x18(%rsp), %rdi
leaq 0x2058(%rip), %rsi      # 0x4716f
callq 0x2190
movq %rax, 0x10(%rsp)
jmp 0x45123
movq 0x10(%rsp), %rdi
movl 0x130(%rsp), %esi
callq 0x2230
movq %rax, 0x8(%rsp)
jmp 0x4513b
movq 0x8(%rsp), %rdi
movq 0x18e71(%rip), %rsi     # 0x5dfb8
callq 0x21d0
jmp 0x4514e
jmp 0x45150
movq 0x558(%rsp), %rdi
callq 0x21a0
jmp 0x4515f
leaq 0xf8(%rsp), %rdi
callq 0x1a030
leaq 0x560(%rsp), %rdi
callq 0x18520
addq $0x588, %rsp            # imm = 0x588
retq
leaq 0x560(%rsp), %rdi
callq 0x18520
movq 0x550(%rsp), %rdi
callq 0x2310
nopl (%rax,%rax)