// File: /workspace/github_cpp_makefile_star2_O3/SilentAssassinMa[P]Sudoku-Solver/SudokuSolver.cpp
// Function: SudokuSolver::UniqueElements(int*)
int SudokuSolver::UniqueElements(int *sudoku)
{
    // This function returns the sum of unique elements in each row, column and subsquare
    int num = 0;
    for (int i = 1; i <= 9; i++)
    {
        int rowsum[10] = {0};
        int columnsum[10] = {0};
        for (int j = 1; j <= 9; j++)
        {
            if (FindElement(sudoku, i, j) != 0)
            {
                columnsum[FindElement(sudoku, i, j)]++;
            }
            if (FindElement(sudoku, j, i) != 0)
            {
                rowsum[FindElement(sudoku, j, i)]++;
            }

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

                for (int m = 1; m <= 9; m++)
                {
                    if (subsquaresum[m] == 1)
                    {
                        num++;
                    }
                }
            }
        }

        for (int n = 1; n <= 9; n++)
        {
            if (rowsum[n] == 1)
            {
                num++;
            }
            if (columnsum[n] == 1)
            {
                num++;
            }
        }
    }

    return num;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq -0x28(%rsi), %rcx
xorl %edx, %edx
movl $0x1, %edi
xorps %xmm0, %xmm0
movl $0xaaaaaaab, %r8d       # imm = 0xAAAAAAAB
xorl %eax, %eax
movaps %xmm0, -0x10(%rsp)
movaps %xmm0, -0x20(%rsp)
movq %rdx, (%rsp)
movq %rdx, -0x30(%rsp)
movaps %xmm0, -0x40(%rsp)
movaps %xmm0, -0x50(%rsp)
movl %edi, %r9d
imulq %r8, %r9
shrq $0x21, %r9
leal (%r9,%r9,2), %r10d
movl %edi, %r9d
subl %r10d, %r9d
leaq (%rdi,%rdi,8), %r10
leaq (%rcx,%r10,4), %r10
leaq (%rcx,%rdi,4), %r11
movq %rsi, %rbx
movl $0x1, %r14d
movslq (%r10,%r14,4), %r15
testq %r15, %r15
je 0x365a
incl -0x50(%rsp,%r15,4)
leaq (%r14,%r14,8), %r15
movslq (%r11,%r15,4), %r15
testq %r15, %r15
je 0x366c
incl -0x20(%rsp,%r15,4)
cmpl $0x1, %r9d
jne 0x36ed
movzbl %r14b, %ebp
imull $0xab, %ebp, %r15d
shrl $0x9, %r15d
leal (%r15,%r15,2), %ebp
movl %r14d, %r15d
subb %bpl, %r15b
cmpb $0x1, %r15b
jne 0x36ed
movaps %xmm0, -0x70(%rsp)
movaps %xmm0, -0x80(%rsp)
movq $0x0, -0x60(%rsp)
movq %rbx, %r15
xorl %r12d, %r12d
xorl %r13d, %r13d
movslq (%r15,%r13,4), %rbp
testq %rbp, %rbp
je 0x36ba
incl -0x80(%rsp,%rbp,4)
incq %r13
cmpq $0x3, %r13
jne 0x36ad
incq %r12
addq $0x24, %r15
cmpq $0x3, %r12
jne 0x36aa
movl $0x1, %r15d
xorl %ebp, %ebp
cmpl $0x1, -0x80(%rsp,%r15,4)
sete %bpl
addl %ebp, %eax
incq %r15
cmpq $0xa, %r15
jne 0x36d6
incq %r14
addq $0x4, %rbx
cmpq $0xa, %r14
jne 0x364c
movl $0x1, %r9d
xorl %r10d, %r10d
cmpl $0x1, -0x20(%rsp,%r9,4)
sete %r10b
addl %eax, %r10d
xorl %eax, %eax
cmpl $0x1, -0x50(%rsp,%r9,4)
sete %al
addl %r10d, %eax
incq %r9
cmpq $0xa, %r9
jne 0x3704
incq %rdi
addq $0x24, %rsi
cmpq $0xa, %rdi
jne 0x3605
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop