// File: 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
subq $0x90, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
leaq -0x28(%rbp), %rdi
movq %rdi, -0x50(%rbp)
callq 0x2270
movq -0x50(%rbp), %rsi
movq 0x53e7(%rip), %rdi      # 0xcfe0
callq 0x2060
jmp 0x7c00
movb $0x0, -0x35(%rbp)
movl $0x0, -0x3c(%rbp)
movb $0x0, -0x3e(%rbp)
movl $0x0, -0x44(%rbp)
movb -0x35(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7c24
jmp 0x7deb
movb $0x1, -0x35(%rbp)
cmpl $0x0, -0x3c(%rbp)
jle 0x7cda
movq 0x538f(%rip), %rdi      # 0xcfc8
leaq 0x184e(%rip), %rsi      # 0x948e
callq 0x2180
movq %rax, -0x58(%rbp)
jmp 0x7c4b
movq -0x58(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0x22c0
jmp 0x7c59
movq 0x5368(%rip), %rdi      # 0xcfc8
leaq 0x1853(%rip), %rsi      # 0x94ba
callq 0x2180
movq %rax, -0x60(%rbp)
jmp 0x7c72
movq -0x60(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x22c0
movq %rax, -0x68(%rbp)
jmp 0x7c84
movq -0x68(%rbp), %rdi
leaq 0x17f1(%rip), %rsi      # 0x9480
callq 0x2180
movq %rax, -0x70(%rbp)
jmp 0x7c9a
movq -0x70(%rbp), %rdi
movq 0x5313(%rip), %rsi      # 0xcfb8
callq 0x21b0
jmp 0x7cac
movq 0x532d(%rip), %rdi      # 0xcfe0
leaq -0x28(%rbp), %rsi
callq 0x2060
jmp 0x7cbe
jmp 0x7cda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x20e0
jmp 0x7e0c
leaq -0x28(%rbp), %rdi
callq 0x2290
cmpq $0x0, %rax
jbe 0x7d98
movl $0x0, -0x48(%rbp)
movslq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x2290
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x7d96
movslq -0x48(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x2310
movq %rax, -0x80(%rbp)
jmp 0x7d28
movq -0x80(%rbp), %rax
movb (%rax), %al
movb %al, -0x3d(%rbp)
cmpl $0x0, -0x48(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movsbl -0x3d(%rbp), %ecx
cmpl $0x2d, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x7d5a
movb $0x1, -0x3e(%rbp)
jmp 0x7d86
movsbl -0x3d(%rbp), %eax
cmpl $0x30, %eax
jl 0x7d7e
movsbl -0x3d(%rbp), %eax
cmpl $0x39, %eax
jg 0x7d7e
imull $0xa, -0x44(%rbp), %eax
movsbl -0x3d(%rbp), %ecx
subl $0x30, %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
jmp 0x7d84
movb $0x0, -0x35(%rbp)
jmp 0x7d96
jmp 0x7d86
jmp 0x7d88
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x7cf4
jmp 0x7d9c
movb $0x0, -0x35(%rbp)
testb $0x1, -0x35(%rbp)
je 0x7db2
testb $0x1, -0x3e(%rbp)
je 0x7db2
imull $0xffffffff, -0x44(%rbp), %eax # imm = 0xFFFFFFFF
movl %eax, -0x44(%rbp)
testb $0x1, -0x35(%rbp)
je 0x7dcc
movl -0x44(%rbp), %eax
cmpl -0x4(%rbp), %eax
jl 0x7dc8
movl -0x44(%rbp), %eax
cmpl -0x8(%rbp), %eax
jle 0x7dcc
movb $0x0, -0x35(%rbp)
testb $0x1, -0x35(%rbp)
jne 0x7ddd
movl $0x0, -0x44(%rbp)
movb $0x0, -0x3e(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x7c16
movl -0x44(%rbp), %eax
movl %eax, -0x84(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x20e0
movl -0x84(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x22d0
nopw %cs:(%rax,%rax)