// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpl $0x2, -0x14(%rbp)
jge 0xf447
leaq 0x7471(%rip), %rdi      # 0x168b1
movb $0x0, %al
callq 0x4cd0
cmpl $0x3, -0x14(%rbp)
jle 0xf45b
leaq 0x747e(%rip), %rdi      # 0x168d2
movb $0x0, %al
callq 0x4cd0
xorl %eax, %eax
subl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x18(%rbp), %esi
callq 0xbca0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x4, (%rax)
je 0xf48d
leaq 0x746d(%rip), %rdi      # 0x168f3
movb $0x0, %al
callq 0x4cd0
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0xf4a5
leaq 0x7482(%rip), %rdi      # 0x16920
movb $0x0, %al
callq 0x4cd0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x18(%rbp), %esi
addl $0x1, %esi
callq 0xbca0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x79c0
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x2, -0x14(%rbp)
jle 0xf4ef
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x18(%rbp), %esi
addl $0x2, %esi
callq 0xbca0
movq %rax, %rdi
callq 0x79c0
movl %eax, -0x54(%rbp)
jmp 0xf4f6
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0xf4f6
movl -0x54(%rbp), %eax
movl %eax, -0x30(%rbp)
movslq -0x2c(%rbp), %rdi
callq 0x3b30
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jl 0xf51d
jmp 0xf5a7
callq 0x3200
movl %eax, -0x40(%rbp)
cmpl $-0x1, -0x40(%rbp)
jne 0xf52d
jmp 0xf5a7
movl -0x40(%rbp), %eax
movb %al, -0x41(%rbp)
cmpl $0x1, -0x30(%rbp)
jne 0xf544
movsbl -0x41(%rbp), %eax
cmpl $0xa, %eax
jne 0xf544
jmp 0xf5a7
cmpl $0x2, -0x30(%rbp)
jne 0xf58b
movsbl -0x41(%rbp), %eax
cmpl $0xd, %eax
jne 0xf57c
callq 0x3200
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movsbl %al, %eax
cmpl $0xa, %eax
jne 0xf568
jmp 0xf5a7
movl -0x48(%rbp), %edi
movq 0xca66(%rip), %rax      # 0x1bfd8
movq (%rax), %rsi
callq 0x3070
jmp 0xf589
movsbl -0x41(%rbp), %eax
cmpl $0xa, %eax
jne 0xf587
jmp 0xf5a7
jmp 0xf589
jmp 0xf58b
movb -0x41(%rbp), %dl
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xf510
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
callq 0xa820
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x50(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
xorl %ecx, %ecx
callq 0x94a0
movq -0x50(%rbp), %rdi
callq 0x77f0
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1b0(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movslq -0x14(%rbp), %rsi
callq 0xbb10
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)