// File: /workspace/github_cpp_makefile_star2_O3/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 0xa434
movl %edx, %r12d
cmpl $0x4, %edx
jae 0xa43d
movq %rsi, %r15
movq %rdi, %rbx
movl %r12d, %esi
negl %esi
movq (%r15), %rdi
callq 0x7b11
cmpl $0x4, (%rax)
jne 0xa446
cmpl $0x0, 0x10(%rax)
jg 0xa44f
movq %rax, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movq (%r15), %rdi
movl $0x1, %esi
subl %r12d, %esi
callq 0x7b11
movq %rax, %rdi
callq 0x4e28
movl %eax, %r14d
xorl %ebp, %ebp
movl $0x0, %ebx
cmpl $0x2, %r12d
je 0xa31b
movq (%r15), %rdi
movl $0x2, %esi
subl %r12d, %esi
callq 0x7b11
movq %rax, %rdi
callq 0x4e28
movl %eax, %ebx
movq %r15, 0x20(%rsp)
movslq %r14d, %r15
leaq 0x2(%r15), %rdi
callq 0x21d0
movq %rax, %r13
testl %r15d, %r15d
js 0xa3a6
movl %r12d, 0xc(%rsp)
incl %r14d
xorl %ebp, %ebp
movl %ebx, %r15d
xorl $0x1, %r15d
callq 0x2200
cmpl $-0x1, %eax
je 0xa3a1
movl %eax, %r12d
shll $0x18, %eax
movl %eax, %ecx
xorl $0xa000000, %ecx        # imm = 0xA000000
orl %r15d, %ecx
je 0xa3a1
cmpl $0x2, %ebx
jne 0xa391
cmpl $0xd000000, %eax        # imm = 0xD000000
jne 0xa38a
callq 0x2200
cmpb $0xa, %al
je 0xa3a1
movq 0xbc5a(%rip), %rcx      # 0x15fd8
movq (%rcx), %rsi
movl %eax, %edi
callq 0x2070
jmp 0xa391
cmpl $0xa000000, %eax        # imm = 0xA000000
je 0xa3a1
movb %r12b, (%r13,%rbp)
incq %rbp
cmpq %rbp, %r14
jne 0xa345
movl %r14d, %ebp
movl 0xc(%rsp), %r12d
movl %ebp, %eax
movb $0x0, (%r13,%rax)
movslq 0xbfeb(%rip), %rax      # 0x163a0
cmpq $0x3f, %rax
jg 0xa3d1
leal 0x1(%rax), %ecx
movl %ecx, 0xbfdc(%rip)      # 0x163a0
leaq 0xbdd5(%rip), %rcx      # 0x161a0
movq (%rcx,%rax,8), %r15
jmp 0xa3de
movl $0x18, %edi
callq 0x21d0
movq %rax, %r15
movl $0x3, (%r15)
movq %r13, 0x8(%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 0x630b
movq %r15, %rdi
callq 0x4cd8
movq 0x20(%rsp), %rax
movl %ebp, 0x1b0(%rax)
movq (%rax), %rdi
movl %r12d, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7a28
leaq 0x61da(%rip), %rdi      # 0x10615
jmp 0xa456
leaq 0x61f2(%rip), %rdi      # 0x10636
jmp 0xa456
leaq 0x620a(%rip), %rdi      # 0x10657
jmp 0xa456
leaq 0x622e(%rip), %rdi      # 0x10684
xorl %eax, %eax
callq 0x344d