// File: Laakeri[P]maxpre/src/./GSLE.cpp
// Function: maxPreprocessor::Preprocessor::doGSLE()
int Preprocessor::doGSLE() {
	rLog.startTechnique(Log::Technique::GSLE);
	int removed = 0;
	if (!rLog.requestTime(Log::Technique::GSLE)) {
		rLog.stopTechnique(Log::Technique::GSLE);
		return 0;
	}
	vector<int> checkVar = pi.tl.getTouchedVariables("GSLE");
	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);
	}
	bool skip = false;
	if (skipTechnique > 0 && (int)checkVar.size() >= skipTechnique * 4) { // magic constant
		for (int tc = 0; tc < skipTechnique; tc++) {
			if (!rLog.requestTime(Log::Technique::GSLE)) break;
			int var = checkVar[getRand(0, (int)checkVar.size() - 1)];
			if (pi.isLabel[var] == VAR_UNDEFINED) continue;
			if (pi.isVarRemoved(var)) continue;
			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;
			}
			
			if (pi.isLabel[var] == VAR_TRUE) {
				removed += tryGSLE(negLit(var));
			}
			else {
				removed += tryGSLE(posLit(var));
			}
		}
		if (removed == 0) {
			skip = true;
			log("GSLE skipped");
		}
	}
	if (!skip) {
		for (int var : checkVar) {
			if (pi.isLabel[var] == VAR_UNDEFINED) continue;
			if (pi.isVarRemoved(var)) continue;
			if (!rLog.requestTime(Log::Technique::GSLE)) 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;
			}
			
			if (pi.isLabel[var] == VAR_TRUE) {
				removed += tryGSLE(negLit(var));
			}
			else {
				removed += tryGSLE(posLit(var));
			}
		}
	}
	
	log(removed, " labels removed by GSLE");
	rLog.stopTechnique(Log::Technique::GSLE);
	return removed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0xb, %esi
