// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %rdi, %rbx
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
movq 0x3852(%rip), %r14      # 0x4fc8
leaq 0x1957(%rip), %rsi      # 0x30d4
movq %r14, %rdi
callq 0x10f0
movq 0x384c(%rip), %rdi      # 0x4fd8
leaq 0x30(%rsp), %rsi
callq 0x1040
leaq 0x1985(%rip), %rsi      # 0x3122
leaq 0x30(%rsp), %rdi
callq 0x1d53
pushq $-0x1
popq %r13
testb %al, %al
jne 0x19e5
leaq 0x1969(%rip), %rsi      # 0x3123
leaq 0x30(%rsp), %rdi
callq 0x1d53
testb %al, %al
jne 0x19e5
leaq 0x1954(%rip), %rsi      # 0x3127
leaq 0x30(%rsp), %rdi
callq 0x1d53
testb %al, %al
jne 0x1b06
leaq 0x1941(%rip), %rsi      # 0x312d
leaq 0x30(%rsp), %rdi
callq 0x1d53
testb %al, %al
jne 0x1b06
movq 0x30(%rsp), %r12
incq %r12
xorl %eax, %eax
movzbl -0x1(%r12), %ebp
cmpl $0x20, %ebp
je 0x182b
cmpl $0x28, %ebp
je 0x182b
cmpl $0x2c, %ebp
je 0x1830
cmpl $0x1, %eax
jg 0x1830
movl %eax, %ecx
movb %bpl, 0x6(%rsp,%rcx)
incl %eax
incq %r12
jmp 0x1808
leaq 0x6(%rsp), %rdi
callq 0x1150
movl %eax, %r15d
leal -0x1(%r15), %r13d
xorl %eax, %eax
cmpb $0x20, %bpl
je 0x1865
movzbl %bpl, %ecx
cmpl $0x2c, %ecx
je 0x1865
cmpl $0x29, %ecx
je 0x186e
cmpl $0x1, %eax
jg 0x186e
movl %eax, %ecx
movb %bpl, 0x6(%rsp,%rcx)
incl %eax
movb (%r12), %bpl
incq %r12
jmp 0x1843
leaq 0x6(%rsp), %rdi
callq 0x1150
movl %r15d, %ecx
addl $-0xa, %ecx
cmpl $-0x9, %ecx
setb %dl
leal -0xa(%rax), %ecx
cmpl $-0x9, %ecx
setb %cl
orb %dl, %cl
je 0x189d
leaq 0x18f7(%rip), %r13      # 0x318f
jmp 0x19c7
leal -0x1(%rax), %edx
movl %r13d, %ecx
movl %edx, 0xc(%rsp)
movl %edx, %ebp
imulq $0x48, %rcx, %r12
addq %rbx, %r12
cmpb $0x1, 0x4(%r12,%rbp,8)
jne 0x19c0
movl %r13d, 0x8(%rsp)
movq %rax, 0x50(%rsp)
movq 0x36fb(%rip), %r14      # 0x4fc8
leaq 0x1942(%rip), %rsi      # 0x3216
movq %r14, %rdi
callq 0x10f0
movq 0x36f5(%rip), %rdi      # 0x4fd8
leaq 0x10(%rsp), %rsi
callq 0x1040
leaq 0x182f(%rip), %rsi      # 0x3123
leaq 0x10(%rsp), %rdi
callq 0x1d53
pushq $-0x1
popq %r13
testb %al, %al
jne 0x19e5
leaq 0x1811(%rip), %rsi      # 0x3122
leaq 0x10(%rsp), %rdi
callq 0x1d53
testb %al, %al
jne 0x19e5
leaq 0x17fd(%rip), %rsi      # 0x3127
leaq 0x10(%rsp), %rdi
callq 0x1d53
testb %al, %al
jne 0x1b49
leaq 0x17ea(%rip), %rsi      # 0x312d
leaq 0x10(%rsp), %rdi
callq 0x1d53
testb %al, %al
jne 0x1b49
leaq (%r12,%rbp,8), %r12
leaq 0x18cb(%rip), %rsi      # 0x322b
leaq 0x10(%rsp), %rdi
callq 0x1d53
testb %al, %al
jne 0x1987
leaq 0x18ba(%rip), %rsi      # 0x322f
leaq 0x10(%rsp), %rdi
callq 0x1d53
testb %al, %al
je 0x1a0b
cmpb $0x0, 0x4(%r12)
jne 0x19b1
movq 0x3632(%rip), %rdi      # 0x4fc8
leaq 0x1896(%rip), %rsi      # 0x3233
callq 0x10f0
leaq 0x1a35(%rip), %rsi      # 0x33de
movq %rax, %rdi
callq 0x10f0
orl $-0x1, (%r12)
movb $0x1, 0x4(%r12)
pushq $0x4
jmp 0x19e3
leaq 0x1809(%rip), %r13      # 0x31d0
movq %r14, %rdi
movq %r13, %rsi
callq 0x10f0
leaq 0x1a05(%rip), %rsi      # 0x33de
movq %rax, %rdi
callq 0x10f0
pushq $-0x2
popq %r13
leaq 0x10(%rsp), %rdi
callq 0x1070
leaq 0x30(%rsp), %rdi
callq 0x1070
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1859(%rip), %rsi      # 0x326b
leaq 0x10(%rsp), %rdi
callq 0x1d53
leaq 0x184b(%rip), %r13      # 0x326e
testb %al, %al
jne 0x19c7
leaq 0x19b0(%rip), %rsi      # 0x33de
leaq 0x10(%rsp), %rdi
callq 0x1d53
testb %al, %al
jne 0x19c7
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x1d60
cvttsd2si %xmm0, %r14d
movq %rbx, %rdi
movl %r14d, %esi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
callq 0x15b8
cmpl $-0x1, %eax
je 0x1a9f
movl %r14d, (%r12)
movb $0x1, 0x4(%r12)
incl 0x288(%rbx)
movq 0x354c(%rip), %rdi      # 0x4fc8
leaq 0x1862(%rip), %rsi      # 0x32e5
callq 0x10f0
xorl %r13d, %r13d
leaq 0x194c(%rip), %rsi      # 0x33de
movq %rax, %rdi
callq 0x10f0
jmp 0x19e5
movq 0x3522(%rip), %rdi      # 0x4fc8
leaq 0x17f5(%rip), %rsi      # 0x32a2
callq 0x10f0
leaq 0x1804(%rip), %rsi      # 0x32bd
movq %rax, %rdi
callq 0x10f0
movq %rax, %rdi
movl %r15d, %esi
callq 0x1160
leaq 0x17ec(%rip), %rsi      # 0x32bf
movq %rax, %rdi
callq 0x10f0
movq %rax, %rdi
movq 0x50(%rsp), %rsi
callq 0x1160
leaq 0x17d2(%rip), %rsi      # 0x32c1
movq %rax, %rdi
callq 0x10f0
movq %rax, %r14
leaq 0x17c2(%rip), %r13      # 0x32c3
jmp 0x19c7
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x2190
testb %al, %al
je 0x1b2e
movl $0x51, 0x288(%rbx)
movq %rbx, %rdi
callq 0x1ba6
xorl %edi, %edi
callq 0x1100
movq 0x3493(%rip), %rdi      # 0x4fc8
leaq 0x15f7(%rip), %rsi      # 0x3133
callq 0x10f0
pushq $-0x1
popq %rdi
callq 0x1100
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x2190
testb %al, %al
je 0x1b6c
movl $0x51, 0x288(%rbx)
movq %rbx, %rdi
callq 0x1ba6
jmp 0x1b27
movq 0x3455(%rip), %rdi      # 0x4fc8
leaq 0x15b9(%rip), %rsi      # 0x3133
callq 0x10f0
jmp 0x1b41
jmp 0x1b87
jmp 0x1b87
jmp 0x1b87
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x1070
leaq 0x30(%rsp), %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x1170