// File: /workspace/github_c_makefile_star2_O0/oridb[P]mc/6/simp.c
// Function: simpcast
static Node *
simpcast(Simp *s, Node *val, Type *to)
{
	Node *r;
	Type *t;

	r = NULL;
	t = tybase(exprtype(val));
	if (tyeq(tybase(to), tybase(t))) {
		r = rval(s, val, NULL);
		r->expr.type = to;
		return r;
	}
	/* do the type conversion */
	switch (tybase(to)->type) {
	case Tybool:
	case Tyint8: case Tyint16: case Tyint32: case Tyint64:
	case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint64:
	case Tyint: case Tyuint: case Tychar: case Tybyte:
	case Typtr:
		switch (t->type) {
			/* ptr -> slice conversion is disallowed */
		case Tyslice:
			/* FIXME: we should only allow casting to pointers. */
			if (tysize(to) != Ptrsz)
				fatal(val, "bad cast from %s to %s", tystr(exprtype(val)), tystr(to));
			val = rval(s, val, NULL);
			r = slicebase(s, val, NULL);
			break;
		case Tyfunc:
			if (to->type != Typtr)
				fatal(val, "bad cast from %s to %s", tystr(exprtype(val)), tystr(to));
			r = getcode(s, val);
			break;
			/* signed conversions */
		case Tyint8: case Tyint16: case Tyint32: case Tyint64:
		case Tyint:
			r = intconvert(s, val, to, 1);
			break;
			/* unsigned conversions */
		case Tybool:
		case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint64:
		case Tyuint: case Tychar: case Tybyte:
		case Typtr:
			r = intconvert(s, val, to, 0);
			break;
		case Tyflt32: case Tyflt64:
			if (tybase(to)->type == Typtr)
				fatal(val, "bad cast from %s to %s",
						tystr(exprtype(val)), tystr(to));
			r = mkexpr(val->loc, Oflt2int, rval(s, val, NULL), NULL);
			r->expr.type = to;
			break;
		default:
			fatal(val, "bad cast from %s to %s",
					tystr(exprtype(val)), tystr(to));
		}
		break;
	case Tyflt32: case Tyflt64:
		switch (t->type) {
		case Tyint8: case Tyint16: case Tyint32: case Tyint64:
		case Tyuint8: case Tyuint16: case Tyuint32: case Tyuint64:
		case Tyint: case Tyuint: case Tychar: case Tybyte:
			r = mkexpr(val->loc, Oint2flt, rval(s, val, NULL), NULL);
			r->expr.type = to;
			break;
		case Tyflt32: case Tyflt64:
			r = mkexpr(val->loc, Oflt2flt, rval(s, val, NULL), NULL);
			r->expr.type = to;
			break;
		default:
			fatal(val, "bad cast from %s to %s",
					tystr(exprtype(val)), tystr(to));
			break;
		}
		break;
		/* no other destination types are handled as things stand */
	default:
		fatal(val, "bad cast from %s to %s",
				tystr(exprtype(val)), tystr(to));
	}
	return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30340
movq %rax, %rdi
callq 0x36a30
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0x36a30
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x36a30
movq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x39360
cmpl $0x0, %eax
je 0x19069
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x177e0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x19426
movq -0x20(%rbp), %rdi
callq 0x36a30
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
addl $-0x2, %eax
subl $0xd, %eax
jb 0x190a0
jmp 0x19081
movl -0x3c(%rbp), %eax
addl $-0xf, %eax
subl $0x2, %eax
jb 0x192c4
jmp 0x19092
movl -0x3c(%rbp), %eax
subl $0x12, %eax
jne 0x193d3
jmp 0x190a0
movq -0x30(%rbp), %rax
movl (%rax), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x12, %eax
ja 0x19274
movq -0x48(%rbp), %rax
leaq 0x34ee1(%rip), %rcx     # 0x4dfa4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rdi
callq 0x1c0f0
cmpq $0x8, %rax
je 0x1911a
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30340
movq %rax, %rdi
callq 0x38a10
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
callq 0x38a10
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rdx
movq %rax, %rcx
leaq 0x352c4(%rip), %rsi     # 0x4e3d7
movb $0x0, %al
callq 0x1dfe0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x177e0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x1a290
movq %rax, -0x28(%rbp)
jmp 0x192bf
movq -0x20(%rbp), %rax
cmpl $0x12, (%rax)
je 0x19191
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30340
movq %rax, %rdi
callq 0x38a10
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rdi
callq 0x38a10
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq %rax, %rcx
leaq 0x3524d(%rip), %rsi     # 0x4e3d7
movb $0x0, %al
callq 0x1dfe0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x169c0
movq %rax, -0x28(%rbp)
jmp 0x192bf
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl $0x1, %ecx
callq 0x1a780
movq %rax, -0x28(%rbp)
jmp 0x192bf
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1a780
movq %rax, -0x28(%rbp)
jmp 0x192bf
movq -0x20(%rbp), %rdi
callq 0x36a30
cmpl $0x12, (%rax)
jne 0x1922f
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30340
movq %rax, %rdi
callq 0x38a10
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
callq 0x38a10
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rdx
movq %rax, %rcx
leaq 0x351af(%rip), %rsi     # 0x4e3d7
movb $0x0, %al
callq 0x1dfe0
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x177e0
movq %rax, %rdx
movq -0x80(%rbp), %rax
movq (%rax), %rdi
movl $0x4c, %esi
xorl %eax, %eax
movl %eax, %ecx
movb $0x0, %al
callq 0x2f400
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x192bf
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30340
movq %rax, %rdi
callq 0x38a10
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
callq 0x38a10
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rdx
movq %rax, %rcx
leaq 0x3511f(%rip), %rsi     # 0x4e3d7
movb $0x0, %al
callq 0x1dfe0
jmp 0x1941e
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x94(%rbp)
addl $-0x3, %eax
subl $0xc, %eax
jb 0x192ed
jmp 0x192da
movl -0x94(%rbp), %eax
addl $-0xf, %eax
subl $0x2, %eax
jb 0x1933b
jmp 0x19386
movq -0x18(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x177e0
movq %rax, %rdx
movq -0xa0(%rbp), %rax
movq (%rax), %rdi
movl $0x4d, %esi
xorl %eax, %eax
movl %eax, %ecx
movb $0x0, %al
callq 0x2f400
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x193d1
movq -0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x177e0
movq %rax, %rdx
movq -0xa8(%rbp), %rax
movq (%rax), %rdi
movl $0x4e, %esi
xorl %eax, %eax
movl %eax, %ecx
movb $0x0, %al
callq 0x2f400
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x193d1
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30340
movq %rax, %rdi
callq 0x38a10
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x38a10
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rdx
movq %rax, %rcx
leaq 0x3500d(%rip), %rsi     # 0x4e3d7
movb $0x0, %al
callq 0x1dfe0
jmp 0x1941e
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30340
movq %rax, %rdi
callq 0x38a10
movq %rax, -0xc0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x38a10
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rdx
movq %rax, %rcx
leaq 0x34fc0(%rip), %rsi     # 0x4e3d7
movb $0x0, %al
callq 0x1dfe0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)