// File: /workspace/github_cpp_makefile_star2_O2/Laakeri[P]maxpre/src/cardinalityconstraint.cpp
// Function: maxPreprocessor::CardinalityConstraint::SMerge(std::vector<int, std::allocator<int>> const&, std::vector<int, std::allocator<int>> const&, maxPreprocessor::CardinalityConstraint::Formula&, bool, bool)
vector<int> CardinalityConstraint::SMerge(const vector<int>& A, const vector<int>& B, Formula& F, bool d1, bool d2) {
	// use the bit reversal trick to do SMerge without recursion
	assert(A.size() == B.size());
	int n = A.size();
	vector<int> c(2*n);
	for (int i = 0; i < n; i++) {
		c[2*i] = F.freeVar++;
		if (i < n/2) c[2*i+1] = F.freeVar++;
		if (d1) {
			if (i < n/2) F.clauses.push_back({-A[i], -B[i], c[2*i+1]});
			F.clauses.push_back({-A[i], c[2*i]});
			F.clauses.push_back({-B[i], c[2*i]});
		}
		if (d2) {
			F.clauses.push_back({A[i], B[i], -c[2*i]});
			if (i < n/2) F.clauses.push_back({A[i], -c[2*i+1]});
			if (i < n/2) F.clauses.push_back({B[i], -c[2*i+1]});
		}
	}
	for (int i = 0; i < n; i++) {
		int u = 0;
		for (int j = 1; j < n; j *= 2) {
			u *= 2;
			if (i & j) u++;
		}
		if (i < u) {
			swap(c[2*i], c[2*u]);
			swap(c[2*i+1], c[2*u+1]);
		}
	}
	int oc = 0;
	for (int le = 4; le <= 2*n; le *= 2) {
		for (int i = 0; i < 2*n; i+=le) {
			if (le == 2*n) oc = 1;
			for (int j = 0; j < le/4; j++) {
				if (d1) {
					if (j+1 < le/4 || !oc) F.clauses.push_back({-c[i+j+1], -c[i+j+le/2], F.freeVar+2*j+1});
					F.clauses.push_back({-c[i+j+1], F.freeVar+2*j});
					F.clauses.push_back({-c[i+j+le/2], F.freeVar+2*j});
				}
				if (d2) {
					F.clauses.push_back({c[i+j+1], c[i+j+le/2], -(F.freeVar+2*j)});
					if (j+1 < le/4 || !oc) F.clauses.push_back({c[i+j+1], -(F.freeVar+2*j+1)});
					if (j+1 < le/4 || !oc) F.clauses.push_back({c[i+j+le/2], -(F.freeVar+2*j+1)});
				}
			}
			for (int j = 1; j < le/2; j++) c[i+j] = F.freeVar++;
			if (!oc) c[i+le/2] = F.freeVar++;
			oc ^= 1;
		}
	}
	c.resize(n);
	return c;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r9d, 0x24(%rsp)
movq 0x8(%rdx), %rbx
subq (%rdx), %rbx
movq 0x8(%rcx), %rax
movq %rcx, 0x18(%rsp)
subq (%rcx), %rax
cmpq %rax, %rbx
jne 0x2afb7
movq %r8, %r14
movq %rdx, %r12
shrq $0x2, %rbx
leal (%rbx,%rbx), %eax
movl %eax, 0x30(%rsp)
movslq %eax, %rsi
leaq 0x40(%rsp), %r13
movq %rdi, 0x10(%rsp)
movq %rsi, 0x90(%rsp)
movq %r13, %rdx
callq 0x6852
pushq $0x2
popq %rcx
movl %ebx, %eax
cltd
idivl %ecx
movslq %eax, %rbp
movq %rbx, %rax
xorl %r15d, %r15d
testl %eax, %eax
movl $0x0, %ebx
movq %rax, 0x68(%rsp)
cmovgl %eax, %ebx
cmpq %r15, %rbx
je 0x2ab65
movl 0x18(%r14), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x18(%r14)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl %ecx, (%rax,%r15,8)
cmpq %rbp, %r15
jge 0x2a9cb
movl 0x18(%r14), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x18(%r14)
movl %ecx, 0x4(%rax,%r15,8)
cmpb $0x0, 0x24(%rsp)
je 0x2aa5e
movq (%r12), %rcx
xorl %edx, %edx
subl (%rcx,%r15,4), %edx
movl %edx, 0x4(%rsp)
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
xorl %edx, %edx
subl (%rcx,%r15,4), %edx
movl %edx, 0x8(%rsp)
movl 0x4(%rax,%r15,8), %eax
movl %eax, 0xc(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x3
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movq 0x10(%rsp), %rax
movq (%rax), %rax
jmp 0x2a9d6
cmpb $0x0, 0x24(%rsp)
je 0x2aa5e
movq (%r12), %rcx
xorl %edx, %edx
subl (%rcx,%r15,4), %edx
movl %edx, 0x4(%rsp)
movl (%rax,%r15,8), %eax
movl %eax, 0x8(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movq 0x18(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl (%rax,%r15,4), %ecx
movl %ecx, 0x4(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl (%rax,%r15,8), %eax
movl %eax, 0x8(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
cmpb $0x0, 0xe0(%rsp)
je 0x2ab5d
movq (%r12), %rax
movl (%rax,%r15,4), %eax
movl %eax, 0x4(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl (%rax,%r15,4), %eax
movl %eax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl (%rax,%r15,8), %ecx
movl %ecx, 0xc(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x3
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
cmpq %rbp, %r15
jge 0x2ab5d
movq (%r12), %rax
movl (%rax,%r15,4), %eax
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%r15,8), %ecx
movl %ecx, 0x8(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl (%rax,%r15,4), %eax
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%r15,8), %ecx
movl %ecx, 0x8(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
incq %r15
jmp 0x2a930
movq 0x10(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
pushq $0x1
popq %rdx
movq 0x68(%rsp), %r9
cmpq %rbx, %rcx
je 0x2abb8
xorl %esi, %esi
movl %edx, %edi
cmpl %r9d, %edi
jge 0x2ab96
xorl %r8d, %r8d
testl %ecx, %edi
setne %r8b
leal (%r8,%rsi,2), %esi
addl %edi, %edi
jmp 0x2ab80
movslq %esi, %rdi
cmpq %rdi, %rcx
jge 0x2abb3
addl %esi, %esi
movslq %esi, %rsi
movq (%rax,%rcx,8), %rdi
movq (%rax,%rsi,4), %r8
movq %r8, (%rax,%rcx,8)
movq %rdi, (%rax,%rsi,4)
incq %rcx
jmp 0x2ab77
pushq $0x4
popq %rdi
leaq 0x40(%rsp), %r13
xorl %r11d, %r11d
movq %r14, %r12
movq %r14, 0x98(%rsp)
cmpl 0x30(%rsp), %edi
jg 0x2af92
movl %edi, %edx
sarl $0x2, %edx
leal -0x1(%rdx), %eax
movl %edi, %ecx
sarl %ecx
movslq %ecx, %r8
cltq
movq %rax, 0x78(%rsp)
testl %edx, %edx
movl $0x0, %eax
cmovlel %eax, %edx
movslq %edi, %rax
addl %edx, %edx
movq %rdx, 0xa0(%rsp)
leaq (,%r8,4), %rcx
movq %rcx, 0x38(%rsp)
movq %rax, 0x88(%rsp)
leaq (,%rax,4), %rax
movq %rax, 0x80(%rsp)
movq $0x0, 0x28(%rsp)
xorl %r10d, %r10d
movl %edi, 0x60(%rsp)
movq %r8, 0x70(%rsp)
cmpq 0x90(%rsp), %r10
jge 0x2af8b
movq %r10, 0x58(%rsp)
cmpl 0x30(%rsp), %edi
pushq $0x1
popq %rax
cmovel %eax, %r11d
movl %r11d, 0x34(%rsp)
xorl %ebx, %ebx
pushq $-0x1
popq %rdx
movl 0x34(%rsp), %r11d
movq $0x0, 0x18(%rsp)
cmpq %rbx, 0xa0(%rsp)
je 0x2af05
cmpb $0x0, 0x24(%rsp)
je 0x2add2
movl %edx, 0x64(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rcx
cmpq 0x78(%rsp), %rcx
jl 0x2acc1
testl %r11d, %r11d
je 0x2acc1
movq %r13, %r15
movq 0x58(%rsp), %rcx
movq 0x18(%rsp), %rdx
leaq (%rcx,%rdx), %r13
movq %rbx, %rbp
jmp 0x2ad33
movq 0x28(%rsp), %rcx
addq %rax, %rcx
xorl %edx, %edx
subl 0x4(%rcx,%rbx,2), %edx
movl %edx, 0x4(%rsp)
addq 0x38(%rsp), %rax
xorl %ecx, %ecx
subl (%rax,%rbx,2), %ecx
movl %ecx, 0x8(%rsp)
movl 0x18(%r12), %eax
addl %ebx, %eax
incl %eax
movl %eax, 0xc(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x3
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %r12, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %r15
movq 0x58(%rsp), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax), %r13
leaq (%rcx,%rcx), %rbp
movq %r15, %rdi
callq 0x7512
movq 0x10(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%r13,4), %ecx
movl %ecx, 0x4(%rsp)
movq 0x98(%rsp), %r12
movl 0x18(%r12), %eax
addl %ebp, %eax
movl %eax, 0x8(%rsp)
movq %r15, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %r12, %rdi
movq %r15, %rsi
callq 0x1cb40
movq %r15, %rdi
callq 0x7512
shlq $0x2, %r13
movq 0x10(%rsp), %rax
addq (%rax), %r13
xorl %eax, %eax
movq 0x70(%rsp), %rcx
subl (%r13,%rcx,4), %eax
movl %eax, 0x4(%rsp)
addl 0x18(%r12), %ebp
movl %ebp, 0x8(%rsp)
movq %r15, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %r15, %r13
movq %r12, %rdi
movq %r15, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movl 0x34(%rsp), %r11d
movl 0x64(%rsp), %edx
cmpb $0x0, 0xe0(%rsp)
je 0x2aef4
movl %r11d, %r14d
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rsp), %rcx
addq %rax, %rcx
movl 0x4(%rcx,%rbx,2), %ecx
movl %ecx, 0x4(%rsp)
addq 0x38(%rsp), %rax
movl (%rax,%rbx,2), %eax
movl %eax, 0x8(%rsp)
movl %edx, %r15d
movl %edx, %eax
movq %r12, %rbp
subl 0x18(%r12), %eax
incl %eax
movl %eax, 0xc(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x3
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movq 0x18(%rsp), %rax
cmpq 0x78(%rsp), %rax
movl %r15d, %edx
jl 0x2ae5d
movl %r14d, %r11d
testl %r14d, %r14d
jne 0x2aef4
movq 0x10(%rsp), %rax
movq (%rax), %rax
addq 0x28(%rsp), %rax
movl 0x4(%rax,%rbx,2), %eax
movl %eax, 0x4(%rsp)
movl %edx, %eax
movq %r12, %rbp
subl 0x18(%r12), %eax
movl %eax, 0x8(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movq 0x10(%rsp), %rax
movq (%rax), %rax
addq 0x38(%rsp), %rax
movl (%rax,%rbx,2), %eax
movl %eax, 0x4(%rsp)
movl %r15d, %eax
subl 0x18(%rbp), %eax
movl %eax, 0x8(%rsp)
movq %r13, %rdi
leaq 0x4(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x3(%rsp), %rcx
callq 0x18af6
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movl %r15d, %edx
movl %r14d, %r11d
incq 0x18(%rsp)
addl $-0x2, %edx
addq $0x2, %rbx
jmp 0x2ac75
movq 0x10(%rsp), %rax
movq (%rax), %rax
addq 0x28(%rsp), %rax
pushq $0x1
popq %rcx
movq 0x68(%rsp), %r9
movl 0x60(%rsp), %edi
movq 0x70(%rsp), %r8
movq 0x58(%rsp), %r10
cmpq %r8, %rcx
jge 0x2af42
movl 0x18(%r12), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x18(%r12)
movl %edx, (%rax,%rcx,4)
incq %rcx
jmp 0x2af28
testl %r11d, %r11d
jne 0x2af68
movl 0x18(%r12), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x18(%r12)
leaq (,%r10,4), %rcx
movq 0x10(%rsp), %rdx
addq (%rdx), %rcx
movl %eax, (%rcx,%r8,4)
xorl $0x1, %r11d
addq 0x88(%rsp), %r10
movq 0x80(%rsp), %rax
addq %rax, 0x38(%rsp)
addq %rax, 0x28(%rsp)
jmp 0x2ac3f
addl %edi, %edi
jmp 0x2abce
movslq %r9d, %rsi
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x68c2
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x62b5(%rip), %rdi      # 0x31273
leaq 0x61cb(%rip), %rsi      # 0x31190
leaq 0x6338(%rip), %rcx      # 0x31304
pushq $0x4a
popq %rdx
callq 0x31c0
jmp 0x2affe
jmp 0x2b007
jmp 0x2affe
jmp 0x2b007
jmp 0x2affe
jmp 0x2b007
jmp 0x2affe
jmp 0x2affe
jmp 0x2affe
jmp 0x2affe
jmp 0x2b007
jmp 0x2b007
jmp 0x2b007
jmp 0x2b007
jmp 0x2affe
jmp 0x2b007
jmp 0x2affe
jmp 0x2b007
jmp 0x2affe
jmp 0x2affe
jmp 0x2affe
movq %rax, %r14
jmp 0x2b014
jmp 0x2b007
jmp 0x2b007
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x7512
movq 0x10(%rsp), %rdi
callq 0x7512
movq %r14, %rdi
callq 0x3490