// File: /workspace/github_cpp_makefile_star2_O2/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), %r8
xorl %ecx, %ecx
movabsq $0x1, %r9
xorps %xmm0, %xmm0
movb $0x3, %r11b
movq %r9, %rdi
cmpq $0xa, %rdi
je 0x31cd
andq $0x0, (%rsp)
movaps %xmm0, -0x10(%rsp)
movaps %xmm0, -0x20(%rsp)
movaps %xmm0, -0x40(%rsp)
movaps %xmm0, -0x50(%rsp)
andq $0x0, -0x30(%rsp)
movl %edi, %eax
xorl %edx, %edx
movl $0x3, %r10d
divl %r10d
imulq $0x24, %rdi, %rbx
addq %r8, %rbx
leaq (%r8,%rdi,4), %r14
movq %rsi, %r15
movq %r9, %r12
cmpq $0xa, %r12
je 0x319b
movslq (%rbx,%r12,4), %rax
testq %rax, %rax
je 0x310e
incl -0x50(%rsp,%rax,4)
imulq $0x24, %r12, %rax
movslq (%r14,%rax), %rax
testq %rax, %rax
je 0x311f
incl -0x20(%rsp,%rax,4)
movzbl %r12b, %eax
divb %r11b
movzbl %ah, %eax
cmpl $0x1, %edx
jne 0x318f
cmpb $0x1, %al
jne 0x318f
andq $0x0, -0x60(%rsp)
movaps %xmm0, -0x70(%rsp)
movaps %xmm0, -0x80(%rsp)
movq %r15, %rax
xorl %r13d, %r13d
cmpq $0x3, %r13
je 0x3172
xorl %ebp, %ebp
cmpq $0x3, %rbp
je 0x3169
movslq (%rax,%rbp,4), %r10
testq %r10, %r10
je 0x3164
incl -0x80(%rsp,%r10,4)
incq %rbp
jmp 0x3150
incq %r13
addq $0x24, %rax
jmp 0x3148
movq %r9, %rax
cmpq $0xa, %rax
je 0x318f
xorl %r10d, %r10d
cmpl $0x1, -0x80(%rsp,%rax,4)
sete %r10b
addl %r10d, %ecx
incq %rax
jmp 0x3175
incq %r12
addq $0x4, %r15
jmp 0x30f7
movq %r9, %rax
cmpq $0xa, %rax
je 0x31c1
xorl %edx, %edx
cmpl $0x1, -0x20(%rsp,%rax,4)
sete %dl
addl %edx, %ecx
xorl %edx, %edx
cmpl $0x1, -0x50(%rsp,%rax,4)
sete %dl
addl %edx, %ecx
incq %rax
jmp 0x319e
incq %rdi
addq $0x24, %rsi
jmp 0x30b0
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq