// File: /workspace/github_cpp_makefile_star2_O1/Laakeri[P]maxpre/src/./BVE.cpp
// Function: maxPreprocessor::Preprocessor::doBVE()
int Preprocessor::doBVE() {
	rLog.startTechnique(Log::Technique::BVE);
	if (!rLog.requestTime(Log::Technique::BVE)) {
		rLog.stopTechnique(Log::Technique::BVE);
		return 0;
	}
	int eliminated = 0;
	vector<int> checkVar = pi.tl.getTouchedVariables("BVE");
	if (rLog.isTimeLimit()) {
		auto cmp = [&](int var1, int var2) {
			return pi.litClauses[negLit(var1)].size() + pi.litClauses[posLit(var1)].size() < pi.litClauses[negLit(var2)].size() + pi.litClauses[posLit(var2)].size();
		};
		sort(checkVar.begin(), checkVar.end(), cmp);
	}
  if (BVEsortMaxFirst) {
    auto cmp = [&](int var1, int var2) {
      return pi.litClauses[negLit(var1)].size() + pi.litClauses[posLit(var1)].size() > pi.litClauses[negLit(var2)].size() + pi.litClauses[posLit(var2)].size();
    };
    sort(checkVar.begin(), checkVar.end(), cmp);
  }
	bool skip = false;
	if (skipTechnique > 0 && (int)checkVar.size() >= skipTechnique * 4) {
		for (int tc = 0; tc < skipTechnique; tc++) {
			if (!rLog.requestTime(Log::Technique::BVE)) break;
			int var = checkVar[getRand(0, (int)checkVar.size() - 1)];
			if (pi.isLabel[var] == 0 && (pi.litClauses[posLit(var)].size() > 0 || pi.litClauses[negLit(var)].size() > 0)) {
				eliminated += tryBVE2(var);
			}
		}
		if (eliminated == 0) {
			skip = true;
			log("BVE skipped");
		}
	}
	if (!skip) {
		for (int var : checkVar) {
			if (!rLog.requestTime(Log::Technique::BVE)) break;
			if (pi.isLabel[var] == 0 && (pi.litClauses[posLit(var)].size() > 0 || pi.litClauses[negLit(var)].size() > 0)) {
				eliminated += tryBVE2(var);
			}
		}
	}
	log(eliminated, " eliminated by BVE");
	rLog.stopTechnique(Log::Technique::BVE);
	return eliminated;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
leaq 0x218(%rdi), %rbx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x298e6
movq %rbx, %rdi
movl $0x3, %esi
callq 0x2a464
testb %al, %al
je 0x100b1
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x28ee2(%rip), %rsi     # 0x38ee1
leaq 0x28ede(%rip), %rdx     # 0x38ee4
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x945c
leaq 0x68(%r14), %rsi
leaq 0x8(%rsp), %rdi
movq %r15, %rdx
callq 0x307c8
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x1003b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x2a792
testb %al, %al
je 0x100d3
movq 0x8(%rsp), %r12
movq 0x10(%rsp), %r15
cmpq %r15, %r12
je 0x100d3
movq %r15, %r13
subq %r12, %r13
movq %r13, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rcx
callq 0x1b7a5
cmpq $0x41, %r13
jl 0x100c5
leaq 0x40(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x1bbdd
cmpq %r15, %r13
je 0x100d3
movq %r13, %rdi
movq %r14, %rsi
callq 0x1bc6d
addq $0x4, %r13
jmp 0x1009b
movq %rbx, %rdi
movl $0x3, %esi
callq 0x29928
xorl %ebp, %ebp
jmp 0x1033a
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1bbdd
cmpb $0x1, 0x3a1(%r14)
jne 0x10151
movq 0x8(%rsp), %r12
movq 0x10(%rsp), %r15
cmpq %r15, %r12
je 0x10151
movq %r15, %r13
subq %r12, %r13
movq %r13, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rcx
callq 0x1bcf2
cmpq $0x41, %r13
jl 0x10143
leaq 0x40(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x1c129
cmpq %r15, %r13
je 0x10151
movq %r13, %rdi
movq %r14, %rsi
callq 0x1c1b9
addq $0x4, %r13
jmp 0x1012d
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1c129
movl 0x468(%r14), %eax
testl %eax, %eax
jle 0x10245
movq 0x10(%rsp), %rcx
subq 0x8(%rsp), %rcx
shrq $0x2, %rcx
shll $0x2, %eax
xorl %ebp, %ebp
movl $0x0, %edx
cmpl %ecx, %eax
jg 0x10271
cmpl $0x0, 0x468(%r14)
jle 0x1024b
leaq 0x470(%r14), %r15
movl $0x0, 0x4(%rsp)
leaq 0x20(%rsp), %r12
xorl %r13d, %r13d
movq %rbx, %rdi
movl $0x3, %esi
callq 0x2a464
testb %al, %al
je 0x10253
movq 0x10(%rsp), %rax
subq 0x8(%rsp), %rax
shrq $0x2, %rax
decl %eax
movl $0x0, 0x20(%rsp)
movl %eax, 0x24(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2152e
cltq
movq 0x8(%rsp), %rcx
movslq (%rcx,%rax,4), %rsi
movq 0x48(%r14), %rax
cmpl $0x0, (%rax,%rsi,4)
jne 0x10233
leal (%rsi,%rsi), %ecx
movslq %ecx, %rdx
movq 0x18(%r14), %rax
leaq (%rdx,%rdx,2), %rdx
movq 0x8(%rax,%rdx,8), %rdi
cmpq (%rax,%rdx,8), %rdi
jne 0x10227
orl $0x1, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
cmpq (%rax,%rcx,8), %rdx
je 0x10233
movq %r14, %rdi
callq 0xebf6
addl %eax, 0x4(%rsp)
incl %r13d
cmpl 0x468(%r14), %r13d
jl 0x101a5
jmp 0x10253
xorl %ebp, %ebp
xorl %edx, %edx
jmp 0x10271
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
movl 0x4(%rsp), %edx
testl %edx, %edx
jne 0x10271
movb $0x1, %bpl
leaq 0x29526(%rip), %rsi     # 0x3978d
movq %r14, %rdi
callq 0x1f6a2
xorl %edx, %edx
testb %bpl, %bpl
movl %edx, 0x4(%rsp)
jne 0x10301
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %rbp
cmpq %rbp, %r13
je 0x10301
addq $0x4, %r13
movslq -0x4(%r13), %r12
movq %rbx, %rdi
movl $0x3, %esi
callq 0x2a464
movl %eax, %r15d
testb %al, %al
je 0x102f2
movq 0x48(%r14), %rax
cmpl $0x0, (%rax,%r12,4)
jne 0x102f2
leal (%r12,%r12), %ecx
movslq %ecx, %rdx
movq 0x18(%r14), %rax
leaq (%rdx,%rdx,2), %rdx
movq 0x8(%rax,%rdx,8), %rsi
cmpq (%rax,%rdx,8), %rsi
jne 0x102e3
orl $0x1, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
cmpq (%rax,%rcx,8), %rdx
je 0x102f2
movq %r14, %rdi
movl %r12d, %esi
callq 0xebf6
addl %eax, 0x4(%rsp)
cmpq %rbp, %r13
setne %al
addq $0x4, %r13
testb %al, %r15b
jne 0x10291
leaq 0x29491(%rip), %rdx     # 0x39799
movq %r14, %rdi
movl 0x4(%rsp), %ebp
movl %ebp, %esi
callq 0x1f426
movq %rbx, %rdi
movl $0x3, %esi
callq 0x29928
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1033a
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1036a
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x10384
movq 0x38(%rsp), %rsi
incq %rsi
jmp 0x1037f
jmp 0x1036a
jmp 0x1036a
jmp 0x1036a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x10384
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x34a0