// File: /workspace/github_cpp_makefile_star2_O2/exrd[P]neteruhsp/neteruhsp/neteruhsp.cc
// Function: neteruhsp::(anonymous namespace)::command_input(neteruhsp::execute_environment_t*, neteruhsp::execute_status_t*, int)
void command_input( execute_environment_t* e, execute_status_t* s, int arg_num )
{
	if ( arg_num < 2 )
	{
		raise_error( "input：引数がたりません" );
	}
	if ( arg_num > 3 )
	{
		raise_error( "input：引数が多すぎます" );
	}

	const auto arg_start = -arg_num;
	const auto v = stack_peek( s->stack_, arg_start );
	if ( v->type_ != VALUE_VARIABLE )
	{
		raise_error( "input：対象が変数ではありません" );
	}
	if ( v->index_ > 0 )
	{
		raise_error( "input：対象の変数が配列として指定されています" );
	}

	const auto n = stack_peek( s->stack_, arg_start +1 );
	const auto len = value_calc_int( *n ) +1;

	const auto mode = ( arg_num>2 ? value_calc_int( *stack_peek( s->stack_, arg_start +2 ) ) : 0 );

	auto buf = create_string( len );
	int w =0;
	for( ; ; )
	{
		if ( w >= len )
		{ break; }

		const auto c = getchar();
		if ( c == EOF )
		{ break; }

		const auto ch = static_cast<char>( c );

		if ( mode==1 && ch=='\n' )
		{ break; }

		if ( mode==2 )
		{
			if ( ch == '\r' )
			{
				const auto nc =getchar();
				if ( static_cast<char>(nc) == '\n' )
				{ break; }
				ungetc( nc, stdin );
			}
			else if ( ch == '\n' )
			{ break; }
		}

		buf[w] = static_cast<char>( ch );
		++w;
	}
	buf[w] = '\0';

	auto t = create_value_move( buf );
	variable_set( e->variable_table_, *t, v->variable_->name_, 0 );
	destroy_value( t );

	s->strsize_ = w;

	stack_pop( s->stack_, arg_num );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x1, %edx
jle 0x8ed2
movl %edx, %r14d
cmpl $0x4, %edx
jae 0x8edb
movq %rsi, %r12
movq %rdi, %rbx
movl %r14d, %esi
negl %esi
movq (%r12), %rdi
callq 0x6d39
cmpl $0x4, (%rax)
jne 0x8ee4
cmpl $0x0, 0x10(%rax)
jg 0x8eed
movq %rax, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq (%r12), %rdi
pushq $0x1
popq %rsi
subl %r14d, %esi
callq 0x6d39
movq %rax, %rdi
callq 0x4834
movl %eax, %r15d
leal 0x1(%r15), %ebp
xorl %ebx, %ebx
cmpl $0x2, %r14d
je 0x8dfa
movq (%r12), %rdi
pushq $0x2
popq %rsi
subl %r14d, %esi
callq 0x6d39
movq %rax, %rdi
callq 0x4834
movl %eax, %ebx
movq %r12, 0x20(%rsp)
movl %r14d, 0xc(%rsp)
movslq %ebp, %rdi
callq 0x2948
movq %rax, %r13
movslq %r15d, %r14
xorl %r12d, %r12d
movl %ebx, %ebp
xorl $0x1, %ebp
cmpq %r14, %r12
jg 0x8e74
callq 0x2200
cmpl $-0x1, %eax
je 0x8e74
movl %eax, %r15d
shll $0x18, %eax
movl %eax, %ecx
xorl $0xa000000, %ecx        # imm = 0xA000000
orl %ebp, %ecx
je 0x8e74
cmpl $0x2, %ebx
jne 0x8e6a
cmpl $0xd000000, %eax        # imm = 0xD000000
jne 0x8e63
callq 0x2200
cmpb $0xa, %al
je 0x8e74
movq 0xc181(%rip), %rcx      # 0x14fd8
movq (%rcx), %rsi
movl %eax, %edi
callq 0x2070
jmp 0x8e6a
cmpl $0xa000000, %eax        # imm = 0xA000000
je 0x8e74
movb %r15b, (%r13,%r12)
incq %r12
jmp 0x8e1a
movb $0x0, (%r13,%r12)
movq %r13, %rdi
callq 0x6206
movq %rax, %r15
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x570b
movq %r15, %rdi
callq 0x4738
movq 0x20(%rsp), %rax
movl %r12d, 0x1b0(%rax)
movq (%rax), %rdi
movl 0xc(%rsp), %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c55
leaq 0x673c(%rip), %rdi      # 0xf615
jmp 0x8ef4
leaq 0x6754(%rip), %rdi      # 0xf636
jmp 0x8ef4
leaq 0x676c(%rip), %rdi      # 0xf657
jmp 0x8ef4
leaq 0x6790(%rip), %rdi      # 0xf684
xorl %eax, %eax
callq 0x326e