// File: /workspace/github_cpp_makefile_star2_O3/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 $0xc8, %rsp
movl %r9d, 0x4c(%rsp)
movq 0x8(%rdx), %rbx
subq (%rdx), %rbx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cmpq %rax, %rbx
jne 0x336f4
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rbx, %r13
shrq $0x2, %r13
leal (,%r13,2), %eax
movl %eax, 0x64(%rsp)
movslq %eax, %rsi
leaq 0x28(%rsp), %rdx
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %rsi, 0x90(%rsp)
callq 0x8c20
movq 0x10(%rsp), %rdi
movq %r13, 0x68(%rsp)
testl %r13d, %r13d
jle 0x336d2
movq %r14, 0x40(%rsp)
shrq $0x3, %rbx
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
andq %r14, %rbx
andq 0x68(%rsp), %r14
xorl %ebp, %ebp
leaq 0x28(%rsp), %r13
movq 0x40(%rsp), %rsi
movl 0x18(%rsi), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x18(%rsi)
movq (%rdi), %rax
movl %ecx, (%rax,%rbp,8)
cmpq %rbx, %rbp
jae 0x33042
movl 0x18(%rsi), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x18(%rsi)
movl %ecx, 0x4(%rax,%rbp,8)
cmpb $0x0, 0x4c(%rsp)
je 0x330f7
movq (%r12), %rcx
xorl %edx, %edx
subl (%rcx,%rbp,4), %edx
movl %edx, 0x1c(%rsp)
movq (%r15), %rcx
xorl %edx, %edx
subl (%rcx,%rbp,4), %edx
movl %edx, 0x20(%rsp)
movl 0x4(%rax,%rbp,8), %eax
movl %eax, 0x24(%rsp)
movl $0x3, %edx
movq %r13, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x33038
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x10(%rsp), %rax
movq (%rax), %rax
jmp 0x3304d
cmpb $0x0, 0x4c(%rsp)
je 0x330f7
movq (%r12), %rcx
xorl %edx, %edx
subl (%rcx,%rbp,4), %edx
movl %edx, 0x1c(%rsp)
movl (%rax,%rbp,8), %eax
movl %eax, 0x20(%rsp)
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3309c
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq (%r15), %rax
xorl %ecx, %ecx
subl (%rax,%rbp,4), %ecx
movl %ecx, 0x1c(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl (%rax,%rbp,8), %eax
movl %eax, 0x20(%rsp)
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x330f2
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x10(%rsp), %rdi
cmpb $0x0, 0x100(%rsp)
je 0x3321e
movq (%r12), %rax
movl (%rax,%rbp,4), %eax
movl %eax, 0x1c(%rsp)
movq (%r15), %rax
movl (%rax,%rbp,4), %eax
movl %eax, 0x20(%rsp)
movq (%rdi), %rax
xorl %ecx, %ecx
subl (%rax,%rbp,8), %ecx
movl %ecx, 0x24(%rsp)
movl $0x3, %edx
movq %r13, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x33161
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
cmpq %rbx, %rbp
movq 0x10(%rsp), %rdi
jae 0x3321e
movq (%r12), %rax
movl (%rax,%rbp,4), %eax
movl %eax, 0x1c(%rsp)
movq (%rdi), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%rbp,8), %ecx
movl %ecx, 0x20(%rsp)
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x331c2
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq (%r15), %rax
movl (%rax,%rbp,4), %eax
movl %eax, 0x1c(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%rbp,8), %ecx
movl %ecx, 0x20(%rsp)
movl $0x2, %edx
movq %r13, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x33219
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x10(%rsp), %rdi
incq %rbp
cmpq %rbp, %r14
jne 0x32fab
cmpl $0x0, 0x68(%rsp)
movq 0x40(%rsp), %rbp
jle 0x336d2
movq (%rdi), %rax
movq 0x68(%rsp), %r9
movl %r9d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
movl $0x0, %esi
cmpl $0x1, %r9d
je 0x33273
movl $0x1, %edi
xorl %esi, %esi
xorl %r8d, %r8d
testl %edx, %edi
setne %r8b
leal (%r8,%rsi,2), %esi
addl %edi, %edi
cmpl %r9d, %edi
jl 0x3325f
movslq %esi, %rdi
cmpq %rdi, %rdx
jge 0x33290
addl %esi, %esi
movslq %esi, %rsi
movq (%rax,%rdx,8), %rdi
movq (%rax,%rsi,4), %r8
movq %r8, (%rax,%rdx,8)
movq %rdi, (%rax,%rsi,4)
incq %rdx
cmpq %rcx, %rdx
jne 0x3324d
cmpl $0x1, %r9d
movq 0x10(%rsp), %rdi
je 0x336d2
movl $0x4, %ecx
xorl %r12d, %r12d
leaq 0x28(%rsp), %r14
movq 0x40(%rsp), %r15
movl %ecx, %edx
sarl $0x2, %edx
leal -0x1(%rdx), %eax
movl %ecx, %r8d
sarl %r8d
cltq
movq %rax, 0x88(%rsp)
movslq %r8d, %rax
movslq %ecx, %rsi
movq %rax, 0x80(%rsp)
leaq (,%rax,4), %rax
movq %rax, 0x70(%rsp)
movq %rsi, 0xa0(%rsp)
leaq (,%rsi,4), %rax
movq %rax, 0x98(%rsp)
movq %rdx, 0xb0(%rsp)
leaq (%rdx,%rdx), %rax
movq %rax, 0xc0(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movl %ecx, 0x7c(%rsp)
movq %r8, 0xa8(%rsp)
cmpl 0x64(%rsp), %ecx
movl $0x1, %eax
cmovel %eax, %r12d
cmpl $0x0, 0xb0(%rsp)
jle 0x33634
movl $0xffffffff, 0x48(%rsp) # imm = 0xFFFFFFFF
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %r12, 0xb8(%rsp)
cmpb $0x0, 0x4c(%rsp)
je 0x334da
movq (%rdi), %rax
cmpq 0x88(%rsp), %rbx
jl 0x33391
testl %r12d, %r12d
je 0x33391
movq 0x50(%rsp), %rcx
leaq (%rcx,%rbx), %r12
movq %r13, %rbp
jmp 0x3340d
movq 0x58(%rsp), %rcx
addq %rax, %rcx
xorl %edx, %edx
subl 0x4(%rcx,%r13,2), %edx
movl %edx, 0x1c(%rsp)
addq 0x70(%rsp), %rax
xorl %ecx, %ecx
subl (%rax,%r13,2), %ecx
movl %ecx, 0x20(%rsp)
movl 0x18(%rbp), %eax
addl %r13d, %eax
incl %eax
movl %eax, 0x24(%rsp)
movl $0x3, %edx
movq %r14, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x333f8
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x50(%rsp), %rax
leaq (%rbx,%rax), %r12
leaq (%rbx,%rbx), %rbp
movq 0x10(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%r12,4), %ecx
movl %ecx, 0x1c(%rsp)
movl 0x18(%r15), %eax
addl %ebp, %eax
movl %eax, 0x20(%rsp)
movl $0x2, %edx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq %r15, %rdi
movq %r14, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x33460
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
shlq $0x2, %r12
movq 0x10(%rsp), %rax
addq (%rax), %r12
xorl %eax, %eax
movq 0x80(%rsp), %rcx
subl (%r12,%rcx,4), %eax
movl %eax, 0x1c(%rsp)
movq 0x40(%rsp), %r12
addl 0x18(%r12), %ebp
movl %ebp, 0x20(%rsp)
movl $0x2, %edx
leaq 0x28(%rsp), %r14
movq %r14, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq %r12, %rdi
movq %r14, %rsi
callq 0x2259a
movq %r12, %rbp
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x334cd
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x10(%rsp), %rdi
movq 0xb8(%rsp), %r12
cmpb $0x0, 0x100(%rsp)
je 0x3361a
movq (%rdi), %rax
movq 0x58(%rsp), %rcx
addq %rax, %rcx
movl 0x4(%rcx,%r13,2), %ecx
movl %ecx, 0x1c(%rsp)
addq 0x70(%rsp), %rax
movl (%rax,%r13,2), %eax
movl %eax, 0x20(%rsp)
movl 0x48(%rsp), %eax
subl 0x18(%rbp), %eax
incl %eax
movl %eax, 0x24(%rsp)
movl $0x3, %edx
movq %r14, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3354f
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
cmpq 0x88(%rsp), %rbx
movq 0x10(%rsp), %rdi
jl 0x33567
testl %r12d, %r12d
jne 0x3361a
movq (%rdi), %rax
addq 0x58(%rsp), %rax
movl 0x4(%rax,%r13,2), %eax
movl %eax, 0x1c(%rsp)
movl 0x48(%rsp), %eax
subl 0x18(%rbp), %eax
movl %eax, 0x20(%rsp)
movl $0x2, %edx
movq %r14, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x335bc
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x10(%rsp), %rax
movq (%rax), %rax
addq 0x70(%rsp), %rax
movl (%rax,%r13,2), %eax
movl %eax, 0x1c(%rsp)
movl 0x48(%rsp), %eax
subl 0x18(%rbp), %eax
movl %eax, 0x20(%rsp)
movl $0x2, %edx
movq %r14, %rdi
leaq 0x1c(%rsp), %rsi
leaq 0xf(%rsp), %rcx
callq 0x1e9a8
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2259a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x33615
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x10(%rsp), %rdi
incq %rbx
addl $-0x2, 0x48(%rsp)
addq $0x2, %r13
cmpq %r13, 0xc0(%rsp)
jne 0x33366
movq 0xa8(%rsp), %r8
cmpl $0x2, %r8d
jl 0x33663
movq (%rdi), %rax
addq 0x58(%rsp), %rax
movl $0x1, %ecx
movl 0x18(%rbp), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x18(%rbp)
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r8
jne 0x3364f
testl %r12d, %r12d
jne 0x3368c
movl 0x18(%rbp), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x18(%rbp)
movq 0x50(%rsp), %rcx
leaq (,%rcx,4), %rcx
addq (%rdi), %rcx
movq 0x80(%rsp), %rdx
movl %eax, (%rcx,%rdx,4)
xorl $0x1, %r12d
movq 0x50(%rsp), %rcx
addq 0xa0(%rsp), %rcx
movq 0x98(%rsp), %rax
addq %rax, 0x70(%rsp)
addq %rax, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
cmpq 0x90(%rsp), %rcx
movl 0x7c(%rsp), %ecx
jl 0x33336
addl %ecx, %ecx
cmpl 0x64(%rsp), %ecx
jle 0x332b9
movslq 0x68(%rsp), %rsi
movq %rdi, %rbx
callq 0x8cac
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6c14(%rip), %rdi      # 0x3a30f
leaq 0x6b2a(%rip), %rsi      # 0x3a22c
leaq 0x6c97(%rip), %rcx      # 0x3a3a0
movl $0x4a, %edx
callq 0x31b0
movq %rax, %r14
jmp 0x33768
jmp 0x33749
jmp 0x33749
jmp 0x33740
jmp 0x33740
jmp 0x33749
jmp 0x33740
jmp 0x33740
jmp 0x33740
jmp 0x33740
jmp 0x33749
jmp 0x33749
jmp 0x33749
jmp 0x33749
jmp 0x33749
jmp 0x33740
jmp 0x33740
jmp 0x33749
jmp 0x33740
jmp 0x33740
jmp 0x33740
movq %rax, %r14
jmp 0x33763
jmp 0x33749
jmp 0x33749
movq %rax, %r14
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x33763
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x10(%rsp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x3377c
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x32b0
movq %r14, %rdi
callq 0x34a0