// File: /workspace/github_cpp_makefile_star2_O1/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 0x15458
xorl %r14d, %r14d
testl %eax, %eax
je 0x156b8
callq 0x156c6
leaq -0x19(%rbp), %r15
movl $0x1, %edx
xorl %edi, %edi
movq %r15, %rsi
callq 0x2240
cmpq $0x1, %rax
movzbl (%r15), %eax
cmovnel %r14d, %eax
cmpl $0xc, %eax
jg 0x155bc
cmpl $0x8, %eax
je 0x15671
cmpl $0xa, %eax
je 0x155ca
cmpb $0x20, %al
jl 0x156b5
movslq 0xa46c(%rip), %rcx      # 0x1fa10
leaq 0xa365(%rip), %rdx      # 0x1f910
movb %al, (%rcx,%rdx)
leal 0x1(%rcx), %eax
movl %eax, 0xa459(%rip)      # 0x1fa10
jmp 0x156b5
cmpl $0x1b, %eax
je 0x156a3
cmpl $0xd, %eax
jne 0x15595
movslq 0xa43f(%rip), %rcx      # 0x1fa10
leaq 0xa338(%rip), %rax      # 0x1f910
movb $0x0, (%rcx,%rax)
movzbl (%rax), %ecx
cmpl $0x20, %ecx
jne 0x155e9
incq %rax
jmp 0x155dc
testl %ecx, %ecx
jne 0x15619
leaq 0x447a(%rip), %rdi      # 0x19a6e
callq 0x2260
movl $0x0, 0xa40d(%rip)      # 0x1fa10
xorl %r14d, %r14d
cmpl $0x0, (%rbx)
leaq 0xa410(%rip), %rax      # 0x1fa20
cmovneq %rax, %r14
jmp 0x156b8
movl $0x1, (%rbx)
movq %rax, 0xa3fa(%rip)      # 0x1fa20
cmpb $0x0, (%rax)
je 0x155ed
cmpl $0x1f, (%rbx)
ja 0x155ed
leaq 0xa3e9(%rip), %rcx      # 0x1fa20
movzbl (%rax), %edx
testl %edx, %edx
je 0x15660
cmpl $0x20, %edx
jne 0x1566c
movb $0x0, (%rax)
movzbl 0x1(%rax), %edx
incq %rax
cmpl $0x20, %edx
je 0x15646
testl %edx, %edx
je 0x15660
movl (%rbx), %edx
movq %rax, (%rcx,%rdx,8)
incl %edx
movl %edx, (%rbx)
cmpb $0x0, (%rax)
je 0x155ed
cmpl $0x20, (%rbx)
jb 0x15637
jmp 0x155ed
incq %rax
jmp 0x15637
movl 0xa399(%rip), %eax      # 0x1fa10
testl %eax, %eax
je 0x156b5
decl %eax
movl %eax, 0xa38d(%rip)      # 0x1fa10
movl $0x8, %edi
callq 0x2210
movl $0x20, %edi
callq 0x2210
movl $0x8, %edi
callq 0x2210
jmp 0x156b5
movslq 0xa366(%rip), %rax      # 0x1fa10
leaq 0xa25f(%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