// File: Laakeri[P]maxpre/src/./SLE.cpp
// Function: maxPreprocessor::Preprocessor::doSLE()
int Preprocessor::doSLE() {
	rLog.startTechnique(Log::Technique::SLE);
	int removed = 0;
	if (!rLog.requestTime(Log::Technique::SLE)) {
		rLog.stopTechnique(Log::Technique::SLE);
		return 0;
	}
	vector<int> checkVar = pi.tl.getTouchedVariables("SLE");
	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::SLE)) break;
		
		if (pi.isLabel[var] == VAR_TRUE && pi.litClauses[negLit(var)].size() == 0){
			setVariable(var, true);
			removed++;
			continue;
		}
		if (pi.isLabel[var] == VAR_FALSE && pi.litClauses[posLit(var)].size() == 0){
			setVariable(var, false);
			removed++;
			continue;
		}
		
		bool f = true;
		while (f) {
			f = false;
			vector<int> clauses;
			if (pi.isLabel[var] == VAR_TRUE) clauses = pi.litClauses[negLit(var)];
			else clauses = pi.litClauses[posLit(var)];
			for (int c : clauses) {
				for (int l : pi.clauses[c].lit) {
					if (pi.isLabel[litVariable(l)] && litVariable(l) != var) {
						if (trySLESlow(var, litVariable(l))) {
							removed++;
							f = true;
							break;
						}
					}
				}
				if (f) break;
			}
		}
	}
	
	log(removed, " labels removed by SLE");
	rLog.stopTechnique(Log::Technique::SLE);
	return removed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x108(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x6, %esi
callq 0x61320
movq -0x108(%rbp), %rdi
movl $0x0, -0x14(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x6, %esi
callq 0x62450
testb $0x1, %al
jne 0x1f4a2
movq -0x108(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x6, %esi
callq 0x61390
movl $0x0, -0x4(%rbp)
jmp 0x1fae6
movq -0x108(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x118(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x4620
movq -0x110(%rbp), %rdx
leaq 0x673a9(%rip), %rsi     # 0x8687b
leaq -0x50(%rbp), %rdi
callq 0xa430
jmp 0x1f4dd
movq -0x118(%rbp), %rsi
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x73700
jmp 0x1f4f3
leaq -0x50(%rbp), %rdi
callq 0x4240
leaq -0x51(%rbp), %rdi
callq 0x43f0
movq -0x108(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x62aa0
movb %al, -0x119(%rbp)
jmp 0x1f520
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x1f52f
jmp 0x1f5c3
movq -0x108(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0xa800
movq -0x128(%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 0x1fb00
jmp 0x1f57f
jmp 0x1f5c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1f5a4
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 0x1faf2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1fadb
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 0x1f610
jmp 0x1fa98
leaq -0x98(%rbp), %rdi
callq 0xa8a0
movq -0x108(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
addq $0x48, %rdi
movslq -0xa4(%rbp), %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
jne 0x1f645
jmp 0x1fa87
movq -0x108(%rbp), %rdi
movl -0xa4(%rbp), %esi
callq 0x5ecc0
movb %al, -0x129(%rbp)
jmp 0x1f65f
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x1f66b
jmp 0x1f670
jmp 0x1fa87
movq -0x108(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x6, %esi
callq 0x62450
movb %al, -0x12a(%rbp)
jmp 0x1f690
movb -0x12a(%rbp), %al
testb $0x1, %al
jne 0x1f6a1
jmp 0x1f69c
jmp 0x1fa98
movq -0x108(%rbp), %rdi
addq $0x48, %rdi
movslq -0xa4(%rbp), %rsi
callq 0xa7c0
cmpl $0x1, (%rax)
jne 0x1f72c
movq -0x108(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x138(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x130(%rbp)
jmp 0x1f6e2
movq -0x138(%rbp), %rdi
movl -0x130(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
jne 0x1f72c
movq -0x108(%rbp), %rdi
movl -0xa4(%rbp), %esi
movl $0x1, %edx
callq 0x10a60
jmp 0x1f71e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1fa87
movq -0x108(%rbp), %rdi
addq $0x48, %rdi
movslq -0xa4(%rbp), %rsi
callq 0xa7c0
cmpl $0x2, (%rax)
jne 0x1f7b4
movq -0x108(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x148(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x13c(%rbp)
jmp 0x1f76d
movq -0x148(%rbp), %rdi
movl -0x13c(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
jne 0x1f7b4
movq -0x108(%rbp), %rdi
movl -0xa4(%rbp), %esi
xorl %edx, %edx
callq 0x10a60
jmp 0x1f7a6
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1fa87
movb $0x1, -0xa5(%rbp)
testb $0x1, -0xa5(%rbp)
je 0x1fa85
movb $0x0, -0xa5(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xa7e0
movq -0x108(%rbp), %rdi
addq $0x48, %rdi
movslq -0xa4(%rbp), %rsi
callq 0xa7c0
cmpl $0x1, (%rax)
jne 0x1f861
movq -0x108(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x158(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x14c(%rbp)
jmp 0x1f81c
movq -0x158(%rbp), %rdi
movl -0x14c(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x3de50
jmp 0x1f842
jmp 0x1f8ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xab00
jmp 0x1fadb
movq -0x108(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x168(%rbp)
movl -0xa4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x15c(%rbp)
jmp 0x1f886
movq -0x168(%rbp), %rdi
movl -0x15c(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x3de50
jmp 0x1f8ac
jmp 0x1f8ae
leaq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
callq 0xa800
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
callq 0xa830
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xa860
testb $0x1, %al
jne 0x1f8fe
jmp 0x1fa74
leaq -0xd0(%rbp), %rdi
callq 0xa8a0
movq -0x108(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xdc(%rbp)
movslq -0xdc(%rbp), %rsi
callq 0x3c600
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
callq 0xa800
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rdi
callq 0xa830
movq %rax, -0xf8(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xa860
testb $0x1, %al
jne 0x1f96e
jmp 0x1fa56
leaq -0xf0(%rbp), %rdi
callq 0xa8a0
movq %rax, %rcx
movq -0x108(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0xfc(%rbp)
addq $0x48, %rax
movq %rax, -0x178(%rbp)
movl -0xfc(%rbp), %edi
callq 0x3c880
movl %eax, -0x16c(%rbp)
jmp 0x1f9aa
movq -0x178(%rbp), %rdi
movl -0x16c(%rbp), %eax
movslq %eax, %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
je 0x1fa43
movl -0xfc(%rbp), %edi
callq 0x3c880
movl %eax, -0x17c(%rbp)
jmp 0x1f9d7
movl -0x17c(%rbp), %eax
cmpl -0xa4(%rbp), %eax
je 0x1fa43
movl -0xa4(%rbp), %eax
movl %eax, -0x184(%rbp)
movl -0xfc(%rbp), %edi
callq 0x3c880
movl %eax, -0x180(%rbp)
jmp 0x1fa04
movl -0x180(%rbp), %edx
movl -0x184(%rbp), %esi
movq -0x108(%rbp), %rdi
callq 0x1ee60
movl %eax, -0x188(%rbp)
jmp 0x1fa24
movl -0x188(%rbp), %eax
cmpl $0x0, %eax
je 0x1fa41
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movb $0x1, -0xa5(%rbp)
jmp 0x1fa56
jmp 0x1fa43
jmp 0x1fa45
leaq -0xf0(%rbp), %rdi
callq 0xa930
jmp 0x1f952
testb $0x1, -0xa5(%rbp)
je 0x1fa61
jmp 0x1fa74
jmp 0x1fa63
leaq -0xd0(%rbp), %rdi
callq 0xa930
jmp 0x1f8e2
leaq -0xc0(%rbp), %rdi
callq 0xab00
jmp 0x1f7bb
jmp 0x1fa87
leaq -0x98(%rbp), %rdi
callq 0xa930
jmp 0x1f5f4
movq -0x108(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq 0x66db6(%rip), %rdx     # 0x8685f
callq 0x3c620
jmp 0x1fab0
movq -0x108(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x6, %esi
callq 0x61390
jmp 0x1faca
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
jmp 0x1fae6
leaq -0x30(%rbp), %rdi
callq 0xab00
jmp 0x1faf2
movl -0x4(%rbp), %eax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x4610
nopl (%rax,%rax)