// File: /workspace/github_cpp_makefile_star2_O2/Laakeri[P]maxpre/src/./GSLE.cpp
// Function: maxPreprocessor::Preprocessor::tryGSLE(int)
int Preprocessor::tryGSLE(int lb) {
	uint64_t lw = pi.labelWeight(litVariable(lb));
	for (int c : pi.litClauses[lb]) {
		bool f = false;
		for (int l : pi.clauses[c].lit) {
			if (l != lb && pi.isLabel[litVariable(l)] && pi.labelWeight(litVariable(l)) <= lw) {
				f = true;
				break;
			}
		}
		if (!f) {
			return 0;
		}
	}
	vector<vector<int> > hs;
	set<int> sel;
	uint64_t selW = 0;
	for (int c : pi.litClauses[lb]) {
		vector<int> s;
		for (int l : pi.clauses[c].lit) {
			if (l != lb && pi.isLabel[litVariable(l)] && pi.labelWeight(litVariable(l)) <= lw) {
				s.push_back(litVariable(l));
			}
		}
		hs.push_back(s);
	}
	for (auto& s : hs) {
		if (s.size() == 1) {
			if (sel.count(s[0]) == 0) {
				sel.insert(s[0]);
				selW += pi.labelWeight(s[0]);
			}
		}
	}
	if (selW > lw) return 0;
	vector<vector<int> > hss;
	uint64_t hsl = 0;
	for (auto& s : hs) {
		if (s.size() > 1) {
			bool f = false;
			for (int l : s) {
				if (sel.count(l) > 0) {
					f = true;
					break;
				}
			}
			if (!f) {
				hss.push_back(s);
				hsl += (uint64_t)(int)s.size();
			}
		}
	}
	auto cmp = [](const vector<int>& a, const vector<int>& b) {
		return a.size() < b.size();
	};
	sort(hss.begin(), hss.end(), cmp);
	// Do coordinate compression
	vector<int> cc;
	for (auto& se : hss) {
		for (int l : se) {
			cc.push_back(l);
		}
	}
	sort(cc.begin(), cc.end());
	cc.erase(unique(cc.begin(), cc.end()), cc.end());
	vector<uint64_t> laWeights(cc.size());
	for (int i = 0; i < (int)cc.size(); i++) {
		laWeights[i] = pi.labelWeight(cc[i]);
	}
	for (auto& se : hss) {
		for (int& l : se) {
			l = lower_bound(cc.begin(), cc.end(), l) - cc.begin();
		}
	}
	vector<int> cnt(cc.size());
	for (int i = (int)hss.size() - 1; i >= 0; i--) {
		for (int l : hss[i]) {
			cnt[l]++;
		}
		auto cmp2 = [&](int a, int b) {// the log-approximation heuristic
			return (double)laWeights[a]/(double)cnt[a] < (double)laWeights[b]/(double)cnt[b];
		};
		sort(hss[i].begin(), hss[i].end(), cmp2);
	}
	bool ok = false;
	hsl = min(hsl, (uint64_t)hss.size()*10); // magic constant
	if (GSLEtryBackTrack(hss, laWeights, lw - selW, hsl)) {
		ok = true;
	}
	if (ok) {
		int rmClauses = 0;
		if (pi.isLabel[litVariable(lb)] == VAR_TRUE) {
			rmClauses = setVariable(litVariable(lb), true);
		}
		else {
			rmClauses = setVariable(litVariable(lb), false);
		}
		assert(pi.isVarRemoved(litVariable(lb)));
		rLog.removeClause(rmClauses);
		rLog.removeLabel(1);
		return 1;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %esi, %r15d
movq %rdi, %rbx
sarl %esi
movl %esi, 0x54(%rsp)
callq 0x20fec
movq %rax, 0x60(%rsp)
movslq %r15d, %rax
movq 0x18(%rbx), %rcx
imulq $0x18, %rax, %r12
movq (%rcx,%r12), %r14
movq 0x8(%rcx,%r12), %rax
movq %rax, (%rsp)
cmpq %rax, %r14
je 0x12e88
movslq (%r14), %rax
movq (%rbx), %rcx
imulq $0x28, %rax, %rax
movq (%rcx,%rax), %rbp
movq 0x8(%rcx,%rax), %r13
cmpq %r13, %rbp
je 0x12e72
movl (%rbp), %esi
cmpl %r15d, %esi
je 0x12e62
sarl %esi
movslq %esi, %rax
movq 0x48(%rbx), %rcx
cmpl $0x0, (%rcx,%rax,4)
je 0x12e62
movq %rbx, %rdi
callq 0x20fec
cmpq 0x60(%rsp), %rax
jbe 0x12e68
addq $0x4, %rbp
jmp 0x12e37
addq $0x4, %r14
movq (%rsp), %rax
jmp 0x12e1f
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x80(%rsp), %rcx
andq $0x0, 0x10(%rcx)
leaq 0xc0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rcx)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq 0x18(%rbx), %rax
movq (%rax,%r12), %rcx
movq 0x8(%rax,%r12), %rax
movq %rax, 0x58(%rsp)
leaq 0x30(%rsp), %rbp
cmpq 0x58(%rsp), %rcx
je 0x12f6b
movq %rcx, (%rsp)
movslq (%rcx), %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movq (%rbx), %rcx
imulq $0x28, %rax, %rax
movq (%rcx,%rax), %r14
movq 0x8(%rcx,%rax), %r13
cmpq %r13, %r14
je 0x12f46
movl (%r14), %r12d
cmpl %r15d, %r12d
je 0x12f40
sarl %r12d
movslq %r12d, %rax
movq 0x48(%rbx), %rcx
cmpl $0x0, (%rcx,%rax,4)
je 0x12f40
movq %rbx, %rdi
movl %r12d, %esi
callq 0x20fec
cmpq 0x60(%rsp), %rax
ja 0x12f40
movl %r12d, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x19ed4
addq $0x4, %r14
jmp 0x12eff
leaq 0x80(%rsp), %rdi
movq %rbp, %rsi
callq 0x18f96
movq %rbp, %rdi
callq 0x7512
movq (%rsp), %rcx
addq $0x4, %rcx
jmp 0x12ecf
movq 0x80(%rsp), %r13
movq 0x88(%rsp), %rbp
xorl %r12d, %r12d
leaq 0xb8(%rsp), %r15
cmpq %rbp, %r13
je 0x12fcc
movq (%r13), %rsi
movq 0x8(%r13), %rax
subq %rsi, %rax
cmpq $0x4, %rax
jne 0x12fc6
movq %r15, %rdi
callq 0x18c86
testq %rax, %rax
jne 0x12fc6
movq (%r13), %rsi
movq %r15, %rdi
callq 0x1c54e
movq (%r13), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x20fec
addq %rax, %r12
addq $0x18, %r13
jmp 0x12f86
xorl %ebp, %ebp
subq %r12, 0x60(%rsp)
jb 0x133bf
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0x80(%rsp), %r13
movq 0x88(%rsp), %rax
movq %rax, (%rsp)
movq $0x0, 0x58(%rsp)
leaq 0xb8(%rsp), %rbp
leaq 0x10(%rsp), %r15
cmpq (%rsp), %r13
je 0x13075
movq (%r13), %r14
movq 0x8(%r13), %r12
movq %r12, %rax
subq %r14, %rax
cmpq $0x5, %rax
jb 0x1306f
cmpq %r12, %r14
je 0x1304f
movl (%r14), %eax
movl %eax, 0x10(%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x18c86
addq $0x4, %r14
testq %rax, %rax
je 0x1302d
jmp 0x1306f
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x18f96
movq 0x8(%r13), %rax
subq (%r13), %rax
shrq $0x2, %rax
cltq
addq %rax, 0x58(%rsp)
addq $0x18, %r13
jmp 0x13013
movq 0x30(%rsp), %r12
movq 0x38(%rsp), %r15
cmpq %r15, %r12
je 0x130e9
movq %r15, %r13
subq %r12, %r13
movq %r13, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x17700
cmpq $0x181, %r13            # imm = 0x181
jl 0x130de
leaq 0x180(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x17a84
jmp 0x130d7
movq %r13, %rdi
callq 0x17b2e
addq $0x18, %r13
cmpq %r15, %r13
jne 0x130cb
jmp 0x130e9
movq %r12, %rdi
movq %r15, %rsi
callq 0x17a84
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
andq $0x0, 0x10(%r15)
movaps %xmm0, (%r15)
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
leaq 0x68(%rsp), %r12
cmpq (%rsp), %r14
je 0x1313d
movq (%r14), %rbp
movq 0x8(%r14), %r13
cmpq %r13, %rbp
je 0x13137
movl (%rbp), %eax
movl %eax, 0x68(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x68a4
addq $0x4, %rbp
jmp 0x1311a
addq $0x18, %r14
jmp 0x1310d
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x1c706
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x1cd6f
leaq 0x10(%rsp), %rdi
movq 0x8(%rdi), %rdx
movq %rax, %rsi
callq 0x1902e
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
leaq 0x68(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x18c34
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r14
jge 0x131c2
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
callq 0x20fec
movq 0x68(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
jmp 0x1318f
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %r12
cmpq %r12, %r14
je 0x13207
movq (%r14), %r15
movq 0x8(%r14), %r13
cmpq %r13, %r15
je 0x13201
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x1cb06
subq 0x10(%rsp), %rax
shrq $0x2, %rax
movl %eax, (%r15)
addq $0x4, %r15
jmp 0x131d8
addq $0x18, %r14
jmp 0x131cc
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
leaq 0xa0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x6852
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movl %eax, %r12d
leaq 0xa0(%rsp), %r13
testl %r12d, %r12d
jle 0x1330c
decq %r12
movq 0x30(%rsp), %rax
imulq $0x18, %r12, %rcx
movq (%rax,%rcx), %rbp
movq 0x8(%rax,%rcx), %r15
movq 0xa0(%rsp), %rax
movq %rbp, %rcx
cmpq %r15, %rcx
je 0x1327e
movslq (%rcx), %rdx
incl (%rax,%rdx,4)
addq $0x4, %rcx
jmp 0x1326d
cmpq %r15, %rbp
je 0x13244
movq %r15, %r14
subq %rbp, %r14
movq %r14, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbp, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rcx
movq %r13, %r8
callq 0x17b98
cmpq $0x41, %r14
jl 0x132ec
movq %r12, %r14
leaq 0x40(%rbp), %r12
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x68(%rsp), %rbp
movq %rbp, %rdx
movq %r13, %rcx
callq 0x17f31
cmpq %r15, %r12
je 0x13304
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x17fcb
addq $0x4, %r12
jmp 0x132d3
movq %rbp, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %r13, %rcx
callq 0x17f31
jmp 0x13244
movq %r14, %r12
jmp 0x13244
leaq 0x30(%rsp), %rsi
movq 0x8(%rsi), %rax
subq (%rsi), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
imulq $0xa, %rax, %rax
movq 0x58(%rsp), %r8
cmpq %r8, %rax
cmovbq %rax, %r8
leaq 0x68(%rsp), %rdx
movq %rbx, %rdi
movq 0x60(%rsp), %rcx
callq 0x12cdc
xorl %ebp, %ebp
testb %al, %al
je 0x13394
movl 0x54(%rsp), %esi
movslq %esi, %rax
movq 0x48(%rbx), %rcx
xorl %edx, %edx
cmpl $0x1, (%rcx,%rax,4)
sete %dl
movq %rbx, %rdi
callq 0x7c98
movl %eax, %ebp
movq %rbx, %rdi
movl 0x54(%rsp), %esi
callq 0x20fae
testb %al, %al
je 0x133de
addq $0x218, %rbx            # imm = 0x218
movq %rbx, %rdi
movl %ebp, %esi
callq 0x21e84
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x21f32
leaq 0xa0(%rsp), %rdi
callq 0x7512
leaq 0x68(%rsp), %rdi
callq 0x6bf4
leaq 0x10(%rsp), %rdi
callq 0x7512
leaq 0x30(%rsp), %rdi
callq 0x6aa2
leaq 0xb8(%rsp), %rdi
callq 0x19878
leaq 0x80(%rsp), %rdi
callq 0x6aa2
jmp 0x12e74
leaq 0x1caf8(%rip), %rdi     # 0x2fedd
leaq 0x1cb12(%rip), %rsi     # 0x2fefe
leaq 0x1cb16(%rip), %rcx     # 0x2ff09
movl $0x92, %edx
callq 0x31c0
jmp 0x13428
jmp 0x1340b
jmp 0x1343e
jmp 0x1344d
jmp 0x1344d
jmp 0x1344d
jmp 0x1344d
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x7512
jmp 0x13441
jmp 0x13428
jmp 0x1343e
movq %rax, %rbx
jmp 0x13464
jmp 0x1342f
movq %rax, %rbx
jmp 0x1345a
jmp 0x1342f
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x7512
jmp 0x13464
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x6bf4
jmp 0x13450
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x7512
leaq 0x30(%rsp), %rdi
callq 0x6aa2
leaq 0xb8(%rsp), %rdi
callq 0x19878
leaq 0x80(%rsp), %rdi
callq 0x6aa2
movq %rbx, %rdi
callq 0x3490