// File: 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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2150
leaq -0x68(%rbp), %rdi
callq 0x2150
movq 0x5462(%rip), %rdi      # 0x7fc8
leaq 0x2567(%rip), %rsi      # 0x50d4
callq 0x2100
jmp 0x2b74
movq 0x545d(%rip), %rdi      # 0x7fd8
leaq -0x48(%rbp), %rsi
callq 0x2040
jmp 0x2b86
leaq 0x2595(%rip), %rsi      # 0x5122
leaq -0x48(%rbp), %rdi
callq 0x36e0
movb %al, -0xb1(%rbp)
jmp 0x2b9e
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x2bce
jmp 0x2baa
leaq 0x2572(%rip), %rsi      # 0x5123
leaq -0x48(%rbp), %rdi
callq 0x36e0
movb %al, -0xb2(%rbp)
jmp 0x2bc2
movb -0xb2(%rbp), %al
testb $0x1, %al
jne 0x2bce
jmp 0x2c04
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x78(%rbp)
jmp 0x3311
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2090
leaq -0x48(%rbp), %rdi
callq 0x2090
jmp 0x332f
leaq 0x251c(%rip), %rsi      # 0x5127
leaq -0x48(%rbp), %rdi
callq 0x36e0
movb %al, -0xb3(%rbp)
jmp 0x2c1c
movb -0xb3(%rbp), %al
testb $0x1, %al
jne 0x2c4c
jmp 0x2c28
leaq 0x24fe(%rip), %rsi      # 0x512d
leaq -0x48(%rbp), %rdi
callq 0x36e0
movb %al, -0xb4(%rbp)
jmp 0x2c40
movb -0xb4(%rbp), %al
testb $0x1, %al
jne 0x2c4c
jmp 0x2cb2
movq -0xb0(%rbp), %rsi
movq %rsi, %rdi
callq 0x4010
movb %al, -0xb5(%rbp)
jmp 0x2c63
movb -0xb5(%rbp), %al
andb $0x1, %al
movb %al, -0x79(%rbp)
testb $0x1, -0x79(%rbp)
jne 0x2c93
movq 0x534d(%rip), %rdi      # 0x7fc8
leaq 0x24b1(%rip), %rsi      # 0x5133
callq 0x2100
jmp 0x2c89
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2120
movq -0xb0(%rbp), %rdi
movl $0x51, 0x288(%rdi)
callq 0x3340
jmp 0x2cab
xorl %edi, %edi
callq 0x2120
leaq -0x48(%rbp), %rdi
callq 0x20c0
movq %rax, -0x88(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x3710
movsbl (%rax), %eax
cmpl $0x2c, %eax
je 0x2d41
leaq -0x88(%rbp), %rdi
callq 0x3710
movsbl (%rax), %eax
cmpl $0x28, %eax
je 0x2cfe
leaq -0x88(%rbp), %rdi
callq 0x3710
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x2d00
jmp 0x2d2a
cmpl $0x1, -0x24(%rbp)
jle 0x2d08
jmp 0x2d41
leaq -0x88(%rbp), %rdi
callq 0x3710
movb (%rax), %cl
movslq -0x24(%rbp), %rax
movb %cl, -0x8a(%rbp,%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x3730
movq %rax, -0x98(%rbp)
jmp 0x2cc2
leaq -0x8a(%rbp), %rdi
callq 0x2180
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x3710
movsbl (%rax), %eax
cmpl $0x29, %eax
je 0x2ddf
leaq -0x88(%rbp), %rdi
callq 0x3710
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0x2d9c
leaq -0x88(%rbp), %rdi
callq 0x3710
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x2d9e
jmp 0x2dc8
cmpl $0x1, -0x24(%rbp)
jle 0x2da6
jmp 0x2ddf
leaq -0x88(%rbp), %rdi
callq 0x3710
movb (%rax), %cl
movslq -0x24(%rbp), %rax
movb %cl, -0x8a(%rbp,%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x3730
movq %rax, -0xa0(%rbp)
jmp 0x2d60
leaq -0x8a(%rbp), %rdi
callq 0x2180
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x8, -0x14(%rbp)
jg 0x2e0f
cmpl $0x0, -0x14(%rbp)
jl 0x2e0f
cmpl $0x0, -0x18(%rbp)
jl 0x2e0f
cmpl $0x8, -0x18(%rbp)
jle 0x2e53
movq 0x51b2(%rip), %rdi      # 0x7fc8
leaq 0x2372(%rip), %rsi      # 0x518f
callq 0x2100
movq %rax, -0xc0(%rbp)
jmp 0x2e2b
movq -0xc0(%rbp), %rdi
leaq 0x25a5(%rip), %rsi      # 0x53de
callq 0x2100
jmp 0x2e40
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl $0x1, -0x78(%rbp)
jmp 0x3311
movq -0xb0(%rbp), %rdi
movslq -0x14(%rbp), %rax
imulq $0x48, %rax, %rax
addq %rax, %rdi
movslq -0x18(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x23b0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2ec3
movq 0x5142(%rip), %rdi      # 0x7fc8
leaq 0x2343(%rip), %rsi      # 0x51d0
callq 0x2100
movq %rax, -0xc8(%rbp)
jmp 0x2e9b
movq -0xc8(%rbp), %rdi
leaq 0x2535(%rip), %rsi      # 0x53de
callq 0x2100
jmp 0x2eb0
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl $0x1, -0x78(%rbp)
jmp 0x3311
movq 0x50fe(%rip), %rdi      # 0x7fc8
leaq 0x2345(%rip), %rsi      # 0x5216
callq 0x2100
jmp 0x2ed8
movq 0x50f9(%rip), %rdi      # 0x7fd8
leaq -0x68(%rbp), %rsi
callq 0x2040
jmp 0x2eea
leaq 0x2232(%rip), %rsi      # 0x5123
leaq -0x68(%rbp), %rdi
callq 0x36e0
movb %al, -0xc9(%rbp)
jmp 0x2f02
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x2f32
jmp 0x2f0e
leaq 0x220d(%rip), %rsi      # 0x5122
leaq -0x68(%rbp), %rdi
callq 0x36e0
movb %al, -0xca(%rbp)
jmp 0x2f26
movb -0xca(%rbp), %al
testb $0x1, %al
jne 0x2f32
jmp 0x2f45
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x78(%rbp)
jmp 0x3311
leaq 0x21db(%rip), %rsi      # 0x5127
leaq -0x68(%rbp), %rdi
callq 0x36e0
movb %al, -0xcb(%rbp)
jmp 0x2f5d
movb -0xcb(%rbp), %al
testb $0x1, %al
jne 0x2f8d
jmp 0x2f69
leaq 0x21bd(%rip), %rsi      # 0x512d
leaq -0x68(%rbp), %rdi
callq 0x36e0
movb %al, -0xcc(%rbp)
jmp 0x2f81
movb -0xcc(%rbp), %al
testb $0x1, %al
jne 0x2f8d
jmp 0x2ff9
movq -0xb0(%rbp), %rsi
movq %rsi, %rdi
callq 0x4010
movb %al, -0xcd(%rbp)
jmp 0x2fa4
movb -0xcd(%rbp), %al
andb $0x1, %al
movb %al, -0xa1(%rbp)
testb $0x1, -0xa1(%rbp)
jne 0x2fda
movq 0x5006(%rip), %rdi      # 0x7fc8
leaq 0x216a(%rip), %rsi      # 0x5133
callq 0x2100
jmp 0x2fd0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2120
movq -0xb0(%rbp), %rdi
movl $0x51, 0x288(%rdi)
callq 0x3340
jmp 0x2ff2
xorl %edi, %edi
callq 0x2120
leaq 0x222b(%rip), %rsi      # 0x522b
leaq -0x68(%rbp), %rdi
callq 0x36e0
movb %al, -0xce(%rbp)
jmp 0x3011
movb -0xce(%rbp), %al
testb $0x1, %al
jne 0x3044
jmp 0x301d
leaq 0x220b(%rip), %rsi      # 0x522f
leaq -0x68(%rbp), %rdi
callq 0x36e0
movb %al, -0xcf(%rbp)
jmp 0x3035
movb -0xcf(%rbp), %al
testb $0x1, %al
jne 0x3044
jmp 0x30dc
movq -0xb0(%rbp), %rdi
movslq -0x14(%rbp), %rax
imulq $0x48, %rax, %rax
addq %rax, %rdi
movslq -0x18(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0x23b0
testb $0x1, %al
jne 0x309d
movq 0x4f57(%rip), %rdi      # 0x7fc8
leaq 0x21bb(%rip), %rsi      # 0x5233
callq 0x2100
movq %rax, -0xd8(%rbp)
jmp 0x3086
movq -0xd8(%rbp), %rdi
leaq 0x234a(%rip), %rsi      # 0x53de
callq 0x2100
jmp 0x309b
jmp 0x309d
movq -0xb0(%rbp), %rdi
movslq -0x14(%rbp), %rax
imulq $0x48, %rax, %rax
addq %rax, %rdi
movslq -0x18(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0x2370
movl $0x4, -0x4(%rbp)
movl $0x1, -0x78(%rbp)
jmp 0x3311
leaq 0x2188(%rip), %rsi      # 0x526b
leaq -0x68(%rbp), %rdi
callq 0x36e0
movb %al, -0xd9(%rbp)
jmp 0x30f4
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0x3124
jmp 0x3100
leaq 0x22d7(%rip), %rsi      # 0x53de
leaq -0x68(%rbp), %rdi
callq 0x36e0
movb %al, -0xda(%rbp)
jmp 0x3118
movb -0xda(%rbp), %al
testb $0x1, %al
jne 0x3124
jmp 0x3168
movq 0x4e9d(%rip), %rdi      # 0x7fc8
leaq 0x213c(%rip), %rsi      # 0x526e
callq 0x2100
movq %rax, -0xe8(%rbp)
jmp 0x3140
movq -0xe8(%rbp), %rdi
leaq 0x2290(%rip), %rsi      # 0x53de
callq 0x2100
jmp 0x3155
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl $0x1, -0x78(%rbp)
jmp 0x3311
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
callq 0x3770
movsd %xmm0, -0xf0(%rbp)
jmp 0x317f
movq -0xb0(%rbp), %rdi
movsd -0xf0(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %esi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
callq 0x2830
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x3295
movq 0x4e11(%rip), %rdi      # 0x7fc8
leaq 0x20e4(%rip), %rsi      # 0x52a2
callq 0x2100
movq %rax, -0xf8(%rbp)
jmp 0x31cc
movq -0xf8(%rbp), %rdi
leaq 0x20e3(%rip), %rsi      # 0x52bd
callq 0x2100
movq %rax, -0x100(%rbp)
jmp 0x31e8
movq -0x100(%rbp), %rdi
movl -0x14(%rbp), %esi
incl %esi
callq 0x2190
movq %rax, -0x108(%rbp)
jmp 0x3202
movq -0x108(%rbp), %rdi
leaq 0x20af(%rip), %rsi      # 0x52bf
callq 0x2100
movq %rax, -0x110(%rbp)
jmp 0x321e
movq -0x110(%rbp), %rdi
movl -0x18(%rbp), %esi
incl %esi
callq 0x2190
movq %rax, -0x118(%rbp)
jmp 0x3238
movq -0x118(%rbp), %rdi
leaq 0x207b(%rip), %rsi      # 0x52c1
callq 0x2100
movq %rax, -0x120(%rbp)
jmp 0x3254
movq -0x120(%rbp), %rdi
leaq 0x2061(%rip), %rsi      # 0x52c3
callq 0x2100
movq %rax, -0x128(%rbp)
jmp 0x3270
movq -0x128(%rbp), %rdi
leaq 0x2160(%rip), %rsi      # 0x53de
callq 0x2100
jmp 0x3285
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl $0x1, -0x78(%rbp)
jmp 0x3311
movq -0xb0(%rbp), %rax
movslq -0x14(%rbp), %rcx
leaq (%rcx,%rcx,8), %rcx
leaq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
leaq (%rax,%rcx,8), %rdi
movl -0x1c(%rbp), %esi
movl $0x1, %edx
callq 0x2370
movq -0xb0(%rbp), %rax
movl 0x288(%rax), %ecx
incl %ecx
movl %ecx, 0x288(%rax)
movq 0x4cef(%rip), %rdi      # 0x7fc8
leaq 0x2005(%rip), %rsi      # 0x52e5
callq 0x2100
movq %rax, -0x130(%rbp)
jmp 0x32ee
movq -0x130(%rbp), %rdi
leaq 0x20e2(%rip), %rsi      # 0x53de
callq 0x2100
jmp 0x3303
movl $0x0, -0x4(%rbp)
movl $0x1, -0x78(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2090
leaq -0x48(%rbp), %rdi
callq 0x2090
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x21a0
nopl (%rax,%rax)