// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movl %esi, %r14d
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leal (%r14,%r14), %eax
cltq
movq %rdi, 0x8(%rsp)
movq 0x18(%rdi), %rcx
imulq $0x18, %rax, %r12
movq (%rcx,%r12), %rbx
movq 0x8(%rcx,%r12), %r13
movq %r13, %rsi
subq %rbx, %rsi
shrq $0x2, %rsi
leal 0x1(,%r14,2), %eax
cltq
imulq $0x18, %rax, %rdx
movq 0x8(%rcx,%rdx), %rax
movq %rdx, 0x30(%rsp)
subq (%rcx,%rdx), %rax
shrq $0x2, %rax
addl %eax, %esi
movq %rsi, 0x90(%rsp)
xorl %eax, %eax
xorl %esi, %esi
movq %r12, 0x58(%rsp)
movq %r13, %rdx
subq %rbx, %rdx
shrq $0x2, %rdx
movslq %edx, %rdx
cmpq %rdx, %rsi
jge 0xc543
movq %rsi, 0x60(%rsp)
xorl %r10d, %r10d
movq 0x8(%rsp), %r13
movq 0x30(%rsp), %rsi
movq (%rcx,%rsi), %rdx
movq 0x8(%rcx,%rsi), %rsi
subq %rdx, %rsi
shrq $0x2, %rsi
movslq %esi, %rsi
cmpq %rsi, %r10
jge 0xc525
movq (%rcx,%r12), %rsi
movq 0x60(%rsp), %rdi
movslq (%rsi,%rdi,4), %rsi
movq (%r13), %rdi
imulq $0x28, %rsi, %rsi
leaq (%rdi,%rsi), %r8
movq %r8, 0x68(%rsp)
movq %r10, 0x38(%rsp)
movslq (%rdx,%r10,4), %rdx
imulq $0x28, %rdx, %rbx
addq %rdi, %rbx
movq (%rdi,%rsi), %rdx
movq 0x8(%rdi,%rsi), %rsi
subq %rdx, %rsi
shrq $0x2, %rsi
testl %esi, %esi
movl $0x0, %edi
cmovlel %edi, %esi
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rsi, %rdi
je 0xc36a
movq (%rbx), %r9
movq 0x8(%rbx), %r11
subq %r9, %r11
movq %r8, %r10
shlq $0x20, %r10
movslq %r8d, %r8
shrq $0x2, %r11
movslq %r11d, %r11
cmpq %r11, %r8
jge 0xc355
movl (%r9,%r8,4), %r15d
movl (%rdx,%rdi,4), %ebp
cmpl %ebp, %r15d
jg 0xc334
xorl %ebp, %r15d
cmpl $0x1, %r15d
sete %r15b
sarl %ebp
cmpl %r14d, %ebp
setne %bpl
testb %bpl, %r15b
jne 0xc35d
incq %r8
movabsq $0x100000000, %r15      # imm = 0x100000000
addq %r15, %r10
jmp 0xc2f8
sarq $0x1e, %r10
movl (%r9,%r10), %r9d
xorl %ebp, %r9d
cmpl $0x1, %r9d
sete %r9b
sarl %ebp
cmpl %r14d, %ebp
setne %r10b
testb %r10b, %r9b
jne 0xc35d
incq %rdi
jmp 0xc2d4
movq 0x38(%rsp), %r10
incq %r10
jmp 0xc266
subq 0x10(%rsp), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpl 0x90(%rsp), %eax
jge 0xc53b
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %r15
movq %r15, %rsi
callq 0x1cb40
movq %r15, %rdi
callq 0x7512
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x68(%rsp), %r12
movq (%r12), %rax
movq 0x8(%r12), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
movslq %ebp, %r12
cmpq %rcx, %r13
jge 0xc46d
leaq (,%r12,4), %r15
movq %r12, %rbp
movq 0x68(%rsp), %r12
movq (%rbx), %rsi
movq 0x8(%rbx), %rcx
subq %rsi, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jge 0xc42a
movl (%rsi,%r15), %ecx
cmpl (%rax,%r13,4), %ecx
jg 0xc42a
sarl %ecx
cmpl %r14d, %ecx
je 0xc421
addq %r15, %rsi
movq 0x18(%rsp), %rdi
addq $-0x18, %rdi
callq 0x68a4
movq (%r12), %rax
incq %rbp
addq $0x4, %r15
jmp 0xc3e5
movq 0x18(%rsp), %rdi
movq -0x10(%rdi), %rdx
movq %rdx, %rcx
subq -0x18(%rdi), %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0xc44d
movl (%rax,%r13,4), %ecx
cmpl %ecx, -0x4(%rdx)
jne 0xc451
jmp 0xc465
movl (%rax,%r13,4), %ecx
sarl %ecx
cmpl %r14d, %ecx
je 0xc465
addq $-0x18, %rdi
leaq (%rax,%r13,4), %rsi
callq 0x68a4
incq %r13
jmp 0xc3b6
movslq %ebp, %r15
shlq $0x2, %r15
movq 0x8(%rsp), %r13
movq (%rbx), %rsi
movq 0x8(%rbx), %rax
subq %rsi, %rax
shrq $0x2, %rax
cltq
cmpq %rax, %r12
jge 0xc4b3
movl (%rsi,%r15), %eax
sarl %eax
cmpl %r14d, %eax
je 0xc4aa
addq %r15, %rsi
movq 0x18(%rsp), %rdi
addq $-0x18, %rdi
callq 0x68a4
incq %r12
addq $0x4, %r15
jmp 0xc479
movq 0x18(%rsp), %rax
movq -0x18(%rax), %rcx
movq -0x10(%rax), %rdx
subq %rcx, %rdx
shrq $0x2, %rdx
movslq %edx, %rdx
pushq $0x1
popq %rsi
movq 0x58(%rsp), %r12
movq 0x38(%rsp), %r10
cmpq %rdx, %rsi
jge 0xc51c
movl (%rcx,%rsi,4), %edi
movl %edi, %r8d
sarl %r8d
cmpl %r14d, %r8d
je 0xc732
movl -0x4(%rcx,%rsi,4), %r8d
movl %r8d, %r9d
sarl %r9d
cmpl %r14d, %r9d
je 0xc751
cmpl %r8d, %edi
jle 0xc6f4
xorl %edi, %r8d
incq %rsi
cmpl $0x1, %r8d
jne 0xc4d7
jmp 0xc713
movq 0x18(%r13), %rcx
jmp 0xc362
movq 0x60(%rsp), %rsi
incq %rsi
movq (%rcx,%r12), %rbx
movq 0x8(%rcx,%r12), %r13
jmp 0xc243
xorl %r15d, %r15d
jmp 0xc6d5
andq $0x0, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
leaq 0x70(%rsp), %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
leaq 0x4(%rsp), %r12
cmpq %r13, %rbx
je 0xc580
movl (%rbx), %eax
movl %eax, 0x4(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x68a4
addq $0x4, %rbx
jmp 0xc564
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx), %rbx
movq 0x8(%rax,%rcx), %r13
leaq 0x70(%rsp), %rbp
leaq 0x4(%rsp), %r12
leaq 0x40(%rsp), %r15
cmpq %r13, %rbx
je 0xc5db
movl (%rbx), %eax
movl %eax, 0x4(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x68a4
movslq 0x4(%rsp), %rax
imulq $0x28, %rax, %rsi
movq 0x8(%rsp), %rax
addq (%rax), %rsi
movq %r15, %rdi
callq 0x18f96
addq $0x4, %rbx
jmp 0xc5a6
movq 0x70(%rsp), %rbx
movq 0x78(%rsp), %r15
movq 0x8(%rsp), %r13
cmpq %r15, %rbx
je 0xc5ff
movl (%rbx), %esi
movq %r13, %rdi
callq 0x21490
addq $0x4, %rbx
jmp 0xc5ea
xorl %ebx, %ebx
movabsq $-0x8000000000000000, %r15 # imm = 0x8000000000000000
xorl %r12d, %r12d
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cltq
cmpq %rax, %r12
jge 0xc641
addq %rbx, %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x214e8
incq %r12
addq $0x18, %rbx
jmp 0xc60e
leaq 0x2f0(%r13), %rdi
leaq 0x40(%rsp), %rdx
movl %r14d, %esi
callq 0x2034a
leaq 0x218(%r13), %r14
pushq $0x1
popq %r15
movq %r14, %rdi
movl %r15d, %esi
callq 0x21ebe
movq 0x78(%rsp), %rsi
subq 0x70(%rsp), %rsi
shrq $0x2, %rsi
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
pushq $-0x18
popq %rcx
cqto
idivq %rcx
addl %eax, %esi
movq %r14, %rdi
callq 0x21e84
movq 0x18(%r13), %rax
movq 0x58(%rsp), %rdx
movq 0x8(%rax,%rdx), %rcx
cmpq (%rax,%rdx), %rcx
jne 0xc770
movq 0x30(%rsp), %rdx
movq 0x8(%rax,%rdx), %rcx
cmpq (%rax,%rdx), %rcx
jne 0xc770
leaq 0x70(%rsp), %rdi
callq 0x7512
leaq 0x40(%rsp), %rdi
callq 0x6aa2
leaq 0x10(%rsp), %rdi
callq 0x6aa2
movl %r15d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23054(%rip), %rdi     # 0x2f74f
leaq 0x22dcd(%rip), %rsi     # 0x2f4cf
leaq 0x22fea(%rip), %rcx     # 0x2f6f3
movl $0x206, %edx            # imm = 0x206
callq 0x31c0
leaq 0x23065(%rip), %rdi     # 0x2f77f
leaq 0x22dae(%rip), %rsi     # 0x2f4cf
leaq 0x22fcb(%rip), %rcx     # 0x2f6f3
movl $0x207, %edx            # imm = 0x207
callq 0x31c0
leaq 0x22f91(%rip), %rdi     # 0x2f6ca
leaq 0x22d8f(%rip), %rsi     # 0x2f4cf
leaq 0x22fac(%rip), %rcx     # 0x2f6f3
movl $0x204, %edx            # imm = 0x204
callq 0x31c0
leaq 0x22fca(%rip), %rdi     # 0x2f722
leaq 0x22d70(%rip), %rsi     # 0x2f4cf
leaq 0x22f8d(%rip), %rcx     # 0x2f6f3
movl $0x205, %edx            # imm = 0x205
callq 0x31c0
leaq 0x22ed2(%rip), %rdi     # 0x2f649
leaq 0x22d51(%rip), %rsi     # 0x2f4cf
leaq 0x22f6e(%rip), %rcx     # 0x2f6f3
movl $0x222, %edx            # imm = 0x222
callq 0x31c0
jmp 0xc797
jmp 0xc797
jmp 0xc797
jmp 0xc797
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x7512
leaq 0x40(%rsp), %rdi
callq 0x6aa2
jmp 0xc7c6
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x7512
jmp 0xc7c6
jmp 0xc7c3
jmp 0xc7c3
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6aa2
movq %rbx, %rdi
callq 0x3490