// File: /workspace/github_c_makefile_star2_O3/michaelforney[P]cproc/decl.c
// Function: declaratortypes
static void
declaratortypes(struct scope *s, struct list *result, char **name, struct scope **funcscope, bool allowabstract)
{
	struct list *ptr, *prev;
	struct type *t;
	struct decl *d, **paramend;
	struct expr *e;
	enum typequal tq;
	bool allowattr;

	while (consume(TMUL)) {
		attr(NULL, 0);
		tq = QUALNONE;
		while (typequal(&tq))
			;
		t = mkpointertype(NULL, tq);
		listinsert(result, &t->link);
	}
	if (name)
		*name = NULL;
	ptr = result->next;
	prev = ptr->prev;
	switch (tok.kind) {
	case TLPAREN:
		next();
		if (allowabstract) {
			switch (tok.kind) {
			case TMUL:
			case TLPAREN:
				break;
			case TIDENT:
				if (!istypename(s, tok.lit))
					break;
				/* fallthrough */
			default:
				allowattr = true;
				goto func;
			}
		}
		declaratortypes(s, result, name, funcscope, allowabstract);
		expect(TRPAREN, "after parenthesized declarator");
		allowattr = false;
		break;
	case TIDENT:
		if (!name)
			error(&tok.loc, "identifier not allowed in abstract declarator");
		*name = tok.lit;
		next();
		allowattr = true;
		break;
	default:
		if (!allowabstract)
			error(&tok.loc, "expected '(' or identifier");
		allowattr = true;
	}
	for (;;) {
		switch (tok.kind) {
		case TLPAREN:  /* function declarator */
			next();
		func:
			t = mktype(TYPEFUNC, 0);
			t->qual = QUALNONE;
			t->u.func.isvararg = false;
			t->u.func.params = NULL;
			t->u.func.nparam = 0;
			paramend = &t->u.func.params;
			s = mkscope(s);
			d = NULL;
			do {
				if (consume(TELLIPSIS)) {
					t->u.func.isvararg = true;
					break;
				}
				if (tok.kind == TRPAREN)
					break;
				d = parameter(s);
				if (d->name)
					scopeputdecl(s, d);
				*paramend = d;
				paramend = &d->next;
				++t->u.func.nparam;
			} while (consume(TCOMMA));
			expect(TRPAREN, "to close function declarator");
			if (funcscope && ptr->prev == prev) {
				/* we may need to re-open the scope later if this is a function definition */
				*funcscope = s;
				s = s->parent;
			} else {
				s = delscope(s);
			}
			if (t->u.func.nparam == 1 && !t->u.func.isvararg && d->type->kind == TYPEVOID && !d->name) {
				t->u.func.params = NULL;
				t->u.func.nparam = 0;
			}
			listinsert(ptr->prev, &t->link);
			allowattr = true;
			break;
		case TLBRACK:  /* array declarator */
			if (allowattr && attr(NULL, 0))
				goto attr;
			next();
			t = mkarraytype(NULL, QUALNONE, 0);
			while (consume(TSTATIC) || typequal(&t->u.array.ptrqual))
				;
			if (tok.kind == TMUL && peek(TRBRACK)) {
				t->prop |= PROPVM;
				t->incomplete = false;
			} else if (!consume(TRBRACK)) {
				e = assignexpr(s);
				if (!(e->type->prop & PROPINT))
					error(&tok.loc, "array length expression must have integer type");
				t->u.array.length = e;
				t->incomplete = false;
				expect(TRBRACK, "after array length");
			}
			listinsert(ptr->prev, &t->link);
			allowattr = true;
			break;
		case T__ATTRIBUTE__:
			if (!allowattr)
				error(&tok.loc, "attribute not allowed after parenthesized declarator");
			/* attribute applies to identifier if ptr->prev == result, otherwise type ptr->prev */
			gnuattr(NULL, 0);
		attr:
			break;
		default:
			return;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %r8d, %ebp
movq %rcx, 0x28(%rsp)
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movl $0x4b, %edi
callq 0xb00a
testb %al, %al
je 0x5bc1
leaq 0x24(%rsp), %r12
xorl %edi, %edi
xorl %esi, %esi
callq 0x33ec
movl $0x0, 0x24(%rsp)
movq %r12, %rdi
callq 0x5726
testl %eax, %eax
jne 0x5b90
movl 0x24(%rsp), %esi
xorl %edi, %edi
callq 0xd803
leaq 0x28(%rax), %rsi
movq %r15, %rdi
callq 0xe277
movl $0x4b, %edi
callq 0xb00a
testb %al, %al
jne 0x5b7f
testq %rbx, %rbx
je 0x5bcd
movq $0x0, (%rbx)
movq 0x8(%r15), %rax
movq %rax, 0x30(%rsp)
movq (%rax), %rax
movq %rax, 0x68(%rsp)
leaq 0x16523(%rip), %r13     # 0x1c108
movl (%r13), %eax
cmpl $0x4, %eax
je 0x5c64
cmpl $0x42, %eax
jne 0x5c89
callq 0xa920
testb %bpl, %bpl
je 0x5c38
movl (%r13), %eax
cmpl $0x4b, %eax
je 0x5c38
cmpl $0x42, %eax
je 0x5c38
cmpl $0x4, %eax
jne 0x5dcc
movq 0x20(%r13), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0xc70d
testq %rax, %rax
je 0x5c38
cmpl $0x0, 0x8(%rax)
je 0x5dcc
movzbl %bpl, %r8d
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq 0x28(%rsp), %rcx
callq 0x5b4a
leaq 0xd1d4(%rip), %rsi      # 0x12e2a
movl $0x43, %edi
callq 0xafeb
xorl %ebx, %ebx
jmp 0x5ca6
testq %rbx, %rbx
jne 0x5c7b
leaq 0x8(%r13), %rdi
leaq 0xd0f8(%rip), %rsi      # 0x12d6c
xorl %eax, %eax
callq 0xd55c
movq 0x20(%r13), %rax
movq %rax, (%rbx)
callq 0xa920
jmp 0x5ca4
movb $0x1, %bl
testb %bpl, %bpl
jne 0x5ca6
leaq 0x8(%r13), %rdi
leaq 0xd0ff(%rip), %rsi      # 0x12d9a
xorl %eax, %eax
callq 0xd55c
jmp 0x5ca6
movb $0x1, %bl
leaq 0x8(%r13), %r15
leaq 0xd163(%rip), %r12      # 0x12e14
leaq 0xd149(%rip), %rbp      # 0x12e01
movl (%r13), %eax
cmpl $0x3f, %eax
je 0x5d33
cmpl $0x40, %eax
jne 0x5dbe
testb $0x1, %bl
je 0x5cdc
xorl %edi, %edi
xorl %esi, %esi
callq 0x33ec
testb %al, %al
jne 0x5cb8
callq 0xa920
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd85e
movq %rax, %rbx
leaq 0x48(%rax), %r13
movl $0x27, %edi
callq 0xb00a
testb %al, %al
jne 0x5cf3
movq %r13, %rdi
callq 0x5726
testl %eax, %eax
jne 0x5cf3
leaq 0x163f4(%rip), %r13     # 0x1c108
cmpl $0x4b, (%r13)
jne 0x5d53
movl $0x41, %edi
callq 0xaf24
testb %al, %al
je 0x5d53
orb $0x40, 0x4(%rbx)
movb $0x0, 0x3c(%rbx)
jmp 0x5da3
testb $0x1, %bl
jne 0x5d45
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0xd55c
xorl %edi, %edi
xorl %esi, %esi
callq 0x3483
jmp 0x5cb8
movl $0x41, %edi
callq 0xb00a
testb %al, %al
jne 0x5da3
movq %r14, %rdi
callq 0x73d0
movq %rax, %r13
movq 0x8(%rax), %rax
testb $0x2, 0x4(%rax)
jne 0x5d87
movq %r15, %rdi
leaq 0xd052(%rip), %rsi      # 0x12dd2
xorl %eax, %eax
callq 0xd55c
movq %r13, 0x40(%rbx)
movb $0x0, 0x3c(%rbx)
movl $0x41, %edi
movq %rbp, %rsi
callq 0xafeb
leaq 0x16365(%rip), %r13     # 0x1c108
movq 0x30(%rsp), %rax
movq (%rax), %rdi
addq $0x28, %rbx
movq %rbx, %rsi
callq 0xe277
movb $0x1, %bl
jmp 0x5cb8
cmpl $0x42, %eax
jne 0x5f99
callq 0xa920
movl $0xe, %edi
xorl %esi, %esi
callq 0xd7d8
movq %rax, %rbx
movl $0x0, 0x38(%rax)
movb $0x0, 0x40(%rax)
leaq 0x48(%rax), %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rax)
movq %r14, %rdi
callq 0xc6a0
movq %rax, %r12
leaq 0x78(%rsp), %r14
leaq 0x8(%r13), %rax
movq %rax, 0x58(%rsp)
xorl %ebp, %ebp
movq %r15, 0x60(%rsp)
movq %r15, %r13
movq %rbx, 0x70(%rsp)
movl $0x62, %edi
callq 0xb00a
testb %al, %al
jne 0x5fab
leaq 0x162d6(%rip), %rax     # 0x1c108
cmpl $0x43, (%rax)
je 0x5faf
xorl %edi, %edi
xorl %esi, %esi
callq 0x33ec
movq %r14, %rdi
movq %r12, %rsi
leaq 0x3c(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x38e3
movq 0x88(%rsp), %rax
movq %rax, 0x50(%rsp)
movups 0x78(%rsp), %xmm0
movaps %xmm0, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x5e8b
movq 0x58(%rsp), %rdi
leaq 0xcfc5(%rip), %rsi      # 0x12e49
xorl %eax, %eax
callq 0xd55c
testl $0xffffffdf, 0x3c(%rsp) # imm = 0xFFFFFFDF
je 0x5ea8
movq 0x58(%rsp), %rdi
leaq 0xcfc9(%rip), %rsi      # 0x12e6a
xorl %eax, %eax
callq 0xd55c
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
movq %r12, %r14
movq %r12, %rsi
leaq 0x90(%rsp), %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x48fe
movq 0x88(%rsp), %rax
movq %rax, 0x50(%rsp)
movups 0x78(%rsp), %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x40(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0xdc0d
movq %rax, %r12
movq %rax, 0x40(%rsp)
movq 0x90(%rsp), %rbx
movl 0x48(%rsp), %r15d
movl $0x48, %edi
callq 0xe142
movq %rax, %rbp
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movups %xmm0, 0x38(%rax)
movq %rbx, (%rax)
movq $0x1, 0x8(%rax)
movq %r12, 0x10(%rax)
movl %r15d, 0x18(%rax)
testq %r12, %r12
je 0x5f50
movl 0x8(%r12), %eax
movl %eax, 0x40(%rbp)
movl $0x2, 0x44(%rbp)
cmpq $0x0, (%rbp)
movq 0x70(%rsp), %rbx
movq %r14, %r12
je 0x5f71
movq %r12, %rdi
movq %rbp, %rsi
callq 0xc644
movq %rbp, (%r13)
movq %rbp, %r13
addq $0x38, %r13
incq 0x50(%rbx)
movl $0x6e, %edi
callq 0xb00a
testb %al, %al
leaq 0x78(%rsp), %r14
jne 0x5e19
jmp 0x5faf
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, 0x40(%rbx)
leaq 0xcdff(%rip), %rsi      # 0x12db5
movl $0x43, %edi
callq 0xafeb
cmpq $0x0, 0x28(%rsp)
je 0x5fd7
movq 0x30(%rsp), %rax
movq 0x68(%rsp), %rcx
cmpq %rcx, (%rax)
je 0x5fe4
movq %r12, %rdi
callq 0xc6cd
movq %rax, %r14
jmp 0x5ff1
movq 0x28(%rsp), %rax
movq %r12, (%rax)
movq 0x58(%r12), %r14
leaq 0x16110(%rip), %r13     # 0x1c108
cmpq $0x1, 0x50(%rbx)
jne 0x6020
cmpb $0x0, 0x40(%rbx)
jne 0x6020
movq 0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x6020
cmpq $0x0, (%rbp)
jne 0x6020
xorps %xmm0, %xmm0
movq 0x60(%rsp), %rax
movups %xmm0, (%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rdi
addq $0x28, %rbx
movq %rbx, %rsi
callq 0xe277
jmp 0x5ca4
nopl (%rax)