// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movq %rdi, %rbx
cmpb $0x1, 0x68(%rdi)
jne 0x183d
movq %rbx, %rdi
callq 0x149c
movl (%rbx), %ebp
leal 0x1(%rbp), %eax
movslq %eax, %r15
pushq $0x18
popq %rcx
movq %r15, %rax
mulq %rcx
movq %rax, %r14
seto %al
movq %r14, %r12
addq $0x8, %r12
pushq $-0x1
popq %rcx
cmovbq %rcx, %r12
testb %al, %al
cmovneq %rcx, %r12
leaq (,%r15,4), %rdi
cmpl $-0x1, %ebp
cmovlq %rcx, %rdi
callq 0x1030
movq %rax, 0x8(%rbx)
movq %r12, %rdi
callq 0x1030
leaq 0x8(%rax), %r13
movq %r15, (%rax)
incl %ebp
pushq $0x18
popq %rbp
je 0x178b
leaq -0x18(%r14), %rcx
movq %rcx, %rax
xorl %edx, %edx
divq %rbp
subq %rdx, %rcx
addq $0x18, %rcx
movq %r13, %rdi
xorl %esi, %esi
movq %rcx, %rdx
callq 0x10b0
movq %r13, 0x28(%rbx)
movq %r12, %rdi
callq 0x1030
leaq 0x8(%rax), %r12
movq %r15, (%rax)
testl %r15d, %r15d
je 0x17c3
addq $-0x18, %r14
movq %r14, %rax
xorl %edx, %edx
divq %rbp
subq %rdx, %r14
addq $0x18, %r14
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x10b0
movq %r12, 0x30(%rbx)
movq 0x10(%rbx), %rcx
xorl %eax, %eax
leaq 0x70(%rsp), %r14
movl %eax, 0x70(%rsp)
movslq %eax, %rdx
movq 0x18(%rbx), %rsi
subq %rcx, %rsi
sarq $0x5, %rsi
cmpq %rdx, %rsi
jbe 0x183d
xorl %r15d, %r15d
movslq %eax, %rsi
shlq $0x5, %rsi
movq 0x8(%rcx,%rsi), %rdx
movq 0x10(%rcx,%rsi), %rsi
subq %rdx, %rsi
sarq $0x2, %rsi
cmpq %r15, %rsi
jbe 0x1839
movl (%rdx,%r15,4), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
xorl %edx, %edx
testl %eax, %eax
setle %dl
imulq $0x18, %rcx, %rdi
addq 0x28(%rbx,%rdx,8), %rdi
movq %r14, %rsi
callq 0x1cd8
incq %r15
movl 0x70(%rsp), %eax
movq 0x10(%rbx), %rcx
jmp 0x17ec
incl %eax
jmp 0x17d2
movb $0x0, 0x68(%rbx)
pushq $0x1
popq %r14
pushq $-0x1
popq %rbp
movslq (%rbx), %rax
cmpq %rax, %r14
jg 0x186c
callq 0x1060
testb $0x1, %al
movl %ebp, %eax
cmovel %r14d, %eax
movq 0x8(%rbx), %rcx
movl %eax, (%rcx,%r14,4)
incq %r14
decl %ebp
jmp 0x1848
leaq 0xa0(%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), %r15
movq 0x78(%rbx), %r12
leaq 0x70(%rsp), %r14
cmpq %r12, %r15
je 0x18cc
movl (%r15), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %ecx, 0x10(%rsp)
movq 0x8(%rbx), %rdx
movl %eax, (%rdx,%rcx,4)
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x2252
addq $0x4, %r15
jmp 0x189f
movq 0x70(%rbx), %rax
cmpq %rax, 0x78(%rbx)
je 0x18da
movq %rax, 0x78(%rbx)
leaq 0x38(%rbx), %rax
movq %rax, 0x50(%rsp)
xorl %eax, %eax
leaq 0x30(%rsp), %r12
leaq 0xc(%rsp), %r15
movl %eax, 0x4(%rsp)
movslq %eax, %rcx
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %r14
subq %rax, %r14
sarq $0x5, %r14
cmpq %rcx, %r14
jbe 0x1a4e
movq %rcx, 0x58(%rsp)
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x68(%rsp)
andq $0x0, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
addq %rcx, %rax
addq $0x8, %rax
movq (%rax), %rbp
movq %rax, 0x60(%rsp)
movq 0x8(%rax), %r13
cmpq %r13, %rbp
je 0x198d
movl (%rbp), %eax
movl %eax, 0xc(%rsp)
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %ecx, 0x8(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x25c6
movq %r12, %rdi
testq %rax, %rax
je 0x197f
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x1cd8
addq $0x4, %rbp
jmp 0x194c
movl 0x38(%rsp), %eax
subl 0x30(%rsp), %eax
shrl $0x2, %eax
movq 0x68(%rsp), %r13
movb %al, (%r13)
movq 0x60(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1c0e
movq 0x10(%r13), %rsi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq %rbp, %rdi
callq 0x1d66
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
movq 0x8(%rbx), %rdx
xorl %ebp, %ebp
cmpq %rcx, %rax
je 0x19f6
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
jmp 0x19d5
cmpb $0x0, (%r13)
jne 0x1a01
testl %ebp, %ebp
je 0x1a35
testl %ebp, %ebp
jne 0x1a14
movq 0x50(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x1cd8
movb %bpl, 0x1(%r13)
movq %r12, %rdi
callq 0x1e3a
leaq 0x10(%rsp), %rdi
callq 0x1e3a
movl 0x4(%rsp), %eax
incl %eax
jmp 0x18ef
leaq 0x30(%rsp), %rdi
callq 0x1e3a
leaq 0x10(%rsp), %rdi
callq 0x1e3a
movq 0x58(%rsp), %rcx
cmpq %rcx, %r14
setbe %bl
leaq 0x70(%rsp), %rdi
callq 0x1d86
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1a7f
jmp 0x1a7f
jmp 0x1a7f
movq %rax, %rbx
jmp 0x1a96
jmp 0x1a7f
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x1e3a
leaq 0x10(%rsp), %rdi
callq 0x1e3a
leaq 0x70(%rsp), %rdi
callq 0x1d86
movq %rbx, %rdi
callq 0x11b0