// File: exrd[P]neteruhsp/neteruhsp/neteruhsp.cc
// Function: neteruhsp::variable_mod(neteruhsp::variable_t*, neteruhsp::value_t const&, int)
void variable_mod( variable_t* var, const value_t& v, int idx )
{
	assert( var != nullptr );
	if ( var->type_ != v.type_ )
	{
		raise_error( "型の異なる変数への剰余代入（\\=）操作@@ %s(%d)", var->name_, idx );
		return;
	}

	assert( var->type_ == v.type_ );
	auto* data_ptr = variable_data_ptr( *var, idx );
	switch( var->type_ )
	{
	case VALUE_INT:
	{
		if ( v.ivalue_ == 0 )
		{
			raise_error( "0剰余が行われました@@ %s(%d)", var->name_, idx );
			break;
		}
		reinterpret_cast<int*>( data_ptr )[0] %= v.ivalue_;
		break;
	}
	case VALUE_DOUBLE:
	{
		if ( v.dvalue_ == 0.0 )
		{
			raise_error( "0.0剰余が行われました@@ %s(%d)", var->name_, idx );
			break;
		}
		auto* const vp = reinterpret_cast<double*>( data_ptr );
		vp[0] = std::fmod( vp[0], v.dvalue_ );
		break;
	}
	case VALUE_STRING:
	{
		raise_error( "文字列に対する剰余代入（\\=）操作は定義されてません@@ %s(%d)", var->name_, idx );
		break;
	}
	default:
		assert( false );
		break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x9e0c
jmp 0x9e2b
leaq 0xa8c7(%rip), %rdi      # 0x146da
leaq 0x8c37(%rip), %rsi      # 0x12a51
movl $0x1036, %edx           # imm = 0x1036
leaq 0xad12(%rip), %rcx      # 0x14b38
callq 0x30f0
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0x9e57
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movl -0x14(%rbp), %edx
leaq 0xad2e(%rip), %rdi      # 0x14b79
movb $0x0, %al
callq 0x4cd0
jmp 0x9f98
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x9e68
jmp 0x9e87
leaq 0xa93c(%rip), %rdi      # 0x147ab
leaq 0x8bdb(%rip), %rsi      # 0x12a51
movl $0x103d, %edx           # imm = 0x103D
leaq 0xacb6(%rip), %rcx      # 0x14b38
callq 0x30f0
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x9700
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
subl $0x1, %eax
je 0x9ec3
jmp 0x9ea8
movl -0x2c(%rbp), %eax
subl $0x2, %eax
je 0x9f09
jmp 0x9eb2
movl -0x2c(%rbp), %eax
subl $0x3, %eax
je 0x9f5f
jmp 0x9f79
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x9eea
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movl -0x14(%rbp), %edx
leaq 0xacdc(%rip), %rdi      # 0x14bba
movb $0x0, %al
callq 0x4cd0
jmp 0x9f98
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movl (%rax), %eax
cltd
idivl %ecx
movq -0x38(%rbp), %rax
movl %edx, (%rax)
jmp 0x9f98
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x9f37
jp 0x9f37
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movl -0x14(%rbp), %edx
leaq 0xac8a(%rip), %rdi      # 0x14bb8
movb $0x0, %al
callq 0x4cd0
jmp 0x9f98
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsd (%rax), %xmm0
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm1
callq 0x31f0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x9f98
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movl -0x14(%rbp), %edx
leaq 0xac70(%rip), %rdi      # 0x14be0
movb $0x0, %al
callq 0x4cd0
jmp 0x9f98
leaq 0x99ef(%rip), %rdi      # 0x1396f
leaq 0x8aca(%rip), %rsi      # 0x12a51
movl $0x105c, %edx           # imm = 0x105C
leaq 0xaba5(%rip), %rcx      # 0x14b38
callq 0x30f0
addq $0x40, %rsp
popq %rbp
retq
nop