// File: /workspace/github_cpp_makefile_star2_O1/SilentAssassinMa[P]Sudoku-Solver/SudokuSolver.cpp
// Function: SudokuSolver::BackTracking()
void SudokuSolver::BackTracking()
{
    if (!isSolvable)
    {
        cout << "Error : The Input Sudoku Is Not Solvable" << endl;
        return;
    }

    int step = 0;
    while (CheckEmpty(Current))
    {
        int x, y;
        int guesstime = 0;
        vector<int> guess_number;
        int original_number;
        FindMaxConstrain(Current, x, y);

        original_number = FindElement(Current, x, y);

        for (int i = 1; i <= 9; i++)
        {
            Current[9 * (x - 1) + (y - 1)] = i;
            if (CheckConsistency(Current))
            {
                guesstime++;
                guess_number.push_back(i);
            }
            Current[9 * (x - 1) + (y - 1)] = 0;
        }

        if (guesstime != 0)
        {
            Current[9 * (x - 1) + (y - 1)] = guess_number.back();
            // Here I use 5 digits to store the change
            RecordChange.push_back(guesstime * 10000 + x * 1000 + y * 100 + original_number * 10 + guess_number.back());
            GuessNumber.push_back(guess_number);
        }
        else
        {
            int ChangeSize = RecordChange.size();
            for (int i = ChangeSize - 1; i >= 0; i--)
            {
                int xc, yc, origin, guess, time;
                // recover the last change
                xc = (RecordChange[i] / 1000) % 10;
                yc = (RecordChange[i] / 100) % 10;
                origin = (RecordChange[i] / 10) % 10;
                guess = RecordChange[i] % 10;
                time = RecordChange[i] / 10000;

                if (time == 1)
                {
                    // if it's the last guess, undo the change
                    Current[9 * (xc - 1) + (yc - 1)] = 0;
                    RecordChange.pop_back(); // delete the change
                    GuessNumber.pop_back();
                }
                else
                {
                    // if we have other possible value, change a guess number
                    GuessNumber.at(i).pop_back();
                    Current[9 * (xc - 1) + (yc - 1)] = GuessNumber.at(i).back();
                    time--;
                    RecordChange.pop_back();
                    RecordChange.push_back(time * 10000 + xc * 1000 + yc * 100 + guess * 10 + GuessNumber.at(i).back());
                    break;
                }
            }
        }

        step++;
    }

    cout << "The Original Sudoku is " << endl;
    PrintSudoku(OriginalSudoku);
    cout << endl;

    cout << "The Filled Sudoku is " << endl;
    PrintSudoku(Current);

    cout << endl;
    cout << "Total Steps : " << step << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpb $0x1, 0x2e1(%rdi)
jne 0x2cbc
movq %rdi, %r14
leaq 0x14c(%rdi), %r15
movq (%rdi), %rax
movq %r15, %rsi
callq *0x28(%rax)
xorl %ebx, %ebx
testb %al, %al
je 0x2bb1
leaq 0x2e8(%r14), %r12
leaq 0x300(%r14), %rax
movq %rax, 0x30(%rsp)
xorl %ebx, %ebx
movl %ebx, 0xc(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
callq *0x30(%rax)
movl 0x8(%rsp), %eax
movl 0x4(%rsp), %ecx
leal (%rax,%rax,8), %eax
addl %ecx, %eax
addl $-0xa, %eax
cltq
movl (%r15,%rax,4), %ebx
movl $0x1, (%rsp)
movl $0x1, %eax
xorl %ebp, %ebp
leaq 0x10(%rsp), %r13
movl 0x8(%rsp), %ecx
leal (%rcx,%rcx,8), %ecx
movl 0x4(%rsp), %edx
addl %edx, %ecx
addl $-0xa, %ecx
movslq %ecx, %rcx
movl %eax, 0x14c(%r14,%rcx,4)
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
callq *0x20(%rax)
testb %al, %al
je 0x28df
incl %ebp
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x28d4
movl (%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x28df
movq %r13, %rdi
movq %rsp, %rdx
callq 0x3944
movl 0x8(%rsp), %eax
leal (%rax,%rax,8), %eax
movl 0x4(%rsp), %ecx
addl %ecx, %eax
addl $-0xa, %eax
cltq
movl $0x0, (%r15,%rax,4)
movl (%rsp), %ecx
leal 0x1(%rcx), %eax
movl %eax, (%rsp)
cmpl $0x9, %ecx
jl 0x288b
testl %ebp, %ebp
je 0x2973
movq 0x18(%rsp), %rcx
movl -0x4(%rcx), %eax
movl 0x8(%rsp), %edx
leal (%rdx,%rdx,8), %esi
movl 0x4(%rsp), %edi
addl %edi, %esi
addl $-0xa, %esi
movslq %esi, %rsi
movl %eax, 0x14c(%r14,%rsi,4)
imull $0x2710, %ebp, %eax     # imm = 0x2710
imull $0x3e8, %edx, %edx      # imm = 0x3E8
imull $0x64, %edi, %esi
leal (%rbx,%rbx,4), %edi
leal (%rax,%rdi,2), %eax
addl %edx, %eax
addl %esi, %eax
addl -0x4(%rcx), %eax
movl %eax, (%rsp)
movq 0x2f0(%r14), %rsi
cmpq 0x2f8(%r14), %rsi
je 0x2b68
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x2f0(%r14)
jmp 0x2b73
movq 0x2f0(%r14), %rax
subq 0x2e8(%r14), %rax
shrq $0x2, %rax
movl %eax, %ebp
leaq (,%rbp,2), %rax
addq %rbp, %rax
decq %rbp
leaq -0x4(,%rax,2), %r13
leal 0x1(%rbp), %eax
testl %eax, %eax
jle 0x2b80
movq (%r12), %rax
movl (%rax,%rbp,4), %eax
movslq %eax, %rcx
imulq $0x10624dd3, %rcx, %rax # imm = 0x10624DD3
movq %rax, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rax
addl %edx, %eax
cltq
imulq $0x66666667, %rax, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
addl %esi, %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
subl %edx, %eax
imulq $0x51eb851f, %rcx, %rdx # imm = 0x51EB851F
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x25, %rdx
addl %esi, %edx
movslq %edx, %rdi
imulq $0x66666667, %rdi, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
addl %esi, %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
subl %edx, %edi
leal -0x2710(%rcx), %ebx
cmpl $0x270f, %ebx           # imm = 0x270F
ja 0x2a71
leal (%rax,%rax,8), %eax
addl %edi, %eax
addl $-0xa, %eax
cltq
movl $0x0, 0x14c(%r14,%rax,4)
addq $-0x4, 0x2f0(%r14)
movq 0x308(%r14), %rax
leaq -0x18(%rax), %rcx
movq %rcx, 0x308(%r14)
movq -0x18(%rax), %rdi
testq %rdi, %rdi
je 0x2b53
movq -0x8(%rax), %rsi
subq %rdi, %rsi
callq 0x2170
jmp 0x2b53
movq 0x300(%r14), %r8
movq 0x308(%r14), %rdx
subq %r8, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
cmpq %rbp, %rdx
jbe 0x2d0d
imulq $0x66666667, %rcx, %rdx # imm = 0x66666667
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rdx
addl %esi, %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
movl %ecx, %r9d
subl %edx, %r9d
movq (%r8,%r13,4), %rdx
leaq -0x4(%rdx), %rsi
movq %rsi, (%r8,%r13,4)
movl -0x8(%rdx), %edx
leal (%rax,%rax,8), %esi
leal -0xa(%rdi,%rsi), %esi
movslq %esi, %rsi
movl %edx, 0x14c(%r14,%rsi,4)
movq 0x2f0(%r14), %rdx
leaq -0x4(%rdx), %rsi
movq %rsi, 0x2f0(%r14)
imulq $0x68db8bad, %rcx, %rcx # imm = 0x68DB8BAD
movq %rcx, %r10
shrq $0x3f, %r10
sarq $0x2c, %rcx
addl %r10d, %ecx
imull $0x2710, %ecx, %ecx     # imm = 0x2710
imull $0x3e8, %eax, %eax      # imm = 0x3E8
imull $0x64, %edi, %edi
leal (%r9,%r9,4), %r9d
movq (%r8,%r13,4), %r8
movl -0x4(%r8), %r8d
leal (%rcx,%r9,2), %ecx
addl %eax, %ecx
addl %edi, %ecx
leal (%r8,%rcx), %eax
addl $0xffffd8f0, %eax       # imm = 0xFFFFD8F0
movl %eax, (%rsp)
cmpq 0x2f8(%r14), %rsi
je 0x2b48
movl %eax, -0x4(%rdx)
movq %rdx, 0x2f0(%r14)
jmp 0x2b53
movq %r12, %rdi
movq %rsp, %rdx
callq 0x3a80
decq %rbp
addq $-0x6, %r13
cmpl $0x2710, %ebx           # imm = 0x2710
jb 0x299d
jmp 0x2b80
movq %r12, %rdi
movq %rsp, %rdx
callq 0x3a80
movq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x390c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2b97
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movl 0xc(%rsp), %ebx
incl %ebx
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
callq *0x28(%rax)
testb %al, %al
jne 0x2837
movq 0x3420(%rip), %r12      # 0x5fd8
leaq 0x151f(%rip), %rsi      # 0x40de
movl $0x17, %edx
movq %r12, %rdi
callq 0x2190
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x8(%r14), %rsi
movq (%r14), %rax
movq %r14, %rdi
callq *0x40(%rax)
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x14c6(%rip), %rsi      # 0x40f6
movl $0x15, %edx
movq %r12, %rdi
callq 0x2190
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
callq *0x40(%rax)
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
leaq 0x146c(%rip), %rsi      # 0x410c
movl $0xe, %edx
movq %r12, %rdi
callq 0x2190
movq %r12, %rdi
movl %ebx, %esi
callq 0x2210
movq %rax, %rbx
jmp 0x2cd7
movq 0x3315(%rip), %rbx      # 0x5fd8
leaq 0x13eb(%rip), %rsi      # 0x40b5
movl $0x28, %edx
movq %rbx, %rdi
callq 0x2190
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1479(%rip), %rdi      # 0x418d
movq %rbp, %rsi
xorl %eax, %eax
callq 0x21b0
jmp 0x2d26
jmp 0x2d26
jmp 0x2d26
jmp 0x2d26
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2d40
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2220