// File: /workspace/github_cpp_makefile_star2_O3/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 0x2b8e
movq %rdi, %r14
leaq 0x14c(%rdi), %r15
movq (%rdi), %rax
movq %r15, %rsi
callq *0x28(%rax)
xorl %ebx, %ebx
testb %al, %al
je 0x2bde
leaq 0x2e8(%r14), %r12
leaq 0x300(%r14), %rax
movq %rax, 0x30(%rsp)
xorl %ebx, %ebx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq *0x30(%rax)
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %ecx
leal (%rax,%rax,8), %edx
addl %ecx, %edx
addl $-0xa, %edx
movslq %edx, %rdx
movl (%r15,%rdx,4), %r13d
movl $0x1, 0x4(%rsp)
movl $0x1, %edx
xorl %ebp, %ebp
leal (%rax,%rax,8), %eax
addl %ecx, %eax
addl $-0xa, %eax
cltq
movl %edx, 0x14c(%r14,%rax,4)
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
callq *0x20(%rax)
testb %al, %al
je 0x28b6
incl %ebp
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x28a7
movl 0x4(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x28b6
leaq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x3944
movl 0xc(%rsp), %eax
leal (%rax,%rax,8), %edx
movl 0x8(%rsp), %ecx
addl %ecx, %edx
addl $-0xa, %edx
movslq %edx, %rsi
movl $0x0, (%r15,%rsi,4)
movl 0x4(%rsp), %edi
leal 0x1(%rdi), %edx
movl %edx, 0x4(%rsp)
cmpl $0x9, %edi
jl 0x2866
testl %ebp, %ebp
je 0x293c
movq 0x18(%rsp), %rdx
movl -0x4(%rdx), %edx
movl %edx, 0x14c(%r14,%rsi,4)
imull $0x2710, %ebp, %esi     # imm = 0x2710
imull $0x3e8, %eax, %edi      # imm = 0x3E8
imull $0x64, %ecx, %ecx
leal (%r13,%r13,4), %eax
leal (%rsi,%rax,2), %eax
addl %edi, %eax
addl %ecx, %eax
addl %edx, %eax
movl %eax, 0x4(%rsp)
movq 0x2f0(%r14), %rsi
cmpq 0x2f8(%r14), %rsi
je 0x2a55
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x2f0(%r14)
jmp 0x2a62
movq 0x2f0(%r14), %r13
subq 0x2e8(%r14), %r13
shrq $0x2, %r13
testl %r13d, %r13d
jle 0x2a71
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
leaq (,%r13,2), %rax
addq %r13, %rax
decq %r13
leaq -0x4(,%rax,2), %rbp
movq (%r12), %rax
movl (%rax,%r13,4), %eax
cltq
imulq $0x10624dd3, %rax, %rcx # imm = 0x10624DD3
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rcx
addl %edx, %ecx
movslq %ecx, %rcx
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
subl %edx, %ecx
imulq $0x51eb851f, %rax, %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(%rax), %r8d
cmpl $0x270f, %r8d           # imm = 0x270F
ja 0x2aa3
leal (%rcx,%rcx,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 0x2a3b
movq -0x8(%rax), %rsi
subq %rdi, %rsi
callq 0x2170
leaq -0x1(%r13), %rax
incq %r13
addq $-0x6, %rbp
cmpq $0x1, %r13
movq %rax, %r13
ja 0x2974
jmp 0x2a71
movq %r12, %rdi
leaq 0x4(%rsp), %rdx
callq 0x3a80
movq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x390c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2a88
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
incl %ebx
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
callq *0x28(%rax)
testb %al, %al
jne 0x2819
jmp 0x2bde
movq 0x300(%r14), %r9
movq 0x308(%r14), %rdx
subq %r9, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
cmpq %r13, %rdx
jbe 0x2d1d
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
movl %eax, %r10d
subl %edx, %r10d
movq (%r9,%rbp,4), %rdx
leaq -0x4(%rdx), %rsi
movq %rsi, (%r9,%rbp,4)
movl -0x8(%rdx), %edx
leal (%rcx,%rcx,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, %rax, %r11 # imm = 0x68DB8BAD
movq %r11, %r13
shrq $0x3f, %r13
sarq $0x2c, %r11
addl %r13d, %r11d
imull $0x2710, %r11d, %r11d   # imm = 0x2710
imull $0x3e8, %ecx, %ecx      # imm = 0x3E8
imull $0x64, %edi, %edi
leal (%r10,%r10,4), %r10d
movq (%r9,%rbp,4), %r9
subl %eax, %r11d
addl %r11d, %r8d
leal (%r8,%r10,2), %eax
addl %ecx, %eax
addl %edi, %eax
addl -0x4(%r9), %eax
movl %eax, 0x4(%rsp)
cmpq 0x2f8(%r14), %rsi
je 0x2b7c
movl %eax, -0x4(%rdx)
movq %rdx, 0x2f0(%r14)
jmp 0x2a71
movq %r12, %rdi
leaq 0x4(%rsp), %rdx
callq 0x3a80
jmp 0x2a71
movq 0x3443(%rip), %rbx      # 0x5fd8
leaq 0x1519(%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
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2100
movq 0x33f3(%rip), %r12      # 0x5fd8
leaq 0x14f2(%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 0x1499(%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 0x143f(%rip), %rsi      # 0x410c
movl $0xe, %edx
movq %r12, %rdi
callq 0x2190
movq %r12, %rdi
movl %ebx, %esi
callq 0x2210
movq %rax, %rbx
movq (%rax), %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 0x1469(%rip), %rdi      # 0x418d
movq %r13, %rsi
xorl %eax, %eax
callq 0x21b0
jmp 0x2d36
jmp 0x2d36
jmp 0x2d36
jmp 0x2d36
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2d50
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2220