// File: /workspace/github_cpp_makefile_star2_O3/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 0x19dc
movq %rbx, %rdi
callq 0x1514
movl (%rbx), %ebp
leal 0x1(%rbp), %eax
movslq %eax, %r14
movl $0x18, %ecx
movq %r14, %rax
mulq %rcx
movq %rax, %r12
seto %al
movq %r12, %r15
addq $0x8, %r15
movq $-0x1, %rcx
cmovbq %rcx, %r15
testb %al, %al
cmovneq %rcx, %r15
leaq (,%r14,4), %rdi
cmpl $-0x1, %ebp
cmovlq %rcx, %rdi
callq 0x1030
movq %rax, 0x8(%rbx)
movq %r15, %rdi
callq 0x1030
leaq 0x8(%rax), %r13
movq %r14, (%rax)
incl %ebp
jne 0x18c2
leaq 0x28(%rbx), %rbp
movq %r13, 0x28(%rbx)
movq %r15, %rdi
callq 0x1030
movq %rax, %r15
movq %r14, (%rax)
addq $0x8, %r15
jmp 0x191a
addq $-0x18, %r12
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
movq %r12, %rax
mulq %rcx
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %r12
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x10b0
leaq 0x28(%rbx), %rbp
movq %r13, 0x28(%rbx)
movq %r15, %rdi
callq 0x1030
movq %rax, %r15
movq %r14, (%rax)
addq $0x8, %r15
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x10b0
movq %r15, 0x30(%rbx)
movl $0x0, 0x60(%rsp)
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %rdx
cmpq %rcx, %rdx
je 0x19dc
xorl %eax, %eax
leaq 0x60(%rsp), %r14
movslq %eax, %rdi
shlq $0x5, %rdi
movq 0x8(%rcx,%rdi), %rsi
cmpq %rsi, 0x10(%rcx,%rdi)
je 0x19c0
xorl %r15d, %r15d
movl (%rsi,%r15,4), %edx
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
testl %edx, %edx
jle 0x1969
movq (%rbp), %rdx
jmp 0x196d
movq 0x30(%rbx), %rdx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x198b
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x1993
movq %r14, %rdx
callq 0x2100
incq %r15
movslq 0x60(%rsp), %rax
movq 0x10(%rbx), %rcx
movq %rax, %rdx
shlq $0x5, %rdx
movq 0x8(%rcx,%rdx), %rsi
movq 0x10(%rcx,%rdx), %rdx
subq %rsi, %rdx
sarq $0x2, %rdx
cmpq %r15, %rdx
ja 0x1954
movq 0x18(%rbx), %rdx
incl %eax
movl %eax, 0x60(%rsp)
movslq %eax, %rsi
movq %rdx, %rdi
subq %rcx, %rdi
sarq $0x5, %rdi
cmpq %rsi, %rdi
ja 0x193e
movb $0x0, 0x68(%rbx)
cmpl $0x0, (%rbx)
jle 0x1a16
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 0x19f0
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 0x1a98
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 0x2418
addq $0x4, %r13
cmpq %rbp, %r13
jne 0x1a58
movq 0x70(%rbx), %rax
cmpq %rax, 0x78(%rbx)
je 0x1a98
movq %rax, 0x78(%rbx)
movl $0x0, 0xc(%rsp)
movq 0x10(%rbx), %rbp
cmpq %rbp, 0x18(%rbx)
je 0x1c96
leaq 0x38(%rbx), %rax
movq %rax, 0x58(%rsp)
xorl %r12d, %r12d
leaq 0x10(%rsp), %r15
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(%rbp,%r12), %r13
movq 0x10(%rbp,%r12), %r14
cmpq %r14, %r13
je 0x1b9d
movl (%r13), %r8d
movl %r8d, 0x54(%rsp)
movl %r8d, %ecx
negl %ecx
cmovsl %r8d, %ecx
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %r9
movq %rcx, %rax
xorl %edx, %edx
divq %r9
movq (%rdi,%rdx,8), %rax
testq %rax, %rax
je 0x1b67
movq %rdx, %rsi
movq (%rax), %r10
cmpl 0x8(%r10), %ecx
je 0x1b45
movq (%r10), %r10
testq %r10, %r10
je 0x1b67
movslq 0x8(%r10), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r9
cmpq %rsi, %rdx
jne 0x1b67
cmpl %edi, %ecx
jne 0x1b28
movq 0x38(%rsp), %rsi
leaq 0x30(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq 0x40(%rsp), %rsi
jne 0x1b7b
leaq 0x54(%rsp), %rdx
callq 0x2100
jmp 0x1b85
movq 0x18(%rsp), %rsi
movq %r15, %rdi
leaq 0x18(%rsp), %rax
cmpq 0x20(%rsp), %rsi
je 0x1b5b
movl %r8d, (%rsi)
addq $0x4, %rsi
movq %rsi, (%rax)
addq $0x4, %r13
cmpq %r14, %r13
jne 0x1aef
movl 0x18(%rsp), %eax
subl 0x10(%rsp), %eax
shrl $0x2, %eax
leaq (%r12,%rbp), %r13
addq %r12, %rbp
addq $0x8, %rbp
movb %al, (%r13)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1eb2
movq 0x10(%r13), %rsi
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq %rbp, %rdi
callq 0x26c0
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
cmpq %rcx, %rax
je 0x1c01
movq 0x8(%rbx), %rdx
xorl %ebp, %ebp
movl (%rax), %esi
movl %esi, %edi
negl %edi
cmovsl %esi, %edi
xorl %r8d, %r8d
cmpl %esi, (%rdx,%rdi,4)
sete %r8b
addl %r8d, %ebp
addq $0x4, %rax
cmpq %rcx, %rax
jne 0x1be0
jmp 0x1c03
xorl %ebp, %ebp
cmpb $0x0, (%r13)
jne 0x1c12
testl %ebp, %ebp
je 0x1c9a
testl %ebp, %ebp
jne 0x1c3f
movq 0x40(%rbx), %rsi
cmpq 0x48(%rbx), %rsi
je 0x1c30
movl 0xc(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x40(%rbx)
jmp 0x1c3f
movq 0x58(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x2100
movb %bpl, 0x1(%r13)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1c5a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1c71
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movslq 0xc(%rsp), %r12
incq %r12
movl %r12d, 0xc(%rsp)
movq 0x10(%rbx), %rbp
movq 0x18(%rbx), %rax
subq %rbp, %rax
sarq $0x5, %rax
cmpq %r12, %rax
ja 0x1abf
movb $0x1, %bl
jmp 0x1cca
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1cb1
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1cc8
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
xorl %ebx, %ebx
leaq 0x60(%rsp), %rdi
callq 0x206a
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1cf3
jmp 0x1cf3
jmp 0x1cf3
movq %rax, %rbx
jmp 0x1d24
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1d0d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1d24
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x1100
leaq 0x60(%rsp), %rdi
callq 0x206a
movq %rbx, %rdi
callq 0x11b0