// File: /workspace/github_cpp_makefile_star2_O2/cb92[P]Battleship/utils.cpp
// Function: getInt(int, int)
int getInt(int min, int max)
{
	std::string retString;
	std::getline(std::cin, retString);
	bool isGoodInput=false;
	int nIter=0;
	char tempChar;
	bool isNeg=false;
	int retInt=0;

	while (!isGoodInput)
	{
		isGoodInput = true;
		// prompt fot input again if input was bad
		if (nIter>0)
		{
			std::cout<<"Bad input! Please enter an integer between "<<min;
			std::cout<<" and "<<max<<"."<<std::endl;
			std::getline(std::cin, retString);
		}
		if (retString.length()>0) 
		{
			// process the string, char by char, to see if it's a numeric
			for (int i=0; i<retString.length(); i++)
			{
				tempChar = static_cast<char>(retString[i]);
				// if the first character is a negatve, note it, and continue
				if (i==0 & tempChar=='-')
				{
					isNeg=true;
				}
				// if char is numeric, update the integer to be returned
				else 
				{
					if (tempChar>=ASCII_INT_MIN && tempChar<=ASCII_INT_MAX)
					{
						retInt = retInt*10+(static_cast<int>(tempChar)-
																ASCII_INT_MIN);
					}
					else // if any non-ints encountered, break loop
					{
						isGoodInput = false;
						break;
					}
				}
			}
		}
		// zero length inputs are bad inputs
		else
		{
			isGoodInput=false;
		}

		// if negative, mutiply by -1
		if (isGoodInput && isNeg)
		{
			retInt = (-1)*retInt;
		}
		// check that int is between limits
		if (isGoodInput && (retInt<min || retInt>max))
		{
			isGoodInput = false;
		}

		// if input was bad, reset trackers and start over again
		if (!isGoodInput) 
		{
			retInt=0;
			isNeg=false;
		}
			
		nIter++;
	}

	return retInt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebx
movl %edi, %r14d
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x3666(%rip), %rdi      # 0x7fe0
leaq -0x48(%rbp), %rsi
callq 0x2040
xorl %eax, %eax
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
testb $0x1, %al
jne 0x4a99
testl %r15d, %r15d
je 0x49fd
movq 0x362e(%rip), %rdi      # 0x7fd0
leaq 0xae5(%rip), %rsi       # 0x548e
callq 0x2160
movq %rax, %rdi
movl %r14d, %esi
callq 0x2220
movq 0x3610(%rip), %rdi      # 0x7fd0
leaq 0xaf3(%rip), %rsi       # 0x54ba
callq 0x2160
movq %rax, %rdi
movl %ebx, %esi
callq 0x2220
movq %rax, %rdi
leaq 0xaa0(%rip), %rsi       # 0x5480
callq 0x2160
movq %rax, %rdi
callq 0x20b0
movq 0x35ec(%rip), %rdi      # 0x7fe0
leaq -0x48(%rbp), %rsi
callq 0x2040
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x4a48
movq -0x48(%rbp), %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x4a4c
movb (%rcx,%rdx), %sil
testq %rdx, %rdx
sete %dil
cmpb $0x2d, %sil
sete %r8b
testb %r8b, %dil
je 0x4a2e
movb $0x1, %r12b
jmp 0x4a43
addb $-0x30, %sil
cmpb $0x9, %sil
ja 0x4a48
imull $0xa, %r13d, %edi
movzbl %sil, %r13d
addl %edi, %r13d
incq %rdx
jmp 0x4a0c
xorl %eax, %eax
jmp 0x4a4e
movb $0x1, %al
movl %r13d, %ecx
negl %ecx
testb $0x1, %r12b
cmovel %r13d, %ecx
testb %al, %al
cmovel %r13d, %ecx
cmpl %r14d, %ecx
setl %dl
cmpl %ebx, %ecx
setg %sil
orb %dl, %sil
movzbl %al, %edx
testb $0x1, %sil
movl %edx, %eax
movl $0x0, %esi
cmovnel %esi, %eax
testb %dl, %dl
cmovel %edx, %eax
andb %al, %r12b
testb %al, %al
cmovel %esi, %ecx
incl %r15d
movl %ecx, %r13d
jmp 0x498e
leaq -0x48(%rbp), %rdi
callq 0x20a0
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4ab6
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x2230