// File: Laakeri[P]maxpre/src/./SE.cpp
// Function: maxPreprocessor::Preprocessor::doSE()
int Preprocessor::doSE() {
	rLog.startTechnique(Log::Technique::SE);
	if (!rLog.requestTime(Log::Technique::SE)) {
		rLog.stopTechnique(Log::Technique::SE);
		return 0;
	}
	
	vector<int> checkLit = pi.tl.getModLiterals("SE");
	if (rLog.isTimeLimit()) {
		auto cmp = [&](int lit1, int lit2) {
			return pi.litClauses[lit1].size() < pi.litClauses[lit2].size();
		};
		sort(checkLit.begin(), checkLit.end(), cmp);
	}
	bool skip = false;
	vector<int> toRemove;
	if (skipTechnique > 0 && (int)checkLit.size() >= skipTechnique*4) { // magic constant
		for (int tc = 0; tc < skipTechnique; tc++) {
			if (!rLog.requestTime(Log::Technique::SE)) break;
			int lit = checkLit[getRand(0, (int)checkLit.size() - 1)];
			trySEgen(lit, toRemove);
		}
		if (toRemove.size() == 0) {
			skip = true;
			log("SE skipped");
		}
	}
	if (!skip) {
		for (int lit : checkLit) {
			if (!rLog.requestTime(Log::Technique::SE)) break;
			trySEgen(lit, toRemove);
		}
	}
	int removed = 0;
	for (int c : toRemove) {
		if (!pi.isClauseRemoved(c)) {
			pi.removeClause(c);
			removed++;
		}
	}
	rLog.removeClause(removed);
	log(removed, " clauses removed by SE");
	rLog.stopTechnique(Log::Technique::SE);
	return removed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x4, %esi
callq 0x61320
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x4, %esi
callq 0x62450
testb $0x1, %al
jne 0x1544b
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x4, %esi
callq 0x61390
movl $0x0, -0x4(%rbp)
jmp 0x158ca
movq -0xf0(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x100(%rbp)
leaq -0x49(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x4620
movq -0xf8(%rbp), %rdx
leaq 0x70f7a(%rip), %rsi     # 0x863f5
leaq -0x48(%rbp), %rdi
callq 0xa430
jmp 0x15486
movq -0x100(%rbp), %rsi
leaq -0x28(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x73130
jmp 0x1549c
leaq -0x48(%rbp), %rdi
callq 0x4240
leaq -0x49(%rbp), %rdi
callq 0x43f0
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
callq 0x62aa0
movb %al, -0x101(%rbp)
jmp 0x154c9
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x154d8
jmp 0x15566
movq -0xf0(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x28(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0xa800
movq -0x110(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0xa830
movq %rax, -0x78(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdx
callq 0x158e0
jmp 0x15522
jmp 0x15566
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x15547
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4240
leaq -0x49(%rbp), %rdi
callq 0x43f0
jmp 0x158d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x158bf
movb $0x0, -0x81(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xa7e0
movq -0xf0(%rbp), %rax
cmpl $0x0, 0x468(%rax)
jle 0x156bf
leaq -0x28(%rbp), %rdi
callq 0xf940
movq -0xf0(%rbp), %rcx
movl 0x468(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jl 0x156bf
movl $0x0, -0xa4(%rbp)
movq -0xf0(%rbp), %rcx
movl -0xa4(%rbp), %eax
cmpl 0x468(%rcx), %eax
jge 0x1568d
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x4, %esi
callq 0x62450
movb %al, -0x111(%rbp)
jmp 0x155f1
movb -0x111(%rbp), %al
testb $0x1, %al
jne 0x1561f
jmp 0x155fd
jmp 0x1568d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xab00
jmp 0x158bf
leaq -0x28(%rbp), %rdi
callq 0xf940
movq -0xf0(%rbp), %rdi
movl %eax, %edx
decl %edx
xorl %esi, %esi
callq 0x3cf00
movl %eax, -0x118(%rbp)
jmp 0x15642
movl -0x118(%rbp), %eax
movslq %eax, %rsi
leaq -0x28(%rbp), %rdi
callq 0xa7c0
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %esi
leaq -0xa0(%rbp), %rdx
callq 0x15200
jmp 0x15677
jmp 0x15679
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x155b8
leaq -0xa0(%rbp), %rdi
callq 0xf940
cmpq $0x0, %rax
jne 0x156bd
movq -0xf0(%rbp), %rdi
movb $0x1, -0x81(%rbp)
leaq 0x70d22(%rip), %rsi     # 0x863d6
callq 0x3cf50
jmp 0x156bb
jmp 0x156bd
jmp 0x156bf
testb $0x1, -0x81(%rbp)
jne 0x15788
leaq -0x28(%rbp), %rax
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 0x15716
jmp 0x15786
leaq -0xb8(%rbp), %rdi
callq 0xa8a0
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x4, %esi
callq 0x62450
movb %al, -0x119(%rbp)
jmp 0x1574a
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x15758
jmp 0x15756
jmp 0x15786
movq -0xf0(%rbp), %rdi
movl -0xc4(%rbp), %esi
leaq -0xa0(%rbp), %rdx
callq 0x15200
jmp 0x15773
jmp 0x15775
leaq -0xb8(%rbp), %rdi
callq 0xa930
jmp 0x156fd
jmp 0x15788
movl $0x0, -0xc8(%rbp)
leaq -0xa0(%rbp), %rax
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 0x157df
jmp 0x1584f
leaq -0xd8(%rbp), %rdi
callq 0xa8a0
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %esi
callq 0x5eb70
movb %al, -0x11a(%rbp)
jmp 0x1580d
movb -0x11a(%rbp), %al
testb $0x1, %al
jne 0x1583c
jmp 0x15819
movq -0xf0(%rbp), %rdi
movl -0xe4(%rbp), %esi
callq 0x5f7f0
jmp 0x1582d
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x1583e
leaq -0xd8(%rbp), %rdi
callq 0xa930
jmp 0x157c6
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl -0xc8(%rbp), %esi
callq 0x61410
jmp 0x1586a
movq -0xf0(%rbp), %rdi
movl -0xc8(%rbp), %esi
leaq 0x70b63(%rip), %rdx     # 0x863e1
callq 0x3c620
jmp 0x15885
movq -0xf0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x4, %esi
callq 0x61390
jmp 0x1589f
movl -0xc8(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xab00
leaq -0x28(%rbp), %rdi
callq 0xab00
jmp 0x158ca
leaq -0x28(%rbp), %rdi
callq 0xab00
jmp 0x158d6
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x4610
nop