// File: /workspace/github_c_makefile_star2_O2/Oric4ever[P]lcc65/6502/build/../src/expr.c
// Function: cast
Tree cast(p, type) Tree p; Type type; {
	Field q;
	Type pty, ty = unqual(type);

	p = value(p);
	if (p->type == type)
		return p;
	pty = unqual(p->type);
	if (pty == ty)
		return retype(p, type);
	if (pty == signedchar || pty == chartype)
		p = simplify(CVC, inttype, p, 0);
	else if (pty == shorttype)
		p = simplify(CVS, inttype, p, 0);
	else if (pty == longtype)
		p = retype(p, inttype);
	else if (pty == floattype)
		p = simplify(CVF, doubletype, p, 0);
	else if (pty == longdouble)
		p = retype(p, doubletype);
	else if (pty == unsignedchar)
		p = simplify(CVC, unsignedtype, p, 0);
	else if (pty == unsignedshort)
		p = simplify(CVS, unsignedtype, p, 0);
	else if (pty == unsignedlong)
		p = retype(p, unsignedtype);
	else if (isptr(pty)) {
		if (isstruct(pty->type) && isptr(ty) && isstruct(ty->type)
		&& (q = extends(pty->type, ty->type)))
			return simplify(ADD+P, ty, p, constnode(q->offset, inttype));
		if (isptr(ty)) {
			if (isfunc(pty->type) && !isfunc(ty->type)
			|| !isfunc(pty->type) &&  isfunc(ty->type))
				warning("conversion from `%t' to `%t' is compiler-dependent\n",
					p->type, ty);
			return retype(p, type);
		}
		p = simplify(CVP, unsignedtype, p, 0);
	}
	else if (isstruct(pty) && isstruct(ty) && (q = extends(pty, ty)))
		return rvalue(simplify(ADD+P, ptr(ty), addrof(p),
			constnode(q->offset, inttype)));
	pty = unqual(p->type);
	if (pty == inttype || isenum(pty)) {
		if (ty == floattype || ty == doubletype || ty == longdouble)
			p = simplify(CVI, doubletype, p, 0);
		else if (ty == unsignedtype  || ty == unsignedchar
		     ||  ty == unsignedshort || ty == unsignedlong || isptr(ty))
			p = simplify(CVI, unsignedtype, p, 0);
	} else if (pty == doubletype) {
		if (ty == signedchar || ty == chartype || isenum(ty)
		||  ty == shorttype  || ty == inttype  || ty == longtype)
			p = simplify(CVD, inttype, p, 0);
		else if (ty == unsignedtype  || ty == unsignedchar
		     ||  ty == unsignedshort || ty == unsignedlong || isptr(ty)) {
			/*
			 * For (unsigned)d for double d, build
			 * d >= INT_MAX+1 ? (unsigned)(int)(d-(INT_MAX+1)) + INT_MAX+1 :
			 *		    (unsigned)(int)d
			 */
			Tree c = tree(CNST+D, doubletype, 0, 0);
			c->u.v.d = (double)INT_MAX + 1;
			p = condnode(
				simplify(GE, doubletype, p, c),
				(*opnode['+'])(ADD,
					cast(cast(simplify(SUB, doubletype, p, c), inttype), unsignedtype),
					constnode((unsigned)INT_MAX + 1, unsignedtype)),
				simplify(CVD, inttype, p, 0));
		}
	} else if (pty == unsignedtype) {
		if (ty == signedchar || ty == chartype || isenum(ty)
		||  ty == shorttype  || ty == inttype  || ty == longtype)
			p = simplify(CVU, inttype, p, 0);
		else if (ty == floattype || ty == doubletype || ty == longdouble) {
			/*
			 * For (double)u for unsigned u, build
			 * (int)u >= 0 ? (double)(int)u : (double)(int)u + UINT_MAX + 1
			 */
			Tree u = simplify(CVU, inttype, p, 0);
			p = tree(CNST+D, doubletype, 0, 0);
			p->u.v.d = utod(UINT_MAX) + 1;
			p = condnode(
				simplify(GE, inttype, u, constnode(0, inttype)),
				simplify(CVI, doubletype, u, 0),
				(*opnode['+'])(ADD, simplify(CVI, doubletype, u, 0), p));
		}
	} else
		assert(0);
	if (ty == signedchar || ty == chartype || ty == shorttype)
		p = simplify(CVI, type, p, 0);
	else if (ty == floattype)
		p = simplify(CVD, type, p, 0);
	else if (ty == unsignedchar || ty == unsignedshort || isptr(ty))
		p = simplify(CVU, type, p, 0);
	else
		p = retype(p, type);
	return p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
cmpl $0xf, (%rsi)
movq %rsi, %r14
jb 0x992f
movq 0x10(%rbx), %r14
callq 0x94a3
movq %rax, %r15
movq 0x8(%rax), %r12
cmpq %rbx, %r12
je 0x9a16
cmpl $0xf, (%r12)
jb 0x9950
movq 0x10(%r12), %r12
cmpq %r14, %r12
je 0xa06d
leaq 0x28658(%rip), %rbp     # 0x31fb8
leaq 0x28619(%rip), %r13     # 0x31f80
cmpq (%rbp), %r12
je 0x9a28
cmpq (%r13), %r12
je 0x9a28
leaq 0x2862e(%rip), %rax     # 0x31fb0
cmpq (%rax), %r12
je 0x9a37
leaq 0x28616(%rip), %rax     # 0x31fa8
cmpq (%rax), %r12
je 0x9ceb
leaq 0x285ee(%rip), %rax     # 0x31f90
cmpq (%rax), %r12
je 0x9e79
leaq 0x285ee(%rip), %rax     # 0x31fa0
cmpq (%rax), %r12
je 0x9e8a
leaq 0x285fe(%rip), %rax     # 0x31fc0
cmpq (%rax), %r12
je 0x9ea1
leaq 0x285fe(%rip), %rax     # 0x31fd0
cmpq (%rax), %r12
je 0x9ead
leaq 0x285e6(%rip), %rax     # 0x31fc8
cmpq (%rax), %r12
je 0x9eb9
movl (%r12), %eax
cmpl $0xf, %eax
jb 0x9ec2
movq 0x10(%r12), %rax
movl (%rax), %eax
cmpl $0x7, %eax
je 0x9fec
cmpl $0x9, %eax
je 0x9f66
jmp 0x9f5d
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28569(%rip), %rax     # 0x31f98
movq (%rax), %rsi
pushq $0x50
popq %rdi
jmp 0x9a46
leaq 0x2855a(%rip), %rax     # 0x31f98
movq (%rax), %rsi
movl $0xa0, %edi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x1131b
movq %rax, %r15
movq 0x8(%r15), %rcx
cmpl $0xf, (%rcx)
jb 0x9a60
movq 0x10(%rcx), %rcx
leaq 0x28531(%rip), %r12     # 0x31f98
movq (%r12), %rsi
cmpq %rsi, %rcx
je 0x9a86
movl (%rcx), %eax
cmpl $0xf, %eax
jb 0x9a7d
movq 0x10(%rcx), %rax
movl (%rax), %eax
cmpl $0xd, %eax
jne 0x9b70
leaq 0x28503(%rip), %rax     # 0x31f90
leaq 0x284f4(%rip), %rcx     # 0x31f88
movq (%rcx), %rsi
cmpq (%rax), %r14
je 0x9af3
cmpq %rsi, %r14
je 0x9af3
leaq 0x284f8(%rip), %rax     # 0x31fa0
cmpq (%rax), %r14
je 0x9af3
leaq 0x28524(%rip), %rax     # 0x31fd8
movq (%rax), %rsi
cmpq %rsi, %r14
je 0x9af3
leaq 0x284fd(%rip), %rax     # 0x31fc0
cmpq (%rax), %r14
je 0x9af3
leaq 0x28501(%rip), %rax     # 0x31fd0
cmpq (%rax), %r14
je 0x9af3
leaq 0x284ed(%rip), %rax     # 0x31fc8
cmpq (%rax), %r14
je 0x9af3
movl (%r14), %eax
cmpl $0xf, %eax
jb 0x9aee
movq 0x10(%r14), %rax
movl (%rax), %eax
cmpl $0x7, %eax
jne 0x9b05
movl $0x80, %edi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x1131b
movq %rax, %r15
cmpq (%rbp), %r14
je 0x9b66
cmpq (%r13), %r14
je 0x9b66
leaq 0x28498(%rip), %rax     # 0x31fb0
cmpq (%rax), %r14
je 0x9b66
leaq 0x2846c(%rip), %rax     # 0x31f90
cmpq (%rax), %r14
je 0x9cc3
leaq 0x2848c(%rip), %rax     # 0x31fc0
cmpq (%rax), %r14
je 0x9b5c
leaq 0x28490(%rip), %rax     # 0x31fd0
cmpq (%rax), %r14
je 0x9b5c
movl (%r14), %eax
cmpl $0xf, %eax
jb 0x9b53
movq 0x10(%r14), %rax
movl (%rax), %eax
cmpl $0x7, %eax
jne 0xa06d
movl $0xb0, %edi
jmp 0x9cc6
movl $0x80, %edi
jmp 0x9cc6
leaq 0x28411(%rip), %rdi     # 0x31f88
movq (%rdi), %rax
cmpq %rax, %rcx
je 0x9cf7
leaq 0x2844e(%rip), %rdx     # 0x31fd8
cmpq (%rdx), %rcx
jne 0xa09a
cmpq (%rbp), %r14
je 0x9ce1
cmpq (%r13), %r14
je 0x9ce1
movl (%r14), %ecx
cmpl $0xf, %ecx
jb 0x9bb5
movq 0x10(%r14), %rcx
movl (%rcx), %ecx
cmpl $0xd, %ecx
je 0x9ce1
cmpq %rsi, %r14
je 0x9ce1
leaq 0x283e2(%rip), %rcx     # 0x31fb0
cmpq (%rcx), %r14
je 0x9ce1
leaq 0x283ca(%rip), %rcx     # 0x31fa8
cmpq (%rcx), %r14
je 0x9ce1
cmpq %rax, %r14
je 0x9c08
leaq 0x2839d(%rip), %rax     # 0x31f90
cmpq (%rax), %r14
je 0x9c08
leaq 0x283a1(%rip), %rax     # 0x31fa0
cmpq (%rax), %r14
jne 0x9b05
movq %rdi, %r13
movl $0xb0, %edi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x1131b
movq %rax, %r15
movq (%r13), %rsi
pushq $0x12
popq %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x165eb
movq %rax, 0x10(%rsp)
movabsq $0x41f0000000000000, %rcx # imm = 0x41F0000000000000
movq %rcx, 0x28(%rax)
movq (%r12), %r13
xorl %edi, %edi
movq %r13, %rsi
callq 0x8726
movl $0x1f0, %edi            # imm = 0x1F0
movq %r13, %rsi
movq %r15, %rdx
movq %rax, %rcx
callq 0x1131b
movq %rax, 0x8(%rsp)
leaq 0x2831b(%rip), %rax     # 0x31f88
movq (%rax), %rsi
movl $0x80, %edi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x1131b
movq %rax, %r13
leaq 0x1e4d7(%rip), %rax     # 0x28160
movq 0x158(%rax), %r12
leaq 0x282f1(%rip), %rax     # 0x31f88
movq (%rax), %rsi
movl $0x80, %edi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x1131b
movl $0x130, %edi            # imm = 0x130
movq %rax, %rsi
movq 0x10(%rsp), %rdx
callq *%r12
movq 0x8(%rsp), %rdi
jmp 0x9e5a
pushq $0x60
popq %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1131b
movl $0xb0, %edi
jmp 0x9af8
leaq 0x282a6(%rip), %rax     # 0x31f98
jmp 0x9e91
cmpq (%rbp), %r14
je 0x9e71
cmpq (%r13), %r14
je 0x9e71
movl (%r14), %ecx
movl %ecx, %edx
cmpl $0xf, %ecx
jb 0x9d1b
movq 0x10(%r14), %rdx
movl (%rdx), %edx
cmpl $0xd, %edx
je 0x9e71
cmpq %rsi, %r14
je 0x9e71
leaq 0x2827c(%rip), %rdx     # 0x31fb0
cmpq (%rdx), %r14
je 0x9e71
leaq 0x28264(%rip), %rdx     # 0x31fa8
cmpq (%rdx), %r14
je 0x9e71
leaq 0x28284(%rip), %rdx     # 0x31fd8
cmpq (%rdx), %r14
je 0x9d91
leaq 0x28260(%rip), %rdx     # 0x31fc0
cmpq (%rdx), %r14
je 0x9d91
leaq 0x28264(%rip), %rdx     # 0x31fd0
cmpq (%rdx), %r14
je 0x9d91
leaq 0x28250(%rip), %rdx     # 0x31fc8
cmpq (%rdx), %r14
je 0x9d91
cmpl $0xf, %ecx
jb 0x9d88
movq 0x10(%r14), %rcx
movl (%rcx), %ecx
cmpl $0x7, %ecx
jne 0x9b05
pushq $0x12
popq %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x165eb
movq %rax, %r13
movabsq $0x41e0000000000000, %rax # imm = 0x41E0000000000000
movq %rax, 0x28(%r13)
leaq 0x281d0(%rip), %rax     # 0x31f88
movq (%rax), %rsi
movl $0x1f0, %edi            # imm = 0x1F0
movq %r15, %rdx
movq %r13, %rcx
callq 0x1131b
movq %rax, 0x10(%rsp)
leaq 0x1e389(%rip), %rax     # 0x28160
movq 0x158(%rax), %rax
movq %rax, 0x8(%rsp)
leaq 0x2819e(%rip), %rax     # 0x31f88
movq (%rax), %rsi
movl $0x140, %edi            # imm = 0x140
movq %r15, %rdx
movq %r13, %rcx
callq 0x1131b
movq (%r12), %rsi
movq %rax, %rdi
callq 0x9912
leaq 0x281c8(%rip), %rcx     # 0x31fd8
movq (%rcx), %rsi
movq %rax, %rdi
callq 0x9912
movq %rax, %r13
leaq 0x281b3(%rip), %rax     # 0x31fd8
movq (%rax), %rsi
movl $0x80000000, %edi       # imm = 0x80000000
callq 0x8726
movl $0x130, %edi            # imm = 0x130
movq %r13, %rsi
movq %rax, %rdx
callq *0x8(%rsp)
movq %rax, %r13
movq (%r12), %rsi
pushq $0x60
popq %rdi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x1131b
movq 0x10(%rsp), %rdi
movq %r13, %rsi
leaq 0x2811c(%rip), %r13     # 0x31f80
movq %rax, %rdx
callq 0x892b
jmp 0x9b02
pushq $0x60
popq %rdi
jmp 0x9af8
leaq 0x28108(%rip), %rax     # 0x31f88
movq (%rax), %rsi
pushq $0x70
jmp 0x9a34
leaq 0x280f7(%rip), %rax     # 0x31f88
movq (%rax), %rsi
movq %r15, %rdi
callq 0x16727
jmp 0x9a50
leaq 0x28130(%rip), %rax     # 0x31fd8
jmp 0x9a2f
leaq 0x28124(%rip), %rax     # 0x31fd8
jmp 0x9a3e
leaq 0x28118(%rip), %rax     # 0x31fd8
jmp 0x9e91
cmpl $0x9, %eax
je 0x9f66
cmpl $0x7, %eax
jne 0x9f5d
movq 0x10(%r12), %rdi
movl (%rdi), %eax
cmpl $0xf, %eax
jb 0x9ee6
movq 0x10(%rdi), %rax
movl (%rax), %eax
cmpl $0x9, %eax
je 0x9ef4
cmpl $0xa, %eax
jne 0x9fec
movl (%r14), %eax
cmpl $0xf, %eax
jb 0x9f02
movq 0x10(%r14), %rax
movl (%rax), %eax
cmpl $0x7, %eax
jne 0x9fec
movq 0x10(%r14), %rsi
movl (%rsi), %eax
cmpl $0xf, %eax
jb 0x9f1c
movq 0x10(%rsi), %rax
movl (%rax), %eax
cmpl $0x9, %eax
je 0x9f2a
cmpl $0xa, %eax
jne 0x9fec
callq 0x17ccb
testq %rax, %rax
je 0x9fec
movl 0x10(%rax), %edi
leaq 0x28056(%rip), %rax     # 0x31f98
movq (%rax), %rsi
callq 0x8726
movl $0x137, %edi            # imm = 0x137
movq %r14, %rsi
movq %r15, %rdx
movq %rax, %rcx
jmp 0x9cce
cmpl $0xa, %eax
jne 0x9a53
movl (%r14), %eax
cmpl $0xf, %eax
jb 0x9f74
movq 0x10(%r14), %rax
movl (%rax), %eax
cmpl $0x9, %eax
je 0x9f82
cmpl $0xa, %eax
jne 0x9a53
movq %r12, %rdi
movq %r14, %rsi
callq 0x17ccb
testq %rax, %rax
je 0x9a53
movq %rax, %r12
movq %r14, %rdi
callq 0x1736a
movq %rax, %rbx
movq %r15, %rdi
callq 0x92ec
movq %rax, %r14
movl 0x10(%r12), %edi
leaq 0x27fdd(%rip), %rax     # 0x31f98
movq (%rax), %rsi
callq 0x8726
movl $0x137, %edi            # imm = 0x137
movq %rbx, %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0x1131b
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0b9
movl (%r14), %eax
cmpl $0xf, %eax
jb 0x9ffa
movq 0x10(%r14), %rax
movl (%rax), %eax
cmpl $0x7, %eax
jne 0xa086
movq 0x10(%r12), %rcx
movl (%rcx), %eax
movl %eax, %edx
cmpl $0xf, %eax
jb 0xa017
movq 0x10(%rcx), %rdx
movl (%rdx), %edx
cmpl $0xb, %edx
jne 0xa032
movq 0x10(%r14), %rsi
movl (%rsi), %edx
cmpl $0xf, %edx
jb 0xa02d
movq 0x10(%rsi), %rdx
movl (%rdx), %edx
cmpl $0xb, %edx
jne 0xa058
cmpl $0xf, %eax
jb 0xa03d
movq 0x10(%rcx), %rax
movl (%rax), %eax
cmpl $0xb, %eax
je 0xa06d
movq 0x10(%r14), %rcx
movl (%rcx), %eax
cmpl $0xf, %eax
jb 0xa053
movq 0x10(%rcx), %rax
movl (%rax), %eax
cmpl $0xb, %eax
jne 0xa06d
movq 0x8(%r15), %rsi
leaq 0x13117(%rip), %rdi     # 0x1d17a
movq %r14, %rdx
xorl %eax, %eax
callq 0x9239
movq %r15, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x16727
leaq 0x27f4b(%rip), %rax     # 0x31fd8
movq (%rax), %rsi
movl $0x90, %edi
jmp 0x9a46
leaq 0x120fa(%rip), %rdi     # 0x1c19b
leaq 0x13061(%rip), %rsi     # 0x1d109
leaq 0x130ff(%rip), %rcx     # 0x1d1ae
movl $0x115, %edx            # imm = 0x115
callq 0x30d0