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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, 0x2c(%rsp)
movq 0x8(%rdx), %r15
subq (%rdx), %r15
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cmpq %rax, %r15
jne 0x2a843
movq %r8, %r14
movq %rdx, %r13
movq %rcx, %r12
shrq $0x2, %r15
leal (%r15,%r15), %eax
movl %eax, 0x50(%rsp)
movslq %eax, %rsi
leaq 0x30(%rsp), %rbp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x68(%rsp)
movq %rbp, %rdx
callq 0x6852
xorl %ebx, %ebx
testl %r15d, %r15d
movl $0x0, %eax
cmovgl %r15d, %eax
movq %rax, 0x48(%rsp)
leaq (,%rax,4), %rax
movq %rax, 0x20(%rsp)
cmpq %rbx, 0x20(%rsp)
je 0x2a52c
movl 0x18(%r14), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x18(%r14)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl %ecx, (%rax,%rbx,2)
movl 0x18(%r14), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x18(%r14)
movl %ecx, 0x4(%rax,%rbx,2)
cmpb $0x0, 0x2c(%rsp)
je 0x2a43c
movq (%r13), %rcx
xorl %edx, %edx
subl (%rcx,%rbx), %edx
movl %edx, 0xc(%rsp)
movq (%r12), %rcx
xorl %edx, %edx
subl (%rcx,%rbx), %edx
movl %edx, 0x10(%rsp)
movl 0x4(%rax,%rbx,2), %eax
movl %eax, 0x14(%rsp)
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x3
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1cb40
movq %rbp, %rdi
callq 0x7512
movq (%r13), %rax
xorl %ecx, %ecx
subl (%rax,%rbx), %ecx
movl %ecx, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl (%rax,%rbx,2), %eax
movl %eax, 0x10(%rsp)
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1cb40
movq %rbp, %rdi
callq 0x7512
movq (%r12), %rax
xorl %ecx, %ecx
subl (%rax,%rbx), %ecx
movl %ecx, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl (%rax,%rbx,2), %eax
movl %eax, 0x10(%rsp)
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1cb40
movq %rbp, %rdi
callq 0x7512
cmpb $0x0, 0xb0(%rsp)
je 0x2a523
movq (%r13), %rax
movl (%rax,%rbx), %eax
movl %eax, 0xc(%rsp)
movq (%r12), %rax
movl (%rax,%rbx), %eax
movl %eax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl (%rax,%rbx,2), %ecx
movl %ecx, 0x14(%rsp)
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x3
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1cb40
movq %rbp, %rdi
callq 0x7512
movq (%r13), %rax
movl (%rax,%rbx), %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%rbx,2), %ecx
movl %ecx, 0x10(%rsp)
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1cb40
movq %rbp, %rdi
callq 0x7512
movq (%r12), %rax
movl (%rax,%rbx), %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
subl 0x4(%rax,%rbx,2), %ecx
movl %ecx, 0x10(%rsp)
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1cb40
movq %rbp, %rdi
callq 0x7512
addq $0x4, %rbx
jmp 0x2a32f
movq 0x18(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
pushq $0x1
popq %rdx
movq 0x48(%rsp), %r9
cmpq %r9, %rcx
je 0x2a57f
xorl %esi, %esi
movl %edx, %edi
cmpl %r15d, %edi
jge 0x2a55d
xorl %r8d, %r8d
testl %ecx, %edi
setne %r8b
leal (%r8,%rsi,2), %esi
addl %edi, %edi
jmp 0x2a547
movslq %esi, %rdi
cmpq %rdi, %rcx
jge 0x2a57a
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 0x2a53e
pushq $0x4
popq %rcx
leaq 0x30(%rsp), %r13
cmpl 0x50(%rsp), %ecx
jg 0x2a82f
movl %ecx, %eax
sarl %eax
cltq
movl %ecx, 0x54(%rsp)
movslq %ecx, %rdi
movq %rax, 0x48(%rsp)
leaq (,%rax,4), %rax
movq %rax, 0x20(%rsp)
leaq (,%rdi,4), %rax
movq %rax, 0x58(%rsp)
xorl %ebx, %ebx
xorl %r8d, %r8d
movq %rdi, 0x60(%rsp)
cmpq 0x68(%rsp), %r8
jge 0x2a824
movq %r8, 0x70(%rsp)
pushq $0x1
popq %r15
xorl %ebp, %ebp
pushq $-0x1
popq %r12
cmpq 0x48(%rsp), %r15
jge 0x2a7de
cmpb $0x0, 0x2c(%rsp)
je 0x2a6de
movq 0x18(%rsp), %rax
movq (%rax), %rax
leaq (%rax,%rbx), %rcx
xorl %edx, %edx
subl 0x4(%rcx,%rbp,2), %edx
movl %edx, 0xc(%rsp)
addq 0x20(%rsp), %rax
xorl %ecx, %ecx
subl (%rax,%rbp,2), %ecx
movl %ecx, 0x10(%rsp)
movl 0x18(%r14), %eax
addl %ebp, %eax
incl %eax
movl %eax, 0x14(%rsp)
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x3
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movq 0x18(%rsp), %rax
movq (%rax), %rax
addq %rbx, %rax
xorl %ecx, %ecx
subl 0x4(%rax,%rbp,2), %ecx
movl %ecx, 0xc(%rsp)
movl 0x18(%r14), %eax
addl %ebp, %eax
movl %eax, 0x10(%rsp)
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movq 0x18(%rsp), %rax
movq (%rax), %rax
addq 0x20(%rsp), %rax
xorl %ecx, %ecx
subl (%rax,%rbp,2), %ecx
movl %ecx, 0xc(%rsp)
movl 0x18(%r14), %eax
addl %ebp, %eax
movl %eax, 0x10(%rsp)
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
cmpb $0x0, 0xb0(%rsp)
je 0x2a7ce
movq 0x18(%rsp), %rax
movq (%rax), %rax
leaq (%rax,%rbx), %rcx
movl 0x4(%rcx,%rbp,2), %ecx
movl %ecx, 0xc(%rsp)
addq 0x20(%rsp), %rax
movl (%rax,%rbp,2), %eax
movl %eax, 0x10(%rsp)
movl %r12d, %eax
subl 0x18(%r14), %eax
incl %eax
movl %eax, 0x14(%rsp)
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x3
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movq 0x18(%rsp), %rax
movq (%rax), %rax
addq %rbx, %rax
movl 0x4(%rax,%rbp,2), %eax
movl %eax, 0xc(%rsp)
movl %r12d, %eax
subl 0x18(%r14), %eax
movl %eax, 0x10(%rsp)
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
movq 0x18(%rsp), %rax
movq (%rax), %rax
addq 0x20(%rsp), %rax
movl (%rax,%rbp,2), %eax
movl %eax, 0xc(%rsp)
movl %r12d, %eax
subl 0x18(%r14), %eax
movl %eax, 0x10(%rsp)
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0xb(%rsp), %rcx
callq 0x18af6
movq %r14, %rdi
movq %r13, %rsi
callq 0x1cb40
movq %r13, %rdi
callq 0x7512
addl $-0x2, %r12d
addq $0x2, %rbp
incq %r15
jmp 0x2a5e1
movq 0x18(%rsp), %rax
movq (%rax), %rax
addq %rbx, %rax
pushq $0x2
popq %rcx
movq 0x60(%rsp), %rdi
movq 0x70(%rsp), %r8
cmpq %rdi, %rcx
jge 0x2a80f
movl 0x18(%r14), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x18(%r14)
movl %edx, -0x4(%rax,%rcx,4)
incq %rcx
jmp 0x2a7f6
addq %rdi, %r8
movq 0x58(%rsp), %rax
addq %rax, 0x20(%rsp)
addq %rax, %rbx
jmp 0x2a5c7
movl 0x54(%rsp), %ecx
addl %ecx, %ecx
jmp 0x2a587
movq 0x18(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6a29(%rip), %rdi      # 0x31273
leaq 0x693f(%rip), %rsi      # 0x31190
leaq 0x6a30(%rip), %rcx      # 0x31288
pushq $0x19
popq %rdx
callq 0x31c0
jmp 0x2a89b
jmp 0x2a89b
jmp 0x2a89b
jmp 0x2a89b
jmp 0x2a89b
jmp 0x2a89b
jmp 0x2a88c
jmp 0x2a88c
jmp 0x2a88c
jmp 0x2a88c
jmp 0x2a88c
jmp 0x2a88c
jmp 0x2a89b
jmp 0x2a89b
jmp 0x2a89b
jmp 0x2a88c
jmp 0x2a89b
jmp 0x2a88c
jmp 0x2a88c
jmp 0x2a88c
jmp 0x2a88c
jmp 0x2a89b
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x7512
jmp 0x2a89e
movq %rax, %r14
movq 0x18(%rsp), %rdi
callq 0x7512
movq %r14, %rdi
callq 0x3490