// File: 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
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x158(%rbp)
testb $0x1, 0x68(%rax)
je 0x1e23
movq -0x158(%rbp), %rdi
callq 0x1740
movq -0x158(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, %rcx
movq -0x158(%rbp), %rax
movq %rcx, 0x8(%rax)
movl (%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x168(%rbp)
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, %rcx
movq -0x168(%rbp), %rax
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x160(%rbp)
cmpq $0x0, %rax
je 0x1c3a
movq -0x160(%rbp), %rax
movq -0x168(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x178(%rbp)
movq %rax, -0x170(%rbp)
movq -0x170(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x2c90
movq -0x180(%rbp), %rax
movq -0x178(%rbp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x170(%rbp)
jne 0x1c09
movq -0x158(%rbp), %rax
movq -0x160(%rbp), %rcx
movq %rcx, 0x28(%rax)
movl (%rax), %eax
addl $0x1, %eax
cltq
movq %rax, -0x190(%rbp)
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, %rcx
movq -0x190(%rbp), %rax
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x188(%rbp)
cmpq $0x0, %rax
je 0x1cf9
movq -0x188(%rbp), %rax
movq -0x190(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x1a0(%rbp)
movq %rax, -0x198(%rbp)
movq -0x198(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x2c90
movq -0x1a8(%rbp), %rax
movq -0x1a0(%rbp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x198(%rbp)
jne 0x1cc8
movq -0x158(%rbp), %rax
movq -0x188(%rbp), %rcx
movq %rcx, 0x30(%rax)
movl $0x0, -0x14(%rbp)
movq -0x158(%rbp), %rdi
movslq -0x14(%rbp), %rax
movq %rax, -0x1b0(%rbp)
addq $0x10, %rdi
callq 0x2c10
movq %rax, %rcx
movq -0x1b0(%rbp), %rax
cmpq %rcx, %rax
jae 0x1e21
movl $0x0, -0x18(%rbp)
movq -0x158(%rbp), %rdi
movslq -0x18(%rbp), %rax
movq %rax, -0x1b8(%rbp)
addq $0x10, %rdi
movslq -0x14(%rbp), %rsi
callq 0x29c0
movq %rax, %rdi
addq $0x8, %rdi
callq 0x28c0
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
cmpq %rcx, %rax
jae 0x1e11
movq -0x158(%rbp), %rdi
addq $0x10, %rdi
movslq -0x14(%rbp), %rsi
callq 0x29c0
movq %rax, %rdi
addq $0x8, %rdi
movslq -0x18(%rbp), %rsi
callq 0x2cb0
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x1de2
movq -0x158(%rbp), %rax
movq 0x28(%rax), %rdi
movslq -0x20(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq -0x14(%rbp), %rsi
callq 0x2a00
jmp 0x1e01
movq -0x158(%rbp), %rax
movq 0x30(%rax), %rdi
movslq -0x20(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq -0x14(%rbp), %rsi
callq 0x2a00
jmp 0x1e03
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1d47
jmp 0x1e13
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1d12
jmp 0x1e23
movq -0x158(%rbp), %rax
movb $0x0, 0x68(%rax)
movl $0x1, -0x24(%rbp)
movq -0x158(%rbp), %rcx
movl -0x24(%rbp), %eax
cmpl (%rcx), %eax
jg 0x1e8e
callq 0x1060
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x1e60
movl -0x24(%rbp), %eax
movl %eax, -0x1bc(%rbp)
jmp 0x1e6b
xorl %eax, %eax
subl -0x24(%rbp), %eax
movl %eax, -0x1bc(%rbp)
movq -0x158(%rbp), %rax
movl -0x1bc(%rbp), %edx
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1e35
leaq -0x60(%rbp), %rdi
callq 0x2cd0
movq -0x158(%rbp), %rax
addq $0x70, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x2900
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
callq 0x2930
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2960
testb $0x1, %al
jne 0x1ed6
jmp 0x1f64
leaq -0x70(%rbp), %rdi
callq 0x29a0
movq %rax, %rcx
movq -0x158(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x7c(%rbp)
movl -0x7c(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
movl %ecx, -0x80(%rbp)
movl -0x7c(%rbp), %edx
movq 0x8(%rax), %rax
movslq -0x80(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2cf0
movb %dl, -0x1c9(%rbp)
movq %rax, -0x1c8(%rbp)
jmp 0x1f25
movb -0x1c9(%rbp), %al
movq -0x1c8(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movb %al, -0x98(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x29e0
jmp 0x1ec0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x2341
movq -0x158(%rbp), %rdi
addq $0x70, %rdi
callq 0x2bf0
movl $0x0, -0xa4(%rbp)
movq -0x158(%rbp), %rdi
movslq -0xa4(%rbp), %rax
movq %rax, -0x1d8(%rbp)
addq $0x10, %rdi
callq 0x2c10
movq %rax, %rcx
movq -0x1d8(%rbp), %rax
cmpq %rcx, %rax
jae 0x231c
movq -0x158(%rbp), %rdi
addq $0x10, %rdi
movslq -0xa4(%rbp), %rsi
callq 0x29c0
movq %rax, -0xb0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x2c90
leaq -0xe0(%rbp), %rdi
callq 0x2c90
movq -0xb0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x2900
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x2930
movq %rax, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x2960
testb $0x1, %al
jne 0x2039
jmp 0x20f6
leaq -0xf0(%rbp), %rdi
callq 0x29a0
movl (%rax), %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x100(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x2d30
movq %rax, -0x1e0(%rbp)
jmp 0x2079
movq -0x1e0(%rbp), %rax
cmpq $0x0, %rax
je 0x20cc
leaq -0xc8(%rbp), %rdi
leaq -0xfc(%rbp), %rsi
callq 0x2a00
jmp 0x209b
jmp 0x20e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x2a70
leaq -0xc8(%rbp), %rdi
callq 0x2a70
jmp 0x2341
leaq -0xe0(%rbp), %rdi
leaq -0xfc(%rbp), %rsi
callq 0x2a00
jmp 0x20e1
jmp 0x20e3
jmp 0x20e5
leaq -0xf0(%rbp), %rdi
callq 0x29e0
jmp 0x201d
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x28c0
movq -0x1e8(%rbp), %rsi
movb %al, %cl
movq -0xb0(%rbp), %rax
movb %cl, (%rax)
movq -0xb0(%rbp), %rdi
addq $0x8, %rdi
callq 0x2650
jmp 0x212d
movq -0xb0(%rbp), %rdi
addq $0x8, %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x2930
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2e10
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0x2900
movq -0x200(%rbp), %rdi
movq %rax, -0x118(%rbp)
callq 0x2930
movq -0x1f8(%rbp), %rdi
movq %rax, -0x120(%rbp)
movq -0x108(%rbp), %rsi
movq -0x118(%rbp), %rdx
movq -0x120(%rbp), %rcx
callq 0x2d60
movq %rax, -0x1f0(%rbp)
jmp 0x21b5
movq -0x1f0(%rbp), %rax
movq %rax, -0x128(%rbp)
movl $0x0, -0x12c(%rbp)
movq -0xb0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rdi
callq 0x2900
movq %rax, -0x140(%rbp)
movq -0x138(%rbp), %rdi
callq 0x2930
movq %rax, -0x148(%rbp)
leaq -0x140(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x2960
testb $0x1, %al
jne 0x221e
jmp 0x227a
leaq -0x140(%rbp), %rdi
callq 0x29a0
movq %rax, %rcx
movq -0x158(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x14c(%rbp)
movq 0x8(%rax), %rax
movl -0x14c(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x14c(%rbp), %eax
jne 0x226a
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x226c
leaq -0x140(%rbp), %rdi
callq 0x29e0
jmp 0x2205
movq -0xb0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x22a2
cmpl $0x0, -0x12c(%rbp)
jne 0x22a2
movb $0x0, -0x1(%rbp)
movl $0x1, -0x150(%rbp)
jmp 0x22e2
cmpl $0x0, -0x12c(%rbp)
jne 0x22c6
movq -0x158(%rbp), %rdi
addq $0x38, %rdi
leaq -0xa4(%rbp), %rsi
callq 0x2a00
jmp 0x22c4
jmp 0x22c6
movl -0x12c(%rbp), %eax
movb %al, %cl
movq -0xb0(%rbp), %rax
movb %cl, 0x1(%rax)
movl $0x0, -0x150(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x2a70
leaq -0xc8(%rbp), %rdi
callq 0x2a70
movl -0x150(%rbp), %eax
testl %eax, %eax
jne 0x232a
jmp 0x2306
jmp 0x2308
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x1f7e
movb $0x1, -0x1(%rbp)
movl $0x1, -0x150(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x2e50
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x2e50
movq -0x88(%rbp), %rdi
callq 0x11a0
nopw %cs:(%rax,%rax)