// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
movq %rdi, %rbx
xorl %eax, %eax
leaq 0x18(%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 0x1a810
movq 0x10(%rbx), %rdi
testb $0x4, 0x11(%rdi)
je 0x1a810
movl $0x100, %esi            # imm = 0x100
callq 0x2afd5
testq %rax, %rax
je 0x1a810
movq 0x40(%rax), %rax
movq 0x38(%rax), %rax
testq %rax, %rax
je 0x1a810
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq *%rax
jmp 0x1ae17
leaq 0x20(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x19753
movq %rax, %rbx
movq 0x8(%r15), %rax
movl %eax, %r14d
andl $0x3141007f, %r14d      # imm = 0x3141007F
andq $-0x31410080, %rax      # imm = 0xCEBEFF80
movq %rax, 0x8(%r15)
orq 0x48(%r15), %r14
movq (%rbx), %rdi
movl $0x3, %esi
callq 0x2b00b
movq %rax, %r15
movq (%rbx), %rdi
movl %edi, %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1a875
cmpl $0x3b, 0x10(%rbx)
jne 0x1a875
leaq 0x20(%rsp), %rsi
callq 0x1a111
movq 0x8(%rbx), %r12
jmp 0x1ae1a
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 %rbx, %rdi
movq %r13, %rsi
callq 0x199a8
movq %rax, %rdi
callq 0x1ae55
movq %rax, %rdi
movq %r13, %rsi
callq 0x1aed1
movq %rax, %r12
movq (%rax), %rdi
movq %r13, %rsi
callq 0x1a111
movaps (%r13), %xmm0
movaps 0x10(%r13), %xmm1
movups %xmm0, 0x60(%r15)
movq 0x20(%r13), %rax
movq %rax, 0x80(%r15)
movups %xmm1, 0x70(%r15)
movq 0x68(%r15), %rax
orq %r14, %rax
movq %rax, 0x68(%r15)
movq 0x38(%r13), %rcx
movq %rcx, 0xb8(%r15)
movq (%r12), %rcx
movq %rcx, 0xc(%r15)
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0x1a99a
movq %rbp, 0x78(%rsp)
movq 0x68(%rsp), %rbp
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x1a9b8
movl $0x10, 0xc(%rsp)
movq %r15, %rdi
movl $0x10, %edx
callq 0x2beca
movq 0x60(%r15), %rbx
testq %rbx, %rbx
je 0x1ab2d
cmpb $0x5, (%rbx)
jne 0x1aa1f
movq 0x60(%rbx), %rax
cmpq 0x4566c(%rip), %rax     # 0x5ffd0
je 0x1aa5e
cmpq 0x455cf(%rip), %rax     # 0x5ff40
jne 0x1aa87
movq 0x18(%r15), %rdi
callq 0x2de35
movq 0x4(%r15), %rdi
leaq 0x286a3(%rip), %rsi     # 0x4302e
movq %rax, %rdx
xorl %eax, %eax
callq 0x118fc
jmp 0x1aa7c
movq (%r12), %rdi
leaq 0x28625(%rip), %rsi     # 0x42fca
xorl %eax, %eax
callq 0x118fc
leaq 0x28639(%rip), %rdx     # 0x42fec
jmp 0x1ae0a
orq $0x20000, %rax          # imm = 0x20000
movq %rax, 0x68(%r15)
movl $0x2, 0xc(%rsp)
movq %r15, %rdi
movl $0x2, %edx
callq 0x2beca
movq 0x60(%r15), %rbx
testq %rbx, %rbx
je 0x1ab2d
movl $0x2, 0xc(%rsp)
cmpq $0x0, 0x18(%rbx)
jne 0x1aafb
movzbl (%rbx), %eax
cmpl $0xd, %eax
ja 0x1aafb
movl $0x2380, %ecx           # imm = 0x2380
btl %eax, %ecx
jae 0x1aafb
movq 0x18(%rsp), %rax
movq %rax, 0x18(%rbx)
jmp 0x1aafb
movl $0x10, 0xc(%rsp)
cmpq 0x4551a(%rip), %rbx     # 0x5ff48
jne 0x1aafb
movl $0x10, 0xc(%rsp)
testb $0x8, 0x68(%r15)
jne 0x1ab2d
movq (%r12), %rdi
leaq 0x285fc(%rip), %rsi     # 0x4304e
xorl %eax, %eax
callq 0x11a80
jmp 0x1ab2d
movq 0x18(%r15), %rdi
callq 0x2de35
movq 0x4(%r15), %rdi
leaq 0x28599(%rip), %rsi     # 0x4300b
movq %rax, %rdx
xorl %eax, %eax
callq 0x11a80
leaq 0x50cb5(%rip), %rax     # 0x6b738
movq %rax, 0x60(%rbx)
movq 0x60(%rsp), %rax
orq %rax, 0x68(%r15)
movl (%r12), %eax
andl $0x3f, %eax
cmpl $0x3, %eax
jne 0x1aaba
movq 0x10(%r12), %rdi
movl $0x12, %esi
callq 0x2afd5
testq %rax, %rax
je 0x1aaba
testb $0x2, 0x1(%rax)
jne 0x1ae43
movl (%r12), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1aae3
cmpl $0x7b, 0x10(%r12)
jne 0x1aae3
movq %r12, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x1b1c0
jmp 0x1ae17
movq 0x68(%r15), %rax
movl $0x10, 0xc(%rsp)
testb $0x4, %al
jne 0x1aafb
orq $0x8, %rax
movq %rax, 0x68(%r15)
cmpq 0x4543e(%rip), %rbx     # 0x5ff40
jne 0x1ab2d
movq 0x18(%r15), %rdi
callq 0x2de35
movq 0x4(%r15), %rdi
leaq 0x28547(%rip), %rsi     # 0x4305f
movq %rax, %rdx
xorl %eax, %eax
callq 0x118fc
leaq 0x50c0f(%rip), %rax     # 0x6b738
movq %rax, 0x60(%r15)
leaq 0x20(%rsp), %r13
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x1abf6
movl (%r12), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1ab8c
cmpl $0x3d, 0x10(%r12)
jne 0x1ab8c
movq 0x8(%r12), %rbx
leaq 0xb0(%r15), %rdi
movq %rbx, %rsi
callq 0x1a3f1
movq %rax, %r12
cmpq %rbx, %rax
jne 0x1ab8c
movq %r12, %rdi
callq 0x2df90
movq (%r12), %rdi
leaq 0x284f4(%rip), %rsi     # 0x43076
movq %rax, %rdx
xorl %eax, %eax
callq 0x11a80
movq 0x78(%rsp), %rax
testq %rax, %rax
je 0x1ab9b
movq %r15, %rdi
callq *%rax
cmpq $0x0, 0xb0(%r15)
sete %cl
movq 0x68(%r15), %rax
testb $0x8, %al
sete %dl
orb %cl, %dl
jne 0x1abd1
movq 0x4(%r15), %rdi
leaq 0x284d8(%rip), %rsi     # 0x43096
xorl %eax, %eax
callq 0x118fc
movq 0x68(%r15), %rax
andq $-0x9, %rax
movq %rax, 0x68(%r15)
testb $0x48, %al
jne 0x1abf6
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x227b4
movq 0x4c347(%rip), %rdi     # 0x66f30
testq %rdi, %rdi
je 0x1abf6
movq %r15, %rsi
callq 0x227b4
movq %r15, %rdi
callq 0x2bc31
movq 0x38(%r15), %rax
testq %rax, %rax
je 0x1ac2e
movq 0xc8(%rax), %rcx
movq %rcx, 0xc8(%r15)
movq 0x40(%rax), %rax
movq %rax, 0x40(%r15)
cmpq $0x20000, %rbp          # imm = 0x20000
jne 0x1ac2e
movq %r15, %rdi
callq 0x36296
cmpb $0x0, 0x71(%rsp)
je 0x1ac6a
leaq 0x28487(%rip), %rdx     # 0x430c3
leaq 0x51e35(%rip), %rax     # 0x6ca78
cmpq %rax, 0x60(%r15)
je 0x1adae
movq 0x4(%r15), %rdi
leaq 0x284b6(%rip), %rsi     # 0x4310e
xorl %eax, %eax
callq 0x11a80
leaq 0x51c52(%rip), %rax     # 0x6c8b8
movq %rax, 0x60(%r15)
movl (%r12), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1ae03
cmpl $0x2c, 0x10(%r12)
jne 0x1ae03
movq 0x8(%r12), %rbx
xorl %r12d, %r12d
movq %r12, 0x18(%rsp)
movq (%rbx), %rdi
movl $0x3, %esi
callq 0x2b00b
movq %rax, %r15
movaps 0x80(%rsp), %xmm0
movaps 0x90(%rsp), %xmm1
movaps %xmm0, 0x20(%rsp)
movaps %xmm1, 0x30(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %r12, 0x58(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1aed1
movq %rax, %rdi
movq %r13, %rsi
callq 0x199a8
movq %rax, %rdi
callq 0x1ae55
movq %rax, %rdi
movq %r13, %rsi
callq 0x1aed1
movq %rax, %r12
movq (%rax), %rdi
movq %r13, %rsi
callq 0x1a111
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movups %xmm0, 0x60(%r15)
movq 0x40(%rsp), %rax
movq %rax, 0x80(%r15)
movups %xmm1, 0x70(%r15)
movq 0x68(%r15), %rax
orq %r14, %rax
movq %rax, 0x68(%r15)
movq 0x58(%rsp), %rcx
movq %rcx, 0xb8(%r15)
movq (%r12), %rcx
movq %rcx, 0xc(%r15)
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0x1ae2f
cmpq $0x20000, %rbp          # imm = 0x20000
jne 0x1ad66
orq $0x20000, %rax          # imm = 0x20000
movq %rax, 0x68(%r15)
movq %r15, %rdi
movl 0xc(%rsp), %edx
callq 0x2beca
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x1ab32
movq 0x60(%r15), %rax
testq %rax, %rax
je 0x1ab32
cmpb $0x5, (%rax)
jne 0x1ab32
movq 0x68(%r15), %rax
testb $0x4, %al
jne 0x1ab32
orq $0x8, %rax
movq %rax, 0x68(%r15)
jmp 0x1ab32
movl (%r12), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1adcd
cmpl $0x2c, 0x10(%r12)
leaq 0x2830e(%rip), %rdx     # 0x430d5
je 0x1ac4d
movq 0xb0(%r15), %rax
leaq 0x2830e(%rip), %rdx     # 0x430e9
testq %rax, %rax
je 0x1ac4d
cmpb $0x3, (%rax)
jne 0x1ac6a
leaq 0x28309(%rip), %rdx     # 0x430fd
cmpq %r15, 0x20(%rax)
jne 0x1ac6a
jmp 0x1ac4d
leaq 0x2862d(%rip), %rdx     # 0x43437
movq %r12, %rdi
movl $0x3b, %esi
callq 0x1950f
movq %rax, %r12
movq %r12, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rdi
leaq 0x282e3(%rip), %rsi     # 0x4311d
xorl %eax, %eax
callq 0x11a80
jmp 0x1ae1a
movq %r12, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x1af03
jmp 0x1ae17