// File: /workspace/github_cpp_makefile_star2_O3/Kingsford-Group[P]ghost2/include/hungarian.hpp
// Function: kuhn_findPrime(float**, signed char**, signed char*, signed char*, unsigned long, unsigned long)
size_t* kuhn_findPrime(cell** t, byte** marks, boolean* rowCovered, boolean* colCovered, size_t n, size_t m)
{
    size_t i, j;
    BitSet zeroes = new_BitSet(n * m);
    
    for (i = 0; i < n; i++)
        if (!*(rowCovered + i))
	    for (j = 0; j < m; j++)
	        if ((!*(colCovered + j)) && (*(*(t + i) + j) == 0))
		  BitSet_set(zeroes, i * m + j);
    
    ssize_t p;
    size_t row, col;
    boolean markInRow;
    
    for (;;)
    {
        p = BitSet_any(zeroes);
	if (p < 0)
        {
	    delete[](zeroes.limbs);
	    delete(zeroes.first);
	    delete[](zeroes.next);
	    delete[](zeroes.prev);
	    return null;
	}
	
	row = (size_t)p / m;
	col = (size_t)p % m;
	
	*(*(marks + row) + col) = PRIME;
	
	markInRow = false;
	for (j = 0; j < m; j++)
	    if (*(*(marks + row) + j) == MARKED)
	    {
		markInRow = true;
		col = j;
	    }
	
	if (markInRow)
	{
	    *(rowCovered + row) = true;
	    *(colCovered + col) = false;
	    
	    for (i = 0; i < n; i++)
	        if ((*(*(t + i) + col) == 0) && (row != i))
		{
		    if ((!*(rowCovered + i)) && (!*(colCovered + col)))
		        BitSet_set(zeroes, i * m + col);
		    else
		        BitSet_unset(zeroes, i * m + col);
		}
	    
	    for (j = 0; j < m; j++)
	        if ((*(*(t + row) + j) == 0) && (col != j))
		{
		    if ((!*(rowCovered + row)) && (!*(colCovered + j)))
		        BitSet_set(zeroes, row * m + j);
		    else
		        BitSet_unset(zeroes, row * m + j);
		}
	    
	    if ((!*(rowCovered + row)) && (!*(colCovered + col)))
	        BitSet_set(zeroes, row * m + col);
	    else
	        BitSet_unset(zeroes, row * m + col);
	}
	else
	{
	    size_t* rc = new size_t[2];
	    *rc = row;
	    *(rc + 1) = col;
	    delete[](zeroes.limbs);
	    delete(zeroes.first);
	    delete[](zeroes.next);
	    delete[](zeroes.prev);
	    return rc;
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %rbx
movq %r8, %r15
movq %rcx, %r13
movq %rdx, 0x20(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdi, %r12
movq %r9, %rsi
imulq %r8, %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x16304
movq (%r14), %r14
movq %r15, 0x30(%rsp)
testq %r15, %r15
movq %r12, 0x38(%rsp)
je 0x15c8c
movq 0x48(%rsp), %r11
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
xorl %edx, %edx
xorps %xmm0, %xmm0
xorl %esi, %esi
testq %rbx, %rbx
sete %dil
movq 0x20(%rsp), %r8
cmpb $0x0, (%r8,%rsi)
setne %r8b
orb %dil, %r8b
je 0x15c21
incq %rsi
addq %rbx, %rdx
cmpq 0x30(%rsp), %rsi
jne 0x15bf8
jmp 0x15c91
xorl %edi, %edi
cmpb $0x0, (%r13,%rdi)
je 0x15c35
incq %rdi
cmpq %rdi, %rbx
jne 0x15c23
jmp 0x15c12
movq (%r12,%rsi,8), %r8
movss (%r8,%rdi,4), %xmm1
ucomiss %xmm0, %xmm1
jne 0x15c2b
jp 0x15c2b
leaq (%rdx,%rdi), %r9
movq %r9, %r8
shrq $0x6, %r8
movq (%r14,%r8,8), %r10
movq %r11, %r15
movq %r10, %r11
btsq %r9, %r11
movq %r11, (%r14,%r8,8)
movq %r15, %r11
testq %r10, %r10
jne 0x15c2b
leaq 0x1(%r8), %r9
movq (%r11), %r10
movq %r9, (%rax,%r10,8)
movq $0x0, 0x8(%rax,%r8,8)
movq (%r11), %r10
movq %r10, 0x8(%rcx,%r8,8)
movq %r9, (%r11)
jmp 0x15c2b
movq 0x48(%rsp), %r11
movq %r11, 0x28(%rsp)
movq (%r11), %rbp
testq %rbp, %rbp
je 0x15ffd
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x1, %rbx
movq %rbx, %r15
adcq $0x0, %r15
movq -0x8(%r14,%rbp,8), %rax
decq %rbp
movq %rax, %rdi
negq %rdi
andq %rax, %rdi
callq 0x164b1
shlq $0x6, %rbp
addq %rax, %rbp
js 0x16002
movq %rbp, %rax
xorl %edx, %edx
divq %rbx
movq %rdx, %rbp
xorl %ecx, %ecx
movq %rax, 0x18(%rsp)
movq 0x60(%rsp), %rsi
movq (%rsi,%rax,8), %rdx
movb $0x2, (%rdx,%rbp)
movq (%rsi,%rax,8), %rdx
xorl %esi, %esi
movl $0x1, %edi
cmpb $0x1, (%rdx,%rsi)
cmoveq %rsi, %rbp
movzbl %cl, %ecx
cmovel %edi, %ecx
incq %rsi
cmpq %rsi, %r15
jne 0x15d0e
testb %cl, %cl
movq 0x30(%rsp), %r11
je 0x16032
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
movb $0x1, (%rcx,%rdx)
movb $0x0, (%r13,%rbp)
testq %r11, %r11
movq 0x28(%rsp), %r10
movq 0x10(%rsp), %r9
xorps %xmm1, %xmm1
je 0x15e48
movq %rbp, %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x15e14
movq 0x38(%rsp), %rsi
movq (%rsi,%rdx,8), %rsi
movss (%rsi,%rbp,4), %xmm0
ucomiss %xmm1, %xmm0
jne 0x15e14
jp 0x15e14
movq 0x20(%rsp), %rsi
cmpb $0x0, (%rsi,%rdx)
jne 0x15d99
cmpb $0x0, (%r13,%rbp)
je 0x15df9
movq %rcx, %rsi
movq $-0x2, %rdi
rolq %cl, %rdi
shrq $0x6, %rsi
movq (%r14,%rsi,8), %r8
andq %r8, %rdi
movq %rdi, (%r14,%rsi,8)
setne %dil
testq %r8, %r8
sete %r8b
orb %dil, %r8b
jne 0x15e14
leaq 0x1(%rsi), %r8
movq 0x10(%rsp), %rdi
movq 0x8(%rdi,%rsi,8), %r9
movq 0x8(%rsp), %r12
movq 0x8(%r12,%rsi,8), %rdi
movq 0x10(%rsp), %rsi
movq %r9, (%rsi,%rdi,8)
movq %rdi, (%r12,%r9,8)
movq 0x10(%rsp), %r9
cmpq %r8, (%r10)
jne 0x15e14
movq %rdi, (%r10)
jmp 0x15e14
movq %rcx, %rsi
shrq $0x6, %rsi
movq (%r14,%rsi,8), %rdi
movq %rdi, %r8
btsq %rcx, %r8
movq %r8, (%r14,%rsi,8)
testq %rdi, %rdi
je 0x15e25
incq %rdx
addq %rbx, %rcx
cmpq %rdx, %r11
jne 0x15d60
jmp 0x15e48
leaq 0x1(%rsi), %rdi
movq (%r10), %r8
movq %rdi, (%r9,%r8,8)
movq $0x0, 0x8(%r9,%rsi,8)
movq (%r10), %r8
movq 0x8(%rsp), %r12
movq %r8, 0x8(%r12,%rsi,8)
jmp 0x15df4
movq 0x38(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
imulq %rbx, %rax
xorl %esi, %esi
movq 0x20(%rsp), %r11
movss (%rdx,%rsi,4), %xmm0
ucomiss %xmm1, %xmm0
jne 0x15f0a
jp 0x15f0a
cmpq %rsi, %rbp
je 0x15f0a
movq 0x18(%rsp), %rcx
cmpb $0x0, (%r11,%rcx)
jne 0x15e92
cmpb $0x0, (%r13,%rsi)
je 0x15ee6
leaq (%rsi,%rax), %rcx
movq %rcx, %rdi
movq $-0x2, %r8
rolq %cl, %r8
shrq $0x6, %rdi
movq (%r14,%rdi,8), %rcx
andq %rcx, %r8
movq %r8, (%r14,%rdi,8)
setne %r8b
testq %rcx, %rcx
sete %cl
orb %r8b, %cl
jne 0x15f0a
leaq 0x1(%rdi), %rcx
movq 0x8(%r9,%rdi,8), %r8
movq 0x8(%rsp), %r12
movq 0x8(%r12,%rdi,8), %rdi
movq %r8, (%r9,%rdi,8)
movq %rdi, (%r12,%r8,8)
cmpq %rcx, (%r10)
jne 0x15f0a
movq %rdi, (%r10)
jmp 0x15f0a
leaq (%rsi,%rax), %rdi
movq %rdi, %rcx
shrq $0x6, %rcx
movq (%r14,%rcx,8), %r8
movq %r8, %r9
btsq %rdi, %r9
movq %r9, (%r14,%rcx,8)
movq 0x10(%rsp), %r9
testq %r8, %r8
je 0x15f18
incq %rsi
cmpq %rsi, %r15
jne 0x15e61
jmp 0x15f3b
leaq 0x1(%rcx), %rdi
movq (%r10), %r8
movq %rdi, (%r9,%r8,8)
movq $0x0, 0x8(%r9,%rcx,8)
movq (%r10), %r8
movq 0x8(%rsp), %r12
movq %r8, 0x8(%r12,%rcx,8)
jmp 0x15ee1
movq 0x18(%rsp), %rcx
cmpb $0x0, (%r11,%rcx)
jne 0x15f4f
cmpb $0x0, (%r13,%rbp)
je 0x15fb6
addq %rax, %rbp
movq %rbp, %rax
movq $-0x2, %rdx
movl %ebp, %ecx
rolq %cl, %rdx
shrq $0x6, %rax
movq (%r14,%rax,8), %rcx
andq %rcx, %rdx
movq %rdx, (%r14,%rax,8)
sete %dl
testq %rcx, %rcx
setne %cl
testb %dl, %cl
je 0x15fa8
leaq 0x1(%rax), %rcx
movq 0x8(%r9,%rax,8), %rdx
movq 0x8(%rsp), %rsi
movq 0x8(%rsi,%rax,8), %rax
movq %rdx, (%r9,%rax,8)
movq %rax, (%rsi,%rdx,8)
movq (%r10), %rbp
cmpq %rcx, %rbp
jne 0x15fab
movq %rax, (%r10)
movq %rax, %rbp
jmp 0x15fab
movq (%r10), %rbp
testq %rbp, %rbp
jne 0x15cc1
jmp 0x16002
addq %rax, %rbp
movq %rbp, %rax
shrq $0x6, %rax
movq (%r14,%rax,8), %rcx
movq %rcx, %rdx
btsq %rbp, %rdx
movq %rdx, (%r14,%rax,8)
movq (%r10), %rbp
testq %rcx, %rcx
jne 0x15fab
leaq 0x1(%rax), %rcx
movq %rcx, (%r9,%rbp,8)
movq $0x0, 0x8(%r9,%rax,8)
movq (%r10), %rdx
movq 0x8(%rsp), %rsi
movq %rdx, 0x8(%rsi,%rax,8)
movq %rcx, (%r10)
movq %rcx, %rbp
jmp 0x15fab
testq %r14, %r14
je 0x1600a
movq %r14, %rdi
callq 0xc710
movl $0x8, %esi
movq 0x28(%rsp), %rdi
callq 0xc550
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x16028
callq 0xc710
movq 0x50(%rsp), %rdi
xorl %r15d, %r15d
jmp 0x1607b
movl $0x10, %edi
callq 0xc040
movq %rax, %r15
movq 0x18(%rsp), %rax
movq %rax, (%r15)
movq %rbp, 0x8(%r15)
testq %r14, %r14
je 0x16058
movq %r14, %rdi
callq 0xc710
movl $0x8, %esi
movq 0x28(%rsp), %rdi
callq 0xc550
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x16076
callq 0xc710
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x16085
callq 0xc710
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq