// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]cproc/decl.c
// Function: declarator
static struct qualtype
declarator(struct scope *s, struct qualtype base, char **name, struct scope **funcscope, bool allowabstract)
{
	struct type *t;
	enum typequal tq;
	struct expr *e;
	struct list result = {&result, &result}, *l, *prev;

	if (funcscope)
		*funcscope = NULL;
	declaratortypes(s, &result, name, funcscope, allowabstract);
	for (l = result.prev; l != &result; l = prev) {
		prev = l->prev;
		t = listelement(l, struct type, link);
		tq = t->qual;
		t->base = base.type;
		t->qual = base.qual;
		t->prop |= base.type->prop & PROPVM;
		switch (t->kind) {
		case TYPEFUNC:
			if (base.type->kind == TYPEFUNC)
				error(&tok.loc, "function declarator specifies function return type");
			if (base.type->kind == TYPEARRAY)
				error(&tok.loc, "function declarator specifies array return type");
			break;
		case TYPEARRAY:
			if (base.type->incomplete)
				error(&tok.loc, "array element has incomplete type");
			if (base.type->kind == TYPEFUNC)
				error(&tok.loc, "array element has function type");
			t->align = base.type->align;
			t->size = 0;
			if (t->u.array.length) {
				e = eval(t->u.array.length);
				if (e->kind == EXPRCONST && base.type->size) {
					if (e->type->u.basic.issigned && e->u.constant.u >> 63)
						error(&tok.loc, "array length must be non-negative");
					if (e->u.constant.u > ULLONG_MAX / base.type->size)
						error(&tok.loc, "array length is too large");
					t->size = base.type->size * e->u.constant.u;
				} else {
					t->prop |= PROPVM;
					t->u.array.length = e;
					t->u.array.size = NULL;
				}
			}
			break;
		}
		base.type = t;
		base.qual = tq;
	}

	return base;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, 0x10(%rsp)
leaq 0x60(%rsp), %rbx
leaq 0x18(%rsp), %r13
movq %r13, (%r13)
movq %r13, 0x8(%r13)
testq %rcx, %rcx
je 0x472b
andq $0x0, (%rcx)
movzbl %r8b, %r8d
movq %rsi, %rdi
movq %r13, %rsi
callq 0x5849
movq 0x18(%rsp), %r15
movq (%rbx), %r14
movl 0x8(%rbx), %eax
leaq 0x179bc(%rip), %rcx     # 0x1c108
addq $0x8, %rcx
movq %rcx, 0x8(%rsp)
movq %r14, %rbp
cmpq %r13, %r15
je 0x48b0
movq %r15, %r12
movq (%r15), %r15
movl 0x10(%r12), %ebx
movq %rbp, -0x8(%r12)
movl %eax, 0x10(%r12)
movl 0x4(%rbp), %eax
andl $0x40, %eax
orl %eax, -0x24(%r12)
leaq -0x28(%r12), %r14
movl -0x28(%r12), %ecx
cmpl $0xd, %ecx
je 0x47d3
movl %ebx, %eax
cmpl $0xe, %ecx
jne 0x4755
movl (%rbp), %ecx
cmpl $0xe, %ecx
jne 0x47b5
movq 0x8(%rsp), %rdi
leaq 0xd4e0(%rip), %rsi      # 0x11c8b
xorl %eax, %eax
callq 0xc536
movl (%rbp), %ecx
movl %ebx, %eax
cmpl $0xd, %ecx
jne 0x4755
movq 0x8(%rsp), %rdi
leaq 0xd4f6(%rip), %rsi      # 0x11cbe
xorl %eax, %eax
callq 0xc536
movl %ebx, %eax
jmp 0x4755
cmpb $0x1, 0x3c(%rbp)
jne 0x47ec
movq 0x8(%rsp), %rdi
leaq 0xd509(%rip), %rsi      # 0x11cee
xorl %eax, %eax
callq 0xc536
cmpl $0xe, (%rbp)
jne 0x4805
movq 0x8(%rsp), %rdi
leaq 0xd512(%rip), %rsi      # 0x11d10
xorl %eax, %eax
callq 0xc536
movl 0x8(%rbp), %eax
movl %eax, -0x20(%r12)
andq $0x0, -0x18(%r12)
movq 0x18(%r12), %rdi
movl %ebx, %eax
testq %rdi, %rdi
je 0x4755
callq 0x5d00
movq %rax, %r13
cmpl $0x1, (%rax)
jne 0x4893
movq 0x10(%rbp), %rcx
testq %rcx, %rcx
je 0x4893
movq 0x8(%r13), %rax
cmpb $0x1, 0x40(%rax)
jne 0x4861
cmpq $0x0, 0x30(%r13)
jns 0x4861
movq 0x8(%rsp), %rdi
leaq 0xd4da(%rip), %rsi      # 0x11d30
xorl %eax, %eax
callq 0xc536
movq 0x10(%rbp), %rcx
movq 0x30(%r13), %rsi
movq %rcx, %rax
mulq %rsi
jno 0x4888
movq 0x8(%rsp), %rdi
leaq 0xd4d9(%rip), %rsi      # 0x11d52
xorl %eax, %eax
callq 0xc536
movq 0x10(%rbp), %rcx
movq 0x30(%r13), %rsi
imulq %rcx, %rsi
movq %rsi, -0x18(%r12)
jmp 0x48a4
orb $0x40, -0x24(%r12)
movq %r13, 0x18(%r12)
andq $0x0, 0x28(%r12)
movl %ebx, %eax
leaq 0x18(%rsp), %r13
jmp 0x4755
leaq 0x60(%rsp), %rdx
movl %eax, 0x8(%rdx)
movq %rbp, (%rdx)
movq 0x10(%rdx), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x10(%rax)
movq (%rdx), %rcx
movq %rcx, (%rax)
movl 0x8(%rdx), %ecx
movl %ecx, 0x8(%rax)
movl 0xc(%rdx), %ecx
movl %ecx, 0xc(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq