// File: /workspace/github_c_makefile_star2_O1/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 $0x88, %rsp
movq %rdi, %rbx
orb $0x8, 0x55(%rsi)
leaq 0x503c3(%rip), %rax     # 0x6c738
movq %rax, 0x60(%rsi)
movq %rsi, 0x10(%rsp)
leaq 0x98(%rsi), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r13d, %r13d
movq $0x0, (%rsp)
movl (%rbx), %eax
andl $0x3f, %eax
cmpl $0x3, %eax
jne 0x1c76e
xorl %eax, %eax
movq %rax, 0x8(%rsp)
movq 0x8(%rbx), %rdi
movq %rax, 0x80(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
leaq 0x30(%rsp), %rsi
callq 0x1afe1
movq %rax, %rbp
movl (%rax), %eax
andl $0x3f, %eax
cmpl $0x12, %eax
jne 0x1c441
cmpl $0x3d, 0x10(%rbp)
jne 0x1c441
movq 0x8(%rbp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3a79d
movq %rax, %rbp
movq 0x8(%rsp), %rdi
callq 0xf23d
movq %rax, %r12
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1c438
movq 0x10(%rax), %r14
testq %r14, %r14
jne 0x1c47e
leaq 0x4fcd9(%rip), %r14     # 0x6c118
jmp 0x1c47e
testq %r14, %r14
je 0x1c477
cmpb $0x3, (%r14)
movq %r14, %rax
jne 0x1c453
movq 0x60(%r14), %rax
cmpb $0x9, (%rax)
jne 0x1c45c
movq 0x60(%rax), %rax
cmpb $0xb, (%rax)
je 0x1c472
leaq 0x4fa10(%rip), %rcx     # 0x6be78
cmpq %rcx, 0x60(%rax)
jne 0x1ca0a
incq %r12
jmp 0x1c47e
leaq 0x502ba(%rip), %r14     # 0x6c738
cmpq $0x0, 0x8(%rsp)
jne 0x1c4ae
movq (%rbx), %r15
xorl %edi, %edi
callq 0x30029
movl (%rax), %ecx
orl $0x1, %ecx
movq %r15, 0x8(%rax)
andl $0xffff0001, %ecx       # imm = 0xFFFF0001
movl %ecx, (%rax)
movq %rax, 0x8(%rsp)
movq %r12, 0x20(%rax)
movq %r14, 0x10(%rax)
movq (%rbx), %rdi
movl $0x3, %esi
callq 0x2b547
movq %rax, %r15
movq 0x10(%rbx), %rsi
movq %rax, %rdi
movl $0x10, %edx
callq 0x2c3dd
andb $-0x2, 0x69(%r15)
movq 0x8(%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 0x2285b
leaq 0x513b6(%rip), %rcx     # 0x6d8b8
cmpq %rcx, %r13
je 0x1c513
cmpb $0x3, (%r14)
jne 0x1c51b
movq 0x60(%r14), %rax
jmp 0x1c51e
movq %rcx, %r13
jmp 0x1c6ca
movq %r14, %rax
cmpb $0x9, (%rax)
jne 0x1c533
movq %r13, %r14
cmpq 0x10(%rsp), %rax
je 0x1c536
movq 0x60(%rax), %r14
jmp 0x1c536
movq %rax, %r14
testq %r13, %r13
sete %al
cmpq %rcx, %r14
sete %cl
orb %al, %cl
je 0x1c54e
movq %r14, %r13
jmp 0x1c6b5
cmpq %r13, %r14
je 0x1c6b5
movzbl (%r13), %eax
movq %r13, %rcx
cmpl $0x3, %eax
jne 0x1c568
movq 0x60(%r13), %rcx
cmpb $0x9, (%rcx)
jne 0x1c571
movq 0x60(%rcx), %rcx
cmpb $0xb, (%rcx)
je 0x1c583
leaq 0x4f8fb(%rip), %rdx     # 0x6be78
cmpq %rdx, 0x60(%rcx)
jne 0x1c5b3
cmpb $0x3, (%r14)
movq %r14, %rcx
jne 0x1c590
movq 0x60(%r14), %rcx
cmpb $0x9, (%rcx)
jne 0x1c599
movq 0x60(%rcx), %rcx
cmpb $0xb, (%rcx)
je 0x1c670
leaq 0x4f8cf(%rip), %rdx     # 0x6be78
cmpq %rdx, 0x60(%rcx)
je 0x1c670
movq %r13, %rcx
cmpl $0x3, %eax
jne 0x1c5bf
movq 0x60(%r13), %rcx
cmpb $0x9, (%rcx)
jne 0x1c5c8
movq 0x60(%rcx), %rcx
cmpb $0x3, (%r14)
movq %r14, %rdx
jne 0x1c5d5
movq 0x60(%r14), %rdx
cmpb $0x9, (%rdx)
jne 0x1c5de
movq 0x60(%rdx), %rdx
movzbl (%rcx), %ecx
cmpl $0xd, %ecx
sete %cl
cmpb $0xd, (%rdx)
setne %dl
xorb %cl, %dl
je 0x1c679
movq %r13, %rcx
cmpl $0x3, %eax
jne 0x1c601
movq 0x60(%r13), %rcx
cmpb $0x9, (%rcx)
jne 0x1c60a
movq 0x60(%rcx), %rcx
cmpb $0xd, (%rcx)
jne 0x1c69d
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x27fd9(%rip), %rsi     # 0x445fc
xorl %eax, %eax
callq 0x11a38
movq 0x8(%rsp), %rbx
movq %r13, %rdi
callq 0x2386c
movq 0x8(%rbx), %rdi
leaq 0x27fd7(%rip), %rsi     # 0x44619
movq %rax, %rdx
xorl %eax, %eax
callq 0x11744
movq 0x8(%rsp), %rbx
movq %r14, %rdi
callq 0x2386c
movq 0x8(%rbx), %rdi
leaq 0x27fc5(%rip), %rsi     # 0x44629
movq %rax, %rdx
xorl %eax, %eax
callq 0x11744
jmp 0x1c6ae
leaq 0x500c1(%rip), %r13     # 0x6c738
jmp 0x1c6b5
movq (%rsp), %rax
leal 0x1(%rax), %ebx
testl %eax, %eax
jne 0x1c6bb
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x27f56(%rip), %rsi     # 0x445ea
xorl %eax, %eax
callq 0x118b4
jmp 0x1c6bb
movq (%rbx), %rdi
leaq 0x27f92(%rip), %rsi     # 0x44639
xorl %eax, %eax
callq 0x11a38
leaq 0x51203(%rip), %r13     # 0x6d8b8
movq (%rsp), %rax
movl %eax, %ebx
movq 0x10(%rsp), %rax
movq %r13, 0x60(%rax)
movl %ebx, %eax
movq %rax, (%rsp)
cmpb $0x3, (%r13)
movq %r13, %rax
jne 0x1c6d8
movq 0x60(%r13), %rax
cmpb $0x9, (%rax)
jne 0x1c6e1
movq 0x60(%rax), %rax
cmpb $0xb, (%rax)
je 0x1c6f3
leaq 0x4f78b(%rip), %rcx     # 0x6be78
cmpq %rcx, 0x60(%rax)
jne 0x1c73d
cmpb $0x3, (%r14)
movq %r14, %rax
jne 0x1c700
movq 0x60(%r14), %rax
cmpb $0x4, (%rax)
jne 0x1c709
xorl %eax, %eax
jmp 0x1c710
testb $0x40, 0x69(%rax)
sete %al
testq %r12, %r12
jns 0x1c72c
testb %al, %al
je 0x1c72c
movq 0x20(%rsp), %rax
cmpq %r12, %rax
cmovgeq %r12, %rax
movq %rax, 0x20(%rsp)
jmp 0x1c73d
movq 0x28(%rsp), %rax
cmpq %r12, %rax
cmovbeq %r12, %rax
movq %rax, 0x28(%rsp)
movq (%rbp), %rax
movq %rax, 0xc(%r15)
movl (%rbp), %ecx
andl $0x3f, %ecx
movb $0x1, %al
cmpl $0x12, %ecx
jne 0x1c759
cmpl $0x2c, 0x10(%rbp)
setne %al
testb %al, %al
jne 0x1c761
movq 0x8(%rbp), %rbp
movq %rbp, %rbx
testb %al, %al
je 0x1c3ad
jmp 0x1c771
movq %rbx, %rbp
testq %r13, %r13
je 0x1c861
cmpb $0x3, (%r13)
movq %r13, %rax
movq 0x10(%rsp), %rbx
movq (%rsp), %r12
jne 0x1c791
movq 0x60(%r13), %rax
cmpb $0x9, (%rax)
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r15
jne 0x1c7a4
movq 0x60(%rax), %rax
cmpb $0xb, (%rax)
je 0x1c7ba
movq 0x60(%rax), %rax
cmpq 0x447cc(%rip), %rax     # 0x60f80
jne 0x1c883
leaq 0x50137(%rip), %r13     # 0x6c8f8
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1ca1b
testl %eax, %eax
jne 0x1c883
leaq 0x4ff5a(%rip), %r13     # 0x6c738
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1ca1b
testl %eax, %eax
jne 0x1c883
leaq 0x5039d(%rip), %r13     # 0x6cb98
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1ca1b
testl %eax, %eax
jne 0x1c883
leaq 0x501c4(%rip), %r13     # 0x6c9d8
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1ca1b
testl %eax, %eax
jne 0x1c883
leaq 0x5060b(%rip), %r13     # 0x6ce38
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1ca1b
testl %eax, %eax
jne 0x1c883
leaq 0x50432(%rip), %r13     # 0x6cc78
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1ca1b
testl %eax, %eax
jne 0x1c883
leaq 0x51059(%rip), %r13     # 0x6d8b8
jmp 0x1c883
movq (%rbp), %rdi
leaq 0x27de1(%rip), %rsi     # 0x4464d
xorl %eax, %eax
callq 0x11a38
leaq 0x5103e(%rip), %r13     # 0x6d8b8
movq 0x10(%rsp), %rbx
movq (%rsp), %r12
movq %r13, 0x60(%rbx)
movq 0x68(%r13), %rax
andl $0x4000, %eax           # imm = 0x4000
orq %rax, 0x68(%rbx)
andb $-0x9, 0x55(%rbx)
testl %r12d, %r12d
jne 0x1c9f5
leaq 0x4fe90(%rip), %rcx     # 0x6c738
cmpb $0x3, (%rcx)
movq %rcx, %rax
jne 0x1c8b4
movq 0x60(%rcx), %rax
movq 0x98(%rbx), %rdx
movq %rdx, 0x18(%rsp)
movl 0x50(%rcx), %ecx
cmpb $0x4, (%rax)
je 0x1c8e7
testb $0x40, 0x69(%rax)
jne 0x1c8e7
decb %cl
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, (%rsp)
leaq -0x1(%rdx), %rax
movq %rax, 0x10(%rsp)
jmp 0x1c900
negb %cl
movq $-0x1, %rax
shrq %cl, %rax
movq %rax, 0x10(%rsp)
movq $0x0, (%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x1c9f5
movq 0x18(%rsp), %r14
movzwl (%r14), %eax
testb %al, %al
jle 0x1c9e6
xorl %r12d, %r12d
movq 0x18(%r14,%r12,8), %rcx
movzwl %ax, %eax
cmpl $0x100, %eax            # imm = 0x100
jb 0x1c938
testq %rcx, %rcx
je 0x1c9d3
movq 0xb0(%rcx), %rbx
cmpb $0x1, (%rbx)
jne 0x1c9d3
movq 0x10(%rbx), %r15
movq %rbx, %rdi
callq 0xf23d
movzbl (%r15), %ecx
movq %r15, %rdx
cmpl $0x3, %ecx
jne 0x1c964
movq 0x60(%r15), %rdx
cmpb $0x9, (%rdx)
jne 0x1c96d
movq 0x60(%rdx), %rdx
cmpb $0xb, (%rdx)
je 0x1c97f
leaq 0x4f4ff(%rip), %rsi     # 0x6be78
cmpq %rsi, 0x60(%rdx)
jne 0x1c9c5
cmpl $0x3, %ecx
jne 0x1c988
movq 0x60(%r15), %r15
cmpb $0x4, (%r15)
jne 0x1c992
xorl %ecx, %ecx
jmp 0x1c99a
testb $0x40, 0x69(%r15)
sete %cl
testq %rax, %rax
jns 0x1c9ac
testb %cl, %cl
je 0x1c9ac
cmpq %rax, (%rsp)
setle %al
jmp 0x1c9b4
cmpq %rax, 0x10(%rsp)
setae %al
testb %al, %al
je 0x1c9c5
leaq 0x4fd79(%rip), %rax     # 0x6c738
movq %rax, 0x10(%rbx)
jmp 0x1c9d3
movq %rbx, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xea84
incq %r12
movl (%r14), %eax
movsbq %al, %rcx
cmpq %rcx, %r12
jl 0x1c920
movq 0x10(%r14), %r14
cmpq 0x18(%rsp), %r14
jne 0x1c911
movq %rbp, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdi
leaq 0x27bb1(%rip), %rsi     # 0x445c5
xorl %eax, %eax
callq 0x11b54