// File: /workspace/github_cpp_makefile_star2_O3/jeffchan[P]blockchain-parser/keyboard.cpp
// Function: getInputString(unsigned int&)
const char ** getInputString(uint32_t &argc)
{
	argc = 0;
	static char buf[256];
	static int index = 0;
	static const char			*argv[MAX_ARGS];

	if ( !kbhit() ) return NULL;

	char c = (char)getch();

	if ( c == 10 || c == 13 )
	{
		buf[index] = 0;

		char *scan = buf;
		while ( *scan == 32 ) scan++;	// skip leading spaces

		if ( *scan )	// if not EOS
		{
			argc = 1;
			argv[0] = scan;	// set the first argument

			while ( *scan && argc < MAX_ARGS)	// while still data and we haven't exceeded the maximum argument count.
			{
				while ( *scan && *scan != 32 ) scan++;	// scan forward to the next space
				if ( *scan == 32 )	// if we hit a space
				{
					*scan = 0; // null-terminate the argument
					scan++;	// skip to the next character
					while ( *scan == 32 ) scan++;	// skip any leading spaces
					if ( *scan )	// if there is still a valid non-space character process that as the next argument
					{
						argv[argc] = scan;
						argc++;
					}
				}
			}
		}
		printf("\r\n");
		index = 0;
		return argc ? argv : NULL;
	}
	else if ( c == 27 )
	{
		buf[index] = 0;
	}
	else if ( c == 8 )
	{
		if ( index )
		{
			index--;
			printf("%c",c);
			printf(" ");
			printf("%c",c);
		}
	}
	else
	{
		if ( c >= 32 && c <= 127 )
		{
			buf[index] = c;
			index++;
#ifdef _MSC_VER
			printf("%c",c);
#else
#endif
		}
	}

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl $0x0, (%rdi)
callq 0x15380
xorl %r14d, %r14d
testl %eax, %eax
je 0x155f6
callq 0x15604
leaq -0x19(%rbp), %r15
movl $0x1, %edx
xorl %edi, %edi
movq %r15, %rsi
callq 0x2240
cmpq $0x1, %rax
movzbl (%r15), %eax
cmovnel %r14d, %eax
movzbl %al, %ecx
cmpl $0xc, %ecx
jg 0x154ed
cmpl $0x8, %ecx
je 0x155af
cmpl $0xa, %ecx
je 0x154fb
cmpb $0x20, %al
jl 0x155f3
movslq 0xa53b(%rip), %rcx      # 0x1fa10
leaq 0xa434(%rip), %rdx      # 0x1f910
movb %al, (%rcx,%rdx)
leal 0x1(%rcx), %eax
movl %eax, 0xa528(%rip)      # 0x1fa10
jmp 0x155f3
cmpl $0x1b, %ecx
je 0x155e1
cmpl $0xd, %ecx
jne 0x154c6
movslq 0xa50e(%rip), %rcx      # 0x1fa10
leaq 0xa407(%rip), %rax      # 0x1f910
movb $0x0, (%rcx,%rax)
movzbl (%rax), %ecx
cmpl $0x20, %ecx
jne 0x1551a
incq %rax
jmp 0x1550d
testl %ecx, %ecx
jne 0x1554a
leaq 0x4549(%rip), %rdi      # 0x19a6e
callq 0x2260
movl $0x0, 0xa4dc(%rip)      # 0x1fa10
xorl %r14d, %r14d
cmpl $0x0, (%rbx)
leaq 0xa4df(%rip), %rax      # 0x1fa20
cmovneq %rax, %r14
jmp 0x155f6
movl $0x1, (%rbx)
movq %rax, 0xa4c9(%rip)      # 0x1fa20
movb (%rax), %dl
testb %dl, %dl
je 0x1551e
cmpl $0x1f, (%rbx)
ja 0x1551e
leaq 0xa4b7(%rip), %rcx      # 0x1fa20
cmpb $0x20, %dl
je 0x1557d
movzbl %dl, %edx
testl %edx, %edx
je 0x1551e
movb 0x1(%rax), %dl
incq %rax
jmp 0x15569
movb $0x0, (%rax)
movzbl 0x1(%rax), %edx
incq %rax
cmpl $0x20, %edx
je 0x15580
testl %edx, %edx
je 0x1551e
movl (%rbx), %edx
movq %rax, (%rcx,%rdx,8)
leal 0x1(%rdx), %esi
movl %esi, (%rbx)
movb (%rax), %dl
testb %dl, %dl
je 0x1551e
cmpl $0x20, %esi
jb 0x15569
jmp 0x1551e
movl 0xa45b(%rip), %eax      # 0x1fa10
testl %eax, %eax
je 0x155f3
decl %eax
movl %eax, 0xa44f(%rip)      # 0x1fa10
movl $0x8, %edi
callq 0x2210
movl $0x20, %edi
callq 0x2210
movl $0x8, %edi
callq 0x2210
jmp 0x155f3
movslq 0xa428(%rip), %rax      # 0x1fa10
leaq 0xa321(%rip), %rcx      # 0x1f910
movb $0x0, (%rax,%rcx)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq