// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq %rsi, %rdi
callq 0x1bf90
movq %rax, %rdi
callq 0x1fcd8
movq %rax, %r12
movq %r14, %rdi
callq 0x1fcd8
movq %rax, %r13
movq %r12, %rdi
callq 0x1fcd8
movq %r13, %rdi
movq %rax, %rsi
callq 0x215f5
testl %eax, %eax
je 0xfa20
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xe4f4
movq %r14, 0x20(%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
callq 0x1fcd8
movl (%rax), %eax
cmpl $0x12, %eax
ja 0xfb52
movl $0x47ffc, %ecx          # imm = 0x47FFC
btl %eax, %ecx
jae 0xfa84
movl (%r12), %eax
addl $-0x2, %eax
cmpl $0x12, %eax
ja 0xfb52
leaq 0x1e7f8(%rip), %rcx     # 0x2e24c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
jmp 0xfa76
pushq $0x1
popq %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x10116
movl $0x18000, %ecx          # imm = 0x18000
btl %eax, %ecx
jae 0xfb52
movl (%r12), %eax
leal -0x3(%rax), %ecx
cmpl $0xc, %ecx
jae 0xfb36
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xe4f4
movq (%rbx), %rdi
pushq $0x4d
jmp 0xfad9
movq %r14, %rdi
callq 0x1fcd8
cmpl $0x12, (%rax)
je 0xfb52
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xe4f4
movq (%rbx), %rdi
pushq $0x4c
popq %rsi
movq %rax, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1b718
jmp 0xfa12
movq %r14, %rdi
callq 0x10d64
cmpq $0x8, %rax
jne 0xfb52
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xe4f4
movq %r15, %rdi
movq %rax, %rsi
xorl %edx, %edx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xfe6e
cmpl $0x12, (%r14)
jne 0xfb52
movq %r15, %rdi
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0xd9da
addl $-0xf, %eax
cmpl $0x2, %eax
jae 0xfb52
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xe4f4
movq (%rbx), %rdi
pushq $0x4e
jmp 0xfad9
movq %rbx, %rdi
callq 0x1bf90
movq %rax, %rdi
callq 0x21009
movq %rax, %r15
movq %r14, %rdi
callq 0x21009
leaq 0x1ea37(%rip), %rsi     # 0x2e5ab
movq %rbx, %rdi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x120fd