// File: /workspace/github_cpp_makefile_star2_O1/biotomas[P]ipasir/sat/lawa/lawa.cpp
// Function: Lawa::initializeSearch()
bool Lawa::initializeSearch() {
    if (clausesAdded) {
        deallocateMemory();
        tvalues = new int[numVariables+1];
        posOccList = new vector<int>[1+numVariables];
        negOccList = new vector<int>[1+numVariables];

        // compute occurrence lists
        for (int ci = 0; ci < clauses.size(); ci++) {
            for (int li = 0; li < clauses[ci].lits.size(); li++) {
                int lit = clauses[ci].lits[li];
                int var = abs(lit);
                if (lit > 0) {
                    posOccList[var].push_back(ci);
                } else {
                    negOccList[var].push_back(ci);
                }
            }
        }
    }
    clausesAdded = false;

    for (int var = 1; var <= numVariables; var++) {
        tvalues[var] = rand()%2 == 0 ? var : -var;
    }

    unordered_set<int> lockedVariables;
    for (int lit : assumptions) {
        int var = abs(lit);
        tvalues[var] = lit;
        lockedVariables.insert(var);
    }
    assumptions.clear();

    for (int ci = 0; ci < clauses.size(); ci++) {
        Clause& cls = clauses[ci];

        vector<int> lockedLits;
        vector<int> freeLits;
        for (int lit : cls.lits) {
            if (lockedVariables.count(abs(lit))) {
                lockedLits.push_back(lit);
            } else {
                freeLits.push_back(lit);
            }
        }
        cls.flippableLits = freeLits.size();
        cls.lits = freeLits;
        cls.lits.insert(cls.lits.end(), lockedLits.begin(), lockedLits.end());

        int satLits = 0;
        for (int lit : cls.lits) {
            if (ISTRUE(lit))
                satLits++;
        }
        if (cls.flippableLits == 0 && satLits == 0) {
            // unsatisfiable formula
            return false;
        }
        if (satLits == 0) {
            unsatClauseIds.push_back(ci);
        }
        cls.satLits = satLits;
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
cmpb $0x1, 0x68(%rdi)
jne 0x19de
movq %rbx, %rdi
callq 0x1514
movl (%rbx), %r13d
leal 0x1(%r13), %eax
movslq %eax, %r14
movl $0x18, %ecx
movq %r14, %rax
mulq %rcx
movq %rax, %r15
seto %al
addq $0x8, %r15
movq $-0x1, %rcx
cmovbq %rcx, %r15
testb %al, %al
cmovneq %rcx, %r15
leaq (,%r14,4), %rdi
cmpl $-0x1, %r13d
cmovlq %rcx, %rdi
callq 0x1030
movq %rax, 0x8(%rbx)
movq %r15, %rdi
callq 0x1030
leaq 0x8(%rax), %r12
movq %r14, (%rax)
movabsq $-0x5555555555555555, %rbp # imm = 0xAAAAAAAAAAAAAAAB
incl %r13d
je 0x18da
leaq (%r14,%r14,2), %rax
leaq -0x18(,%rax,8), %rax
mulq %rbp
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x10b0
movq %r12, 0x28(%rbx)
movq %r15, %rdi
callq 0x1030
leaq 0x8(%rax), %r15
movq %r14, (%rax)
testl %r14d, %r14d
je 0x191b
leaq (%r14,%r14,2), %rax
leaq -0x18(,%rax,8), %rax
mulq %rbp
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x10b0
movq %r15, 0x30(%rbx)
movl $0x0, 0x60(%rsp)
movq 0x18(%rbx), %rax
cmpq 0x10(%rbx), %rax
je 0x19de
leaq 0x60(%rsp), %r14
movslq 0x60(%rsp), %rax
movq 0x10(%rbx), %rdx
movq %rax, %rsi
shlq $0x5, %rsi
movq 0x8(%rdx,%rsi), %rcx
cmpq %rcx, 0x10(%rdx,%rsi)
je 0x19c1
xorl %r15d, %r15d
movl (%rcx,%r15,4), %edx
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
testl %edx, %edx
jle 0x196e
movq 0x28(%rbx), %rdx
jmp 0x1972
movq 0x30(%rbx), %rdx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x1990
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x1998
movq %r14, %rdx
callq 0x20da
incq %r15
movslq 0x60(%rsp), %rax
movq 0x10(%rbx), %rdx
movq %rax, %rsi
shlq $0x5, %rsi
movq 0x8(%rdx,%rsi), %rcx
movq 0x10(%rdx,%rsi), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %r15, %rdx
ja 0x1959
incl %eax
movl %eax, 0x60(%rsp)
cltq
movq 0x18(%rbx), %rcx
subq 0x10(%rbx), %rcx
sarq $0x5, %rcx
cmpq %rax, %rcx
ja 0x193a
movb $0x0, 0x68(%rbx)
cmpl $0x0, (%rbx)
jle 0x1a18
movl $0x1, %r14d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
callq 0x1060
testb $0x1, %al
movl %r14d, %eax
cmovnel %ebp, %eax
movq 0x8(%rbx), %rcx
movl %eax, (%rcx,%r14,4)
leaq 0x1(%r14), %rax
movslq (%rbx), %rcx
decl %ebp
cmpq %rcx, %r14
movq %rax, %r14
jl 0x19f2
leaq 0x90(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movq 0x70(%rbx), %r13
movq 0x78(%rbx), %rbp
cmpq %rbp, %r13
je 0x1a8c
leaq 0x60(%rsp), %r14
leaq 0x10(%rsp), %r15
leaq 0x30(%rsp), %r12
movl (%r13), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %ecx, 0x10(%rsp)
movq 0x8(%rbx), %rdx
movl %eax, (%rdx,%rcx,4)
movq %r14, 0x30(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x240c
addq $0x4, %r13
cmpq %rbp, %r13
jne 0x1a5a
movq 0x70(%rbx), %rax
cmpq %rax, 0x78(%rbx)
je 0x1a9a
movq %rax, 0x78(%rbx)
movl $0x0, 0x8(%rsp)
movq 0x10(%rbx), %r15
cmpq %r15, 0x18(%rbx)
sete %r14b
je 0x1cb0
leaq 0x38(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0x54(%rsp), %rbp
xorl %r12d, %r12d
movb %r14b, 0x7(%rsp)
shlq $0x5, %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x8(%r15,%r12), %r14
movq 0x10(%r15,%r12), %r13
cmpq %r13, %r14
je 0x1b6f
movl (%r14), %eax
movl %eax, 0xc(%rsp)
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %ecx, 0x54(%rsp)
leaq 0x60(%rsp), %rdi
movq %rbp, %rsi
callq 0x26ec
testq %rax, %rax
je 0x1b33
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x1b53
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
leaq 0x38(%rsp), %rax
jmp 0x1b4a
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x1b5a
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
leaq 0x18(%rsp), %rax
addq $0x4, %rsi
movq %rsi, (%rax)
jmp 0x1b69
leaq 0x30(%rsp), %rdi
jmp 0x1b5f
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x20da
addq $0x4, %r14
jmp 0x1af1
leaq (%r15,%r12), %r14
addq %r12, %r15
addq $0x8, %r15
movl 0x18(%rsp), %eax
subl 0x10(%rsp), %eax
shrl $0x2, %eax
movb %al, (%r14)
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
callq 0x1ea0
movq 0x10(%r14), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq %r15, %rdi
callq 0x2720
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
cmpq %rcx, %rax
je 0x1be0
movq 0x8(%rbx), %rdx
xorl %r15d, %r15d
movl (%rax), %esi
movl %esi, %edi
negl %edi
cmovsl %esi, %edi
xorl %r8d, %r8d
cmpl %esi, (%rdx,%rdi,4)
sete %r8b
addl %r8d, %r15d
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x1bbf
jmp 0x1be3
xorl %r15d, %r15d
cmpb $0x0, (%r14)
jne 0x1bf2
testl %r15d, %r15d
je 0x1c7d
testl %r15d, %r15d
jne 0x1c20
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x1c11
movl 0x8(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x40(%rbx)
jmp 0x1c20
movq 0x58(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x20da
movb %r15b, 0x1(%r14)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1c3b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1c52
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movslq 0x8(%rsp), %r12
incq %r12
movl %r12d, 0x8(%rsp)
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %rax
subq %r15, %rax
sarq $0x5, %rax
cmpq %r12, %rax
setbe %r14b
ja 0x1ac5
jmp 0x1cb0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1c94
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
movb 0x7(%rsp), %r14b
je 0x1cb0
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq 0x60(%rsp), %rdi
callq 0x2044
andb $0x1, %r14b
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1ce0
jmp 0x1ce0
jmp 0x1ce0
movq %rax, %rbx
jmp 0x1d11
jmp 0x1ce0
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1cfa
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1d11
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq 0x60(%rsp), %rdi
callq 0x2044
movq %rbx, %rdi
callq 0x11b0
nop