// File: /workspace/github_cpp_makefile_star2_O3/bestcoder12[P]Sudoku_Game/functions.cpp
// Function: s_brd::Sudoku::input()
int Sudoku::input() 
{
	int row = 0,col = 0, inp_num = 0, err_cd = 0, cnt = 0;
	 string loc, num;

	/* Asking the location of the box in which to enter the number */
	cout << "Enter the location where you want to insert the element in the format (x,y): "; 
	getline(cin,loc);

	if ( loc == " #!Q" || loc == "#!Q" )
	{
		return -1;
	}

	if (loc == "solve" || loc == "Solve")
	{
		bool solved = this->solveSudoku(board);
		if (!solved)
		{
			cout << "Could not solve board in the current state. Most probably due to some user entered number.\n";
			exit(-1);
		}
		filled = 81;
		print_board();
		exit(0);
	} 

	/* Declaring a string iterator to traverse the string character by character */
	string::iterator it = loc.begin();
	char c_to_num[2];

	for (; *it != ','; it++)
	{
		if (*it == '(' || *it == ' ')
		{
			continue;
		}
		if (cnt > 1)
		{
			break;
		}
		c_to_num[cnt] = *it;
		cnt++;
	}
	row = atoi(c_to_num);
	row -= 1;
	cnt = 0;

	for (; *it != ')'; it++)
	{
		if (*it == ' ' || *it == ',')
		{
			continue;
		}
		if (cnt > 1)
		{
			break;
		}
		c_to_num[cnt] = *it;
		cnt++;
	}
	col = atoi(c_to_num);
	col -= 1;

	if (row > 8 || row < 0 || col < 0 || col > 8) 			                                                                                         
	{
		cout << "Error! Wrong position entered. Please enter the position again.\n" << "\n";
		return -2;
	}

	if (board[row][col].get_Editable() == false)
	{
		cout << "Error! This is already filled cell. Please enter the position again.\n" << "\n";
		return -2;
	}

	cout << "Enter your Element: ";
	getline(cin,num);

	if ( num == "#!Q" || num == " #!Q" )
	{
		return -1;
	} 
	
	if ( num == "solve" || num == "Solve" )
	{
		bool solved = this->solveSudoku(board);
		if (!solved)
		{
			cout << "Could not solve board in the current state. Most probably due to some user entered number.\n";
			exit(-1);
		}
		filled = 81;
		print_board();
		exit(0);
		
	}

	if ( num == "del" || num == "Del")
	{
		if (!board[row][col].get_Editable())
		{
			cout << "The cell cannot be deleted! Please select correct cell." << "\n";
		}
		board[row][col].set_Val(-1,true);
		return 4;
	} 

	if (num == " \n" || num == "\n")
	{
		cout << "Could not recognize the number. Please enter again." << "\n";
		return -2;
	}

	inp_num = stod(num);

	/* Checking the entered number for repetition in row, column or box. */
	err_cd = chk_num(inp_num,row,col);
	if (err_cd == -1)
	{
		cout << "The number you entered at " << "(" << row+1 << "," << col+1 << ")" << " repeats in a row, column or box." << "\n";
		return -2;
	}

	/* Inputing the element in the 9 x 9 sudoku board */
	
	board[row][col].set_Val(inp_num,true);
	filled += 1;
	cout << "Number entered successfully!" << "\n"; 

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r15
leaq 0x50(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x28(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq 0x3646(%rip), %r14      # 0x5fc8
leaq 0x1793(%rip), %rsi      # 0x411c
movl $0x4d, %edx
movq %r14, %rdi
callq 0x2130
movq 0x363b(%rip), %rdi      # 0x5fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %edx
movq 0x3620(%rip), %r13      # 0x5fd8
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
callq 0x21c0
leaq 0x179e(%rip), %rsi      # 0x416a
leaq 0x40(%rsp), %rdi
callq 0x2060
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x2cd4
leaq 0x1781(%rip), %rsi      # 0x416b
leaq 0x40(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2cd4
leaq 0x176c(%rip), %rsi      # 0x416f
leaq 0x40(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2df8
leaq 0x1759(%rip), %rsi      # 0x4175
leaq 0x40(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2df8
movq 0x40(%rsp), %r12
incq %r12
xorl %eax, %eax
movzbl -0x1(%r12), %ebx
cmpl $0x20, %ebx
je 0x2a5a
cmpl $0x28, %ebx
je 0x2a5a
cmpl $0x2c, %ebx
je 0x2a5f
cmpl $0x1, %eax
jg 0x2a5f
movl %eax, %ecx
movb %bl, 0xe(%rsp,%rcx)
incl %eax
incq %r12
jmp 0x2a38
movq %r15, 0x10(%rsp)
leaq 0xe(%rsp), %rdi
callq 0x2190
movl %eax, %r15d
leal -0x1(%r15), %ebp
xorl %eax, %eax
cmpb $0x20, %bl
je 0x2a96
movzbl %bl, %ecx
cmpl $0x2c, %ecx
je 0x2a96
cmpl $0x29, %ecx
je 0x2a9f
cmpl $0x1, %eax
jg 0x2a9f
movl %eax, %ecx
movb %bl, 0xe(%rsp,%rcx)
incl %eax
movb (%r12), %bl
incq %r12
jmp 0x2a77
leaq 0xe(%rsp), %rdi
callq 0x2190
movl %eax, %r12d
movl %r15d, %eax
addl $-0xa, %eax
cmpl $-0x9, %eax
setb %al
leal -0xa(%r12), %ecx
cmpl $-0x9, %ecx
setb %cl
orb %al, %cl
je 0x2ad9
movl $0x40, %r13d
leaq 0x1703(%rip), %rbp      # 0x41d7
jmp 0x2cad
leal -0x1(%r12), %ecx
movl %ebp, %eax
movl %ecx, 0x3c(%rsp)
movl %ecx, %edx
leaq (%rax,%rax,8), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %rbx
movq %rdx, 0x60(%rsp)
cmpb $0x1, 0x4(%rbx,%rdx,8)
jne 0x2ca0
movl %ebp, 0x38(%rsp)
movq 0x34ba(%rip), %rdi      # 0x5fc8
leaq 0x1749(%rip), %rsi      # 0x425e
movl $0x14, %edx
callq 0x2130
movq (%r13), %rax
addq -0x18(%rax), %r13
movq %r13, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %edx
movq 0x349a(%rip), %rdi      # 0x5fd8
leaq 0x18(%rsp), %rsi
callq 0x21c0
leaq 0x161c(%rip), %rsi      # 0x416b
leaq 0x18(%rsp), %rdi
callq 0x2060
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x2cd4
leaq 0x15fd(%rip), %rsi      # 0x416a
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2cd4
leaq 0x15e9(%rip), %rsi      # 0x416f
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2e40
leaq 0x15d6(%rip), %rsi      # 0x4175
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2e40
movq 0x60(%rsp), %rax
leaq (%rbx,%rax,8), %rbx
leaq 0x16b2(%rip), %rsi      # 0x4273
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2d1d
leaq 0x169d(%rip), %rsi      # 0x4277
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2d1d
leaq 0x16c0(%rip), %rsi      # 0x42b3
leaq 0x18(%rsp), %rdi
callq 0x2060
movl $0x33, %r13d
leaq 0x16ac(%rip), %rbp      # 0x42b6
testl %eax, %eax
je 0x2cad
leaq 0x180d(%rip), %rsi      # 0x4426
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2cad
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x30b8
movq %rbx, %r14
cvttsd2si %xmm0, %ebp
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %esi
movl 0x38(%rsp), %edx
movl 0x3c(%rsp), %ecx
callq 0x277c
cmpl $-0x1, %eax
je 0x2d67
movl %ebp, (%r14)
movb $0x1, 0x4(%r14)
incl 0x288(%rbx)
movq 0x3355(%rip), %rdi      # 0x5fc8
leaq 0x16b3(%rip), %rsi      # 0x432d
movl $0x1c, %edx
callq 0x2130
xorl %ebp, %ebp
movq 0x333b(%rip), %rdi      # 0x5fc8
leaq 0x1792(%rip), %rsi      # 0x4426
movl $0x1, %edx
callq 0x2130
jmp 0x2cd4
movl $0x45, %r13d
leaq 0x156b(%rip), %rbp      # 0x4218
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2130
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
leaq 0x175f(%rip), %rsi      # 0x4426
movl $0x1, %edx
movq %r14, %rdi
callq 0x2130
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2cf0
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2120
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x2d0c
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2120
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0x4(%rbx)
jne 0x2d53
movq 0x329e(%rip), %rdi      # 0x5fc8
leaq 0x154a(%rip), %rsi      # 0x427b
movl $0x37, %edx
callq 0x2130
movq 0x3286(%rip), %rdi      # 0x5fc8
leaq 0x16dd(%rip), %rsi      # 0x4426
movl $0x1, %edx
callq 0x2130
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movb $0x1, 0x4(%rbx)
movl $0x4, %ebp
jmp 0x2cd4
movq 0x325a(%rip), %rdi      # 0x5fc8
leaq 0x1575(%rip), %rsi      # 0x42ea
movl $0x1a, %edx
callq 0x2130
movq 0x3242(%rip), %rdi      # 0x5fc8
leaq 0x1578(%rip), %rsi      # 0x4305
movl $0x1, %edx
callq 0x2130
movq 0x322a(%rip), %rdi      # 0x5fc8
movl %r15d, %esi
callq 0x21a0
movq %rax, %r14
leaq 0x1557(%rip), %rsi      # 0x4307
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movq %r14, %rdi
movl %r12d, %esi
callq 0x21a0
movq %rax, %r14
leaq 0x1537(%rip), %rsi      # 0x4309
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
leaq 0x1525(%rip), %rsi      # 0x430b
movl $0x21, %edx
movq %r14, %rdi
callq 0x2130
jmp 0x2cbb
movq %r15, %rdi
movq %r15, %rbx
movq %r15, %rsi
callq 0x34fe
testb %al, %al
je 0x2e23
movq %rbx, %rdi
movl $0x51, 0x288(%rbx)
callq 0x2ec6
xorl %edi, %edi
callq 0x2140
movq 0x319e(%rip), %rdi      # 0x5fc8
leaq 0x134a(%rip), %rsi      # 0x417b
callq 0x2110
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2140
movq 0x10(%rsp), %rdi
movq %rdi, %rsi
callq 0x34fe
testb %al, %al
je 0x2e67
movq 0x10(%rsp), %rdi
movl $0x51, 0x288(%rdi)
callq 0x2ec6
jmp 0x2e1c
movq 0x315a(%rip), %rdi      # 0x5fc8
leaq 0x1306(%rip), %rsi      # 0x417b
callq 0x2110
jmp 0x2e36
jmp 0x2e82
jmp 0x2e82
jmp 0x2e82
movq %rax, %r14
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2ea1
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2120
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x2ebd
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2120
movq %r14, %rdi
callq 0x21b0
nop