// File: Laakeri[P]maxpre/src/./BCE.cpp
// Function: maxPreprocessor::Preprocessor::doBCE()
int Preprocessor::doBCE() {
	rLog.startTechnique(Log::Technique::BCE);
	if (!rLog.requestTime(Log::Technique::BCE)) {
		rLog.stopTechnique(Log::Technique::BCE);
		return 0;
	}
	int removed = 0;
	vector<int> checkVar = pi.tl.getTouchedVariables("BCE");
	if (rLog.isTimeLimit()) {
		auto cmp = [&](int var1, int var2) {
			return pi.litClauses[posLit(var1)].size() + pi.litClauses[negLit(var1)].size() < pi.litClauses[posLit(var2)].size() + pi.litClauses[negLit(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::BCE)) break;
			int var = checkVar[getRand(0, (int)checkVar.size() - 1)];
			if (pi.isLabel[var] == 0) {
				removed += tryBCE(negLit(var));
				removed += tryBCE(posLit(var));
			}
		}
		if (removed == 0) {
			log("BCE skipped");
			skip = true;
		}
	}
	if (!skip) {
		for (int var : checkVar) {
			if (!rLog.requestTime(Log::Technique::BCE)) break;
			if (pi.isLabel[var] == 0) {
				removed += tryBCE(negLit(var));
				removed += tryBCE(posLit(var));
			}
		}
	}
	log(removed, " removed by BCE");
	rLog.stopTechnique(Log::Technique::BCE);
	return removed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x1, %esi
callq 0x61320
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x1, %esi
callq 0x62450
testb $0x1, %al
jne 0x1e7fb
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x1, %esi
callq 0x61390
movl $0x0, -0x4(%rbp)
jmp 0x1ec48
movq -0xc0(%rbp), %rax
movl $0x0, -0x14(%rbp)
addq $0x68, %rax
movq %rax, -0xd0(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x4620
movq -0xc8(%rbp), %rdx
leaq 0x67f55(%rip), %rsi     # 0x86787
leaq -0x50(%rbp), %rdi
callq 0xa430
jmp 0x1e83d
movq -0xd0(%rbp), %rsi
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x73700
jmp 0x1e853
leaq -0x50(%rbp), %rdi
callq 0x4240
leaq -0x51(%rbp), %rdi
callq 0x43f0
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x62aa0
movb %al, -0xd1(%rbp)
jmp 0x1e880
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x1e88f
jmp 0x1e92c
movq -0xc0(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0xa800
movq -0xe0(%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 0x1ec60
jmp 0x1e8df
jmp 0x1e92c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1e904
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 0x1ec54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
jmp 0x1ec54
movq -0xc0(%rbp), %rax
movb $0x0, -0x89(%rbp)
cmpl $0x0, 0x468(%rax)
jle 0x1eac3
leaq -0x30(%rbp), %rdi
callq 0xf940
movq -0xc0(%rbp), %rcx
movl 0x468(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jl 0x1eac3
movl $0x0, -0x90(%rbp)
movq -0xc0(%rbp), %rcx
movl -0x90(%rbp), %eax
cmpl 0x468(%rcx), %eax
jge 0x1ea9f
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x1, %esi
callq 0x62450
movb %al, -0xe1(%rbp)
jmp 0x1e9ab
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x1e9bc
jmp 0x1e9b7
jmp 0x1ea9f
leaq -0x30(%rbp), %rdi
callq 0xf940
movq -0xc0(%rbp), %rdi
movl %eax, %edx
decl %edx
xorl %esi, %esi
callq 0x3cf00
movl %eax, -0xe8(%rbp)
jmp 0x1e9df
movl -0xe8(%rbp), %eax
movslq %eax, %rsi
leaq -0x30(%rbp), %rdi
callq 0xa7c0
movq -0xc0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x94(%rbp)
addq $0x48, %rdi
movslq -0x94(%rbp), %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
jne 0x1ea89
movl -0x94(%rbp), %edi
callq 0x3c5e0
movl %eax, -0xec(%rbp)
jmp 0x1ea28
movl -0xec(%rbp), %esi
movq -0xc0(%rbp), %rdi
callq 0x1e3a0
movl %eax, -0xf0(%rbp)
jmp 0x1ea42
movl -0xf0(%rbp), %ecx
movl -0x14(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x94(%rbp), %edi
callq 0x3c5d0
movl %eax, -0xf4(%rbp)
jmp 0x1ea63
movl -0xf4(%rbp), %esi
movq -0xc0(%rbp), %rdi
callq 0x1e3a0
movl %eax, -0xf8(%rbp)
jmp 0x1ea7d
movl -0xf8(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x1ea8b
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x1e972
cmpl $0x0, -0x14(%rbp)
jne 0x1eac1
movq -0xc0(%rbp), %rdi
leaq 0x67cbc(%rip), %rsi     # 0x8676f
callq 0x3cf50
jmp 0x1eaba
movb $0x1, -0x89(%rbp)
jmp 0x1eac3
testb $0x1, -0x89(%rbp)
jne 0x1ec07
leaq -0x30(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
callq 0xa800
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rdi
callq 0xa830
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xa860
testb $0x1, %al
jne 0x1eb1d
jmp 0x1ec05
leaq -0xa8(%rbp), %rdi
callq 0xa8a0
movq -0xc0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xb4(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x1, %esi
callq 0x62450
movb %al, -0xf9(%rbp)
jmp 0x1eb51
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x1eb62
jmp 0x1eb5d
jmp 0x1ec05
movq -0xc0(%rbp), %rdi
addq $0x48, %rdi
movslq -0xb4(%rbp), %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
jne 0x1ebf2
movl -0xb4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x100(%rbp)
jmp 0x1eb91
movl -0x100(%rbp), %esi
movq -0xc0(%rbp), %rdi
callq 0x1e3a0
movl %eax, -0x104(%rbp)
jmp 0x1ebab
movl -0x104(%rbp), %ecx
movl -0x14(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0xb4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x108(%rbp)
jmp 0x1ebcc
movl -0x108(%rbp), %esi
movq -0xc0(%rbp), %rdi
callq 0x1e3a0
movl %eax, -0x10c(%rbp)
jmp 0x1ebe6
movl -0x10c(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x1ebf4
leaq -0xa8(%rbp), %rdi
callq 0xa930
jmp 0x1eb01
jmp 0x1ec07
movq -0xc0(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq 0x67b63(%rip), %rdx     # 0x8677b
callq 0x3c620
jmp 0x1ec1f
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x1, %esi
callq 0x61390
jmp 0x1ec39
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x4610
nopl (%rax)