// File: /workspace/github_cpp_makefile_star2_O1/Kingsford-Group[P]ghost2/include/hungarian.hpp
// Function: kuhn_match(float**, unsigned long, unsigned long)
ssize_t** kuhn_match(cell** table, size_t n, size_t m)
{
    size_t i;
    
    /* not copying table since it will only be used once */
    
    kuhn_reduceRows(table, n, m);
    byte** marks = kuhn_mark(table, n, m);
    
    boolean* rowCovered = new boolean[n];
    boolean* colCovered = new boolean[m];
    for (i = 0; i < n; i++)
    {
        *(rowCovered + i) = false;
        *(colCovered + i) = false;
    }
    for (i = n; i < m; i++)
        *(colCovered + i) = false;
    
    size_t* altRow = new size_t[n*m];
    size_t* altCol = new size_t[n*m];
    
    ssize_t* rowPrimes = new ssize_t[n];
    ssize_t* colMarks  = new ssize_t[m];
    
    size_t* prime;
    
    for (;;)
    {
	if (kuhn_isDone(marks, colCovered, n, m))
	    break;
	
        for (;;)
	{
	    prime = kuhn_findPrime(table, marks, rowCovered, colCovered, n, m);
	    if (prime != null)
	    {
		kuhn_altMarks(marks, altRow, altCol, colMarks, rowPrimes, prime, n, m);
		for (i = 0; i < n; i++)
		{
		    *(rowCovered + i) = false;
		    *(colCovered + i) = false;
		}
		for (i = n; i < m; i++)
		    *(colCovered + i) = false;
		delete[](prime);
		break;
	    }
	    kuhn_addAndSubtract(table, rowCovered, colCovered, n, m);
	}
    }
    
    delete[](rowCovered);
    delete[](colCovered);
    delete[](altRow);
    delete[](altCol);
    delete[](rowPrimes);
    delete[](colMarks);
    
    ssize_t** rc = kuhn_assign(marks, n, m);
    
    for (i = 0; i < n; i++)
        delete[](*(marks + i));
    delete[](marks);
    
    return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x16c69
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x16cc7
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0xd040
movq %rax, %r13
movq %rbp, %rdi
callq 0xd040
movq %rax, %r12
testq %rbx, %rbx
je 0x16a07
movq %r13, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0xd2e0
movq %r12, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0xd2e0
movq %r12, 0x8(%rsp)
movq %r14, 0x60(%rsp)
movq %rbp, %rax
subq %rbx, %rax
movq %rax, 0x18(%rsp)
jbe 0x16a33
movq 0x8(%rsp), %rax
leaq (%rax,%rbx), %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0xd2e0
movq %rbp, %rax
imulq %rbx, %rax
movq %rax, %rcx
shrq $0x3d, %rcx
shlq $0x3, %rax
xorl %r12d, %r12d
negq %rcx
movl $0x0, %r14d
sbbq %r14, %r14
orq %rax, %r14
movq %r14, %rdi
callq 0xd040
movq %rax, 0x38(%rsp)
movq %r14, %rdi
callq 0xd040
movq %rax, 0x30(%rsp)
movq %rbx, %rax
shrq $0x3d, %rax
leaq (,%rbx,8), %rcx
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0xd040
movq %rax, 0x28(%rsp)
movq %rbp, %rax
shrq $0x3d, %rax
leaq (,%rbp,8), %rcx
negq %rax
sbbq %r12, %r12
orq %rcx, %r12
movq %r12, %rdi
callq 0xd040
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x16de6
testb %al, %al
jne 0x16be8
movq %r14, %rax
addq %rbx, %rax
movq %rax, 0x40(%rsp)
movq %rbp, 0x58(%rsp)
movq %rbx, 0x50(%rsp)
movq %r13, 0x48(%rsp)
movq 0x60(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0x16e31
movq %r14, %r12
testq %rax, %rax
jne 0x16b4d
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbx, %rcx
movq %rbp, %r8
callq 0x174be
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq %r13, %rdx
movq %r12, %rcx
movq %rbx, %r8
movq %rbp, %r9
callq 0x16e31
jmp 0x16b19
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r8
movq %rax, %r9
movq 0x58(%rsp), %rbp
pushq %rbp
movq 0x58(%rsp), %rbx
pushq %rbx
callq 0x17373
addq $0x10, %rsp
testq %rbx, %rbx
movq 0x48(%rsp), %r13
je 0x16ba7
movq %r13, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0xd2e0
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0xd2e0
cmpq %rbx, %rbp
jbe 0x16bbd
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0xd2e0
movq %r14, %rdi
callq 0xd710
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
callq 0x16de6
testb %al, %al
je 0x16aff
movq %r13, %rdi
callq 0xd710
movq %r14, %rdi
callq 0xd710
movq 0x38(%rsp), %rdi
callq 0xd710
movq 0x30(%rsp), %rdi
callq 0xd710
movq 0x28(%rsp), %rdi
callq 0xd710
movq 0x20(%rsp), %rdi
callq 0xd710
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x17562
movq %rax, %r14
testq %rbx, %rbx
je 0x16c4f
xorl %r15d, %r15d
movq (%r12,%r15,8), %rdi
testq %rdi, %rdi
je 0x16c47
callq 0xd710
incq %r15
cmpq %r15, %rbx
jne 0x16c39
movq %r12, %rdi
callq 0xd710
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq