// File: /workspace/github_cpp_makefile_star2_O2/Laakeri[P]maxpre/src/./BCR.cpp
// Function: maxPreprocessor::Preprocessor::doBCR()
int Preprocessor::doBCR() {
	rLog.startTechnique(Log::Technique::BCR);
	int removed = 0;
	if (!rLog.requestTime(Log::Technique::BCR)) {
		rLog.stopTechnique(Log::Technique::BCR);
		return 0;
	}
	vector<int> checkVar = pi.tl.getTouchedVariables("BCR");
	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);
	}
	for (int var : checkVar) {
		if (pi.isLabel[var] == VAR_UNDEFINED) continue;
		if (pi.isVarRemoved(var)) continue;
		if (!rLog.requestTime(Log::Technique::BCR)) break;
		if (pi.isLabel[var] == VAR_TRUE) {
			assert(pi.litClauses[posLit(var)].size() == 1);
			for (int c : pi.litClauses[negLit(var)]) {
				if (pi.clauses[c].lit.size() == 2) {
					if (pi.isLabel[litVariable(pi.clauses[c].lit[0])] && pi.isLabel[litVariable(pi.clauses[c].lit[1])]) {
						if (pi.labelWeight(litVariable(pi.clauses[c].lit[0])) == pi.labelWeight(litVariable(pi.clauses[c].lit[1]))) {
							if (tryBCR(c, negLit(var))) {
								removed++;
								break;
							}
						}
					}
				}
			}
		}
		else if(pi.isLabel[var] == VAR_FALSE) {
			assert(pi.litClauses[negLit(var)].size() == 1);
			for (int c : pi.litClauses[posLit(var)]) {
				if (pi.clauses[c].lit.size() == 2) {
					if (pi.isLabel[litVariable(pi.clauses[c].lit[0])] && pi.isLabel[litVariable(pi.clauses[c].lit[1])]) {
						if (pi.labelWeight(litVariable(pi.clauses[c].lit[0])) == pi.labelWeight(litVariable(pi.clauses[c].lit[1]))) {
							if (tryBCR(c, posLit(var))) {
								removed++;
								break;
							}
						}
					}
				}
			}
		}
		else{
			assert(0);
		}
	}
	rLog.stopTechnique(Log::Technique::BCR);
	log(removed, " labels removed by BCR");
	return removed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
leaq 0x218(%rdi), %r14
pushq $0x7
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x21e0a
movq %r14, %rdi
movl %ebp, %esi
callq 0x227d2
testb %al, %al
je 0xef00
leaq 0x20bfa(%rip), %rsi     # 0x2fa4a
leaq 0x48(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x6788
leaq 0x68(%rbx), %rsi
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x2778e
leaq 0x48(%rsp), %rdi
callq 0x3130
movq %r14, %rdi
callq 0x22ac8
testb %al, %al
movq %r14, 0x10(%rsp)
je 0xef25
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r15
cmpq %r15, %r12
je 0xef25
movq %r15, %r14
subq %r12, %r14
movq %r14, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rcx
callq 0x16e90
cmpq $0x41, %r14
jl 0xef12
leaq 0x40(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x17224
movq 0x10(%rsp), %r14
cmpq %r15, %r13
je 0xef25
movq %r13, %rdi
movq %rbx, %rsi
callq 0x172af
addq $0x4, %r13
jmp 0xeeea
pushq $0x7
popq %rsi
movq %r14, %rdi
callq 0x21e46
xorl %eax, %eax
jmp 0xf164
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x17224
movq 0x10(%rsp), %r14
movq 0x20(%rsp), %r15
movq 0x28(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x8(%rsp)
cmpq 0x38(%rsp), %r15
je 0xf138
movslq (%r15), %r12
movq 0x48(%rbx), %rax
cmpl $0x0, (%rax,%r12,4)
movq %r15, 0x40(%rsp)
je 0xef69
movq %rbx, %rdi
movl %r12d, %esi
callq 0x20fae
testb %al, %al
je 0xef79
movq 0x40(%rsp), %r15
addq $0x4, %r15
movq 0x10(%rsp), %r14
jmp 0xef3c
movq %r14, %rdi
pushq $0x7
popq %rsi
callq 0x227d2
testb %al, %al
je 0xf138
movq 0x48(%rbx), %rax
movl (%rax,%r12,4), %eax
cmpl $0x2, %eax
je 0xf06b
cmpl $0x1, %eax
jne 0xf173
addl %r12d, %r12d
movslq %r12d, %rcx
movq 0x18(%rbx), %rax
imulq $0x18, %rcx, %rcx
movq 0x8(%rax,%rcx), %rdx
subq (%rax,%rcx), %rdx
cmpq $0x4, %rdx
jne 0xf18c
orl $0x1, %r12d
movq %r12, 0x18(%rsp)
movslq %r12d, %rcx
imulq $0x18, %rcx, %rcx
movq (%rax,%rcx), %r14
movq 0x8(%rax,%rcx), %rbp
cmpq %rbp, %r14
je 0xef69
movslq (%r14), %r13
movq (%rbx), %rcx
imulq $0x28, %r13, %r12
movq (%rcx,%r12), %rax
movq 0x8(%rcx,%r12), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
jne 0xf062
movl (%rax), %esi
sarl %esi
movslq %esi, %rdx
movq 0x48(%rbx), %rcx
cmpl $0x0, (%rcx,%rdx,4)
je 0xf062
movl 0x4(%rax), %eax
sarl %eax
cltq
cmpl $0x0, (%rcx,%rax,4)
je 0xf062
movq %rbx, %rdi
callq 0x20fec
movq %rax, %r15
movq (%rbx), %rax
movq (%rax,%r12), %rax
movl 0x4(%rax), %esi
sarl %esi
movq %rbx, %rdi
callq 0x20fec
cmpq %rax, %r15
jne 0xf062
movq %rbx, %rdi
movl %r13d, %esi
movq 0x18(%rsp), %rdx
callq 0xe83e
movzbl %al, %eax
addl %eax, 0x8(%rsp)
testb %al, %al
jne 0xef69
addq $0x4, %r14
jmp 0xefe0
leal 0x1(,%r12,2), %eax
movslq %eax, %rcx
movq 0x18(%rbx), %rax
imulq $0x18, %rcx, %rcx
movq 0x8(%rax,%rcx), %rdx
subq (%rax,%rcx), %rdx
cmpq $0x4, %rdx
jne 0xf1a5
addl %r12d, %r12d
movq %r12, 0x18(%rsp)
movslq %r12d, %rcx
imulq $0x18, %rcx, %rcx
movq (%rax,%rcx), %r14
movq 0x8(%rax,%rcx), %rbp
cmpq %rbp, %r14
je 0xef69
movslq (%r14), %r13
movq (%rbx), %rcx
imulq $0x28, %r13, %r12
movq (%rcx,%r12), %rax
movq 0x8(%rcx,%r12), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
jne 0xf12f
movl (%rax), %esi
sarl %esi
movslq %esi, %rdx
movq 0x48(%rbx), %rcx
cmpl $0x0, (%rcx,%rdx,4)
je 0xf12f
movl 0x4(%rax), %eax
sarl %eax
cltq
cmpl $0x0, (%rcx,%rax,4)
je 0xf12f
movq %rbx, %rdi
callq 0x20fec
movq %rax, %r15
movq (%rbx), %rax
movq (%rax,%r12), %rax
movl 0x4(%rax), %esi
sarl %esi
movq %rbx, %rdi
callq 0x20fec
cmpq %rax, %r15
jne 0xf12f
movq %rbx, %rdi
movl %r13d, %esi
movq 0x18(%rsp), %rdx
callq 0xe83e
movzbl %al, %eax
addl %eax, 0x8(%rsp)
testb %al, %al
jne 0xef69
addq $0x4, %r14
jmp 0xf0a9
pushq $0x7
popq %rsi
movq %r14, %rdi
callq 0x21e46
leaq 0x208ed(%rip), %rdx     # 0x2fa37
movq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x189d8
leaq 0x20(%rsp), %rdi
callq 0x7512
movl 0x8(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21b4b(%rip), %rdi     # 0x30cc5
leaq 0x207a8(%rip), %rsi     # 0x2f929
leaq 0x2085d(%rip), %rcx     # 0x2f9e5
pushq $0x7f
jmp 0xf1bc
leaq 0x2082b(%rip), %rdi     # 0x2f9be
leaq 0x2078f(%rip), %rsi     # 0x2f929
leaq 0x20844(%rip), %rcx     # 0x2f9e5
pushq $0x61
jmp 0xf1bc
leaq 0x20864(%rip), %rdi     # 0x2fa10
leaq 0x20776(%rip), %rsi     # 0x2f929
leaq 0x2082b(%rip), %rcx     # 0x2f9e5
pushq $0x70
popq %rdx
callq 0x31c0
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3130
jmp 0xf1e9
movq %rax, %rbx
jmp 0xf1e9
jmp 0xf1dc
jmp 0xf1dc
jmp 0xf1dc
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x7512
movq %rbx, %rdi
callq 0x3490
nop