// File: Laakeri[P]maxpre/src/./SSR.cpp
// Function: maxPreprocessor::Preprocessor::doSSR()
int Preprocessor::doSSR() {
	rLog.startTechnique(Log::Technique::SSR);
	if (!rLog.requestTime(Log::Technique::SSR)) {
		rLog.stopTechnique(Log::Technique::SSR);
		return 0;
	}
	int eliminated = 0;
	vector<int> checkVar = pi.tl.getModVariables("SSR");
	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::SSR)) break;
			int var = checkVar[getRand(0, (int)checkVar.size() -1)];
			eliminated += trySSRgen(var);
		}
		if (eliminated == 0) {
			skip = true;
			log("SSR skipped");
		}
	}
	if (!skip) {
		for (int var : checkVar) {
			if (!rLog.requestTime(Log::Technique::SSR)) break;
			eliminated += trySSRgen(var);
		}
	}
	log(eliminated, " eliminated by SSR");
	rLog.stopTechnique(Log::Technique::SSR);
	return eliminated;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x5, %esi
callq 0x61320
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x5, %esi
callq 0x62450
testb $0x1, %al
jne 0x1dedb
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x5, %esi
callq 0x61390
movl $0x0, -0x4(%rbp)
jmp 0x1e249
movq -0xc0(%rbp), %rax
movl $0x0, -0x14(%rbp)
addq $0x68, %rax
movq %rax, -0xd0(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x4620
movq -0xc8(%rbp), %rdx
leaq 0x6884f(%rip), %rsi     # 0x86761
leaq -0x50(%rbp), %rdi
callq 0xa430
jmp 0x1df1d
movq -0xd0(%rbp), %rsi
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x73320
jmp 0x1df33
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 0x1df60
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x1df6f
jmp 0x1e00c
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 0x1e260
jmp 0x1dfbf
jmp 0x1e00c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1dfe4
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 0x1e255
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
jmp 0x1e255
movq -0xc0(%rbp), %rax
movb $0x0, -0x89(%rbp)
cmpl $0x0, 0x468(%rax)
jle 0x1e136
leaq -0x30(%rbp), %rdi
callq 0xf940
movq -0xc0(%rbp), %rcx
movl 0x468(%rcx), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jl 0x1e136
movl $0x0, -0x90(%rbp)
movq -0xc0(%rbp), %rcx
movl -0x90(%rbp), %eax
cmpl 0x468(%rcx), %eax
jge 0x1e110
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x5, %esi
callq 0x62450
movb %al, -0xe1(%rbp)
jmp 0x1e08b
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x1e099
jmp 0x1e097
jmp 0x1e110
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 0x1e0bc
movl -0xe8(%rbp), %eax
movslq %eax, %rsi
leaq -0x30(%rbp), %rdi
callq 0xa7c0
movq -0xc0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %esi
callq 0x1da90
movl %eax, -0xec(%rbp)
jmp 0x1e0f0
movl -0xec(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x1e052
cmpl $0x0, -0x14(%rbp)
jne 0x1e134
movq -0xc0(%rbp), %rdi
movb $0x1, -0x89(%rbp)
leaq 0x6861b(%rip), %rsi     # 0x86746
callq 0x3cf50
jmp 0x1e132
jmp 0x1e134
jmp 0x1e136
testb $0x1, -0x89(%rbp)
jne 0x1e208
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 0x1e18d
jmp 0x1e206
leaq -0xa8(%rbp), %rdi
callq 0xa8a0
movq -0xc0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xb4(%rbp)
addq $0x218, %rdi            # imm = 0x218
movl $0x5, %esi
callq 0x62450
movb %al, -0xed(%rbp)
jmp 0x1e1c1
movb -0xed(%rbp), %al
testb $0x1, %al
jne 0x1e1cf
jmp 0x1e1cd
jmp 0x1e206
movq -0xc0(%rbp), %rdi
movl -0xb4(%rbp), %esi
callq 0x1da90
movl %eax, -0xf4(%rbp)
jmp 0x1e1e9
movl -0xf4(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xa930
jmp 0x1e174
jmp 0x1e208
movq -0xc0(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq 0x68539(%rip), %rdx     # 0x86752
callq 0x3c620
jmp 0x1e220
movq -0xc0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
movl $0x5, %esi
callq 0x61390
jmp 0x1e23a
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xab00
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x4610
nop