// File: /workspace/github_c_makefile_star2_O2/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 $0xb8, %rsp
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %rbx
leaq 0x18(%rsp), %rax
andq $0x0, (%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x80(%rsp)
movq %rax, 0x58(%rsp)
movl (%rdi), %eax
andl $0x3f, %eax
cmpl $0x3, %eax
jne 0x1864d
movq 0x10(%rbx), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x18e4b
testq %rax, %rax
je 0x1864d
movq 0x40(%rax), %rax
movq 0x38(%rax), %rax
testq %rax, %rax
je 0x1864d
movq %rbx, %rdi
movq %rbp, %rsi
callq *%rax
jmp 0x18b3b
leaq 0x30(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x176c5
movq %rax, %rbx
movq 0x8(%r14), %rax
movl %eax, %r12d
andl $0x3141007f, %r12d      # imm = 0x3141007F
andq $-0x31410080, %rax      # imm = 0xCEBEFF80
movq %rax, 0x8(%r14)
orq 0x48(%r14), %r12
movq (%rbx), %rdi
pushq $0x3
popq %rsi
callq 0x2671f
movq %rax, %r15
movq (%rbx), %rdi
movl %edi, %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x186b0
cmpl $0x3b, 0x10(%rbx)
jne 0x186b0
leaq 0x30(%rsp), %rsi
callq 0x17fba
movq 0x8(%rbx), %r14
jmp 0x18b3e
movq %r13, 0x8(%rsp)
leaq 0x30(%rsp), %r13
movq 0x20(%r13), %rax
movq %rax, 0xb0(%rsp)
movaps (%r13), %xmm0
movaps 0x10(%r13), %xmm1
movaps %xmm1, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x178e3
movq %rax, %rdi
callq 0x18e58
movq %rax, %rdi
movq %r13, %rsi
callq 0x18eca
movq %rax, %r14
movq (%rax), %rdi
movq %r13, %rsi
callq 0x17fba
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 %r12, %rax
movq %rax, 0x68(%r15)
movq 0x38(%r13), %rcx
movq %rcx, 0xb8(%r15)
movq (%r14), %rcx
movq %rcx, 0xc(%r15)
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0x18769
movq %rbp, 0x20(%rsp)
movq 0x78(%rsp), %rbp
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x18786
pushq $0x10
jmp 0x18792
movq (%r14), %rdi
leaq 0x238b7(%rip), %rsi     # 0x3c02a
xorl %eax, %eax
callq 0x1108a
leaq 0x238cb(%rip), %rdx     # 0x3c04c
jmp 0x18b30
orq $0x20000, %rax          # imm = 0x20000
movq %rax, 0x68(%r15)
pushq $0x2
popq %rdx
movq 0x8(%rsp), %r13
movq %r15, %rdi
movl %edx, 0x10(%rsp)
callq 0x274ad
movq 0x60(%r15), %rbx
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x18800
testq %rbx, %rbx
je 0x18868
cmpb $0x5, (%rbx)
jne 0x18829
movq 0x60(%rbx), %rax
cmpq 0x417fe(%rip), %rax     # 0x59fc8
je 0x18b62
cmpq 0x41769(%rip), %rax     # 0x59f40
jne 0x18b8b
movq 0x18(%r15), %rdi
callq 0x2936d
movq 0x4(%r15), %rdi
leaq 0x2389d(%rip), %rsi     # 0x3c08e
movq %rax, %rdx
xorl %eax, %eax
callq 0x1108a
jmp 0x18b80
testq %rbx, %rbx
je 0x18868
cmpq $0x0, 0x18(%rbx)
jne 0x18836
movzbl (%rbx), %eax
cmpl $0xd, %eax
ja 0x18836
movl $0x2380, %ecx           # imm = 0x2380
btl %eax, %ecx
jae 0x18836
movq 0x18(%rsp), %rax
movq %rax, 0x18(%rbx)
jmp 0x18836
cmpq 0x41718(%rip), %rbx     # 0x59f48
je 0x18dea
cmpq 0x41703(%rip), %rbx     # 0x59f40
jne 0x18868
movq 0x18(%r15), %rdi
callq 0x2936d
movq 0x4(%r15), %rdi
leaq 0x2386c(%rip), %rsi     # 0x3c0bf
movq %rax, %rdx
xorl %eax, %eax
callq 0x1108a
leaq 0x4ced4(%rip), %rax     # 0x65738
movq %rax, 0x60(%r15)
leaq 0x30(%rsp), %rbx
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x18922
movl (%r14), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x188c8
cmpl $0x3d, 0x10(%r14)
jne 0x188c8
movq 0x8(%r14), %r13
leaq 0xb0(%r15), %rdi
movq %r13, %rsi
callq 0x1825e
movq %rax, %r14
cmpq %r13, %rax
jne 0x188c3
movq %r14, %rdi
callq 0x294bb
movq (%r14), %rdi
leaq 0x2381d(%rip), %rsi     # 0x3c0d6
movq %rax, %rdx
xorl %eax, %eax
callq 0x1120e
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0x188d3
movq %r15, %rdi
callq *%r13
cmpq $0x0, 0xb0(%r15)
sete %cl
movq 0x68(%r15), %rax
testb $0x8, %al
sete %dl
orb %cl, %dl
jne 0x18909
movq 0x4(%r15), %rdi
leaq 0x23800(%rip), %rsi     # 0x3c0f6
xorl %eax, %eax
callq 0x1108a
movq 0x68(%r15), %rax
andq $-0x9, %rax
movq %rax, 0x68(%r15)
testb $0x48, %al
jne 0x18922
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x1fae9
movq %r15, %rdi
callq 0x175a3
movq %r15, %rdi
callq 0x27254
movq 0x38(%r15), %rax
testq %rax, %rax
je 0x1895a
movq 0xc8(%rax), %rcx
movq %rcx, 0xc8(%r15)
movq 0x40(%rax), %rax
movq %rax, 0x40(%r15)
cmpq $0x20000, %rbp          # imm = 0x20000
jne 0x1895a
movq %r15, %rdi
callq 0x3043c
cmpb $0x0, 0x81(%rsp)
je 0x18999
leaq 0x237b8(%rip), %rdx     # 0x3c123
leaq 0x4e106(%rip), %rax     # 0x66a78
cmpq %rax, 0x60(%r15)
je 0x18ad6
movq 0x4(%r15), %rdi
leaq 0x237e7(%rip), %rsi     # 0x3c16e
xorl %eax, %eax
callq 0x1120e
leaq 0x4df23(%rip), %rax     # 0x668b8
movq %rax, 0x60(%r15)
movl (%r14), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x18b29
cmpl $0x2c, 0x10(%r14)
jne 0x18b29
movq 0x8(%r14), %r14
andq $0x0, 0x18(%rsp)
movq (%r14), %rdi
pushq $0x3
popq %rsi
callq 0x2671f
movq %rax, %r15
movaps 0x90(%rsp), %xmm0
movaps 0xa0(%rsp), %xmm1
movaps %xmm0, 0x30(%rsp)
movaps %xmm1, 0x40(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x50(%rsp)
andq $0x0, 0x68(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x18eca
movq %rax, %rdi
movq %rbx, %rsi
callq 0x178e3
movq %rax, %rdi
callq 0x18e58
movq %rax, %rdi
movq %rbx, %rsi
callq 0x18eca
movq %rax, %r14
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x17fba
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movups %xmm0, 0x60(%r15)
movq 0x50(%rsp), %rax
movq %rax, 0x80(%r15)
movups %xmm1, 0x70(%r15)
movq 0x68(%r15), %rax
orq %r12, %rax
movq %rax, 0x68(%r15)
movq 0x68(%rsp), %rcx
movq %rcx, 0xb8(%r15)
movq (%r14), %rcx
movq %rcx, 0xc(%r15)
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0x18b53
cmpq $0x20000, %rbp          # imm = 0x20000
jne 0x18a8e
orq $0x20000, %rax          # imm = 0x20000
movq %rax, 0x68(%r15)
movq %r15, %rdi
movl 0x10(%rsp), %edx
callq 0x274ad
cmpq $0x20000, %rbp          # imm = 0x20000
je 0x1886d
movq 0x60(%r15), %rax
testq %rax, %rax
je 0x1886d
cmpb $0x5, (%rax)
jne 0x1886d
movq 0x68(%r15), %rax
testb $0x4, %al
jne 0x1886d
orq $0x8, %rax
movq %rax, 0x68(%r15)
jmp 0x1886d
movl (%r14), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x18af3
cmpl $0x2c, 0x10(%r14)
leaq 0x23648(%rip), %rdx     # 0x3c135
je 0x1897c
movq 0xb0(%r15), %rax
leaq 0x23648(%rip), %rdx     # 0x3c149
testq %rax, %rax
je 0x1897c
cmpb $0x3, (%rax)
jne 0x18999
leaq 0x23643(%rip), %rdx     # 0x3c15d
cmpq %r15, 0x20(%rax)
jne 0x18999
jmp 0x1897c
leaq 0x23967(%rip), %rdx     # 0x3c497
pushq $0x3b
popq %rsi
movq %r14, %rdi
callq 0x17480
movq %rax, %r14
movq %r14, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rdi
leaq 0x23620(%rip), %rsi     # 0x3c17d
jmp 0x18dde
movq 0x18(%r15), %rdi
callq 0x2936d
movq 0x4(%r15), %rdi
leaq 0x234f5(%rip), %rsi     # 0x3c06b
movq %rax, %rdx
xorl %eax, %eax
callq 0x1120e
leaq 0x4cbb1(%rip), %rax     # 0x65738
movq %rax, 0x60(%rbx)
movq 0x70(%rsp), %rax
orq %rax, 0x68(%r15)
movq %r14, %rdi
callq 0x18efc
testl %eax, %eax
je 0x18e0b
andq $0x0, 0x28(%rsp)
leaq 0x41a17(%rip), %rax     # 0x5a5c8
cmpl $0x0, (%rax)
je 0x18bd3
movq 0x18(%r15), %rdi
callq 0x2936d
movq (%r14), %rdi
leaq 0x259a2(%rip), %rsi     # 0x3e56b
movq %rax, %rdx
xorl %eax, %eax
callq 0x1108a
movq %r15, %r12
addq $0x60, %r12
leaq 0x28(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x19b2f
movq %rax, %r14
movq (%rax), %rdi
movl %edi, %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x18c13
cmpl $0x3b, 0x10(%r14)
jne 0x18c13
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x18efc
testl %eax, %eax
jne 0x18bdf
jmp 0x18c21
leaq 0x25976(%rip), %rsi     # 0x3e590
xorl %eax, %eax
callq 0x1120e
movq 0x28(%rsp), %r13
movq (%r12), %rax
movq 0x88(%rax), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x18d69
movq 0x10(%rsp), %rbx
xorl %ebp, %ebp
movl (%rbx), %eax
movsbq %al, %rcx
cmpq %rcx, %rbp
jge 0x18d5a
movq 0x18(%rbx,%rbp,8), %r12
cmpw $0x100, %ax             # imm = 0x100
jb 0x18c69
testq %r12, %r12
je 0x18d52
testq %r13, %r13
je 0x18cb6
movq %r13, %rcx
movzwl (%rcx), %edx
movsbl %dl, %eax
testw %ax, %ax
movl $0x0, %esi
cmovgl %eax, %esi
movzwl %si, %esi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x18cad
movq 0x18(%rcx,%rdi,8), %rax
cmpw $0x100, %dx             # imm = 0x100
jb 0x18c9d
testq %rax, %rax
je 0x18ca8
movq 0x18(%rax), %r8
cmpq 0x18(%r12), %r8
je 0x18d05
incq %rdi
jmp 0x18c87
movq 0x10(%rcx), %rcx
cmpq %r13, %rcx
jne 0x18c71
leaq 0x418f3(%rip), %rax     # 0x5a5b0
cmpl $0x0, (%rax)
je 0x18ce2
movq 0x18(%r12), %rdi
callq 0x2936d
movq 0x4(%r12), %rdi
leaq 0x258fc(%rip), %rsi     # 0x3e5d4
movq %rax, %rdx
xorl %eax, %eax
callq 0x1108a
movq 0x4(%r12), %rdi
pushq $0x3
popq %rsi
callq 0x2671f
movq 0x18(%r12), %rcx
movq %rcx, 0x18(%rax)
leaq 0x4ca39(%rip), %rcx     # 0x65738
movq %rcx, 0x60(%rax)
jmp 0x18d09
movq 0x60(%rax), %rcx
orb $0x2, 0x2(%rax)
addq $0x60, %rax
testq %rcx, %rcx
je 0x18d33
leaq 0x4c15b(%rip), %rdx     # 0x64e78
cmpq %rdx, 0x60(%rcx)
jne 0x18d33
testb $0x2, 0x57(%rcx)
je 0x18d33
leaq 0x4ca08(%rip), %rcx     # 0x65738
movq %rcx, (%rax)
movq 0x20(%rax), %rcx
movq %rcx, 0x80(%r12)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x70(%r12)
movups %xmm0, 0x60(%r12)
incq %rbp
jmp 0x18c46
movq 0x10(%rbx), %rbx
cmpq 0x10(%rsp), %rbx
jne 0x18c44
testq %r13, %r13
je 0x18dc3
movq %r13, %r12
xorl %ebp, %ebp
movl (%r12), %eax
movsbq %al, %rcx
cmpq %rcx, %rbp
jge 0x18db9
movq 0x18(%r12,%rbp,8), %rbx
cmpw $0x100, %ax             # imm = 0x100
jb 0x18d90
testq %rbx, %rbx
je 0x18db4
testb $0x2, 0x2(%rbx)
jne 0x18db4
movq 0x18(%rbx), %rdi
callq 0x2936d
movq 0x4(%rbx), %rdi
leaq 0x25856(%rip), %rsi     # 0x3e600
movq %rax, %rdx
xorl %eax, %eax
callq 0x1108a
incq %rbp
jmp 0x18d73
movq 0x10(%r12), %r12
cmpq %r13, %r12
jne 0x18d71
movq (%r14), %rdi
movl %edi, %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x18dd7
cmpl $0x7b, 0x10(%r14)
je 0x18e1d
leaq 0x257df(%rip), %rsi     # 0x3e5bd
xorl %eax, %eax
callq 0x1120e
jmp 0x18b3e
testb $0x8, 0x68(%r15)
jne 0x18868
movq (%r14), %rdi
leaq 0x232af(%rip), %rsi     # 0x3c0ae
xorl %eax, %eax
callq 0x1120e
jmp 0x18868
movl (%r14), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x18e32
cmpl $0x7b, 0x10(%r14)
jne 0x18e32
movq %r14, %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
callq 0x18f26
jmp 0x18b3b
movq 0x68(%r15), %rax
testb $0x4, %al
jne 0x18836
orq $0x8, %rax
movq %rax, 0x68(%r15)
jmp 0x18836