// File: 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
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x7, %esi
callq 0x61320
movq -0xf0(%rbp), %rdi
movl $0x0, -0x14(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x7, %esi
callq 0x62450
testb $0x1, %al
jne 0x20a02
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x7, %esi
callq 0x61390
movl $0x0, -0x4(%rbp)
jmp 0x212cc
movq -0xf0(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x100(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x4620
movq -0xf8(%rbp), %rdx
leaq 0x65f78(%rip), %rsi     # 0x869aa
leaq -0x50(%rbp), %rdi
callq 0xa430
jmp 0x20a3d
movq -0x100(%rbp), %rsi
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x73700
jmp 0x20a53
leaq -0x50(%rbp), %rdi
callq 0x4240
leaq -0x51(%rbp), %rdi
callq 0x43f0
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x62aa0
movb %al, -0x101(%rbp)
jmp 0x20a80
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x20a8f
jmp 0x20b2c
movq -0xf0(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0xa800
movq -0x110(%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 0x212f0
jmp 0x20adf
jmp 0x20b2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x20b04
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 0x212d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
jmp 0x212d8
leaq -0x30(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
callq 0xa800
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
callq 0xa830
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xa860
testb $0x1, %al
jne 0x20b79
jmp 0x2128b
leaq -0x98(%rbp), %rdi
callq 0xa8a0
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
addq $0x48, %rdi
movslq -0xa4(%rbp), %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
jne 0x20bae
jmp 0x2127a
movq -0xf0(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x5ecc0
movb %al, -0x111(%rbp)
jmp 0x20bc8
movb -0x111(%rbp), %al
testb $0x1, %al
jne 0x20bd4
jmp 0x20bd9
jmp 0x2127a
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x7, %esi
callq 0x62450
movb %al, -0x112(%rbp)
jmp 0x20bf9
movb -0x112(%rbp), %al
testb $0x1, %al
jne 0x20c0a
jmp 0x20c05
jmp 0x2128b
movq -0xf0(%rbp), %rdi
addq $0x48, %rdi
movslq -0xa4(%rbp), %rsi
callq 0xa7c0
cmpl $0x1, (%rax)
jne 0x20f32
movq -0xf0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x120(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x118(%rbp)
jmp 0x20c4f
movq -0x120(%rbp), %rdi
movl -0x118(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x1, %rax
jne 0x20c74
jmp 0x20c93
leaq 0x65ca3(%rip), %rdi     # 0x8691e
leaq 0x65c07(%rip), %rsi     # 0x86889
movl $0x61, %edx
leaq 0x65cb7(%rip), %rcx     # 0x86945
callq 0x4260
movq -0xf0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x130(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x124(%rbp)
jmp 0x20cb8
movq -0x130(%rbp), %rdi
movl -0x124(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0xa800
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdi
callq 0xa830
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xa860
testb $0x1, %al
jne 0x20d16
jmp 0x20f2d
leaq -0xb8(%rbp), %rdi
callq 0xa8a0
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
movslq -0xc4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
callq 0xf940
cmpq $0x2, %rax
jne 0x20f1a
movq -0xf0(%rbp), %rdi
movq %rdi, %rax
addq $0x48, %rax
movq %rax, -0x140(%rbp)
movslq -0xc4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xa7c0
movl (%rax), %edi
callq 0x3c880
movl %eax, -0x134(%rbp)
jmp 0x20d8b
movq -0x140(%rbp), %rdi
movl -0x134(%rbp), %eax
movslq %eax, %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
je 0x20f18
movq -0xf0(%rbp), %rdi
movq %rdi, %rax
addq $0x48, %rax
movq %rax, -0x150(%rbp)
movslq -0xc4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
movl $0x1, %esi
callq 0xa7c0
movl (%rax), %edi
callq 0x3c880
movl %eax, -0x144(%rbp)
jmp 0x20de6
movq -0x150(%rbp), %rdi
movl -0x144(%rbp), %eax
movslq %eax, %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
je 0x20f18
movq -0xf0(%rbp), %rdi
movq %rdi, %rax
movq %rax, -0x160(%rbp)
movslq -0xc4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xa7c0
movl (%rax), %edi
callq 0x3c880
movl %eax, -0x154(%rbp)
jmp 0x20e3c
movl -0x154(%rbp), %esi
movq -0x160(%rbp), %rdi
callq 0x5ed50
movq %rax, -0x168(%rbp)
jmp 0x20e57
movq -0xf0(%rbp), %rdi
movq %rdi, %rax
movq %rax, -0x178(%rbp)
movslq -0xc4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
movl $0x1, %esi
callq 0xa7c0
movl (%rax), %edi
callq 0x3c880
movl %eax, -0x16c(%rbp)
jmp 0x20e90
movl -0x16c(%rbp), %esi
movq -0x178(%rbp), %rdi
callq 0x5ed50
movq %rax, -0x180(%rbp)
jmp 0x20eab
movq -0x168(%rbp), %rax
movq -0x180(%rbp), %rcx
cmpq %rcx, %rax
jne 0x20f16
movl -0xc4(%rbp), %eax
movl %eax, -0x188(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x184(%rbp)
jmp 0x20edd
movl -0x184(%rbp), %edx
movl -0x188(%rbp), %esi
movq -0xf0(%rbp), %rdi
callq 0x1fd60
movb %al, -0x189(%rbp)
jmp 0x20efd
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x20f09
jmp 0x20f14
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x20f2d
jmp 0x20f16
jmp 0x20f18
jmp 0x20f1a
jmp 0x20f1c
leaq -0xb8(%rbp), %rdi
callq 0xa930
jmp 0x20cfa
jmp 0x21278
movq -0xf0(%rbp), %rdi
addq $0x48, %rdi
movslq -0xa4(%rbp), %rsi
callq 0xa7c0
cmpl $0x2, (%rax)
jne 0x21257
movq -0xf0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x198(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x190(%rbp)
jmp 0x20f77
movq -0x198(%rbp), %rdi
movl -0x190(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x1, %rax
jne 0x20f9c
jmp 0x20fbb
leaq 0x659cd(%rip), %rdi     # 0x86970
leaq 0x658df(%rip), %rsi     # 0x86889
movl $0x70, %edx
leaq 0x6598f(%rip), %rcx     # 0x86945
callq 0x4260
movq -0xf0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x1a8(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x19c(%rbp)
jmp 0x20fe0
movq -0x1a8(%rbp), %rdi
movl -0x19c(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
callq 0xa800
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rdi
callq 0xa830
movq %rax, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xa860
testb $0x1, %al
jne 0x2103e
jmp 0x21255
leaq -0xd8(%rbp), %rdi
callq 0xa8a0
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xe4(%rbp)
movslq -0xe4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
callq 0xf940
cmpq $0x2, %rax
jne 0x21242
movq -0xf0(%rbp), %rdi
movq %rdi, %rax
addq $0x48, %rax
movq %rax, -0x1b8(%rbp)
movslq -0xe4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xa7c0
movl (%rax), %edi
callq 0x3c880
movl %eax, -0x1ac(%rbp)
jmp 0x210b3
movq -0x1b8(%rbp), %rdi
movl -0x1ac(%rbp), %eax
movslq %eax, %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
je 0x21240
movq -0xf0(%rbp), %rdi
movq %rdi, %rax
addq $0x48, %rax
movq %rax, -0x1c8(%rbp)
movslq -0xe4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
movl $0x1, %esi
callq 0xa7c0
movl (%rax), %edi
callq 0x3c880
movl %eax, -0x1bc(%rbp)
jmp 0x2110e
movq -0x1c8(%rbp), %rdi
movl -0x1bc(%rbp), %eax
movslq %eax, %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
je 0x21240
movq -0xf0(%rbp), %rdi
movq %rdi, %rax
movq %rax, -0x1d8(%rbp)
movslq -0xe4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xa7c0
movl (%rax), %edi
callq 0x3c880
movl %eax, -0x1cc(%rbp)
jmp 0x21164
movl -0x1cc(%rbp), %esi
movq -0x1d8(%rbp), %rdi
callq 0x5ed50
movq %rax, -0x1e0(%rbp)
jmp 0x2117f
movq -0xf0(%rbp), %rdi
movq %rdi, %rax
movq %rax, -0x1f0(%rbp)
movslq -0xe4(%rbp), %rsi
callq 0x3c600
movq %rax, %rdi
movl $0x1, %esi
callq 0xa7c0
movl (%rax), %edi
callq 0x3c880
movl %eax, -0x1e4(%rbp)
jmp 0x211b8
movl -0x1e4(%rbp), %esi
movq -0x1f0(%rbp), %rdi
callq 0x5ed50
movq %rax, -0x1f8(%rbp)
jmp 0x211d3
movq -0x1e0(%rbp), %rax
movq -0x1f8(%rbp), %rcx
cmpq %rcx, %rax
jne 0x2123e
movl -0xe4(%rbp), %eax
movl %eax, -0x200(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x1fc(%rbp)
jmp 0x21205
movl -0x1fc(%rbp), %edx
movl -0x200(%rbp), %esi
movq -0xf0(%rbp), %rdi
callq 0x1fd60
movb %al, -0x201(%rbp)
jmp 0x21225
movb -0x201(%rbp), %al
testb $0x1, %al
jne 0x21231
jmp 0x2123c
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x21255
jmp 0x2123e
jmp 0x21240
jmp 0x21242
jmp 0x21244
leaq -0xd8(%rbp), %rdi
callq 0xa930
jmp 0x21022
jmp 0x21276
leaq 0x669c4(%rip), %rdi     # 0x87c22
leaq 0x65624(%rip), %rsi     # 0x86889
movl $0x7f, %edx
leaq 0x656d4(%rip), %rcx     # 0x86945
callq 0x4260
jmp 0x21278
jmp 0x2127a
leaq -0x98(%rbp), %rdi
callq 0xa930
jmp 0x20b5d
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x7, %esi
callq 0x61390
jmp 0x212a5
movq -0xf0(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq 0x656e1(%rip), %rdx     # 0x86997
callq 0x3c620
jmp 0x212bd
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
movl -0x4(%rbp), %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x4610
nopw %cs:(%rax,%rax)