// File: /workspace/github_cpp_makefile_star2_O1/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
cmpl %r13d, %r12d
jge 0x3b5b
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x57f6
movq (%r15), %rax
movq %rax, (%r14)
leaq 0x8(%r14), %rdi
leaq 0x48(%rsp), %r15
movq %r15, %rsi
callq 0x6746
movq (%r15), %rdi
testq %rdi, %rdi
je 0x3b5b
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movl (%r14), %esi
movb 0x4(%r14), %cl
movl $0x1, %ebp
movl $0x1, %edx
shll %cl, %edx
leaq 0x40(%rsp), %rdi
movl $0x80000000, %ecx       # imm = 0x80000000
callq 0x5864
movl (%r14), %esi
movb 0x4(%r14), %cl
shll %cl, %ebp
leaq 0x20(%rsp), %rdi
movl %ebp, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x5864
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 0x39d3
movl %eax, %ebp
movslq (%r14), %rsi
leaq 0x8(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x58ca
movl 0x4(%r14), %eax
cmpl $0x0, (%r14)
setg %cl
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x3c53
movl %eax, %ecx
movq $-0x1, %rax
shlq %cl, %rax
notq %rax
movq 0x28(%rsp), %rdx
movq (%rbx), %rsi
xorl %edi, %edi
movl 0x24(%rsp), %ecx
imull %edi, %ecx
addl %eax, %ecx
movslq %ecx, %rcx
movl (%rdx,%rcx,4), %ecx
movl %ecx, (%rsi,%rdi,4)
movl 0x24(%rsp), %ecx
imull %edi, %ecx
addl %eax, %ecx
movslq %ecx, %rcx
movl (%rdx,%rcx,4), %ecx
movl $0x1, %r8d
shlq %cl, %r8
cmpl $-0x1, %ecx
movl $0x0, %ecx
cmovneq %r8, %rcx
incq %rdi
movslq (%r14), %r8
cmpq %r8, %rdi
jge 0x3c53
movq %rcx, %r8
xorq %rax, %r8
cmpq %rax, %rcx
movq %r8, %rax
jne 0x3c04
cmpl %r13d, %r12d
jge 0x3ce3
movslq 0x4(%r14), %rsi
leaq 0x64(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rcx
callq 0x58fe
cmpl $0x0, (%r14)
jle 0x3ca2
movq (%rbx), %rax
movq 0x8(%rsp), %rcx
xorl %edx, %edx
movslq (%rax,%rdx,4), %rsi
cmpq $-0x1, %rsi
je 0x3c97
movl %edx, (%rcx,%rsi,4)
incq %rdx
movslq (%r14), %rsi
cmpq %rsi, %rdx
jl 0x3c8a
movq (%rbx), %rdi
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rsi
movq 0x8(%rsp), %rcx
movq %rcx, (%rbx)
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rbx)
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rbx)
movq %rdi, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
testq %rdi, %rdi
je 0x3ce3
subq %rdi, %rsi
callq 0x3230
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3cfa
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3d11
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 0x3d24
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3d43
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
jmp 0x3d43
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3d5a
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x33e0