// File: 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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x3, %esi
callq 0x61320
movq -0xe0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x3, %esi
callq 0x62450
testb $0x1, %al
jne 0x1b4fb
movq -0xe0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x3, %esi
callq 0x61390
movl $0x0, -0x4(%rbp)
jmp 0x1ba4a
movq -0xe0(%rbp), %rax
movl $0x0, -0x14(%rbp)
addq $0x68, %rax
movq %rax, -0xf0(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x4620
movq -0xe8(%rbp), %rdx
leaq 0x6a9af(%rip), %rsi     # 0x85ee1
leaq -0x50(%rbp), %rdi
callq 0xa430
jmp 0x1b53d
movq -0xf0(%rbp), %rsi
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x73700
jmp 0x1b553
leaq -0x50(%rbp), %rdi
callq 0x4240
leaq -0x51(%rbp), %rdi
callq 0x43f0
movq -0xe0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x62aa0
movb %al, -0xf1(%rbp)
jmp 0x1b580
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x1b58f
jmp 0x1b62c
movq -0xe0(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0xa800
movq -0x100(%rbp), %rdi
movq %rax, -0x78(%rbp)
callq 0xa830
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0x1ba60
jmp 0x1b5df
jmp 0x1b62c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1b604
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4240
leaq -0x51(%rbp), %rdi
callq 0x43f0
jmp 0x1ba56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
jmp 0x1ba56
movq -0xe0(%rbp), %rax
testb $0x1, 0x3a1(%rax)
je 0x1b6a0
movq -0xe0(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0xa800
movq -0x108(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0xa830
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0x1bab0
jmp 0x1b69e
jmp 0x1b6a0
movq -0xe0(%rbp), %rax
movb $0x0, -0xa9(%rbp)
cmpl $0x0, 0x468(%rax)
jle 0x1b87f
leaq -0x30(%rbp), %rdi
callq 0xf940
movq -0xe0(%rbp), %rcx
movl 0x468(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jl 0x1b87f
movl $0x0, -0xb0(%rbp)
movq -0xe0(%rbp), %rcx
movl -0xb0(%rbp), %eax
cmpl 0x468(%rcx), %eax
jge 0x1b859
movq -0xe0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x3, %esi
callq 0x62450
movb %al, -0x109(%rbp)
jmp 0x1b71f
movb -0x109(%rbp), %al
testb $0x1, %al
jne 0x1b730
jmp 0x1b72b
jmp 0x1b859
leaq -0x30(%rbp), %rdi
callq 0xf940
movq -0xe0(%rbp), %rdi
movl %eax, %edx
decl %edx
xorl %esi, %esi
callq 0x3cf00
movl %eax, -0x110(%rbp)
jmp 0x1b753
movl -0x110(%rbp), %eax
movslq %eax, %rsi
leaq -0x30(%rbp), %rdi
callq 0xa7c0
movq -0xe0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xb4(%rbp)
addq $0x48, %rdi
movslq -0xb4(%rbp), %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
jne 0x1b843
movq -0xe0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x120(%rbp)
movl -0xb4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x114(%rbp)
jmp 0x1b7b2
movq -0x120(%rbp), %rdi
movl -0x114(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
ja 0x1b81d
movq -0xe0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x130(%rbp)
movl -0xb4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x124(%rbp)
jmp 0x1b7fa
movq -0x130(%rbp), %rdi
movl -0x124(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
jbe 0x1b843
movq -0xe0(%rbp), %rdi
movl -0xb4(%rbp), %esi
callq 0x19340
movl %eax, -0x134(%rbp)
jmp 0x1b837
movl -0x134(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x1b845
movl -0xb0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb0(%rbp)
jmp 0x1b6e6
cmpl $0x0, -0x14(%rbp)
jne 0x1b87d
movq -0xe0(%rbp), %rdi
movb $0x1, -0xa9(%rbp)
leaq 0x6aea9(%rip), %rsi     # 0x8671d
callq 0x3cf50
jmp 0x1b87b
jmp 0x1b87d
jmp 0x1b87f
testb $0x1, -0xa9(%rbp)
jne 0x1ba09
leaq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
callq 0xa800
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
callq 0xa830
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xa860
testb $0x1, %al
jne 0x1b8d9
jmp 0x1ba07
leaq -0xc8(%rbp), %rdi
callq 0xa8a0
movq -0xe0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xd4(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x3, %esi
callq 0x62450
movb %al, -0x135(%rbp)
jmp 0x1b90d
movb -0x135(%rbp), %al
testb $0x1, %al
jne 0x1b91e
jmp 0x1b919
jmp 0x1ba07
movq -0xe0(%rbp), %rdi
addq $0x48, %rdi
movslq -0xd4(%rbp), %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
jne 0x1b9f4
movq -0xe0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x148(%rbp)
movl -0xd4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x13c(%rbp)
jmp 0x1b963
movq -0x148(%rbp), %rdi
movl -0x13c(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
ja 0x1b9ce
movq -0xe0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x158(%rbp)
movl -0xd4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x14c(%rbp)
jmp 0x1b9ab
movq -0x158(%rbp), %rdi
movl -0x14c(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
jbe 0x1b9f4
movq -0xe0(%rbp), %rdi
movl -0xd4(%rbp), %esi
callq 0x19340
movl %eax, -0x15c(%rbp)
jmp 0x1b9e8
movl -0x15c(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x1b9f6
leaq -0xc8(%rbp), %rdi
callq 0xa930
jmp 0x1b8bd
jmp 0x1ba09
movq -0xe0(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq 0x6ad0f(%rip), %rdx     # 0x86729
callq 0x3c620
jmp 0x1ba21
movq -0xe0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x3, %esi
callq 0x61390
jmp 0x1ba3b
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x4610
nop