// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
callq 0x147c2
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x14812
movq %rax, (%rsp)
movq %rbx, %rdi
callq 0xe040
movq %rax, %r13
movq %r15, %rdi
callq 0xe040
movq %rax, %rbp
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x145f7
movb %al, (%r13,%rcx)
movb %al, (%rbp,%rcx)
incq %rcx
jmp 0x145e4
movq %rbx, %rax
cmpq %r15, %rax
jae 0x14609
movb $0x0, (%rbp,%rax)
incq %rax
jmp 0x145fa
movq %r15, %rax
imulq %rbx, %rax
movq %rax, %rcx
shrq $0x3d, %rcx
shlq $0x3, %rax
negq %rcx
movl $0x0, %r14d
sbbq %r14, %r14
orq %rax, %r14
movq %r14, %rdi
callq 0xe040
movq %rax, 0x20(%rsp)
movq %r14, %rdi
callq 0xe040
movq %rax, 0x18(%rsp)
movq %rbx, %rax
shrq $0x3d, %rax
leaq (,%rbx,8), %rcx
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0xe040
movq %rax, 0x10(%rsp)
movq %r15, %rax
shrq $0x3d, %rax
leaq (,%r15,8), %rcx
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0xe040
movq %rax, 0x8(%rsp)
movq (%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x14920
testb %al, %al
je 0x146c1
jmp 0x1473e
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x14e59
movq %r12, %rdi
movq (%rsp), %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %rbx, %r8
movq %r15, %r9
callq 0x14963
testq %rax, %rax
je 0x146ad
movq %rax, %r14
movq (%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movq %rax, %r9
pushq %r15
pushq %rbx
callq 0x14d5c
addq $0x10, %rsp
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, %rbx
je 0x1471f
movb %cl, (%r13,%rax)
movb %cl, (%rbp,%rax)
incq %rax
jmp 0x1470c
movq %rbx, %rax
cmpq %r15, %rax
jae 0x14731
movb $0x0, (%rbp,%rax)
incq %rax
jmp 0x14722
movq %r14, %rdi
callq 0xe720
jmp 0x14692
movq %r13, %rdi
callq 0xe720
movq %rbp, %rdi
callq 0xe720
movq 0x20(%rsp), %rdi
callq 0xe720
movq 0x18(%rsp), %rdi
callq 0xe720
movq 0x10(%rsp), %rdi
callq 0xe720
movq 0x8(%rsp), %rdi
callq 0xe720
movq (%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x14ee8
movq %rax, %r14
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x147a7
movq (%rsp), %rax
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x147a2
callq 0xe720
incq %r15
jmp 0x1478b
movq (%rsp), %rdi
callq 0xe720
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq