// File: /workspace/github_cpp_makefile_star2_O3/Kingsford-Group[P]ghost2/include/hungarian.hpp
// Function: kuhn_altMarks(signed char**, unsigned long*, unsigned long*, long*, long*, unsigned long*, unsigned long, unsigned long)
void kuhn_altMarks(byte** marks, size_t* altRow, size_t* altCol, ssize_t* colMarks, ssize_t* rowPrimes, size_t* prime, size_t n, size_t m)
{
    size_t index = 0, i, j;
    *altRow = *prime;
    *altCol = *(prime + 1);
    
    for (i = 0; i < n; i++)
    {
        *(rowPrimes + i) = -1;
        *(colMarks + i) = -1;
    }
    for (i = n; i < m; i++)
        *(colMarks + i) = -1;
    
    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
	    if (*(*(marks + i) + j) == MARKED)
	        *(colMarks + j) = (ssize_t)i;
	    else if (*(*(marks + i) + j) == PRIME)
	        *(rowPrimes + i) = (ssize_t)j;
    
    ssize_t row, col;
    for (;;)
    {
        row = *(colMarks + *(altCol + index));
	if (row < 0)
	    break;
	
	index++;
	*(altRow + index) = (size_t)row;
	*(altCol + index) = *(altCol + index - 1);
	
	col = *(rowPrimes + *(altRow + index));
	
	index++;
	*(altRow + index) = *(altRow + index - 1);
	*(altCol + index) = (size_t)col;
    }
    
    byte* markx;
    for (i = 0; i <= index; i++)
    {
        markx = *(marks + *(altRow + i)) + *(altCol + i);
        if (*markx == MARKED)
	    *markx = UNMARKED;
	else
	    *markx = MARKED;
    }
    
    byte* marksi;
    for (i = 0; i < n; i++)
    {
        marksi = *(marks + i);
        for (j = 0; j < m; j++)
	    if (*(marksi + j) == PRIME)
	        *(marksi + j) = UNMARKED;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r12
movq %rcx, %r13
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x48(%rsp), %rbp
movq 0x40(%rsp), %rdi
movq (%r9), %rax
movq %rax, (%rsi)
movq 0x8(%r9), %rax
movq %rax, (%rdx)
testq %rdi, %rdi
je 0x160e7
xorl %eax, %eax
movq $-0x1, %rcx
movq %rcx, (%r12,%rax,8)
movq %rcx, (%r13,%rax,8)
incq %rax
cmpq %rax, %rdi
jne 0x160d6
movq %rbp, %rdx
subq %rdi, %rdx
jbe 0x16112
movq 0x40(%rsp), %rax
leaq (,%rax,8), %rdi
addq %r13, %rdi
shlq $0x3, %rdx
movl $0xff, %esi
callq 0xc2e0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1614d
xorl %eax, %eax
testq %rbp, %rbp
je 0x16145
movq (%rbx,%rax,8), %rcx
xorl %edx, %edx
movzbl (%rcx,%rdx), %esi
cmpl $0x2, %esi
je 0x16139
cmpl $0x1, %esi
jne 0x1613d
movq %rax, (%r13,%rdx,8)
jmp 0x1613d
movq %rdx, (%r12,%rax,8)
incq %rdx
cmpq %rdx, %rbp
jne 0x16124
incq %rax
cmpq %rdi, %rax
jne 0x16119
movq (%r14), %rax
movq (%r13,%rax,8), %rcx
movl $0x1, %eax
testq %rcx, %rcx
js 0x16189
movq %rcx, (%r15,%rax,8)
movq -0x8(%r14,%rax,8), %rcx
movq %rcx, (%r14,%rax,8)
movq (%r15,%rax,8), %rcx
movq (%r12,%rcx,8), %rdx
movq %rcx, 0x8(%r15,%rax,8)
movq %rdx, 0x8(%r14,%rax,8)
movq (%r13,%rdx,8), %rcx
addq $0x2, %rax
jmp 0x1615a
xorl %ecx, %ecx
movq (%r15,%rcx,8), %rdx
movq (%rbx,%rdx,8), %rdx
movq (%r14,%rcx,8), %rsi
cmpb $0x1, (%rdx,%rsi)
setne (%rdx,%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0x1618b
testq %rdi, %rdi
je 0x161d3
xorl %eax, %eax
testq %rbp, %rbp
je 0x161cb
movq (%rbx,%rax,8), %rcx
xorl %edx, %edx
cmpb $0x2, (%rcx,%rdx)
jne 0x161c3
movb $0x0, (%rcx,%rdx)
incq %rdx
cmpq %rdx, %rbp
jne 0x161b9
incq %rax
cmpq %rdi, %rax
jne 0x161ae
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq