// File: bestcoder12[P]Sudoku_Game/main.cpp
// Function: main
int main(int argc, char const *argv[])
{
    if (argc != 1)
    {
        cerr << "Usage: ./game\n Or game.exe\n"; 
        return -2;
    }

    int err_chk = 0;

    #ifdef __linux__
        err_chk = system("clear");
    #elif defined(_WIN32)
        err_chk = system("cls");
    #endif

    char new_game = '0';
    
    cout << "\n\n\n\n\n\n\t\t\t\tWelcome to the SUDOKU GAME!!" << "\n\n\n\n";

    cout << "\n\n\n\n\nAfter the game starts -> \nEnter:\n";
	cout << "\t#!Q (to quit the game)\n";
	cout << "\tdel (to delete the entry in a cell)\n";
	cout << "\tsolve (to solve the puzzle automatically)\n\n";

    cout << "Press Enter to start the game: ";
    while (new_game != '\n')
    {
        cin.get(new_game);
    }

    #ifdef __linux__
        err_chk = system("clear");
    #elif defined(_WIN32)
        err_chk = system("cls");
    #endif

    /* Board is contained within the Sudoku class */
    Sudoku game_Board;
    game_Board.cell_remover();
    
    int ext_cd = 0;

    /* Player class used to conceptualize the idea of time taken by the user */
    Player p1;
    std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
    
    /* calling the functions sudoku,input and print */
    for (;;)
    {
        if (err_chk != 0)
        {
            cerr << "Unable to clear the screen.";
        }
    
        #ifdef __linux__
            sleep(2);
        #elif defined (_WIN32)
            Sleep(2000);
        #endif

        #ifdef __linux__
            err_chk = system("clear");
        #elif defined(_WIN32)
            err_chk = system("cls");
        #endif

        p1.timer(start);
        
        if (p1.show_Time() > 900.0)
        {
            cout << "Game lost!" << endl;
            exit(-1);
        }

        cout << "#!Q (to quit the game)\n";
	    cout << "del (to delete the entry in a cell)\n";
	    cout << "solve (to solve the puzzle automatically)\n\n";

        game_Board.print_board();
        ext_cd = game_Board.input();
        
        if (ext_cd == -1)
        {
            return -1;
        }

        ext_cd = game_Board.chk_win();

        if (ext_cd == 1)
        {
            break;
        }
    }
    
    return 0;	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x690, %rsp            # imm = 0x690
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
je 0x3b6e
movq 0x449a(%rip), %rdi      # 0x7ff0
leaq 0x183b(%rip), %rsi      # 0x5398
callq 0x2100
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d8c
movl $0x0, -0x14(%rbp)
leaq 0x17b5(%rip), %rdi      # 0x5331
callq 0x20b0
movl %eax, -0x14(%rbp)
movb $0x30, -0x15(%rbp)
movq 0x4439(%rip), %rdi      # 0x7fc8
leaq 0x181e(%rip), %rsi      # 0x53b4
callq 0x2100
movq %rax, %rdi
leaq 0x1836(%rip), %rsi      # 0x53db
callq 0x2100
movq 0x4417(%rip), %rdi      # 0x7fc8
leaq 0x1828(%rip), %rsi      # 0x53e0
callq 0x2100
movq 0x4404(%rip), %rdi      # 0x7fc8
leaq 0x183c(%rip), %rsi      # 0x5407
callq 0x2100
movq 0x43f1(%rip), %rdi      # 0x7fc8
leaq 0x1842(%rip), %rsi      # 0x5420
callq 0x2100
movq 0x43de(%rip), %rdi      # 0x7fc8
leaq 0x1855(%rip), %rsi      # 0x5446
callq 0x2100
movq 0x43cb(%rip), %rdi      # 0x7fc8
leaq 0x186f(%rip), %rsi      # 0x5473
callq 0x2100
movsbl -0x15(%rbp), %eax
cmpl $0xa, %eax
je 0x3c24
movq 0x43bf(%rip), %rdi      # 0x7fd8
leaq -0x15(%rbp), %rsi
callq 0x2140
jmp 0x3c09
leaq 0x1706(%rip), %rdi      # 0x5331
callq 0x20b0
movl %eax, -0x14(%rbp)
leaq -0x670(%rbp), %rdi
callq 0x24f0
leaq -0x670(%rbp), %rdi
callq 0x42d0
movl $0x0, -0x674(%rbp)
callq 0x2130
movq %rax, -0x688(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x3c7a
movq 0x4382(%rip), %rdi      # 0x7ff0
leaq 0x16c9(%rip), %rsi      # 0x533e
callq 0x2100
movl $0x2, %edi
callq 0x20a0
leaq 0x16a6(%rip), %rdi      # 0x5331
callq 0x20b0
movl %eax, -0x14(%rbp)
movq -0x688(%rbp), %rax
movq %rax, -0x690(%rbp)
movq -0x690(%rbp), %rsi
leaq -0x680(%rbp), %rdi
callq 0x2a10
leaq -0x680(%rbp), %rdi
callq 0x3da0
movsd 0x16c8(%rip), %xmm1     # 0x5390
ucomisd %xmm1, %xmm0
jbe 0x3cfa
movq 0x42f3(%rip), %rdi      # 0x7fc8
leaq 0x17b7(%rip), %rsi      # 0x5493
callq 0x2100
movq %rax, %rdi
movq 0x42c5(%rip), %rsi      # 0x7fb0
callq 0x2110
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2120
movq 0x42c7(%rip), %rdi      # 0x7fc8
leaq 0x1700(%rip), %rsi      # 0x5408
callq 0x2100
movq 0x42b4(%rip), %rdi      # 0x7fc8
leaq 0x1706(%rip), %rsi      # 0x5421
callq 0x2100
movq 0x42a1(%rip), %rdi      # 0x7fc8
leaq 0x1719(%rip), %rsi      # 0x5447
callq 0x2100
leaq -0x670(%rbp), %rdi
callq 0x3340
leaq -0x670(%rbp), %rdi
callq 0x2b10
movl %eax, -0x674(%rbp)
cmpl $-0x1, -0x674(%rbp)
jne 0x3d63
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d8c
leaq -0x670(%rbp), %rdi
callq 0x34a0
movl %eax, -0x674(%rbp)
cmpl $0x1, -0x674(%rbp)
jne 0x3d80
jmp 0x3d85
jmp 0x3c61
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x690, %rsp            # imm = 0x690
popq %rbp
retq
nopl (%rax,%rax)