callq 0x61320
movq -0xc0(%rbp), %rdi
movl $0x0, -0x14(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0xb, %esi
callq 0x62450
testb $0x1, %al
jne 0x2b422
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0xb, %esi
callq 0x61390
movl $0x0, -0x4(%rbp)
jmp 0x2bb28
movq -0xc0(%rbp), %rax
addq $0x68, %rax
movq %rax, -0xd0(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x4620
movq -0xc8(%rbp), %rdx
leaq 0x5ba71(%rip), %rsi     # 0x86ec3
leaq -0x50(%rbp), %rdi
callq 0xa430
jmp 0x2b45d
movq -0xd0(%rbp), %rsi
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x73700
jmp 0x2b473
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 0x2b4a0
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x2b4af
jmp 0x2b54c
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 0x2bb40
jmp 0x2b4ff
jmp 0x2b54c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2b524
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 0x2bb34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
jmp 0x2bb34
movq -0xc0(%rbp), %rax
movb $0x0, -0x89(%rbp)
cmpl $0x0, 0x468(%rax)
jle 0x2b844
leaq -0x30(%rbp), %rdi
callq 0xf940
movq -0xc0(%rbp), %rcx
movl 0x468(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jl 0x2b844
movl $0x0, -0x90(%rbp)
movq -0xc0(%rbp), %rcx
movl -0x90(%rbp), %eax
cmpl 0x468(%rcx), %eax
jge 0x2b81e
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0xb, %esi
callq 0x62450
movb %al, -0xe1(%rbp)
jmp 0x2b5cb
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x2b5dc
jmp 0x2b5d7
jmp 0x2b81e
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 0x2b5ff
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 0x2b63a
jmp 0x2b80a
movq -0xc0(%rbp), %rdi
movl -0x94(%rbp), %esi
callq 0x5ecc0
movb %al, -0xe9(%rbp)
jmp 0x2b654
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0x2b660
jmp 0x2b665
jmp 0x2b80a
movq -0xc0(%rbp), %rdi
addq $0x48, %rdi
movslq -0x94(%rbp), %rsi
callq 0xa7c0
cmpl $0x1, (%rax)
jne 0x2b6f0
movq -0xc0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0xf8(%rbp)
movl -0x94(%rbp), %edi
callq 0x3c5e0
movl %eax, -0xf0(%rbp)
jmp 0x2b6a6
movq -0xf8(%rbp), %rdi
movl -0xf0(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
jne 0x2b6f0
movq -0xc0(%rbp), %rdi
movl -0x94(%rbp), %esi
movl $0x1, %edx
callq 0x10a60
jmp 0x2b6e2
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2b80a
movq -0xc0(%rbp), %rdi
addq $0x48, %rdi
movslq -0x94(%rbp), %rsi
callq 0xa7c0
cmpl $0x2, (%rax)
jne 0x2b778
movq -0xc0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x108(%rbp)
movl -0x94(%rbp), %edi
callq 0x3c5d0
movl %eax, -0xfc(%rbp)
jmp 0x2b731
movq -0x108(%rbp), %rdi
movl -0xfc(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
jne 0x2b778
movq -0xc0(%rbp), %rdi
movl -0x94(%rbp), %esi
xorl %edx, %edx
callq 0x10a60
jmp 0x2b76a
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2b80a
movq -0xc0(%rbp), %rdi
addq $0x48, %rdi
movslq -0x94(%rbp), %rsi
callq 0xa7c0
cmpl $0x1, (%rax)
jne 0x2b7cf
movl -0x94(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x10c(%rbp)
jmp 0x2b7a7
movl -0x10c(%rbp), %esi
movq -0xc0(%rbp), %rdi
callq 0x2a280
movl %eax, -0x110(%rbp)
jmp 0x2b7c1
movl -0x110(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x2b808
movl -0x94(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x114(%rbp)
jmp 0x2b7e2
movl -0x114(%rbp), %esi
movq -0xc0(%rbp), %rdi
callq 0x2a280
movl %eax, -0x118(%rbp)
jmp 0x2b7fc
movl -0x118(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x2b80a
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x2b592
cmpl $0x0, -0x14(%rbp)
jne 0x2b842
movq -0xc0(%rbp), %rdi
movb $0x1, -0x89(%rbp)
leaq 0x5b660(%rip), %rsi     # 0x86e99
callq 0x3cf50
jmp 0x2b840
jmp 0x2b842
jmp 0x2b844
testb $0x1, -0x89(%rbp)
jne 0x2bae7
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 0x2b89e
jmp 0x2bae5
leaq -0xa8(%rbp), %rdi
callq 0xa8a0
movq -0xc0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xb4(%rbp)
addq $0x48, %rdi
movslq -0xb4(%rbp), %rsi
callq 0xa7c0
cmpl $0x0, (%rax)
jne 0x2b8d3
jmp 0x2bad4
movq -0xc0(%rbp), %rdi
movl -0xb4(%rbp), %esi
callq 0x5ecc0
movb %al, -0x119(%rbp)
jmp 0x2b8ed
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x2b8f9
jmp 0x2b8fe
jmp 0x2bad4
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0xb, %esi
callq 0x62450
movb %al, -0x11a(%rbp)
jmp 0x2b91e
movb -0x11a(%rbp), %al
testb $0x1, %al
jne 0x2b92f
jmp 0x2b92a
jmp 0x2bae5
movq -0xc0(%rbp), %rdi
addq $0x48, %rdi
movslq -0xb4(%rbp), %rsi
callq 0xa7c0
cmpl $0x1, (%rax)
jne 0x2b9ba
movq -0xc0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x128(%rbp)
movl -0xb4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x120(%rbp)
jmp 0x2b970
movq -0x128(%rbp), %rdi
movl -0x120(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
jne 0x2b9ba
movq -0xc0(%rbp), %rdi
movl -0xb4(%rbp), %esi
movl $0x1, %edx
callq 0x10a60
jmp 0x2b9ac
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2bad4
movq -0xc0(%rbp), %rdi
addq $0x48, %rdi
movslq -0xb4(%rbp), %rsi
callq 0xa7c0
cmpl $0x2, (%rax)
jne 0x2ba42
movq -0xc0(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x138(%rbp)
movl -0xb4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x12c(%rbp)
jmp 0x2b9fb
movq -0x138(%rbp), %rdi
movl -0x12c(%rbp), %eax
movslq %eax, %rsi
callq 0xaab0
movq %rax, %rdi
callq 0xf940
cmpq $0x0, %rax
jne 0x2ba42
movq -0xc0(%rbp), %rdi
movl -0xb4(%rbp), %esi
xorl %edx, %edx
callq 0x10a60
jmp 0x2ba34
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2bad4
movq -0xc0(%rbp), %rdi
addq $0x48, %rdi
movslq -0xb4(%rbp), %rsi
callq 0xa7c0
cmpl $0x1, (%rax)
jne 0x2ba99
movl -0xb4(%rbp), %edi
callq 0x3c5e0
movl %eax, -0x13c(%rbp)
jmp 0x2ba71
movl -0x13c(%rbp), %esi
movq -0xc0(%rbp), %rdi
callq 0x2a280
movl %eax, -0x140(%rbp)
jmp 0x2ba8b
movl -0x140(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x2bad2
movl -0xb4(%rbp), %edi
callq 0x3c5d0
movl %eax, -0x144(%rbp)
jmp 0x2baac
movl -0x144(%rbp), %esi
movq -0xc0(%rbp), %rdi
callq 0x2a280
movl %eax, -0x148(%rbp)
jmp 0x2bac6
movl -0x148(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x2bad4
leaq -0xa8(%rbp), %rdi
callq 0xa930
jmp 0x2b882
jmp 0x2bae7
movq -0xc0(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq 0x5b3ae(%rip), %rdx     # 0x86ea6
callq 0x3c620
jmp 0x2baff
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0xb, %esi
callq 0x61390
jmp 0x2bb19
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x4610
nopl (%rax)