// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]cproc/expr.c
// Function: castexpr
static struct expr *
castexpr(struct scope *s)
{
	struct type *t, *ct;
	struct decl *d;
	enum typequal tq;
	struct expr *r, *e, **end, *toeval;

	ct = NULL;
	end = &r;
	while (consume(TLPAREN)) {
		tq = QUALNONE;
		t = typename(s, &tq, &toeval);
		if (!t) {
			e = expr(s);
			expect(TRPAREN, "after expression to match '('");
			e = postfixexpr(s, e);
			goto done;
		}
		expect(TRPAREN, "after type name");
		if (tok.kind == TLBRACE) {
			e = mkexpr(EXPRCOMPOUND, t, NULL);
			e->toeval = toeval;
			e->qual = tq;
			e->lvalue = true;
			d = mkdecl(NULL, DECLOBJECT, t, tq, LINKNONE);
			d->u.obj.storage = s == &filescope ? SDSTATIC : SDAUTO;
			e->u.compound.decl = d;
			e->u.compound.init = parseinit(s, t);
			e = postfixexpr(s, decay(e));
			goto done;
		}
		if (t != &typevoid && !(t->prop & PROPSCALAR))
			error(&tok.loc, "cast type must be scalar");
		e = mkexpr(EXPRCAST, t, NULL);
		e->toeval = toeval;
		*end = e;
		end = &e->base;
		ct = t;
	}
	e = unaryexpr(s);

done:
	if (ct && ct != &typevoid && !(e->type->prop & PROPSCALAR))
		error(&tok.loc, "cast operand must have scalar type");
	*end = e;
	return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
leaq 0x20(%rsp), %rbx
pushq $0x42
popq %rbp
leaq 0x1489c(%rip), %r13     # 0x1c108
leaq 0x8(%r13), %rax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
movl %ebp, %edi
callq 0xa28d
testb %al, %al
je 0x7907
andl $0x0, 0xc(%rsp)
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x3784
testq %rax, %rax
je 0x7914
movq %rax, %r15
pushq $0x43
popq %rdi
leaq 0xaf2d(%rip), %rsi      # 0x127dd
callq 0xa26e
cmpl $0x44, (%r13)
je 0x7936
cmpq 0x136dd(%rip), %r15     # 0x1afa0
je 0x78df
testb $0x10, 0x4(%r15)
jne 0x78df
movq 0x10(%rsp), %rdi
leaq 0xaf15(%rip), %rsi      # 0x127ed
xorl %eax, %eax
callq 0xc536
pushq $0x8
popq %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x6efa
movq 0x18(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq %rax, (%rbx)
addq $0x18, %rax
movq %r15, %r12
movq %rax, %rbx
jmp 0x7878
movq %r14, %rdi
callq 0x8aca
jmp 0x79a3
movq %r14, %rdi
callq 0x6e32
movq %rax, %r15
leaq 0xae99(%rip), %rsi      # 0x127bf
pushq $0x43
popq %rdi
callq 0xa26e
movq %r14, %rdi
movq %r15, %rsi
jmp 0x799e
pushq $0x6
popq %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x6efa
movq %rax, %r13
movq 0x18(%rsp), %rax
movq %rax, 0x28(%r13)
movl 0xc(%rsp), %ecx
movl %ecx, 0x10(%r13)
movb $0x1, 0x4(%r13)
pushq $0x1
popq %rsi
xorl %edi, %edi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0x3724
xorl %ecx, %ecx
cmpq 0x13663(%rip), %r14     # 0x1afd8
setne %cl
addl %ecx, %ecx
movl %ecx, 0x44(%rax)
movq %rax, 0x30(%r13)
movq %r14, %rdi
movq %r15, %rsi
callq 0x8f44
movq %rax, 0x38(%r13)
movq %r13, %rdi
callq 0x8a72
movq %r14, %rdi
movq %rax, %rsi
callq 0x7a07
movq %rax, %r14
testq %r12, %r12
sete %al
cmpq 0x135ed(%rip), %r12     # 0x1afa0
sete %cl
orb %al, %cl
jne 0x79d7
movq 0x8(%r14), %rax
testb $0x10, 0x4(%rax)
jne 0x79d7
leaq 0xae3b(%rip), %rsi      # 0x12806
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0xc536
movq %r14, (%rbx)
movq 0x20(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq