// File: /workspace/github_c_makefile_star2_O2/lucvoo[P]sparse-dev/parse.c
// Function: parse_enum_declaration
static struct token *parse_enum_declaration(struct token *token, struct symbol *parent)
{
	unsigned long long lastval = 0;
	struct symbol *ctype = NULL, *base_type = NULL;
	struct range range = { };
	int mix_bitwise = 0;

	parent->examined = 1;
	parent->ctype.base_type = &int_ctype;
	while (token_type(token) == TOKEN_IDENT) {
		struct expression *expr = NULL;
		struct token *next = token->next;
		struct decl_state ctx = { };
		struct symbol *sym;

		// FIXME: only 'deprecated' should be accepted
		next = handle_attributes(next, &ctx);

		if (match_op(next, '=')) {
			next = constant_expression(next->next, &expr);
			lastval = get_expression_value(expr);
			ctype = &void_ctype;
			if (expr && expr->ctype)
				ctype = expr->ctype;
		} else if (!ctype) {
			ctype = &int_ctype;
		} else if (is_int_type(ctype)) {
			lastval++;
		} else {
			error_die(token->pos, "can't increment the last enum member");
		}

		if (!expr) {
			expr = alloc_expression(token->pos, EXPR_VALUE);
			expr->value = lastval;
			expr->ctype = ctype;
		}

		sym = alloc_symbol(token->pos, SYM_NODE);
		bind_symbol(sym, token->ident, NS_SYMBOL);
		sym->ctype.modifiers &= ~MOD_ADDRESSABLE;
		sym->initializer = expr;
		sym->enum_member = 1;
		sym->ctype.base_type = parent;
		add_ptr_list(&parent->symbol_list, sym);

		if (base_type != &bad_ctype) {
			if (ctype->type == SYM_NODE)
				ctype = ctype->ctype.base_type;
			if (ctype->type == SYM_ENUM) {
				if (ctype == parent)
					ctype = base_type;
				else 
					ctype = ctype->ctype.base_type;
			}
			/*
			 * base_type rules:
			 *  - if all enums are of the same type, then
			 *    the base_type is that type (two first
			 *    cases)
			 *  - if enums are of different types, they
			 *    all have to be integer types, and the
			 *    base type is at least "int_ctype".
			 *  - otherwise the base_type is "bad_ctype".
			 */
			if (!base_type || ctype == &bad_ctype) {
				base_type = ctype;
			} else if (ctype == base_type) {
				/* nothing */
			} else if (is_int_type(base_type) && is_int_type(ctype)) {
				base_type = &int_ctype;
			} else if (is_restricted_type(base_type) != is_restricted_type(ctype)) {
				if (!mix_bitwise++) {
					warning(expr->pos, "mixed bitwiseness");
				}
			} else if (is_restricted_type(base_type) && base_type != ctype) {
				sparse_error(expr->pos, "incompatible restricted type");
				info(expr->pos, "   expected: %s", show_typename(base_type));
				info(expr->pos, "        got: %s", show_typename(ctype));
				base_type = &bad_ctype;
			} else if (base_type != &bad_ctype) {
				sparse_error(token->pos, "bad enum definition");
				base_type = &bad_ctype;
			}
			parent->ctype.base_type = base_type;
		}
		if (is_int_type(base_type)) {
			update_range(&range, lastval, ctype);
		}
		token = next;

		sym->endpos = token->pos;

		if (!match_op(token, ','))
			break;
		token = token->next;
	}
	if (!base_type) {
		sparse_error(token->pos, "empty enum definition");
		base_type = &bad_ctype;
	}
	else if (!is_int_type(base_type))
		;
	else if (type_is_ok(&uint_ctype, range))
		base_type = &uint_ctype;
	else if (type_is_ok(&int_ctype, range))
		base_type = &int_ctype;
	else if (type_is_ok(&ulong_ctype, range))
		base_type = &ulong_ctype;
	else if (type_is_ok(&long_ctype, range))
		base_type = &long_ctype;
	else if (type_is_ok(&ullong_ctype, range))
		base_type = &ullong_ctype;
	else if (type_is_ok(&llong_ctype, range))
		base_type = &llong_ctype;
	else
		base_type = &bad_ctype;
	parent->ctype.base_type = base_type;
	parent->ctype.modifiers |= (base_type->ctype.modifiers & MOD_UNSIGNED);
	parent->examined = 0;

	if (mix_bitwise)
		return token;
	cast_enum_list(parent->symbol_list, base_type);

	return token;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
leaq 0x30(%rsp), %rax
andq $0x0, (%rax)
leaq 0x28(%rsp), %rax
andq $0x0, (%rax)
movq %rdi, %rbx
orb $0x8, 0x55(%rsi)
leaq 0x4b827(%rip), %rax     # 0x65738
movq %rax, 0x60(%rsi)
movq %rsi, 0x10(%rsp)
leaq 0x98(%rsi), %rax
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r13d, %r13d
movl $0x0, 0x8(%rsp)
movl (%rbx), %eax
andl $0x3f, %eax
cmpl $0x3, %eax
jne 0x1a221
andq $0x0, (%rsp)
movq 0x8(%rbx), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x90(%rsp)
leaq 0x40(%rsp), %rsi
callq 0x18eca
movl (%rax), %ecx
andl $0x3f, %ecx
cmpl $0x12, %ecx
jne 0x19fc7
cmpl $0x3d, 0x10(%rax)
jne 0x19fc7
movq 0x8(%rax), %rdi
movq %rsp, %rsi
callq 0x33498
movq %rax, 0x20(%rsp)
movq (%rsp), %rdi
callq 0xfe1b
movq %rax, %rbp
movq (%rsp), %rax
testq %rax, %rax
je 0x19ff9
movq 0x10(%rax), %r14
testq %r14, %r14
jne 0x19fed
leaq 0x4b153(%rip), %r14     # 0x65118
jmp 0x19fed
movq %rax, 0x20(%rsp)
testq %r14, %r14
je 0x19fe6
movq %r14, %rdi
callq 0x19e3c
testl %eax, %eax
je 0x1a42d
incq %rbp
jmp 0x19fed
leaq 0x4b74b(%rip), %r14     # 0x65738
cmpq $0x0, (%rsp)
movq %r14, %r12
jne 0x1a01a
jmp 0x1a000
leaq 0x4b118(%rip), %r14     # 0x65118
movq (%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x185a7
movq %rax, (%rsp)
movq %rbp, 0x20(%rax)
movq %r14, 0x10(%rax)
movq %r14, %r12
movq (%rbx), %rdi
pushq $0x3
popq %rsi
callq 0x2671f
movq %rax, %r15
movq 0x10(%rbx), %rsi
movq %rax, %rdi
pushq $0x10
popq %rdx
callq 0x274ad
andb $-0x2, 0x69(%r15)
movq (%rsp), %rax
movq %rax, 0xb0(%r15)
orb $0x10, 0x2(%r15)
movq 0x10(%rsp), %rax
movq %rax, 0x60(%r15)
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x1fae9
leaq 0x4c84f(%rip), %rax     # 0x668b8
cmpq %rax, %r13
je 0x1a098
movzbl (%r12), %eax
cmpl $0x3, %eax
jne 0x1a082
movq 0x60(%r12), %r12
movzbl (%r12), %eax
cmpl $0x9, %eax
jne 0x1a0a3
movq %r13, %r14
cmpq 0x10(%rsp), %r12
je 0x1a0a6
movq 0x60(%r12), %r14
jmp 0x1a0a6
movq %r12, %r14
movq %rax, %r13
jmp 0x1a1c2
movq %r12, %r14
testq %r13, %r13
sete %al
cmpq 0x3fead(%rip), %r14     # 0x59f60
sete %cl
orb %al, %cl
je 0x1a0c2
movq %r14, %r13
jmp 0x1a1b9
cmpq %r13, %r14
je 0x1a1b9
movq %r13, %rdi
callq 0x19e3c
testl %eax, %eax
je 0x1a0ef
movq %r14, %rdi
callq 0x19e3c
testl %eax, %eax
je 0x1a0ef
leaq 0x4b64e(%rip), %r13     # 0x65738
jmp 0x1a1b9
movq %r13, %rdi
callq 0x1a43e
movl %eax, 0x3c(%rsp)
cmpl $0xd, %eax
sete %r12b
movq %r14, %rdi
callq 0x1a43e
cmpl $0xd, %eax
setne %al
xorb %r12b, %al
je 0x1a176
cmpl $0xd, 0x3c(%rsp)
jne 0x1a182
movq (%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x224f1(%rip), %rsi     # 0x3c61c
xorl %eax, %eax
callq 0x1120e
movq (%rsp), %rbx
movq %r13, %rdi
callq 0x20b5a
movq 0x8(%rbx), %rdi
leaq 0x224f0(%rip), %rsi     # 0x3c639
movq %rax, %rdx
xorl %eax, %eax
callq 0x10ddc
movq (%rsp), %rbx
movq %r14, %rdi
callq 0x20b5a
movq 0x8(%rbx), %rdi
leaq 0x224df(%rip), %rsi     # 0x3c649
movq %rax, %rdx
xorl %eax, %eax
callq 0x10ddc
jmp 0x1a193
movl 0x8(%rsp), %eax
testl %eax, %eax
je 0x1a19c
incl %eax
jmp 0x1a1b5
movq (%rbx), %rdi
leaq 0x224cd(%rip), %rsi     # 0x3c659
xorl %eax, %eax
callq 0x1120e
leaq 0x4c71e(%rip), %r13     # 0x668b8
jmp 0x1a1b9
movq (%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x2245f(%rip), %rsi     # 0x3c60a
xorl %eax, %eax
callq 0x1108a
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
movq 0x10(%rsp), %rax
movq %r13, 0x60(%rax)
movq %r13, %rdi
callq 0x19e3c
testl %eax, %eax
je 0x1a1fc
movq %r14, %rdi
callq 0x1a4ac
testq %rbp, %rbp
jns 0x1a1ed
testl %eax, %eax
je 0x1a1ed
leaq 0x30(%rsp), %rax
cmpq %rbp, 0x30(%rsp)
jg 0x1a1f9
jmp 0x1a1fc
leaq 0x28(%rsp), %rax
cmpq %rbp, 0x28(%rsp)
jae 0x1a1fc
movq %rbp, (%rax)
movq 0x20(%rsp), %rbx
movq (%rbx), %rax
movq %rax, 0xc(%r15)
movl (%rbx), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1a221
cmpl $0x2c, 0x10(%rbx)
jne 0x1a221
movq 0x8(%rbx), %rbx
jmp 0x19f36
testq %r13, %r13
movq %rbx, 0x20(%rsp)
je 0x1a2e5
movq %r13, %rdi
callq 0x19e3c
testl %eax, %eax
je 0x1a2fd
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r14
leaq 0x4b6a8(%rip), %r13     # 0x658f8
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1a45a
testl %eax, %eax
jne 0x1a2fd
leaq 0x4b4cb(%rip), %r13     # 0x65738
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1a45a
testl %eax, %eax
jne 0x1a2fd
leaq 0x4b912(%rip), %r13     # 0x65b98
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1a45a
testl %eax, %eax
jne 0x1a2fd
leaq 0x4b739(%rip), %r13     # 0x659d8
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1a45a
testl %eax, %eax
jne 0x1a2fd
leaq 0x4bb80(%rip), %r13     # 0x65e38
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1a45a
testl %eax, %eax
jne 0x1a2fd
leaq 0x4b9a7(%rip), %r13     # 0x65c78
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1a45a
testl %eax, %eax
je 0x1a2f6
jmp 0x1a2fd
movq (%rbx), %rdi
leaq 0x2237e(%rip), %rsi     # 0x3c66d
xorl %eax, %eax
callq 0x1120e
leaq 0x4c5bb(%rip), %r13     # 0x668b8
movq 0x10(%rsp), %rcx
movq %r13, 0x60(%rcx)
movq 0x68(%r13), %rax
andl $0x4000, %eax           # imm = 0x4000
orq %rax, 0x68(%rcx)
andb $-0x9, 0x55(%rcx)
cmpl $0x0, 0x8(%rsp)
jne 0x1a416
movq 0x18(%rsp), %rax
movq (%rax), %rbx
leaq 0x4b407(%rip), %rdi     # 0x65738
movb 0x50(%rdi), %r14b
callq 0x1a4ac
leal -0x1(%r14), %ecx
pushq $0x1
popq %rdx
shlq %cl, %rdx
leaq -0x1(%rdx), %rsi
negb %r14b
pushq $-0x1
popq %rdi
movl %r14d, %ecx
shrq %cl, %rdi
xorl %ecx, %ecx
testl %eax, %eax
cmovneq %rsi, %rdi
movq %rdi, 0x10(%rsp)
cmovneq %rdx, %rcx
movq %rcx, 0x18(%rsp)
movq %rbx, 0x8(%rsp)
testq %rbx, %rbx
je 0x1a416
movq 0x8(%rsp), %r12
xorl %ebx, %ebx
movl (%r12), %eax
movsbq %al, %rcx
cmpq %rcx, %rbx
jge 0x1a406
movq 0x18(%r12,%rbx,8), %rcx
cmpw $0x100, %ax             # imm = 0x100
jb 0x1a39c
testq %rcx, %rcx
je 0x1a3fe
movq 0xb0(%rcx), %r14
cmpb $0x1, (%r14)
jne 0x1a3fe
movq 0x10(%r14), %rbp
movq %r14, %rdi
callq 0xfe1b
movq %rax, %r15
movq %rbp, %rdi
callq 0x19e3c
testl %eax, %eax
je 0x1a3f0
movq %rbp, %rdi
callq 0x1a4ac
testq %r15, %r15
jns 0x1a3e9
testl %eax, %eax
je 0x1a3e9
cmpq %r15, 0x18(%rsp)
jg 0x1a3f0
leaq 0x4b355(%rip), %rax     # 0x65738
movq %rax, 0x10(%r14)
jmp 0x1a3fe
cmpq %r15, 0x10(%rsp)
jae 0x1a3dc
movq %r14, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0xe4ec
incq %rbx
jmp 0x1a37f
movq 0x10(%r12), %r12
cmpq 0x8(%rsp), %r12
jne 0x1a37d
movq 0x20(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdi
leaq 0x221ae(%rip), %rsi     # 0x3c5e5
xorl %eax, %eax
callq 0x1132a