// File: /workspace/github_cpp_makefile_star2_O3/canzarlab[P]Trajan/src/match.cpp
// Function: bipartite_aux(array2d&, std::vector<int, std::allocator<int>>&)
int bipartite_aux(array2d& D, vector<int>& sol)
{
    // complexity of bipartite is O(n2^m) so make sure m < n
    bool transposed = false;
    if (D.n < D.m)
    {
        D = D.transpose();
        transposed = true;
    }

    // dp table for the matching
    array2d bdp(D.n, 1 << D.m), pdp(D.n, 1 << D.m, -1);

    // compute the matching
    int weight = bipartite(D, bdp, pdp, 0, fm(D.m));

    // store the matching
    // note: -1 is unmatched
    sol.resize(D.n, -1);
    mask m = fm(D.m);
    for (int k = 0; k < D.n && m > 0; ++k)
    {
        sol[k] = pdp(k, m);
        if (pdp(k, m) != -1)
            m ^= in(pdp(k, m));
    }

    // transpose the matching back
    if (transposed)
    {
        vector<int> zol(D.m, -1);
        for (int i = 0; i < D.n; ++i)
            if (sol[i] != -1)
                zol[sol[i]] = i;
        swap(sol, zol);
    }
    return weight;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl (%rdi), %r12d
movl 0x4(%rdi), %r13d
movl %r13d, %ecx
movl %r12d, %esi
cmpl %r13d, %r12d
jge 0x3b8e
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x58f6
movq (%r15), %rax
movq %rax, (%r14)
movq 0x8(%r14), %rdi
movq 0x18(%r14), %rsi
movups 0x8(%r15), %xmm0
movups %xmm0, 0x8(%r14)
movq 0x18(%r15), %rax
movq %rax, 0x18(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r15)
movq $0x0, 0x18(%r15)
testq %rdi, %rdi
je 0x3b87
subq %rdi, %rsi
callq 0x3230
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3b87
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movl (%r14), %esi
movl 0x4(%r14), %ecx
movl $0x1, %ebp
movl $0x1, %edx
shll %cl, %edx
leaq 0x40(%rsp), %rdi
movl $0x80000000, %ecx       # imm = 0x80000000
callq 0x5968
movl (%r14), %esi
movb 0x4(%r14), %cl
shll %cl, %ebp
leaq 0x20(%rsp), %rdi
movl %ebp, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x5968
movb 0x4(%r14), %cl
movq $-0x1, %r8
shlq %cl, %r8
notq %r8
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x39f0
movl %eax, %ebp
movslq (%r14), %rsi
leaq 0x8(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x59ce
movl 0x4(%r14), %eax
cmpl $0x0, (%r14)
setg %cl
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x3c86
movl %eax, %ecx
movq $-0x1, %rax
shlq %cl, %rax
notq %rax
movq 0x28(%rsp), %rdx
movq (%rbx), %rsi
movl 0x24(%rsp), %r8d
xorl %edi, %edi
imull %edi, %r8d
addl %eax, %r8d
movslq %r8d, %rcx
movl (%rdx,%rcx,4), %ecx
movl %ecx, (%rsi,%rdi,4)
movl 0x24(%rsp), %r8d
movl %r8d, %ecx
imull %edi, %ecx
addl %eax, %ecx
movslq %ecx, %rcx
movl (%rdx,%rcx,4), %ecx
movl $0x1, %r9d
shlq %cl, %r9
cmpl $-0x1, %ecx
movl $0x0, %ecx
cmovneq %r9, %rcx
incq %rdi
movslq (%r14), %r9
cmpq %r9, %rdi
jge 0x3c86
movq %rcx, %r9
xorq %rax, %r9
cmpq %rax, %rcx
movq %r9, %rax
jne 0x3c35
cmpl %r13d, %r12d
jge 0x3d05
movslq 0x4(%r14), %rsi
leaq 0x64(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x5a02
movl (%r14), %ecx
movq (%rbx), %rdi
movq 0x8(%rsp), %rax
testl %ecx, %ecx
jle 0x3cd5
xorl %edx, %edx
movslq (%rdi,%rdx,4), %rsi
cmpq $-0x1, %rsi
je 0x3cca
movl %edx, (%rax,%rsi,4)
movl (%r14), %ecx
incq %rdx
movslq %ecx, %rsi
cmpq %rsi, %rdx
jl 0x3cba
movq 0x8(%rbx), %rcx
movq 0x10(%rbx), %rsi
movq %rax, (%rbx)
movups 0x10(%rsp), %xmm0
movups %xmm0, 0x8(%rbx)
movq %rdi, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
testq %rdi, %rdi
je 0x3d05
subq %rdi, %rsi
callq 0x3230
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3d1c
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3d33
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3d46
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3d65
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
jmp 0x3d65
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3d7c
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x33e0