// File: /workspace/github_cpp_makefile_star2_O1/Laakeri[P]maxpre/src/./BVE.cpp
// Function: maxPreprocessor::Preprocessor::tryBVE(int)
int Preprocessor::tryBVE(int var) {
	vector<vector<int> > newClauses;
	int sizeLimit = pi.litClauses[posLit(var)].size() + pi.litClauses[negLit(var)].size();
	for (int i = 0; i < (int)pi.litClauses[posLit(var)].size(); i++) {
		for (int ii = 0; ii < (int)pi.litClauses[negLit(var)].size(); ii++) {
			// Check if resulting clause will be a tautology
			Clause& c1 = pi.clauses[pi.litClauses[posLit(var)][i]];
			Clause& c2 = pi.clauses[pi.litClauses[negLit(var)][ii]];
			int j2 = 0;
			bool f = false;
			for (int j = 0; j < (int)c1.lit.size(); j++) {
				while (j2 < (int)c2.lit.size() && c2.lit[j2] <= c1.lit[j]) {
					if (litNegation(c2.lit[j2]) == c1.lit[j] && litVariable(c1.lit[j]) != var) {
						f = true;
						break;
					}
					j2++;
				}
				if (f) break;
				if (j2 < (int)c2.lit.size() && litNegation(c2.lit[j2]) == c1.lit[j] && litVariable(c1.lit[j]) != var) {
					f = true;
					break;
				}
			}
			if (f) continue;
			if ((int)newClauses.size() >= sizeLimit) return 0;
			newClauses.push_back(vector<int>());
			j2 = 0;
			for (int j = 0; j < (int)c1.lit.size(); j++) {
				while ((int)j2 < (int)c2.lit.size() && c2.lit[j2] <= c1.lit[j]) {
					if (litVariable(c2.lit[j2]) != var) {
						newClauses.back().push_back(c2.lit[j2]);
					}
					j2++;
				}
				if (!((int)newClauses.back().size() > 0 && newClauses.back().back() == c1.lit[j]) && litVariable(c1.lit[j]) != var) {
					newClauses.back().push_back(c1.lit[j]);
				}
			}
			while ((int)j2 < (int)c2.lit.size()) {
				if (litVariable(c2.lit[j2]) != var) {
					newClauses.back().push_back(c2.lit[j2]);
				}
				j2++;
			}
			
			// Check if valid, this can be deleted
			for (int j = 1; j < (int)newClauses.back().size(); j++) {
				assert(litVariable(newClauses.back()[j]) != var);
				assert(litVariable(newClauses.back()[j - 1]) != var);
				assert(newClauses.back()[j] > newClauses.back()[j - 1]);
				assert(litNegation(newClauses.back()[j]) != newClauses.back()[j - 1]);
			}
		}
	}
	
	vector<vector<int> > nClauses;
	
	vector<int> toRemove;
	for (int c : pi.litClauses[posLit(var)]) {
		toRemove.push_back(c);
	}
	for (int c : pi.litClauses[negLit(var)]) {
		toRemove.push_back(c);
		nClauses.push_back(pi.clauses[c].lit);
	}
	for (int c : toRemove) {
		pi.removeClause(c);
	}
	for (int i = 0; i < (int)newClauses.size(); i++) {
		pi.addClause(newClauses[i]);
	}
	trace.BVE(var, nClauses);
	
	rLog.removeVariable(1);
	rLog.removeClause((int)toRemove.size() - (int)newClauses.size());
	
	//Check if valid, this can be deleted
	assert(pi.litClauses[posLit(var)].size() == 0 && pi.litClauses[negLit(var)].size() == 0);
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %esi, %r14d
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
leal (%r14,%r14), %eax
cltq
movq 0x18(%rdi), %rcx
leaq (%rax,%rax,2), %rdx
movq 0x8(%rcx,%rdx,8), %rax
movq %rdx, 0x48(%rsp)
subq (%rcx,%rdx,8), %rax
shrq $0x2, %rax
leal 0x1(,%r14,2), %edx
movslq %edx, %rdx
leaq (%rdx,%rdx,2), %rdx
movq %rdx, 0x28(%rsp)
testl %eax, %eax
setg %r8b
jle 0xfc93
movq 0x28(%rsp), %rdx
movq 0x8(%rcx,%rdx,8), %rsi
subq (%rcx,%rdx,8), %rsi
shrq $0x2, %rsi
addl %eax, %esi
movq %rsi, 0x88(%rsp)
movq $0x0, 0x70(%rsp)
movq %rdi, 0x80(%rsp)
movb %r8b, 0xb(%rsp)
movq 0x18(%rdi), %rcx
movq 0x28(%rsp), %rdx
movq (%rcx,%rdx,8), %rax
movq 0x8(%rcx,%rdx,8), %rdx
subq %rax, %rdx
shrq $0x2, %rdx
testl %edx, %edx
jle 0xfc49
xorl %esi, %esi
movq 0x48(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x70(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movq (%rdi), %rdx
leaq (%rcx,%rcx,4), %rcx
movq %rsi, 0xa0(%rsp)
movslq (%rax,%rsi,4), %rax
leaq (%rax,%rax,4), %rax
leaq (%rdx,%rax,8), %rbp
movq (%rdx,%rcx,8), %r12
movq %rdx, 0x98(%rsp)
movq %rcx, 0x90(%rsp)
movq 0x8(%rdx,%rcx,8), %rcx
subq %r12, %rcx
shrq $0x2, %rcx
xorl %edx, %edx
testl %ecx, %ecx
jle 0xf9a2
movq (%rbp), %rsi
movq 0x8(%rbp), %rdi
subq %rsi, %rdi
shrq $0x2, %rdi
movslq %edi, %r9
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %r10d, %r10d
xorl %r8d, %r8d
movq %r12, 0x78(%rsp)
cmpl %edi, %edx
setl %r11b
jge 0xf966
movl (%r12,%r10,4), %ebx
movslq %edx, %r15
movl (%rsi,%r15,4), %r13d
cmpl %ebx, %r13d
jg 0xf966
movl %ebx, %r12d
sarl %r12d
incq %r15
cmpl %r14d, %r12d
setne %al
xorl %ebx, %r13d
cmpl $0x1, %r13d
sete %r13b
testb %al, %r13b
jne 0xf95a
cmpq %r9, %r15
setl %r11b
je 0xf95f
movl (%rsi,%r15,4), %r13d
incl %edx
incq %r15
cmpl %ebx, %r13d
jle 0xf92b
jmp 0xf961
movb $0x1, %r8b
jmp 0xf961
movl %edi, %edx
movq 0x78(%rsp), %r12
testb $0x1, %r8b
jne 0xf9aa
testb $0x1, %r11b
je 0xf994
movslq %edx, %rax
movl (%r12,%r10,4), %r11d
movl (%rsi,%rax,4), %eax
xorl %r11d, %eax
cmpl $0x1, %eax
sete %al
sarl %r11d
cmpl %r14d, %r11d
setne %r11b
testb %r11b, %al
jne 0xf9a7
incq %r10
cmpq %rcx, %r10
jne 0xf90a
jmp 0xf9aa
xorl %r8d, %r8d
jmp 0xf9aa
movb $0x1, %r8b
movl $0x7, %eax
testb $0x1, %r8b
jne 0xfc08
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %ecx # imm = 0xAAAAAAAB
movl $0x1, %eax
cmpl 0x88(%rsp), %ecx
jge 0xfc08
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x23202
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xfa16
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x98(%rsp), %rax
movq 0x90(%rsp), %rcx
leaq (%rax,%rcx,8), %r13
movq 0x8(%r13), %rax
subq (%r13), %rax
shrq $0x2, %rax
testl %eax, %eax
jle 0xfb2b
xorl %ebx, %ebx
xorl %r12d, %r12d
movq (%rbp), %rdx
movq 0x8(%rbp), %rax
subq %rdx, %rax
shrq $0x2, %rax
cmpl %eax, %r12d
jge 0xfabc
movslq %r12d, %r12
leaq (,%r12,4), %r15
movl (%rdx,%r15), %eax
movq (%r13), %rcx
cmpl (%rcx,%rbx,4), %eax
jg 0xfabc
movl %eax, %ecx
sarl %ecx
cmpl %r14d, %ecx
je 0xfa9f
movq 0x38(%rsp), %rdi
movq -0x10(%rdi), %rsi
cmpq -0x8(%rdi), %rsi
je 0xfa93
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x10(%rdi)
jmp 0xfa9f
addq %r15, %rdx
addq $-0x18, %rdi
callq 0x98e8
incq %r12
movq (%rbp), %rdx
movq 0x8(%rbp), %rax
subq %rdx, %rax
shrq $0x2, %rax
cltq
addq $0x4, %r15
cmpq %rax, %r12
jl 0xfa62
movq 0x38(%rsp), %rdi
movq -0x10(%rdi), %rsi
movq %rsi, %rax
subq -0x18(%rdi), %rax
shrq $0x2, %rax
testl %eax, %eax
jle 0xfae0
movl -0x4(%rsi), %eax
movq (%r13), %rcx
cmpl (%rcx,%rbx,4), %eax
je 0xfb0f
movq (%r13), %rax
movl (%rax,%rbx,4), %ecx
movl %ecx, %edx
sarl %edx
cmpl %r14d, %edx
je 0xfb0f
cmpq -0x8(%rdi), %rsi
je 0xfb02
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x10(%rdi)
jmp 0xfb0f
addq $-0x18, %rdi
leaq (%rax,%rbx,4), %rdx
callq 0x98e8
movq 0x8(%r13), %rax
subq (%r13), %rax
incq %rbx
shrq $0x2, %rax
cltq
cmpq %rax, %rbx
jl 0xfa43
jmp 0xfb2e
xorl %r12d, %r12d
movq (%rbp), %rdx
movq 0x8(%rbp), %rax
subq %rdx, %rax
shrq $0x2, %rax
cmpl %eax, %r12d
jge 0xfb9e
movslq %r12d, %rbx
leaq (,%rbx,4), %r15
movl (%rdx,%r15), %eax
movl %eax, %ecx
sarl %ecx
cmpl %r14d, %ecx
je 0xfb81
movq 0x38(%rsp), %rdi
movq -0x10(%rdi), %rsi
cmpq -0x8(%rdi), %rsi
je 0xfb75
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x10(%rdi)
jmp 0xfb81
addq %r15, %rdx
addq $-0x18, %rdi
callq 0x98e8
incq %rbx
movq (%rbp), %rdx
movq 0x8(%rbp), %rax
subq %rdx, %rax
shrq $0x2, %rax
cltq
addq $0x4, %r15
cmpq %rax, %rbx
jl 0xfb4d
movq 0x38(%rsp), %rax
movq -0x18(%rax), %rcx
movq -0x10(%rax), %rdx
subq %rcx, %rdx
shrq $0x2, %rdx
xorl %eax, %eax
cmpl $0x2, %edx
jl 0xfc08
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x1, %esi
movl (%rcx,%rsi,4), %edi
movl %edi, %r8d
sarl %r8d
cmpl %r14d, %r8d
je 0xff12
movl -0x4(%rcx,%rsi,4), %r8d
movl %r8d, %r9d
sarl %r9d
cmpl %r14d, %r9d
je 0xfeb5
cmpl %r8d, %edi
jle 0xfed4
xorl %edi, %r8d
cmpl $0x1, %r8d
je 0xfef3
incq %rsi
cmpq %rsi, %rdx
jne 0xfbc4
cmpl $0x7, %eax
je 0xfc11
testl %eax, %eax
jne 0xfc7e
movq 0xa0(%rsp), %rsi
incq %rsi
movq 0x80(%rsp), %rdi
movq 0x18(%rdi), %rcx
movq 0x28(%rsp), %rdx
movq (%rcx,%rdx,8), %rax
movq 0x8(%rcx,%rdx,8), %rdx
subq %rax, %rdx
shrq $0x2, %rdx
movslq %edx, %rdx
cmpq %rdx, %rsi
jl 0xf890
movq 0x70(%rsp), %rsi
incq %rsi
movq 0x18(%rdi), %rax
movq 0x48(%rsp), %rdx
movq 0x8(%rax,%rdx,8), %rcx
subq (%rax,%rdx,8), %rcx
shrq $0x2, %rcx
movslq %ecx, %rax
movq %rsi, 0x70(%rsp)
cmpq %rax, %rsi
setl %r8b
jl 0xf868
jmp 0xfc93
xorl %ebp, %ebp
testb $0x1, 0xb(%rsp)
movq 0x80(%rsp), %rdi
jne 0xfe97
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
xorl %eax, %eax
movq %rax, 0x60(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x18(%rdi), %rax
movq 0x48(%rsp), %rcx
movq (%rax,%rcx,8), %rbx
movq 0x8(%rax,%rcx,8), %r12
cmpq %r12, %rbx
movq %rdi, %rbp
je 0xfd03
leaq 0x10(%rsp), %r15
leaq 0xc(%rsp), %r13
movl (%rbx), %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xfcef
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0xfcfa
movq %r15, %rdi
movq %r13, %rdx
callq 0x98e8
addq $0x4, %rbx
cmpq %r12, %rbx
jne 0xfcd0
movq %rbp, %r13
movq 0x18(%rbp), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rbx
movq 0x8(%rax,%rcx,8), %r12
cmpq %r12, %rbx
je 0xfd75
leaq 0xc(%rsp), %rbp
leaq 0x50(%rsp), %r15
movl (%rbx), %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xfd46
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0xfd53
leaq 0x10(%rsp), %rdi
movq %rbp, %rdx
callq 0x98e8
movslq 0xc(%rsp), %rax
leaq (%rax,%rax,4), %rsi
shlq $0x3, %rsi
addq (%r13), %rsi
movq %r15, %rdi
callq 0x1fc42
addq $0x4, %rbx
cmpq %r12, %rbx
jne 0xfd27
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r15
cmpq %r15, %rbx
je 0xfd94
movl (%rbx), %esi
movq %r13, %rdi
callq 0x28c34
addq $0x4, %rbx
jmp 0xfd7f
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rax
subq %rsi, %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
testl %eax, %eax
jle 0xfdf1
xorl %ebx, %ebx
movabsq $-0x8000000000000000, %r15 # imm = 0x8000000000000000
xorl %r12d, %r12d
addq %rbx, %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x28c8e
incq %r12
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rax
subq %rsi, %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
cltq
addq $0x18, %rbx
cmpq %rax, %r12
jl 0xfdbe
leaq 0x2f0(%r13), %rdi
leaq 0x50(%rsp), %rdx
movl %r14d, %esi
callq 0x275dc
leaq 0x218(%r13), %r14
movq %r14, %rdi
movl $0x1, %esi
callq 0x299ac
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
movq 0x38(%rsp), %rcx
subq 0x30(%rsp), %rcx
shrq $0x2, %rax
shrq $0x3, %rcx
imull $0x55555555, %ecx, %esi # imm = 0x55555555
addl %eax, %esi
movq %r14, %rdi
callq 0x29970
movq 0x18(%r13), %rax
movq 0x48(%rsp), %rdx
movq 0x8(%rax,%rdx,8), %rcx
cmpq (%rax,%rdx,8), %rcx
jne 0xff31
movq 0x28(%rsp), %rdx
movq 0x8(%rax,%rdx,8), %rcx
cmpq (%rax,%rdx,8), %rcx
jne 0xff31
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xfe88
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
leaq 0x50(%rsp), %rdi
callq 0x8f6e
movl $0x1, %ebp
leaq 0x30(%rsp), %rdi
callq 0x8f6e
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x29836(%rip), %rdi     # 0x396f2
leaq 0x295dc(%rip), %rsi     # 0x3949f
leaq 0x297f9(%rip), %rcx     # 0x396c3
movl $0x205, %edx            # imm = 0x205
callq 0x31b0
leaq 0x29844(%rip), %rdi     # 0x3971f
leaq 0x295bd(%rip), %rsi     # 0x3949f
leaq 0x297da(%rip), %rcx     # 0x396c3
movl $0x206, %edx            # imm = 0x206
callq 0x31b0
leaq 0x29855(%rip), %rdi     # 0x3974f
leaq 0x2959e(%rip), %rsi     # 0x3949f
leaq 0x297bb(%rip), %rcx     # 0x396c3
movl $0x207, %edx            # imm = 0x207
callq 0x31b0
leaq 0x29781(%rip), %rdi     # 0x3969a
leaq 0x2957f(%rip), %rsi     # 0x3949f
leaq 0x2979c(%rip), %rcx     # 0x396c3
movl $0x204, %edx            # imm = 0x204
callq 0x31b0
leaq 0x296e1(%rip), %rdi     # 0x39619
leaq 0x29560(%rip), %rsi     # 0x3949f
leaq 0x2977d(%rip), %rcx     # 0x396c3
movl $0x222, %edx            # imm = 0x222
callq 0x31b0
jmp 0xff74
jmp 0xff74
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xffa1
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
jmp 0xffa1
jmp 0xff74
jmp 0xff74
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xff8e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
leaq 0x50(%rsp), %rdi
callq 0x8f6e
jmp 0xffa1
jmp 0xff9e
jmp 0xff9e
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x8f6e
movq %rbx, %rdi
callq 0x34a0
nop