// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movaps %xmm0, -0x10(%rsp)
andq $0x0, 0x10(%rsp)
movaps %xmm0, -0x30(%rsp)
andq $0x0, -0x20(%rsp)
movaps %xmm0, -0x40(%rsp)
andl $0x0, -0x50(%rsp)
movaps %xmm0, -0x60(%rsp)
movaps %xmm0, -0x70(%rsp)
leaq -0x28(%rsi), %rax
movq %rax, -0x80(%rsp)
movabsq $0x1, %r8
movl $0x3, %r11d
movb $0x3, %bpl
movq %rsi, %r15
cmpq $0xa, %r8
je 0x300b
movl %r8d, %eax
xorl %edx, %edx
divl %r11d
movl %edx, %r9d
imulq $0x24, %r8, %r12
addq -0x80(%rsp), %r12
imulq $0xc, %rax, %rax
leaq (%rsp,%rax), %r13
addq $-0x70, %r13
movq %r15, -0x78(%rsp)
movabsq $0x1, %r10
cmpq $0xa, %r10
je 0x2ffa
cmpl $0x0, (%r12,%r10,4)
je 0x2f9f
incl -0x10(%rsp,%r8,4)
incl -0x40(%rsp,%r10,4)
movzbl %r10b, %eax
divb %bpl
movzbl %ah, %eax
cmpl $0x1, %r9d
jne 0x2ff1
cmpb $0x1, %al
jne 0x2ff1
movl %r10d, %eax
xorl %edx, %edx
divl %r11d
leaq (,%rax,4), %rax
addq %r13, %rax
movq %r15, %rdx
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0x2ff1
xorl %r14d, %r14d
cmpq $0x3, %r14
je 0x2fe8
cmpl $0x0, (%rdx,%r14,4)
je 0x2fe3
incl (%rax)
incq %r14
jmp 0x2fd4
incq %rbx
addq $0x24, %rdx
jmp 0x2fcb
incq %r10
addq $0x4, %r15
jmp 0x2f88
incq %r8
movq -0x78(%rsp), %r15
addq $0x24, %r15
jmp 0x2f4f
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movabsq $0x1, %r8
movb $0x3, %r9b
cmpq $0xa, %r8
je 0x307d
leal -0x1(%r8), %eax
xorl %edx, %edx
divl %r11d
imulq $0xc, %rax, %rax
leaq (%rsp,%rax), %rdx
addq $-0x70, %rdx
xorl %ebx, %ebx
cmpq $0x9, %rbx
je 0x3074
cmpl $0x0, (%rsi,%rbx,4)
jne 0x306f
movl -0x3c(%rsp,%rbx,4), %ebp
addl -0x10(%rsp,%r8,4), %ebp
movsbl %bl, %eax
idivb %r9b
movsbq %al, %rax
movl %eax, %eax
addl (%rdx,%rax,4), %ebp
cmpl %r10d, %ebp
jle 0x306f
leal 0x1(%rbx), %eax
movl %r8d, (%rdi)
movl %eax, (%rcx)
movl %ebp, %r10d
incq %rbx
jmp 0x303b
incq %r8
addq $0x24, %rsi
jmp 0x301e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq