// File: SilentAssassinMa[P]Sudoku-Solver/SudokuSolver.cpp
// Function: SudokuSolver::FindMaxConstrain(int*, int&, int&)
void SudokuSolver::FindMaxConstrain(int *sudoku, int &x, int &y)
{
    // This returns the empty element with maximum constrain
    int rowconstrain[10] = {0};
    int columnconstrain[10] = {0};
    int subsquareconstrain[3][3] = {0};
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if (FindElement(sudoku, i, j) != 0)
            {
                rowconstrain[i]++;
                columnconstrain[j]++;
            }

            if ((i % 3) == 1 && (j % 3) == 1)
            {
                for (int m = 0; m < 3; m++)
                {
                    for (int n = 0; n < 3; n++)
                    {
                        if (FindElement(sudoku, i + m, j + n) != 0)
                            subsquareconstrain[i / 3][j / 3]++;
                    }
                }
            }
        }
    }
    int maxconstrain = -1;

    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if (FindElement(sudoku, i, j) == 0)
            {
                int sumconstrain = rowconstrain[i] + columnconstrain[j] + subsquareconstrain[(i - 1) / 3][(j - 1) / 3];
                if (sumconstrain > maxconstrain)
                {
                    maxconstrain = sumconstrain;
                    x = i;
                    y = j;
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x20a0
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x20a0
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movl $0x24, %edx
callq 0x20a0
movl $0x1, -0xb4(%rbp)
cmpl $0x9, -0xb4(%rbp)
jg 0x3aef
movl $0x1, -0xb8(%rbp)
cmpl $0x9, -0xb8(%rbp)
jg 0x3ad9
movq -0x10(%rbp), %rdi
movl -0xb4(%rbp), %esi
movl -0xb8(%rbp), %edx
callq 0x40b0
cmpl $0x0, %eax
je 0x39ca
movslq -0xb4(%rbp), %rax
movl -0x50(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x50(%rbp,%rax,4)
movslq -0xb8(%rbp), %rax
movl -0x80(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x80(%rbp,%rax,4)
movl -0xb4(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x3ac3
movl -0xb8(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x3ac3
movl $0x0, -0xbc(%rbp)
cmpl $0x3, -0xbc(%rbp)
jge 0x3ac1
movl $0x0, -0xc0(%rbp)
cmpl $0x3, -0xc0(%rbp)
jge 0x3aab
movq -0x10(%rbp), %rdi
movl -0xb4(%rbp), %esi
addl -0xbc(%rbp), %esi
movl -0xb8(%rbp), %edx
addl -0xc0(%rbp), %edx
callq 0x40b0
cmpl $0x0, %eax
je 0x3a95
movl -0xb4(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movslq %eax, %rcx
leaq -0xb0(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movl -0xb8(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xd8(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x3a97
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x3a19
jmp 0x3aad
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x3a02
jmp 0x3ac3
jmp 0x3ac5
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x397f
jmp 0x3adb
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x3968
movl $0xffffffff, -0xc4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xc8(%rbp)
cmpl $0x9, -0xc8(%rbp)
jg 0x3c07
movl $0x1, -0xcc(%rbp)
cmpl $0x9, -0xcc(%rbp)
jg 0x3bf1
movq -0x10(%rbp), %rdi
movl -0xc8(%rbp), %esi
movl -0xcc(%rbp), %edx
callq 0x40b0
cmpl $0x0, %eax
jne 0x3bdb
movslq -0xc8(%rbp), %rax
movl -0x50(%rbp,%rax,4), %eax
movslq -0xcc(%rbp), %rcx
addl -0x80(%rbp,%rcx,4), %eax
movl %eax, -0xdc(%rbp)
movl -0xc8(%rbp), %eax
subl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
cltq
leaq -0xb0(%rbp), %rcx
imulq $0xc, %rax, %rax
addq %rax, %rcx
movl -0xcc(%rbp), %eax
subl $0x1, %eax
movl $0x3, %esi
cltd
idivl %esi
movl %eax, %edx
movl -0xdc(%rbp), %eax
movslq %edx, %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
cmpl -0xc4(%rbp), %eax
jle 0x3bd9
movl -0xd0(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0xc8(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0xcc(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x3bdb
jmp 0x3bdd
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x3b1a
jmp 0x3bf3
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x3b03
addq $0xe0, %rsp
popq %rbp
retq