// File: /workspace/github_c_makefile_star2_O1/lucvoo[P]sparse-dev/parse.c
// Function: external_declaration
struct token *external_declaration(struct token *token, struct symbol_list **list,
		validate_decl_t validate_decl)
{
	struct ident *ident = NULL;
	struct symbol *decl;
	struct decl_state ctx = { .ident = &ident };
	struct ctype saved;
	struct symbol *base_type;
	unsigned long mod;
	int is_typedef;

	/* Top-level inline asm or static assertion? */
	if (token_type(token) == TOKEN_IDENT) {
		struct symbol *s = lookup_keyword(token->ident, NS_KEYWORD);
		if (s && s->op->toplevel)
			return s->op->toplevel(token, list);
	}

	/* Parse declaration-specifiers, if any */
	token = declaration_specifiers(token, &ctx);
	mod = decl_modifiers(&ctx);
	decl = alloc_symbol(token->pos, SYM_NODE);
	/* Just a type declaration? */
	if (match_op(token, ';')) {
		apply_modifiers(token->pos, &ctx);
		return token->next;
	}

	saved = ctx.ctype;
	token = declarator(token, &ctx);
	token = handle_asm_name(token, &ctx);
	token = handle_attributes(token, &ctx);
	apply_modifiers(token->pos, &ctx);

	decl->ctype = ctx.ctype;
	decl->ctype.modifiers |= mod;
	decl->cleanup = ctx.cleanup;
	decl->endpos = token->pos;

	/* Just a type declaration? */
	if (!ident) {
		warning(token->pos, "missing identifier in declaration");
		return expect(token, ';', "at the end of type declaration");
	}

	/* type define declaration? */
	is_typedef = ctx.storage_class == MOD_USERTYPE;

	/* Typedefs don't have meaningful storage */
	if (is_typedef)
		decl->ctype.modifiers |= MOD_USERTYPE;

	bind_symbol(decl, ident, is_typedef ? NS_TYPEDEF: NS_SYMBOL);

	base_type = decl->ctype.base_type;

	if (is_typedef) {
		if (base_type && !base_type->ident) {
			switch (base_type->type) {
			case SYM_STRUCT:
			case SYM_UNION:
			case SYM_ENUM:
			case SYM_RESTRICT:
				base_type->ident = ident;
				break;
			default:
				break;
			}
		}
	} else if (base_type && base_type->type == SYM_FN) {
		if (base_type->ctype.base_type == &autotype_ctype) {
			sparse_error(decl->pos, "'%s()' has __auto_type return type",
				show_ident(decl->ident));
			base_type->ctype.base_type = &int_ctype;
		}
		if (base_type->ctype.base_type == &incomplete_ctype) {
			warning(decl->pos, "'%s()' has implicit return type",
				show_ident(decl->ident));
			base_type->ctype.base_type = &int_ctype;
		}
		/* apply attributes placed after the declarator */
		decl->ctype.modifiers |= ctx.f_modifiers;

		/* K&R argument declaration? */
		if (lookup_type(token))
			return parse_k_r_arguments(token, decl, list);
		if (match_op(token, '{'))
			return parse_function_body(token, decl, list);

		if (!(decl->ctype.modifiers & MOD_STATIC))
			decl->ctype.modifiers |= MOD_EXTERN;
	} else if (base_type == &void_ctype && !(decl->ctype.modifiers & MOD_EXTERN)) {
		sparse_error(token->pos, "void declaration");
	}
	if (base_type == &incomplete_ctype) {
		warning(decl->pos, "'%s' has implicit type", show_ident(decl->ident));
		decl->ctype.base_type = &int_ctype;;
	}

	for (;;) {
		if (!is_typedef && match_op(token, '=')) {
			struct token *next = token->next;
			token = initializer(&decl->initializer, next);
			if (token == next)
				sparse_error(token->pos, "expression expected before '%s'", show_token(token));
		}
		if (!is_typedef) {
			if (validate_decl)
				validate_decl(decl);

			if (decl->initializer && decl->ctype.modifiers & MOD_EXTERN) {
				warning(decl->pos, "symbol with external linkage has initializer");
				decl->ctype.modifiers &= ~MOD_EXTERN;
			}

			if (!(decl->ctype.modifiers & (MOD_EXTERN | MOD_INLINE))) {
				add_symbol(list, decl);
				fn_local_symbol(decl);
			}
		}
		check_declaration(decl);
		if (decl->same_symbol) {
			decl->definition = decl->same_symbol->definition;
			decl->op = decl->same_symbol->op;
			if (is_typedef) {
				// TODO: handle -std=c89 --pedantic
				check_duplicates(decl);
			}
		}

		if (ctx.autotype) {
			const char *msg = NULL;
			if (decl->ctype.base_type != &autotype_ctype)
				msg = "on non-identifier";
			else if (match_op(token, ','))
				msg = "on declaration list";
			else if (!decl->initializer)
				msg = "without initializer";
			else if (decl->initializer->type == EXPR_SYMBOL &&
				 decl->initializer->symbol == decl)
				msg = "on self-init var";
			if (msg) {
				sparse_error(decl->pos, "__auto_type %s", msg);
				decl->ctype.base_type = &bad_ctype;
			}
		}

		if (!match_op(token, ','))
			break;

		token = token->next;
		ident = NULL;
		decl = alloc_symbol(token->pos, SYM_NODE);
		ctx.ctype = saved;
		ctx.cleanup = NULL;
		token = handle_attributes(token, &ctx);
		token = declarator(token, &ctx);
		token = handle_asm_name(token, &ctx);
		token = handle_attributes(token, &ctx);
		apply_modifiers(token->pos, &ctx);
		decl->ctype = ctx.ctype;
		decl->ctype.modifiers |= mod;
		decl->cleanup = ctx.cleanup;
		decl->endpos = token->pos;
		if (!ident) {
			sparse_error(token->pos, "expected identifier name in type definition");
			return token;
		}

		if (is_typedef)
			decl->ctype.modifiers |= MOD_USERTYPE;

		bind_symbol(decl, ident, is_typedef ? NS_TYPEDEF: NS_SYMBOL);

		/* Function declarations are automatically extern unless specifically static */
		base_type = decl->ctype.base_type;
		if (!is_typedef && base_type && base_type->type == SYM_FN) {
			if (!(decl->ctype.modifiers & MOD_STATIC))
				decl->ctype.modifiers |= MOD_EXTERN;
		}
	}
	return expect(token, ';', "at end of declaration");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r12
xorl %eax, %eax
movq %rsp, %rcx
movq %rax, (%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq %rax, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq %rcx, 0x48(%rsp)
movl (%rdi), %eax
andl $0x3f, %eax
cmpl $0x3, %eax
jne 0x1a928
movq 0x10(%r12), %rdi
testb $0x4, 0x11(%rdi)
jne 0x1a8f3
xorl %eax, %eax
jmp 0x1a8fd
movl $0x100, %esi            # imm = 0x100
callq 0x2b511
movb $0x1, %cl
testq %rax, %rax
je 0x1a920
movq 0x40(%rax), %rax
movq 0x38(%rax), %rax
testq %rax, %rax
je 0x1a920
movq %r12, %rdi
movq %rbx, %rsi
callq *%rax
movq %rax, %r15
xorl %ecx, %ecx
jmp 0x1a920
testb %cl, %cl
je 0x1af27
leaq 0x20(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x1981b
movq %rax, %r15
movq 0x8(%r13), %rax
movl %eax, %ecx
andl $0x3141007f, %ecx       # imm = 0x3141007F
andq $-0x31410080, %rax      # imm = 0xCEBEFF80
movq %rax, 0x8(%r13)
orq 0x48(%r13), %rcx
movq %rcx, 0x18(%rsp)
movq (%r15), %rdi
movl $0x3, %esi
callq 0x2b547
movq %rax, %r12
movq (%r15), %rdi
movl %edi, %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1a991
cmpl $0x3b, 0x10(%r15)
jne 0x1a991
leaq 0x20(%rsp), %rsi
callq 0x1a1c6
movq 0x8(%r15), %r15
jmp 0x1af27
leaq 0x20(%rsp), %r13
movq 0x20(%r13), %rax
movq %rax, 0xa0(%rsp)
movaps (%r13), %xmm0
movaps 0x10(%r13), %xmm1
movaps %xmm1, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x19a74
movq %rax, %rdi
callq 0x1af61
movq %rax, %rdi
movq %r13, %rsi
callq 0x1afe1
movq %rax, %r15
movq (%rax), %rdi
movq %r13, %rsi
callq 0x1a1c6
movaps (%r13), %xmm0
movaps 0x10(%r13), %xmm1
movups %xmm0, 0x60(%r12)
movq 0x20(%r13), %rax
movq %rax, 0x80(%r12)
movups %xmm1, 0x70(%r12)
movq 0x68(%r12), %rax
orq 0x18(%rsp), %rax
movq %rax, 0x68(%r12)
movq 0x38(%r13), %rcx
movq %rcx, 0xb8(%r12)
movq (%r15), %rcx
movq %rcx, 0xc(%r12)
movq (%rsp), %rsi
testq %rsi, %rsi
je 0x1ab65
movq %rbp, 0x78(%rsp)
movq %rbx, 0x8(%rsp)
movq 0x68(%rsp), %rbp
movl $0x10, %r13d
cmpq $0x20000, %rbp          # imm = 0x20000
jne 0x1aa69
orq $0x20000, %rax          # imm = 0x20000
movq %rax, 0x68(%r12)
movl $0x2, %r13d
movq %r12, %rdi
movl %r13d, %edx
callq 0x2c3dd
movq 0x60(%r12), %rbx
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x1ab82
testq %rbx, %rbx
je 0x1abaa
cmpb $0x5, (%rbx)
jne 0x1abaa
movq 0x60(%rbx), %rax
cmpq 0x46525(%rip), %rax     # 0x60fc8
jne 0x1aad0
movq 0x18(%r12), %rdi
callq 0x2e465
movq 0x4(%r12), %rdi
leaq 0x29590(%rip), %rsi     # 0x4404b
movq %rax, %rdx
xorl %eax, %eax
callq 0x11a38
leaq 0x51c6c(%rip), %rax     # 0x6c738
movq %rax, 0x60(%rbx)
movq 0x60(%rbx), %rax
cmpq 0x46455(%rip), %rax     # 0x60f30
jne 0x1ab08
movq 0x18(%r12), %rdi
callq 0x2e465
movq 0x4(%r12), %rdi
leaq 0x2957b(%rip), %rsi     # 0x4406e
movq %rax, %rdx
xorl %eax, %eax
callq 0x118b4
leaq 0x51c34(%rip), %rax     # 0x6c738
movq %rax, 0x60(%rbx)
movq 0x60(%rsp), %rax
orq %rax, 0x68(%r12)
movl (%r15), %eax
andl $0x3f, %eax
cmpl $0x3, %eax
jne 0x1ab3a
movq 0x10(%r15), %rdi
movl $0x12, %esi
callq 0x2b511
testq %rax, %rax
je 0x1ab3a
testb $0x2, 0x1(%rax)
jne 0x1af4f
movl (%r15), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1abce
cmpl $0x7b, 0x10(%r15)
jne 0x1abce
movq %r15, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
callq 0x1b2c4
jmp 0x1af24
movq (%r15), %rdi
leaq 0x2949b(%rip), %rsi     # 0x4400a
xorl %eax, %eax
callq 0x118b4
leaq 0x294af(%rip), %rdx     # 0x4402c
jmp 0x1af17
testq %rbx, %rbx
je 0x1abe0
cmpq $0x0, 0x18(%rbx)
jne 0x1abe0
movzbl (%rbx), %eax
cmpl $0xd, %eax
ja 0x1abe0
movl $0x2380, %ecx           # imm = 0x2380
btl %eax, %ecx
jae 0x1abe0
movq (%rsp), %rax
movq %rax, 0x18(%rbx)
jmp 0x1abe0
cmpq 0x46387(%rip), %rbx     # 0x60f38
jne 0x1abe0
testb $0x8, 0x68(%r12)
jne 0x1abe0
movq (%r15), %rdi
leaq 0x294c9(%rip), %rsi     # 0x4408e
xorl %eax, %eax
callq 0x11a38
jmp 0x1abe0
movq 0x68(%r12), %rax
testb $0x4, %al
jne 0x1abe0
orq $0x8, %rax
movq %rax, 0x68(%r12)
movl %r13d, 0x14(%rsp)
cmpq 0x46344(%rip), %rbx     # 0x60f30
jne 0x1ac1a
movq 0x18(%r12), %rdi
callq 0x2e465
movq 0x4(%r12), %rdi
leaq 0x2949b(%rip), %rsi     # 0x4409f
movq %rax, %rdx
xorl %eax, %eax
callq 0x118b4
leaq 0x51b23(%rip), %rax     # 0x6c738
movq %rax, 0x60(%r12)
xorl %r14d, %r14d
leaq 0x20(%rsp), %r13
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x1ac75
movl (%r15), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1ac75
cmpl $0x3d, 0x10(%r15)
jne 0x1ac75
movq 0x8(%r15), %rbx
leaq 0xb0(%r12), %rdi
movq %rbx, %rsi
callq 0x1a4b6
movq %rax, %r15
cmpq %rbx, %rax
jne 0x1ac75
movq %r15, %rdi
callq 0x2e5c0
movq (%r15), %rdi
leaq 0x2944b(%rip), %rsi     # 0x440b6
movq %rax, %rdx
xorl %eax, %eax
callq 0x11a38
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x1ace2
movq 0x78(%rsp), %rax
testq %rax, %rax
je 0x1ac8d
movq %r12, %rdi
callq *%rax
cmpq $0x0, 0xb0(%r12)
je 0x1acb9
testb $0x8, 0x68(%r12)
je 0x1acb9
movq 0x4(%r12), %rdi
leaq 0x2942a(%rip), %rsi     # 0x440d6
xorl %eax, %eax
callq 0x118b4
andb $-0x9, 0x68(%r12)
testb $0x48, 0x68(%r12)
jne 0x1ace2
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x2285b
movq 0x4d25b(%rip), %rdi     # 0x67f30
testq %rdi, %rdi
je 0x1ace2
movq %r12, %rsi
callq 0x2285b
movq %r12, %rdi
callq 0x2c15d
movq 0x38(%r12), %rax
testq %rax, %rax
je 0x1ad1d
movq 0xc8(%rax), %rcx
movq %rcx, 0xc8(%r12)
movq 0x40(%rax), %rax
movq %rax, 0x40(%r12)
cmpq $0x20000, %rbp          # imm = 0x20000
jne 0x1ad1d
movq %r12, %rdi
callq 0x36dad
cmpb $0x0, 0x71(%rsp)
je 0x1ad62
leaq 0x52d4d(%rip), %rax     # 0x6da78
cmpq %rax, 0x60(%r12)
je 0x1aeb0
xorl %eax, %eax
leaq 0x293c4(%rip), %rdx     # 0x44103
testb %al, %al
jne 0x1ad62
movq 0x4(%r12), %rdi
leaq 0x293ff(%rip), %rsi     # 0x4414e
xorl %eax, %eax
callq 0x11a38
leaq 0x52b5b(%rip), %rax     # 0x6d8b8
movq %rax, 0x60(%r12)
movl (%r15), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1af10
cmpl $0x2c, 0x10(%r15)
jne 0x1af10
movq 0x8(%r15), %rbx
xorl %r15d, %r15d
movq %r15, (%rsp)
movq (%rbx), %rdi
movl $0x3, %esi
callq 0x2b547
movq %rax, %r12
movaps 0x80(%rsp), %xmm0
movaps 0x90(%rsp), %xmm1
movaps %xmm0, 0x20(%rsp)
movaps %xmm1, 0x30(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x40(%rsp)
xorl %r14d, %r14d
movq %r15, 0x58(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1afe1
movq %rax, %rdi
movq %r13, %rsi
callq 0x19a74
movq %rax, %rdi
callq 0x1af61
movq %rax, %rdi
movq %r13, %rsi
callq 0x1afe1
movq %rax, %r15
movq (%rax), %rdi
movq %r13, %rsi
callq 0x1a1c6
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movups %xmm0, 0x60(%r12)
movq 0x40(%rsp), %rax
movq %rax, 0x80(%r12)
movups %xmm1, 0x70(%r12)
movq 0x68(%r12), %rax
orq 0x18(%rsp), %rax
movq %rax, 0x68(%r12)
movq 0x58(%rsp), %rcx
movq %rcx, 0xb8(%r12)
movq (%r15), %rcx
movq %rcx, 0xc(%r12)
movq (%rsp), %rsi
testq %rsi, %rsi
je 0x1af3c
cmpq $0x20000, %rbp          # imm = 0x20000
jne 0x1ae65
orq $0x20000, %rax          # imm = 0x20000
movq %rax, 0x68(%r12)
movq %r12, %rdi
movl 0x14(%rsp), %edx
callq 0x2c3dd
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x1ac22
movq 0x60(%r12), %rax
testq %rax, %rax
je 0x1ac22
cmpb $0x5, (%rax)
jne 0x1ac22
movq 0x68(%r12), %rax
testb $0x4, %al
jne 0x1ac22
orq $0x8, %rax
movq %rax, 0x68(%r12)
jmp 0x1ac22
movl (%r15), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1aed0
cmpl $0x2c, 0x10(%r15)
jne 0x1aed0
xorl %eax, %eax
leaq 0x2924a(%rip), %rdx     # 0x44115
jmp 0x1ad3f
movq 0xb0(%r12), %rax
testq %rax, %rax
je 0x1aef9
cmpb $0x3, (%rax)
jne 0x1af07
cmpq %r12, 0x20(%rax)
setne %al
leaq 0x2924d(%rip), %rdx     # 0x4413d
cmovneq %r14, %rdx
jmp 0x1ad3f
xorl %eax, %eax
leaq 0x29227(%rip), %rdx     # 0x44129
jmp 0x1ad3f
movb $0x1, %al
xorl %edx, %edx
jmp 0x1ad3f
leaq 0x29560(%rip), %rdx     # 0x44477
movq %r15, %rdi
movl $0x3b, %esi
callq 0x195d7
movq %rax, %r15
movq %r15, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rdi
leaq 0x29217(%rip), %rsi     # 0x4415d
xorl %eax, %eax
callq 0x11a38
jmp 0x1af27
movq %r15, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
callq 0x1b013
jmp 0x1af24