// File: /workspace/github_cpp_makefile_star2_O1/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 0x364c(%rip), %r14      # 0x5fc8
leaq 0x1751(%rip), %rsi      # 0x40d4
movl $0x4d, %edx
movq %r14, %rdi
callq 0x2130
movq 0x3641(%rip), %rdi      # 0x5fd8
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %edx
movq 0x3626(%rip), %r13      # 0x5fd8
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
callq 0x21c0
leaq 0x175c(%rip), %rsi      # 0x4122
leaq 0x40(%rsp), %rdi
callq 0x2060
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x2cc4
leaq 0x173f(%rip), %rsi      # 0x4123
leaq 0x40(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2cc4
leaq 0x172a(%rip), %rsi      # 0x4127
leaq 0x40(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2de8
leaq 0x1717(%rip), %rsi      # 0x412d
leaq 0x40(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2de8
movq 0x40(%rsp), %rbx
xorl %eax, %eax
movzbl (%rbx), %ecx
cmpl $0x20, %ecx
je 0x2a4e
cmpl $0x28, %ecx
je 0x2a4e
cmpl $0x2c, %ecx
je 0x2a53
cmpl $0x1, %eax
jg 0x2a53
movl %eax, %edx
movb %cl, 0xe(%rsp,%rdx)
incl %eax
incq %rbx
jmp 0x2a2f
movq %r15, 0x10(%rsp)
leaq 0xe(%rsp), %rdi
callq 0x2190
movl %eax, %r15d
leal -0x1(%r15), %ebp
xorl %eax, %eax
movzbl (%rbx), %ecx
cmpl $0x20, %ecx
je 0x2a8a
cmpl $0x2c, %ecx
je 0x2a8a
cmpl $0x29, %ecx
je 0x2a8f
cmpl $0x1, %eax
jg 0x2a8f
movl %eax, %edx
movb %cl, 0xe(%rsp,%rdx)
incl %eax
incq %rbx
jmp 0x2a6b
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 0x2ac9
movl $0x40, %r13d
leaq 0x16cb(%rip), %rbp      # 0x418f
jmp 0x2c9d
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 0x2c90
movl %ebp, 0x38(%rsp)
movq 0x34ca(%rip), %rdi      # 0x5fc8
leaq 0x1711(%rip), %rsi      # 0x4216
movl $0x14, %edx
callq 0x2130
movq (%r13), %rax
addq -0x18(%rax), %r13
movq %r13, %rdi
movl $0xa, %esi
callq 0x2100
movsbl %al, %edx
movq 0x34aa(%rip), %rdi      # 0x5fd8
leaq 0x18(%rsp), %rsi
callq 0x21c0
leaq 0x15e4(%rip), %rsi      # 0x4123
leaq 0x18(%rsp), %rdi
callq 0x2060
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x2cc4
leaq 0x15c5(%rip), %rsi      # 0x4122
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2cc4
leaq 0x15b1(%rip), %rsi      # 0x4127
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2e30
leaq 0x159e(%rip), %rsi      # 0x412d
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2e30
movq 0x60(%rsp), %rax
leaq (%rbx,%rax,8), %rbx
leaq 0x167a(%rip), %rsi      # 0x422b
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2d0d
leaq 0x1665(%rip), %rsi      # 0x422f
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2d0d
leaq 0x1688(%rip), %rsi      # 0x426b
leaq 0x18(%rsp), %rdi
callq 0x2060
movl $0x33, %r13d
leaq 0x1674(%rip), %rbp      # 0x426e
testl %eax, %eax
je 0x2c9d
leaq 0x17d5(%rip), %rsi      # 0x43de
leaq 0x18(%rsp), %rdi
callq 0x2060
testl %eax, %eax
je 0x2c9d
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x30ba
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 0x2776
cmpl $-0x1, %eax
je 0x2d57
movl %ebp, (%r14)
movb $0x1, 0x4(%r14)
incl 0x288(%rbx)
movq 0x3365(%rip), %rdi      # 0x5fc8
leaq 0x167b(%rip), %rsi      # 0x42e5
movl $0x1c, %edx
callq 0x2130
xorl %ebp, %ebp
movq 0x334b(%rip), %rdi      # 0x5fc8
leaq 0x175a(%rip), %rsi      # 0x43de
movl $0x1, %edx
callq 0x2130
jmp 0x2cc4
movl $0x45, %r13d
leaq 0x1533(%rip), %rbp      # 0x41d0
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2130
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
leaq 0x1727(%rip), %rsi      # 0x43de
movl $0x1, %edx
movq %r14, %rdi
callq 0x2130
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2ce0
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2120
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x2cfc
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 0x2d43
movq 0x32ae(%rip), %rdi      # 0x5fc8
leaq 0x1512(%rip), %rsi      # 0x4233
movl $0x37, %edx
callq 0x2130
movq 0x3296(%rip), %rdi      # 0x5fc8
leaq 0x16a5(%rip), %rsi      # 0x43de
movl $0x1, %edx
callq 0x2130
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movb $0x1, 0x4(%rbx)
movl $0x4, %ebp
jmp 0x2cc4
movq 0x326a(%rip), %rdi      # 0x5fc8
leaq 0x153d(%rip), %rsi      # 0x42a2
movl $0x1a, %edx
callq 0x2130
movq 0x3252(%rip), %rdi      # 0x5fc8
leaq 0x1540(%rip), %rsi      # 0x42bd
movl $0x1, %edx
callq 0x2130
movq 0x323a(%rip), %rdi      # 0x5fc8
movl %r15d, %esi
callq 0x21a0
movq %rax, %r14
leaq 0x151f(%rip), %rsi      # 0x42bf
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movq %r14, %rdi
movl %r12d, %esi
callq 0x21a0
movq %rax, %r14
leaq 0x14ff(%rip), %rsi      # 0x42c1
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
leaq 0x14ed(%rip), %rsi      # 0x42c3
movl $0x21, %edx
movq %r14, %rdi
callq 0x2130
jmp 0x2cab
movq %r15, %rdi
movq %r15, %rbx
movq %r15, %rsi
callq 0x3528
testb %al, %al
je 0x2e13
movq %rbx, %rdi
movl $0x51, 0x288(%rbx)
callq 0x2eb6
xorl %edi, %edi
callq 0x2140
movq 0x31ae(%rip), %rdi      # 0x5fc8
leaq 0x1312(%rip), %rsi      # 0x4133
callq 0x2110
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2140
movq 0x10(%rsp), %rdi
movq %rdi, %rsi
callq 0x3528
testb %al, %al
je 0x2e57
movq 0x10(%rsp), %rdi
movl $0x51, 0x288(%rdi)
callq 0x2eb6
jmp 0x2e0c
movq 0x316a(%rip), %rdi      # 0x5fc8
leaq 0x12ce(%rip), %rsi      # 0x4133
callq 0x2110
jmp 0x2e26
jmp 0x2e72
jmp 0x2e72
jmp 0x2e72
movq %rax, %r14
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2e91
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2120
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x2ead
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2120
movq %r14, %rdi
callq 0x21b0
nop