// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %r9, %r13
movq %rcx, %rbp
movq %rdx, 0x40(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdi, %r15
movq %r9, %rsi
movq %r8, 0x58(%rsp)
imulq %r8, %rsi
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
callq 0x14f6c
movq (%rbx), %r14
movq 0x8(%rbx), %rax
movq %rax, 0x28(%rsp)
movq 0x10(%rbx), %r12
xorl %eax, %eax
movq 0x18(%rbx), %rbx
xorps %xmm0, %xmm0
xorl %ecx, %ecx
cmpq 0x58(%rsp), %rcx
je 0x14a3d
movq 0x40(%rsp), %rdx
cmpb $0x0, (%rdx,%rcx)
je 0x149d8
incq %rcx
addq %r13, %rax
jmp 0x149be
xorl %edx, %edx
cmpq %rdx, %r13
je 0x149d0
cmpb $0x0, (%rbp,%rdx)
je 0x149eb
incq %rdx
jmp 0x149da
movq (%r15,%rcx,8), %rsi
movss (%rsi,%rdx,4), %xmm1
ucomiss %xmm0, %xmm1
jne 0x149e6
jp 0x149e6
leaq (%rax,%rdx), %rdi
movq %rdi, %rsi
shrq $0x6, %rsi
movq (%r14,%rsi,8), %r8
movq %r8, %r9
btsq %rdi, %r9
movq %r9, (%r14,%rsi,8)
testq %r8, %r8
jne 0x149e6
leaq 0x1(%rsi), %rdi
movq 0x28(%rsp), %r9
movq (%r9), %r8
movq %rdi, (%r12,%r8,8)
andq $0x0, 0x8(%r12,%rsi,8)
movq (%r9), %r8
movq %r8, 0x8(%rbx,%rsi,8)
movq %rdi, (%r9)
jmp 0x149e6
movq %r12, 0x48(%rsp)
movq %rbx, 0x30(%rsp)
movq %r14, 0x38(%rsp)
movq %rbp, 0x50(%rsp)
movups 0x60(%rsp), %xmm0
movups 0x70(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x15054
testq %rax, %rax
js 0x14cd1
xorl %edx, %edx
divq %r13
movq %rax, %rbp
movq %rdx, %rbx
xorl %eax, %eax
movq 0x80(%rsp), %rdx
movq (%rdx,%rbp,8), %rcx
movb $0x2, (%rcx,%rbx)
movq (%rdx,%rbp,8), %rcx
xorl %edx, %edx
pushq $0x1
popq %rsi
cmpq %rax, %r13
je 0x14ab0
cmpb $0x1, (%rcx,%rax)
cmoveq %rax, %rbx
movzbl %dl, %edx
cmovel %esi, %edx
incq %rax
jmp 0x14a98
testb %dl, %dl
je 0x14cfd
movq 0x40(%rsp), %rax
movb $0x1, (%rax,%rbp)
movq 0x50(%rsp), %rax
movb $0x0, (%rax,%rbx)
movq %rbx, %r12
xorl %r14d, %r14d
cmpq %r14, 0x58(%rsp)
je 0x14b7b
cmpq %r14, %rbp
je 0x14b26
movq (%r15,%r14,8), %rax
movss (%rax,%rbx,4), %xmm0
ucomiss 0x2b700(%rip), %xmm0    # 0x401f0
jne 0x14b26
jp 0x14b26
movq 0x40(%rsp), %rax
cmpb $0x0, (%rax,%r14)
jne 0x14b0b
movq 0x50(%rsp), %rax
cmpb $0x0, (%rax,%rbx)
je 0x14b2e
movups 0x60(%rsp), %xmm0
movups 0x70(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x15091
incq %r14
addq %r13, %r12
jmp 0x14ad0
movq %r12, %rax
shrq $0x6, %rax
movq 0x38(%rsp), %rsi
movq (%rsi,%rax,8), %rcx
movq %rcx, %rdx
btsq %r12, %rdx
movq %rdx, (%rsi,%rax,8)
testq %rcx, %rcx
jne 0x14b26
leaq 0x1(%rax), %rcx
movq 0x28(%rsp), %rdi
movq (%rdi), %rdx
movq 0x48(%rsp), %rsi
movq %rcx, (%rsi,%rdx,8)
andq $0x0, 0x8(%rsi,%rax,8)
movq (%rdi), %rdx
movq 0x30(%rsp), %rsi
movq %rdx, 0x8(%rsi,%rax,8)
movq %rcx, (%rdi)
jmp 0x14b26
movq %rbp, %r12
imulq %r13, %r12
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x14c31
movq (%r15,%rbp,8), %rax
movss (%rax,%r14,4), %xmm0
ucomiss 0x2b651(%rip), %xmm0    # 0x401f0
jne 0x14bdb
jp 0x14bdb
cmpq %r14, %rbx
je 0x14bdb
movq 0x40(%rsp), %rax
cmpb $0x0, (%rax,%rbp)
jne 0x14bbf
movq 0x50(%rsp), %rax
cmpb $0x0, (%rax,%r14)
je 0x14be0
leaq (%r14,%r12), %rdi
movups 0x60(%rsp), %xmm0
movups 0x70(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x15091
incq %r14
jmp 0x14b85
leaq (%r14,%r12), %rcx
movq %rcx, %rax
shrq $0x6, %rax
movq 0x38(%rsp), %rdi
movq (%rdi,%rax,8), %rdx
movq %rdx, %rsi
btsq %rcx, %rsi
movq %rsi, (%rdi,%rax,8)
testq %rdx, %rdx
jne 0x14bdb
leaq 0x1(%rax), %rcx
movq 0x28(%rsp), %rdi
movq (%rdi), %rdx
movq 0x48(%rsp), %rsi
movq %rcx, (%rsi,%rdx,8)
andq $0x0, 0x8(%rsi,%rax,8)
movq (%rdi), %rdx
movq 0x30(%rsp), %rsi
movq %rdx, 0x8(%rsi,%rax,8)
movq %rcx, (%rdi)
jmp 0x14bdb
movq 0x40(%rsp), %rax
cmpb $0x0, (%rax,%rbp)
movq 0x50(%rsp), %rbp
jne 0x14c48
cmpb $0x0, (%rbp,%rbx)
je 0x14c7a
addq %r12, %rbx
movups 0x60(%rsp), %xmm0
movups 0x70(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x15091
movq 0x48(%rsp), %r12
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r14
jmp 0x14a51
addq %r12, %rbx
movq %rbx, %rax
shrq $0x6, %rax
movq 0x38(%rsp), %r14
movq (%r14,%rax,8), %rcx
movq %rcx, %rdx
btsq %rbx, %rdx
movq %rdx, (%r14,%rax,8)
testq %rcx, %rcx
movq 0x48(%rsp), %r12
movq 0x30(%rsp), %rbx
jne 0x14a51
leaq 0x1(%rax), %rcx
movq 0x28(%rsp), %rsi
movq (%rsi), %rdx
movq %rcx, (%r12,%rdx,8)
andq $0x0, 0x8(%r12,%rax,8)
movq (%rsi), %rdx
movq %rdx, 0x8(%rbx,%rax,8)
movq %rcx, (%rsi)
jmp 0x14a51
testq %r14, %r14
je 0x14cde
movq %r14, %rdi
callq 0xe720
pushq $0x8
popq %rsi
movq 0x28(%rsp), %rdi
callq 0xe590
testq %rbx, %rbx
je 0x14cf8
movq %rbx, %rdi
callq 0xe720
xorl %r14d, %r14d
jmp 0x14d3a
pushq $0x10
popq %rdi
callq 0xe040
movq %rax, %r14
movq %rbp, (%rax)
movq %rbx, 0x8(%rax)
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x14d1e
callq 0xe720
pushq $0x8
popq %rsi
movq 0x28(%rsp), %rdi
callq 0xe590
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x14d3a
callq 0xe720
testq %r12, %r12
je 0x14d47
movq %r12, %rdi
callq 0xe720
movq %r14, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq