// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rdi, %rbp
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, 0x50(%rsp)
subq (%rcx,%rdx,8), %rax
shrq $0x2, %rax
leal 0x1(,%r14,2), %edx
movslq %edx, %rdx
leaq (%rdx,%rdx,2), %r9
testl %eax, %eax
movq %r9, 0x8(%rsp)
jle 0xf7f3
movq 0x8(%rcx,%r9,8), %rdx
subq (%rcx,%r9,8), %rdx
shrq $0x2, %rdx
addl %eax, %edx
movq %rdx, 0x88(%rsp)
movq $0x0, 0x80(%rsp)
movq $0x0, 0x78(%rsp)
movq %rbp, 0x48(%rsp)
movq (%rcx,%r9,8), %rdx
movq 0x8(%rcx,%r9,8), %rax
subq %rdx, %rax
shrq $0x2, %rax
testl %eax, %eax
jle 0xf7c9
xorl %r10d, %r10d
movq 0x50(%rsp), %rax
movq (%rcx,%rax,8), %rax
movq 0x78(%rsp), %rcx
movslq (%rax,%rcx,4), %rax
movq (%rbp), %rbx
leaq (%rax,%rax,4), %rsi
movq %r10, 0x58(%rsp)
movslq (%rdx,%r10,4), %rax
leaq (%rax,%rax,4), %rax
leaq (%rbx,%rax,8), %r15
movq (%rbx,%rsi,8), %rcx
movq %rsi, 0x90(%rsp)
movq 0x8(%rbx,%rsi,8), %rdx
subq %rcx, %rdx
shrq $0x2, %rdx
testl %edx, %edx
jle 0xf53f
movq (%r15), %rsi
movq 0x8(%r15), %rdi
subq %rsi, %rdi
shrq $0x2, %rdi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %r8d, %r8d
xorl %r9d, %r9d
cmpl %edi, %r9d
jge 0xf537
movl (%rcx,%r8,4), %r10d
movl %r10d, %ebp
sarl %ebp
movslq %r9d, %r11
leaq (%rsi,%r11,4), %r13
shlq $0x20, %r11
movl (%r13), %eax
cmpl %r10d, %eax
jg 0xf518
cmpl %r14d, %ebp
setne %r12b
xorl %r10d, %eax
cmpl $0x1, %eax
sete %al
testb %r12b, %al
jne 0xf798
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r11
incl %r9d
addq $0x4, %r13
cmpl %r9d, %edi
jne 0xf4d8
movl %edi, %r9d
jmp 0xf537
cmpl %r14d, %ebp
setne %al
sarq $0x1e, %r11
xorl (%rsi,%r11), %r10d
cmpl $0x1, %r10d
sete %r10b
testb %al, %r10b
jne 0xf798
incq %r8
cmpq %rdx, %r8
jne 0xf4bf
movq 0x80(%rsp), %rax
subq 0x30(%rsp), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
cmpl 0x88(%rsp), %eax
jge 0xf8ea
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x2259a
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xf59a
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x90(%rsp), %rax
leaq (%rbx,%rax,8), %rbx
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0xf6a9
xorl %r13d, %r13d
xorl %r12d, %r12d
movq (%r15), %rdx
movq 0x8(%r15), %rcx
subq %rdx, %rcx
shrq $0x2, %rcx
cmpl %ecx, %r12d
jge 0xf63b
movslq %r12d, %r12
leaq (,%r12,4), %rbp
movl (%rdx,%rbp), %ecx
movq (%rbx), %rax
cmpl (%rax,%r13,4), %ecx
jg 0xf63b
movl %ecx, %eax
sarl %eax
cmpl %r14d, %eax
je 0xf61f
movq 0x38(%rsp), %rdi
movq -0x10(%rdi), %rsi
cmpq -0x8(%rdi), %rsi
je 0xf610
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x10(%rdi)
jmp 0xf61f
addq %rbp, %rdx
addq $-0x18, %rdi
callq 0x98f8
movq (%r15), %rdx
incq %r12
movq 0x8(%r15), %rax
subq %rdx, %rax
shrq $0x2, %rax
cltq
addq $0x4, %rbp
cmpq %rax, %r12
jl 0xf5e0
movq (%rbx), %rax
movq 0x38(%rsp), %rdi
movq -0x10(%rdi), %rsi
movq %rsi, %rcx
subq -0x18(%rdi), %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0xf65e
movl (%rax,%r13,4), %ecx
cmpl %ecx, -0x4(%rsi)
jne 0xf662
jmp 0xf68d
movl (%rax,%r13,4), %ecx
movl %ecx, %edx
sarl %edx
cmpl %r14d, %edx
je 0xf68d
cmpq -0x8(%rdi), %rsi
je 0xf67d
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x10(%rdi)
jmp 0xf68d
addq $-0x18, %rdi
leaq (%rax,%r13,4), %rdx
callq 0x98f8
movq (%rbx), %rax
incq %r13
movq 0x8(%rbx), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jl 0xf5c2
jmp 0xf6ac
xorl %r12d, %r12d
movq (%r15), %rdx
movq 0x8(%r15), %rax
subq %rdx, %rax
shrq $0x2, %rax
cmpl %eax, %r12d
jge 0xf71a
movslq %r12d, %rbx
leaq (,%rbx,4), %r12
movl (%rdx,%r12), %eax
movl %eax, %ecx
sarl %ecx
cmpl %r14d, %ecx
je 0xf701
movq 0x38(%rsp), %rdi
movq -0x10(%rdi), %rsi
cmpq -0x8(%rdi), %rsi
je 0xf6f2
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x10(%rdi)
jmp 0xf701
addq %r12, %rdx
addq $-0x18, %rdi
callq 0x98f8
movq (%r15), %rdx
incq %rbx
movq 0x8(%r15), %rax
subq %rdx, %rax
shrq $0x2, %rax
cltq
addq $0x4, %r12
cmpq %rax, %rbx
jl 0xf6ca
movq 0x38(%rsp), %rax
movq -0x18(%rax), %rcx
movq -0x10(%rax), %rdx
subq %rcx, %rdx
shrq $0x2, %rdx
cmpl $0x2, %edx
movq %rax, 0x80(%rsp)
jl 0xf798
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x1, %esi
movq 0x48(%rsp), %rbp
movq 0x8(%rsp), %r9
movq 0x58(%rsp), %r10
movl (%rcx,%rsi,4), %edi
movl %edi, %eax
sarl %eax
cmpl %r14d, %eax
je 0xfa31
movl -0x4(%rcx,%rsi,4), %r8d
movl %r8d, %eax
sarl %eax
cmpl %r14d, %eax
je 0xfa50
cmpl %r8d, %edi
jle 0xfa6f
xorl %edi, %r8d
cmpl $0x1, %r8d
je 0xfa12
incq %rsi
cmpq %rsi, %rdx
jne 0xf755
jmp 0xf7a7
movq 0x48(%rsp), %rbp
movq 0x8(%rsp), %r9
movq 0x58(%rsp), %r10
incq %r10
movq 0x18(%rbp), %rcx
movq (%rcx,%r9,8), %rdx
movq 0x8(%rcx,%r9,8), %rax
subq %rdx, %rax
shrq $0x2, %rax
cltq
cmpq %rax, %r10
jl 0xf45a
movq 0x50(%rsp), %rdx
movq 0x8(%rcx,%rdx,8), %rax
subq (%rcx,%rdx,8), %rax
movq 0x78(%rsp), %rsi
incq %rsi
shrq $0x2, %rax
cltq
movq %rsi, 0x78(%rsp)
cmpq %rax, %rsi
jl 0xf43f
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
xorl %eax, %eax
movq %rax, 0x70(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x50(%rsp), %rax
movq (%rcx,%rax,8), %rbx
movq 0x8(%rcx,%rax,8), %r12
cmpq %r12, %rbx
je 0xf865
leaq 0x10(%rsp), %r15
leaq 0x4(%rsp), %r13
movl (%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xf848
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0xf853
movq %r15, %rdi
movq %r13, %rdx
callq 0x98f8
addq $0x4, %rbx
cmpq %r12, %rbx
jne 0xf829
movq 0x18(%rbp), %rcx
movq 0x8(%rsp), %r9
movq (%rcx,%r9,8), %rbx
movq 0x8(%rcx,%r9,8), %r12
cmpq %r12, %rbx
je 0xf8cb
leaq 0x4(%rsp), %r15
leaq 0x60(%rsp), %r13
movl (%rbx), %eax
movl %eax, 0x4(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xf89c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0xf8a9
leaq 0x10(%rsp), %rdi
movq %r15, %rdx
callq 0x98f8
movslq 0x4(%rsp), %rax
leaq (%rax,%rax,4), %rsi
shlq $0x3, %rsi
addq (%rbp), %rsi
movq %r13, %rdi
callq 0x1f07e
addq $0x4, %rbx
cmpq %r12, %rbx
jne 0xf87d
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r15
cmpq %r15, %rbx
je 0xf8f1
movl (%rbx), %esi
movq %rbp, %rdi
callq 0x27f28
addq $0x4, %rbx
jmp 0xf8d5
xorl %ebx, %ebx
jmp 0xf9f4
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rax
subq %rsi, %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
testl %eax, %eax
jle 0xf94e
xorl %ebx, %ebx
movabsq $-0x8000000000000000, %r15 # imm = 0x8000000000000000
xorl %r12d, %r12d
addq %rbx, %rsi
movq %rbp, %rdi
movq %r15, %rdx
callq 0x27f82
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 0xf91b
leaq 0x2f0(%rbp), %rdi
leaq 0x60(%rsp), %rdx
movl %r14d, %esi
callq 0x26904
leaq 0x218(%rbp), %r14
movq %r14, %rdi
movl $0x1, %esi
callq 0x28c64
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 0x28c28
movq 0x18(%rbp), %rax
movq 0x50(%rsp), %rdx
movq 0x8(%rax,%rdx,8), %rcx
cmpq (%rax,%rdx,8), %rcx
movq 0x8(%rsp), %rdx
jne 0xfa8e
movq 0x8(%rax,%rdx,8), %rcx
cmpq (%rax,%rdx,8), %rcx
jne 0xfa8e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xf9e5
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
leaq 0x60(%rsp), %rdi
callq 0x8f5e
movl $0x1, %ebx
leaq 0x30(%rsp), %rdi
callq 0x8f5e
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28de6(%rip), %rdi     # 0x387ff
leaq 0x28b2f(%rip), %rsi     # 0x3854f
leaq 0x28d4c(%rip), %rcx     # 0x38773
movl $0x207, %edx            # imm = 0x207
callq 0x31b0
leaq 0x28d12(%rip), %rdi     # 0x3874a
leaq 0x28b10(%rip), %rsi     # 0x3854f
leaq 0x28d2d(%rip), %rcx     # 0x38773
movl $0x204, %edx            # imm = 0x204
callq 0x31b0
leaq 0x28d4b(%rip), %rdi     # 0x387a2
leaq 0x28af1(%rip), %rsi     # 0x3854f
leaq 0x28d0e(%rip), %rcx     # 0x38773
movl $0x205, %edx            # imm = 0x205
callq 0x31b0
leaq 0x28d59(%rip), %rdi     # 0x387cf
leaq 0x28ad2(%rip), %rsi     # 0x3854f
leaq 0x28cef(%rip), %rcx     # 0x38773
movl $0x206, %edx            # imm = 0x206
callq 0x31b0
leaq 0x28c34(%rip), %rdi     # 0x386c9
leaq 0x28ab3(%rip), %rsi     # 0x3854f
leaq 0x28cd0(%rip), %rcx     # 0x38773
movl $0x222, %edx            # imm = 0x222
callq 0x31b0
jmp 0xfab5
jmp 0xfab5
jmp 0xfab5
jmp 0xfab5
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xfacf
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
leaq 0x60(%rsp), %rdi
callq 0x8f5e
jmp 0xfafe
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xfafe
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
jmp 0xfafe
jmp 0xfafb
jmp 0xfafb
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x8f5e
movq %rbx, %rdi
callq 0x34a0