// File: Laakeri[P]maxpre/src/cardinalityconstraint.cpp
// Function: maxPreprocessor::CardinalityConstraint::getEqualNetwork(int, std::vector<int, std::allocator<int>>)
pair<CardinalityConstraint::Formula, int> CardinalityConstraint::getEqualNetwork(int freeVar, vector<int> input) {
	int KK = K;
	if ((int)input.size() - K < KK) {
		KK = (int)input.size() - K;
		for (int& lit : input) {
			lit = -lit;
		}
	}
	int k = 1;
	while (k <= KK) k *= 2;
	Formula F(freeVar);
	while ((int)input.size()%k != 0) {
		F.clauses.push_back({-F.freeVar});
		input.push_back(F.freeVar++);
	}
	vector<int> output = Card(input, 0, (int)input.size()-1, k, F, true, true);
	int oV = F.freeVar++;
	F.clauses.push_back({output[KK-1], -oV});
	F.clauses.push_back({-output[KK], -oV});
	if (iff) {
		F.clauses.push_back({-output[KK-1], output[KK], oV});
	}
	return {F, oV};
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rcx, -0x198(%rbp)
movq %rdi, %rax
movq -0x198(%rbp), %rdi
movq %rax, -0x190(%rbp)
movq %rax, %rcx
movq %rcx, -0x188(%rbp)
movq %rax, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rdi, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x180(%rbp)
movl 0x38(%rax), %eax
movl %eax, -0x24(%rbp)
callq 0xf940
movq -0x180(%rbp), %rcx
subl 0x38(%rcx), %eax
cmpl -0x24(%rbp), %eax
jge 0x7e68d
movq -0x198(%rbp), %rdi
callq 0xf940
movq -0x180(%rbp), %rdx
movq %rax, %rcx
movq -0x198(%rbp), %rax
subl 0x38(%rdx), %ecx
movl %ecx, -0x24(%rbp)
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0xa800
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0xa830
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa860
testb $0x1, %al
jne 0x7e665
jmp 0x7e68b
leaq -0x38(%rbp), %rdi
callq 0xa8a0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
xorl %ecx, %ecx
subl (%rax), %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
leaq -0x38(%rbp), %rdi
callq 0xa930
jmp 0x7e652
jmp 0x7e68d
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jg 0x7e6a6
movl -0x4c(%rbp), %eax
shll %eax
movl %eax, -0x4c(%rbp)
jmp 0x7e694
movl -0x14(%rbp), %esi
leaq -0x70(%rbp), %rdi
callq 0x7b6b0
movq -0x198(%rbp), %rdi
callq 0xf940
cltd
idivl -0x4c(%rbp)
cmpl $0x0, %edx
je 0x7e7e1
leaq -0x70(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movl -0x58(%rbp), %eax
negl %eax
movl %eax, -0x9c(%rbp)
leaq -0x9c(%rbp), %rax
movq %rax, -0x98(%rbp)
movq $0x1, -0x90(%rbp)
leaq -0x9d(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0xa710
movq -0x1a0(%rbp), %rcx
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
leaq -0x88(%rbp), %rdi
callq 0x3c9b0
jmp 0x7e730
movq -0x1a8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3e200
jmp 0x7e745
leaq -0x88(%rbp), %rdi
callq 0xab00
leaq -0x9d(%rbp), %rdi
callq 0xa7a0
movq -0x198(%rbp), %rdi
movl -0x58(%rbp), %eax
movl %eax, %ecx
incl %ecx
movl %ecx, -0x58(%rbp)
movl %eax, -0xb0(%rbp)
leaq -0xb0(%rbp), %rsi
callq 0x3c850
jmp 0x7e782
jmp 0x7e6b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x7e7b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xab00
leaq -0x9d(%rbp), %rdi
callq 0xa7a0
jmp 0x7eba5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x7eba5
movq -0x198(%rbp), %rdi
callq 0xf940
movq -0x180(%rbp), %rsi
movq -0x198(%rbp), %rdx
movl %eax, %r8d
decl %r8d
movl -0x4c(%rbp), %r9d
movq %rsp, %rax
leaq -0x70(%rbp), %rcx
movq %rcx, (%rax)
movl $0x1, 0x10(%rax)
movl $0x1, 0x8(%rax)
leaq -0xc8(%rbp), %rdi
xorl %ecx, %ecx
callq 0x7de10
jmp 0x7e82d
movl -0x58(%rbp), %eax
movl %eax, %ecx
incl %ecx
movl %ecx, -0x58(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x70(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movl -0x24(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0xc8(%rbp), %rdi
callq 0xa7c0
movl (%rax), %eax
movl %eax, -0x100(%rbp)
movl -0xcc(%rbp), %eax
negl %eax
movl %eax, -0xfc(%rbp)
leaq -0x100(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq $0x2, -0xf0(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0xa710
movq -0x1b0(%rbp), %rcx
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x3c9b0
jmp 0x7e8c1
movq -0x1b8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3e200
jmp 0x7e8d6
leaq -0xe8(%rbp), %rdi
callq 0xab00
leaq -0x101(%rbp), %rdi
callq 0xa7a0
leaq -0x70(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movslq -0x24(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0xa7c0
movl (%rax), %eax
negl %eax
movl %eax, -0x138(%rbp)
movl -0xcc(%rbp), %eax
negl %eax
movl %eax, -0x134(%rbp)
leaq -0x138(%rbp), %rax
movq %rax, -0x130(%rbp)
movq $0x2, -0x128(%rbp)
leaq -0x139(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0xa710
movq -0x1c0(%rbp), %rcx
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rdx
leaq -0x120(%rbp), %rdi
callq 0x3c9b0
jmp 0x7e970
movq -0x1c8(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3e200
jmp 0x7e985
leaq -0x120(%rbp), %rdi
callq 0xab00
leaq -0x139(%rbp), %rdi
callq 0xa7a0
movq -0x180(%rbp), %rax
testb $0x1, 0x58(%rax)
je 0x7eb49
leaq -0x70(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movl -0x24(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0xa7c0
movq -0x1d8(%rbp), %rdi
movl (%rax), %eax
negl %eax
movl %eax, -0x174(%rbp)
movslq -0x24(%rbp), %rsi
callq 0xa7c0
movl (%rax), %eax
movl %eax, -0x170(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0x16c(%rbp)
leaq -0x174(%rbp), %rax
movq %rax, -0x168(%rbp)
movq $0x3, -0x160(%rbp)
leaq -0x175(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0xa710
movq -0x1d0(%rbp), %rcx
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rdx
leaq -0x158(%rbp), %rdi
callq 0x3c9b0
jmp 0x7ea51
movq -0x1e0(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x3e200
jmp 0x7ea66
leaq -0x158(%rbp), %rdi
callq 0xab00
leaq -0x175(%rbp), %rdi
callq 0xa7a0
jmp 0x7eb49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x7eab5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0xab00
leaq -0x101(%rbp), %rdi
callq 0xa7a0
jmp 0x7eb99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x7eaf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x120(%rbp), %rdi
callq 0xab00
leaq -0x139(%rbp), %rdi
callq 0xa7a0
jmp 0x7eb99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x7eb3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x158(%rbp), %rdi
callq 0xab00
leaq -0x175(%rbp), %rdi
callq 0xa7a0
jmp 0x7eb99
movq -0x190(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0xcc(%rbp), %rdx
callq 0x840a0
jmp 0x7eb62
leaq -0xc8(%rbp), %rdi
callq 0xab00
leaq -0x70(%rbp), %rdi
callq 0x84080
movq -0x188(%rbp), %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xab00
leaq -0x70(%rbp), %rdi
callq 0x84080
movq -0xa8(%rbp), %rdi
callq 0x4610
nopw (%rax,%rax)