// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
leaq 0x218(%rdi), %rbx
pushq $0xb
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x21e0a
movq %rbx, %rdi
movl %ebp, %esi
callq 0x227d2
testb %al, %al
je 0x13566
leaq 0x1ca9f(%rip), %rsi     # 0x2ff63
leaq 0x28(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x6788
leaq 0x68(%r14), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2778e
leaq 0x28(%rsp), %rdi
callq 0x3130
movq %rbx, %rdi
callq 0x22ac8
testb %al, %al
je 0x13586
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r15
cmpq %r15, %r12
je 0x13586
movq %r15, %r13
subq %r12, %r13
movq %r13, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rcx
callq 0x18011
cmpq $0x41, %r13
jl 0x13578
leaq 0x40(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x183a6
cmpq %r15, %r13
je 0x13586
movq %r13, %rdi
movq %r14, %rsi
callq 0x18431
addq $0x4, %r13
jmp 0x13550
pushq $0xb
popq %rsi
movq %rbx, %rdi
callq 0x21e46
xorl %ebp, %ebp
jmp 0x137aa
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x183a6
movl 0x468(%r14), %eax
xorl %ebp, %ebp
movq 0x10(%rsp), %r12
testl %eax, %eax
jle 0x136af
movq 0x18(%rsp), %rcx
subq %r12, %rcx
shrq $0x2, %rcx
leal (,%rax,4), %edx
cmpl %ecx, %edx
jg 0x136af
xorl %r12d, %r12d
pushq $0xb
popq %r15
xorl %ebp, %ebp
cmpl %eax, %r12d
jge 0x136a2
movq %rbx, %rdi
movl %r15d, %esi
callq 0x227d2
testb %al, %al
je 0x136a2
movq 0x18(%rsp), %rdx
subq 0x10(%rsp), %rdx
shrq $0x2, %rdx
decl %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x18bca
cltq
movq 0x10(%rsp), %rcx
movslq (%rcx,%rax,4), %r13
movq 0x48(%r14), %rax
cmpl $0x0, (%rax,%r13,4)
je 0x13693
movq %r14, %rdi
movl %r13d, %esi
callq 0x20fae
testb %al, %al
jne 0x13693
movq 0x48(%r14), %rax
movl (%rax,%r13,4), %eax
leal (,%r13,2), %esi
cmpl $0x2, %eax
je 0x13662
cmpl $0x1, %eax
jne 0x13678
orl $0x1, %esi
movslq %esi, %rax
movq 0x18(%r14), %rcx
imulq $0x18, %rax, %rax
movq 0x8(%rcx,%rax), %rdx
cmpq (%rcx,%rax), %rdx
jne 0x13678
movq %r14, %rdi
movl %r13d, %esi
pushq $0x1
popq %rdx
callq 0x7c98
jmp 0x13691
movslq %esi, %rax
movq 0x18(%r14), %rcx
imulq $0x18, %rax, %rax
movq 0x8(%rcx,%rax), %rdx
cmpq (%rcx,%rax), %rdx
je 0x13684
movq %r14, %rdi
callq 0x12de0
addl %eax, %ebp
jmp 0x13693
movq %r14, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x7c98
incl %ebp
incl %r12d
movl 0x468(%r14), %eax
jmp 0x135c0
testl %ebp, %ebp
je 0x13773
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r15
cmpq %r15, %r12
je 0x13784
movslq (%r12), %r13
movq 0x48(%r14), %rax
cmpl $0x0, (%rax,%r13,4)
je 0x1376a
movq %r14, %rdi
movl %r13d, %esi
callq 0x20fae
testb %al, %al
jne 0x1376a
movq %rbx, %rdi
pushq $0xb
popq %rsi
callq 0x227d2
testb %al, %al
je 0x13784
movq 0x48(%r14), %rax
movl (%rax,%r13,4), %eax
leal (,%r13,2), %esi
cmpl $0x2, %eax
je 0x13739
cmpl $0x1, %eax
jne 0x1374f
orl $0x1, %esi
movslq %esi, %rax
movq 0x18(%r14), %rcx
imulq $0x18, %rax, %rax
movq 0x8(%rcx,%rax), %rdx
cmpq (%rcx,%rax), %rdx
jne 0x1374f
movq %r14, %rdi
movl %r13d, %esi
pushq $0x1
popq %rdx
callq 0x7c98
jmp 0x13768
movslq %esi, %rax
movq 0x18(%r14), %rcx
imulq $0x18, %rax, %rax
movq 0x8(%rcx,%rax), %rdx
cmpq (%rcx,%rax), %rdx
je 0x1375b
movq %r14, %rdi
callq 0x12de0
addl %eax, %ebp
jmp 0x1376a
movq %r14, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x7c98
incl %ebp
addq $0x4, %r12
jmp 0x136b4
xorl %ebp, %ebp
leaq 0x1c7bd(%rip), %rsi     # 0x2ff39
movq %r14, %rdi
callq 0x18be4
leaq 0x1c7bb(%rip), %rdx     # 0x2ff46
movq %r14, %rdi
movl %ebp, %esi
callq 0x189d8
pushq $0xb
popq %rsi
movq %rbx, %rdi
callq 0x21e46
leaq 0x10(%rsp), %rdi
callq 0x7512
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x137d7
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3130
jmp 0x137e4
movq %rax, %rbx
jmp 0x137e4
jmp 0x137d7
jmp 0x137d7
jmp 0x137d7
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x7512
movq %rbx, %rdi
callq 0x3490