// File: /workspace/github_cpp_makefile_star2_O3/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), %rbp
movq %rbp, %rdi
movl $0x7, %esi
callq 0x28b9e
movq %rbp, %rdi
movl $0x7, %esi
callq 0x29718
testb %al, %al
je 0x128ac
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x262d0(%rip), %rsi     # 0x38aca
leaq 0x262cc(%rip), %rdx     # 0x38acd
leaq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0x9466
leaq 0x68(%rbx), %rsi
leaq 0x18(%rsp), %rdi
movq %r15, %rdx
callq 0x2f8c0
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x12836
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %rbp, %rdi
callq 0x29a46
testb %al, %al
je 0x128ce
movq 0x18(%rsp), %r12
movq 0x20(%rsp), %r15
cmpq %r15, %r12
je 0x128ce
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 0x1c717
cmpq $0x41, %r14
jl 0x128c0
leaq 0x40(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x1cb16
cmpq %r15, %r13
je 0x128ce
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1cb96
addq $0x4, %r13
jmp 0x12896
movq %rbp, %rdi
movl $0x7, %esi
callq 0x28be0
xorl %eax, %eax
jmp 0x12b39
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x1cb16
movq 0x18(%rsp), %r14
movq 0x20(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpq %rax, %r14
je 0x12af6
movl $0x0, 0xc(%rsp)
movq %rbp, 0x30(%rsp)
movslq (%r14), %r15
movq 0x48(%rbx), %rax
cmpl $0x0, (%rax,%r15,4)
movq %r14, 0x40(%rsp)
je 0x12915
movq %rbx, %rdi
movl %r15d, %esi
callq 0x278a0
testb %al, %al
je 0x1292f
movq 0x40(%rsp), %r14
addq $0x4, %r14
cmpq 0x38(%rsp), %r14
movq 0x30(%rsp), %rbp
jne 0x128f3
jmp 0x12afe
movq %rbp, %rdi
movl $0x7, %esi
callq 0x29718
testb %al, %al
je 0x12afe
movq 0x48(%rbx), %rax
movl (%rax,%r15,4), %eax
cmpl $0x2, %eax
je 0x12a28
cmpl $0x1, %eax
jne 0x12b67
addl %r15d, %r15d
movslq %r15d, %rcx
movq 0x18(%rbx), %rax
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
subq (%rax,%rcx,8), %rdx
cmpq $0x4, %rdx
jne 0x12b86
orl $0x1, %r15d
movq %r15, 0x10(%rsp)
movslq %r15d, %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rbp
movq 0x8(%rax,%rcx,8), %r15
cmpq %r15, %rbp
je 0x12915
movslq (%rbp), %r12
movq (%rbx), %rcx
leaq (%r12,%r12,4), %r14
movq (%rcx,%r14,8), %rax
movq 0x8(%rcx,%r14,8), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
jne 0x12a1f
movl (%rax), %esi
sarl %esi
movslq %esi, %rdx
movq 0x48(%rbx), %rcx
cmpl $0x0, (%rcx,%rdx,4)
je 0x12a1f
movl 0x4(%rax), %eax
sarl %eax
cltq
cmpl $0x0, (%rcx,%rax,4)
je 0x12a1f
movq %rbx, %rdi
callq 0x278de
movq %rax, %r13
movq (%rbx), %rax
movq (%rax,%r14,8), %rax
movl 0x4(%rax), %esi
sarl %esi
movq %rbx, %rdi
callq 0x278de
cmpq %rax, %r13
jne 0x12a1f
movq %rbx, %rdi
movl %r12d, %esi
movq 0x10(%rsp), %rdx
callq 0x120b0
movzbl %al, %eax
addl %eax, 0xc(%rsp)
testb %al, %al
jne 0x12915
addq $0x4, %rbp
jmp 0x12998
leal 0x1(,%r15,2), %eax
movslq %eax, %rcx
movq 0x18(%rbx), %rax
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
subq (%rax,%rcx,8), %rdx
cmpq $0x4, %rdx
jne 0x12b48
addl %r15d, %r15d
movq %r15, 0x10(%rsp)
movslq %r15d, %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rbp
movq 0x8(%rax,%rcx,8), %r15
cmpq %r15, %rbp
je 0x12915
movslq (%rbp), %r12
movq (%rbx), %rcx
leaq (%r12,%r12,4), %r14
movq (%rcx,%r14,8), %rax
movq 0x8(%rcx,%r14,8), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
jne 0x12aed
movl (%rax), %esi
sarl %esi
movslq %esi, %rdx
movq 0x48(%rbx), %rcx
cmpl $0x0, (%rcx,%rdx,4)
je 0x12aed
movl 0x4(%rax), %eax
sarl %eax
cltq
cmpl $0x0, (%rcx,%rax,4)
je 0x12aed
movq %rbx, %rdi
callq 0x278de
movq %rax, %r13
movq (%rbx), %rax
movq (%rax,%r14,8), %rax
movl 0x4(%rax), %esi
sarl %esi
movq %rbx, %rdi
callq 0x278de
cmpq %rax, %r13
jne 0x12aed
movq %rbx, %rdi
movl %r12d, %esi
movq 0x10(%rsp), %rdx
callq 0x120b0
movzbl %al, %eax
addl %eax, 0xc(%rsp)
testb %al, %al
jne 0x12915
addq $0x4, %rbp
jmp 0x12a66
movl $0x0, 0xc(%rsp)
movq %rbp, %rdi
movl $0x7, %esi
callq 0x28be0
leaq 0x25fa5(%rip), %rdx     # 0x38ab7
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x1e844
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x12b35
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movl 0xc(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x25f41(%rip), %rdi     # 0x38a90
leaq 0x25e53(%rip), %rsi     # 0x389a9
leaq 0x25f08(%rip), %rcx     # 0x38a65
movl $0x70, %edx
callq 0x31b0
leaq 0x271f3(%rip), %rdi     # 0x39d61
leaq 0x25e34(%rip), %rsi     # 0x389a9
leaq 0x25ee9(%rip), %rcx     # 0x38a65
movl $0x7f, %edx
callq 0x31b0
leaq 0x25eb1(%rip), %rdi     # 0x38a3e
leaq 0x25e15(%rip), %rsi     # 0x389a9
leaq 0x25eca(%rip), %rcx     # 0x38a65
movl $0x61, %edx
callq 0x31b0
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x12bdc
movq 0x58(%rsp), %rsi
incq %rsi
jmp 0x12bd7
jmp 0x12bc2
jmp 0x12bc2
jmp 0x12bc2
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x12bdc
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x34a0