// File: /workspace/github_cpp_makefile_star2_O2/Manca[P]algorithms2/./assignment6.hpp
// Function: assignment6::Check2SAT(std::unordered_map<int, std::vector<int, std::allocator<int>>, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, std::vector<int, std::allocator<int>>>>>&, std::unordered_map<int, std::vector<int, std::allocator<int>>, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, std::vector<int, std::allocator<int>>>>>&)
bool Check2SAT(Graph& G, Graph& GRev)
    {
        // Kosaraju SCC Algorithm
        // step 1: while stack size less than graph size
        // push elements according to their finish times
        while (_S.size() < G.size())
        {
            for (auto element : G)
            {
                // if not found in stack (not explored), let's DFS
                if (!_explored[element.first])
                {
                    DFSFillStack(G, element.first);
                }
            }
        }
        
        _explored.clear();
        std::vector<std::vector<int>> allSCC;

        // step 2: pop elements from stack and DFS
        // on transposed graph
        while (!_S.empty())
        {
            int el = _S.top();
            _S.pop();
            if (_explored[el])
                continue;

            std::vector<int> scc;
            DFSSCC(GRev, el, scc);
            allSCC.push_back(scc);
        }

        // Prints SCCs on reversed graph
        /*  for (auto vec : allSCC)
        {
        for (int el : vec)
        std::cout << " " << el;
        std::cout << std::endl;
        }*/

        // step 3: added step for 2SAT problem
        // if we find X and not X in SCC then
        // 2SAT is unsatisfiable
        for (auto vec : allSCC)
        {
            for (int i = 0; i < vec.size(); i++)
            {
                for (int j = 0; j < vec.size(); j++)
                    if (vec[i] == -vec[j])
                    {
                        return false;
                    }
            }
        }
        return true;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, 0x50(%rsp)
movq %rdi, %r15
leaq 0x10(%rdi), %r12
leaq 0x38(%rsp), %r14
leaq 0x30(%rsp), %r13
leaq 0x10c0d(%rip), %rbp     # 0x162c8
leaq 0x10bb6(%rip), %rdi     # 0x16278
callq 0xc5ea
cmpq 0x18(%r15), %rax
jae 0x570a
movq %r12, %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x56bb
leaq 0x8(%rbx), %rsi
movq %r13, %rdi
callq 0x7956
movq %rbp, %rdi
movq %r13, %rsi
callq 0xa62a
cmpb $0x0, (%rax)
jne 0x5700
movl 0x30(%rsp), %esi
movq %r15, %rdi
callq 0x556e
movq %r14, %rdi
callq 0x9cda
jmp 0x56d0
leaq 0x10bb7(%rip), %r14     # 0x162c8
movq %r14, %rdi
callq 0x8b4c
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
leaq 0x10b47(%rip), %r12     # 0x16278
leaq 0xc(%rsp), %r13
leaq 0x10(%rsp), %rbp
movq 0x50(%rsp), %rbx
movq 0x10b61(%rip), %rax     # 0x162a8
cmpq 0x10b3a(%rip), %rax     # 0x16288
je 0x57bd
cmpq 0x10b59(%rip), %rax     # 0x162b0
jne 0x576c
movq 0x10b60(%rip), %rax     # 0x162c0
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movl -0x4(%rax), %eax
movl %eax, 0xc(%rsp)
movq %r12, %rdi
callq 0xc776
movq %r14, %rdi
movq %r13, %rsi
callq 0xa62a
cmpb $0x0, (%rax)
jne 0x5740
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movl 0xc(%rsp), %esi
movq %rbx, %rdi
movq %rbp, %rdx
callq 0x5600
movq %r15, %rdi
movq %rbp, %rsi
callq 0x7968
movq %rbp, %rdi
callq 0x9cda
jmp 0x5740
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r15
leaq 0x10(%rsp), %r14
cmpq %r15, %rbx
je 0x5829
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7994
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
xorl %edx, %edx
cmpq %rcx, %rdx
je 0x5811
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x580c
movl (%rax,%rdx,4), %edi
leaq 0x1(%rsi), %r8
addl (%rax,%rsi,4), %edi
movq %r8, %rsi
jne 0x57f6
jmp 0x581f
incq %rdx
jmp 0x57ef
movq %r14, %rdi
callq 0x9cda
addq $0x18, %rbx
jmp 0x57cc
leaq 0x10(%rsp), %rdi
callq 0x9cda
cmpq %r15, %rbx
sete %bl
leaq 0x30(%rsp), %rdi
callq 0x7718
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x584c
movq %rax, %rbx
jmp 0x585e
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x9cda
leaq 0x30(%rsp), %rdi
callq 0x7718
jmp 0x5875
movq %rax, %rbx
movq %r14, %rdi
callq 0x9cda
movq %rbx, %rdi
callq 0x2380