// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x1, -0x18(%rbp)
cmpl $0x9, -0x18(%rbp)
jg 0x3e5e
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x20a0
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x20a0
movl $0x1, -0x74(%rbp)
cmpl $0x9, -0x74(%rbp)
jg 0x3dfa
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x74(%rbp), %edx
callq 0x40b0
cmpl $0x0, %eax
je 0x3c9c
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x74(%rbp), %edx
callq 0x40b0
cltq
movl -0x70(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x70(%rbp,%rax,4)
movq -0x10(%rbp), %rdi
movl -0x74(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x40b0
cmpl $0x0, %eax
je 0x3ccc
movq -0x10(%rbp), %rdi
movl -0x74(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x40b0
cltq
movl -0x40(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x40(%rbp,%rax,4)
movl -0x18(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x3dea
movl -0x74(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x3dea
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x20a0
movl $0x0, -0xa4(%rbp)
cmpl $0x3, -0xa4(%rbp)
jge 0x3da8
movl $0x0, -0xa8(%rbp)
cmpl $0x3, -0xa8(%rbp)
jge 0x3d92
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
addl -0xa4(%rbp), %esi
movl -0x74(%rbp), %edx
addl -0xa8(%rbp), %edx
callq 0x40b0
cmpl $0x0, %eax
je 0x3d7f
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
addl -0xa4(%rbp), %esi
movl -0x74(%rbp), %edx
addl -0xa8(%rbp), %edx
callq 0x40b0
cltq
movl -0xa0(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0xa0(%rbp,%rax,4)
jmp 0x3d81
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x3d28
jmp 0x3d94
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x3d11
movl $0x1, -0xac(%rbp)
cmpl $0x9, -0xac(%rbp)
jg 0x3de8
movslq -0xac(%rbp), %rax
cmpl $0x1, -0xa0(%rbp,%rax,4)
jne 0x3dd5
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3dd7
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x3db2
jmp 0x3dea
jmp 0x3dec
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x3c62
movl $0x1, -0xb0(%rbp)
cmpl $0x9, -0xb0(%rbp)
jg 0x3e4e
movslq -0xb0(%rbp), %rax
cmpl $0x1, -0x40(%rbp,%rax,4)
jne 0x3e24
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movslq -0xb0(%rbp), %rax
cmpl $0x1, -0x70(%rbp,%rax,4)
jne 0x3e3b
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3e3d
movl -0xb0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb0(%rbp)
jmp 0x3e04
jmp 0x3e50
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3c31
movl -0x14(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)