// File: /workspace/github_cpp_makefile_star2_O1/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 $0xb8, %rsp
movl %r9d, 0x3c(%rsp)
movq 0x8(%rdx), %rbx
subq (%rdx), %rbx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cmpq %rax, %rbx
jne 0x3469d
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r12
movq %rbx, %r13
shrq $0x2, %r13
leal (,%r13,2), %eax
movl %eax, 0x38(%rsp)
movslq %eax, %rsi
leaq 0x20(%rsp), %rdx
movq %rdi, 0x8(%rsp)
movq 0x8(%rsp), %rdi
callq 0x8c32
movq 0x8(%rsp), %rsi
movq %r13, 0x48(%rsp)
testl %r13d, %r13d
jle 0x34202
shrq $0x3, %rbx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rbx
andq 0x48(%rsp), %rax
movq %rax, 0x40(%rsp)
xorl %ebp, %ebp
leaq 0x20(%rsp), %r13
movl 0x18(%r14), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x18(%r14)
movq (%rsi), %rax
movl %ecx, (%rax,%rbp,8)
cmpq %rbx, %rbp
jae 0x33fbb
movl 0x18(%r14), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x18(%r14)
movl %ecx, 0x4(%rax,%rbp,8)
cmpb $0x0, 0x3c(%rsp)
je 0x340d3
cmpq %rbx, %rbp
jae 0x3402a
movq (%r12), %rcx
xorl %edx, %edx
subl (%rcx,%rbp,4), %edx
movl %edx, 0x14(%rsp)
movq (%r15), %rcx
xorl %edx, %edx
subl (%rcx,%rbp,4), %edx
movl %edx, 0x18(%rsp)
movl 0x4(%rax,%rbp,8), %eax
movl %eax, 0x1c(%rsp)
movl $0x3, %edx
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r13, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x34025
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x8(%rsp), %rsi
movq (%r12), %rax
xorl %ecx, %ecx
subl (%rax,%rbp,4), %ecx
movl %ecx, 0x14(%rsp)
movq (%rsi), %rax
movl (%rax,%rbp,8), %eax
movl %eax, 0x18(%rsp)
movl $0x2, %edx
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r13, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3407a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq (%r15), %rax
xorl %ecx, %ecx
subl (%rax,%rbp,4), %ecx
movl %ecx, 0x14(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl (%rax,%rbp,8), %eax
movl %eax, 0x18(%rsp)
movl $0x2, %edx
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r13, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x340ce
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x8(%rsp), %rsi
cmpb $0x0, 0xf0(%rsp)
je 0x341f4
movq (%r12), %rax
movl (%rax,%rbp,4), %eax
movl %eax, 0x14(%rsp)
movq (%r15), %rax
movl (%rax,%rbp,4), %eax
movl %eax, 0x18(%rsp)
movq (%rsi), %rax
xorl %ecx, %ecx
subl (%rax,%rbp,8), %ecx
movl %ecx, 0x1c(%rsp)
movl $0x3, %edx
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r13, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3413b
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
cmpq %rbx, %rbp
movq 0x8(%rsp), %rsi
jae 0x341f4
movq (%r12), %rax
movl (%rax,%rbp,4), %eax
movl %eax, 0x14(%rsp)
movq (%rsi), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%rbp,8), %ecx
movl %ecx, 0x18(%rsp)
movl $0x2, %edx
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r13, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3419a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq (%r15), %rax
movl (%rax,%rbp,4), %eax
movl %eax, 0x14(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%rbp,8), %ecx
movl %ecx, 0x18(%rsp)
movl $0x2, %edx
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r13, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x341ef
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x8(%rsp), %rsi
incq %rbp
cmpq %rbp, 0x40(%rsp)
jne 0x33f96
movq 0x48(%rsp), %r10
testl %r10d, %r10d
jle 0x34282
movq 0x8(%rsp), %rax
movq (%rax), %rax
movl %r10d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
movl $0x0, %esi
cmpl $0x1, %r10d
je 0x34245
movl $0x1, %edi
xorl %esi, %esi
xorl %r8d, %r8d
testl %edx, %edi
setne %r8b
leal (%r8,%rsi,2), %esi
addl %edi, %edi
cmpl %r10d, %edi
jl 0x34231
movslq %esi, %rdi
cmpq %rdi, %rdx
jge 0x3427a
leal (%rsi,%rsi), %edi
movslq %edi, %rdi
movl (%rax,%rdx,8), %r8d
movl (%rax,%rdi,4), %r9d
movl %r9d, (%rax,%rdx,8)
movl %r8d, (%rax,%rdi,4)
leal 0x1(%rsi,%rsi), %esi
movslq %esi, %rsi
movl 0x4(%rax,%rdx,8), %edi
movl (%rax,%rsi,4), %r8d
movl %r8d, 0x4(%rax,%rdx,8)
movl %edi, (%rax,%rsi,4)
incq %rdx
cmpq %rcx, %rdx
jne 0x3421f
cmpl $0x2, %r10d
movq 0x8(%rsp), %rdi
jl 0x3467b
movl 0x38(%rsp), %eax
movq %rax, 0x80(%rsp)
movl $0x4, %ecx
xorl %edx, %edx
leaq 0x20(%rsp), %r15
movl %ecx, %esi
sarl $0x2, %esi
leal -0x1(%rsi), %eax
movl %ecx, %r8d
sarl %r8d
cltq
movq %rax, 0x40(%rsp)
movslq %r8d, %rax
movslq %ecx, %r9
movq %rax, 0x78(%rsp)
leaq (,%rax,4), %rax
movq %r9, 0x90(%rsp)
leaq (,%r9,4), %r9
movq %r9, 0x88(%rsp)
movq %rsi, 0xa0(%rsp)
addq %rsi, %rsi
movq %rsi, 0xb0(%rsp)
movq %rax, 0x68(%rsp)
xorl %ebx, %ebx
movq %rax, 0x70(%rsp)
movq %rax, 0x50(%rsp)
xorl %r9d, %r9d
movl %ecx, 0x64(%rsp)
movq %r8, 0x98(%rsp)
movq %r9, 0xa8(%rsp)
cmpl 0x38(%rsp), %ecx
movl $0x1, %eax
cmovel %eax, %edx
movq %rdx, 0x58(%rsp)
cmpl $0x0, 0xa0(%rsp)
jle 0x345da
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpb $0x0, 0x3c(%rsp)
je 0x34488
cmpq 0x40(%rsp), %rbp
jl 0x34367
cmpl $0x0, 0x58(%rsp)
jne 0x343d3
movq (%rdi), %rax
leaq (%rax,%rbx), %rcx
xorl %edx, %edx
subl 0x4(%rcx,%r12,2), %edx
movl %edx, 0x14(%rsp)
addq 0x68(%rsp), %rax
xorl %ecx, %ecx
subl (%rax,%r12,2), %ecx
movl %ecx, 0x18(%rsp)
movl 0x18(%r14), %eax
addl %r12d, %eax
incl %eax
movl %eax, 0x1c(%rsp)
movl $0x3, %edx
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r15, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x343ce
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
addq %rbx, %rax
xorl %ecx, %ecx
subl 0x4(%rax,%r12,2), %ecx
movl %ecx, 0x14(%rsp)
movl 0x18(%r14), %eax
addl %r12d, %eax
movl %eax, 0x18(%rsp)
movl $0x2, %edx
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r15, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x34428
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x8(%rsp), %rax
movq (%rax), %rax
addq 0x70(%rsp), %rax
xorl %ecx, %ecx
subl (%rax,%r12,2), %ecx
movl %ecx, 0x14(%rsp)
movl 0x18(%r14), %eax
addl %r12d, %eax
movl %eax, 0x18(%rsp)
movl $0x2, %edx
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r15, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x34483
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x8(%rsp), %rdi
cmpb $0x0, 0xf0(%rsp)
je 0x345c1
movq (%rdi), %rax
leaq (%rax,%rbx), %rcx
movl 0x4(%rcx,%r12,2), %ecx
movl %ecx, 0x14(%rsp)
addq 0x50(%rsp), %rax
movl (%rax,%r12,2), %eax
movl %eax, 0x18(%rsp)
movl %r13d, %eax
subl 0x18(%r14), %eax
incl %eax
movl %eax, 0x1c(%rsp)
movl $0x3, %edx
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r15, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x344f9
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
cmpq 0x40(%rsp), %rbp
movq 0x8(%rsp), %rdi
jl 0x34510
cmpl $0x0, 0x58(%rsp)
jne 0x345c1
movq (%rdi), %rax
addq %rbx, %rax
movl 0x4(%rax,%r12,2), %eax
movl %eax, 0x14(%rsp)
movl %r13d, %eax
subl 0x18(%r14), %eax
movl %eax, 0x18(%rsp)
movl $0x2, %edx
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r15, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x34563
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x8(%rsp), %rax
movq (%rax), %rax
addq 0x50(%rsp), %rax
movl (%rax,%r12,2), %eax
movl %eax, 0x14(%rsp)
movl %r13d, %eax
subl 0x18(%r14), %eax
movl %eax, 0x18(%rsp)
movl $0x2, %edx
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x7(%rsp), %rcx
callq 0x1f586
movq %r14, %rdi
movq %r15, %rsi
callq 0x23202
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x345bc
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x8(%rsp), %rdi
incq %rbp
addq $0x2, %r12
addl $-0x2, %r13d
cmpq %r12, 0xb0(%rsp)
jne 0x3434e
movq 0x98(%rsp), %r8
cmpl $0x2, %r8d
jl 0x34609
movq (%rdi), %rax
addq %rbx, %rax
movl $0x1, %ecx
movl 0x18(%r14), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x18(%r14)
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r8
jne 0x345f3
movq 0x58(%rsp), %rdx
testl %edx, %edx
movq 0xa8(%rsp), %r9
jne 0x34638
movl 0x18(%r14), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x18(%r14)
leaq (,%r9,4), %rcx
addq (%rdi), %rcx
movq 0x78(%rsp), %rsi
movl %eax, (%rcx,%rsi,4)
xorl $0x1, %edx
addq 0x90(%rsp), %r9
movq 0x88(%rsp), %rax
addq %rax, 0x50(%rsp)
addq %rax, %rbx
addq %rax, 0x68(%rsp)
addq %rax, 0x70(%rsp)
cmpq 0x80(%rsp), %r9
movl 0x64(%rsp), %ecx
jl 0x3431c
addl %ecx, %ecx
cmpl 0x38(%rsp), %ecx
jle 0x342a9
movslq 0x48(%rsp), %rsi
movq %rdi, %rbx
callq 0x8cbc
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6b57(%rip), %rdi      # 0x3b1fb
leaq 0x6a6d(%rip), %rsi      # 0x3b118
leaq 0x6bda(%rip), %rcx      # 0x3b28c
movl $0x4a, %edx
callq 0x31b0
movq %rax, %r14
jmp 0x34711
jmp 0x346f2
jmp 0x346f2
jmp 0x346e9
jmp 0x346e9
jmp 0x346f2
jmp 0x346e9
jmp 0x346e9
jmp 0x346e9
jmp 0x346e9
jmp 0x346f2
jmp 0x346f2
jmp 0x346f2
jmp 0x346f2
jmp 0x346f2
jmp 0x346e9
jmp 0x346e9
jmp 0x346f2
jmp 0x346e9
jmp 0x346e9
jmp 0x346e9
movq %rax, %r14
jmp 0x3470c
jmp 0x346f2
jmp 0x346f2
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3470c
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x34725
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x32b0
movq %r14, %rdi
callq 0x34a0
nop