// File: /workspace/github_c_makefile_star2_O2/saltyJeff[P]uClibcpp/extra/config/./menu.c
// Function: menu_finalize
void menu_finalize(struct menu *parent)
{
	struct menu *menu, *last_menu;
	struct symbol *sym;
	struct property *prop;
	struct expr *parentdep, *basedep, *dep, *dep2, **ep;

	sym = parent->sym;
	if (parent->list) {
		if (sym && sym_is_choice(sym)) {
			/* find the first choice value and find out choice type */
			for (menu = parent->list; menu; menu = menu->next) {
				if (menu->sym) {
					current_entry = parent;
					menu_set_type(menu->sym->type);
					current_entry = menu;
					menu_set_type(sym->type);
					break;
				}
			}
			parentdep = expr_alloc_symbol(sym);
		} else if (parent->prompt)
			parentdep = parent->prompt->visible.expr;
		else
			parentdep = parent->dep;

		for (menu = parent->list; menu; menu = menu->next) {
			basedep = expr_transform(menu->dep);
			basedep = expr_alloc_and(expr_copy(parentdep), basedep);
			basedep = expr_eliminate_dups(basedep);
			menu->dep = basedep;
			if (menu->sym)
				prop = menu->sym->prop;
			else
				prop = menu->prompt;
			for (; prop; prop = prop->next) {
				if (prop->menu != menu)
					continue;
				dep = expr_transform(prop->visible.expr);
				dep = expr_alloc_and(expr_copy(basedep), dep);
				dep = expr_eliminate_dups(dep);
				if (menu->sym && menu->sym->type != S_TRISTATE)
					dep = expr_trans_bool(dep);
				prop->visible.expr = dep;
				if (prop->type == P_SELECT) {
					struct symbol *es = prop_get_symbol(prop);
					es->rev_dep.expr = expr_alloc_or(es->rev_dep.expr,
							expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep)));
				}
			}
		}
		for (menu = parent->list; menu; menu = menu->next)
			menu_finalize(menu);
	} else if (sym) {
		basedep = parent->prompt ? parent->prompt->visible.expr : NULL;
		basedep = expr_trans_compare(basedep, E_UNEQUAL, &symbol_no);
		basedep = expr_eliminate_dups(expr_transform(basedep));
		last_menu = NULL;
		for (menu = parent->next; menu; menu = menu->next) {
			dep = menu->prompt ? menu->prompt->visible.expr : menu->dep;
			if (!expr_contains_symbol(dep, sym))
				break;
			if (expr_depends_symbol(dep, sym))
				goto next;
			dep = expr_trans_compare(dep, E_UNEQUAL, &symbol_no);
			dep = expr_eliminate_dups(expr_transform(dep));
			dep2 = expr_copy(basedep);
			expr_eliminate_eq(&dep, &dep2);
			expr_free(dep);
			if (!expr_is_yes(dep2)) {
				expr_free(dep2);
				break;
			}
			expr_free(dep2);
		next:
			menu_finalize(menu);
			menu->parent = parent;
			last_menu = menu;
		}
		if (last_menu) {
			parent->list = parent->next;
			parent->next = last_menu->next;
			last_menu->next = NULL;
		}
	}
	for (menu = parent->list; menu; menu = menu->next) {
		if (sym && sym_is_choice(sym) && menu->sym) {
			menu->sym->flags |= SYMBOL_CHOICEVAL;
			if (!menu->prompt)
				fprintf(stderr, "%s:%d:warning: choice value must have a prompt\n",
					menu->file->name, menu->lineno);
			for (prop = menu->sym->prop; prop; prop = prop->next) {
				if (prop->type == P_PROMPT && prop->menu != menu) {
					fprintf(stderr, "%s:%d:warning: choice values currently only support a single prompt\n",
						prop->file->name, prop->lineno);
					
				}
				if (prop->type == P_DEFAULT)
					fprintf(stderr, "%s:%d:warning: defaults for choice values not supported\n",
						prop->file->name, prop->lineno);
			}
			current_entry = menu;
			menu_set_type(sym->type);
			menu_add_symbol(P_CHOICE, sym, NULL);
			prop = sym_get_choice_prop(sym);
			for (ep = &prop->expr; *ep; ep = &(*ep)->left.expr)
				;
			*ep = expr_alloc_one(E_CHOICE, NULL);
			(*ep)->right.sym = menu->sym;
		}
		if (menu->list && (!menu->prompt || !menu->prompt->text)) {
			for (last_menu = menu->list; ; last_menu = last_menu->next) {
				last_menu->parent = parent;
				if (!last_menu->next)
					break;
			}
			last_menu->next = menu->next;
			menu->next = menu->list;
			menu->list = NULL;
		}
	}

	if (sym && !(sym->flags & SYMBOL_WARNED)) {
		struct symbol *sym2;
		if (sym->type == S_UNKNOWN)
			fprintf(stderr, "%s:%d:warning: config symbol defined without type\n",
				parent->file->name, parent->lineno);

		if (sym_is_choice(sym) && !parent->prompt)
			fprintf(stderr, "%s:%d:warning: choice must have a prompt\n",
				parent->file->name, parent->lineno);

		for (prop = sym->prop; prop; prop = prop->next) {
			switch (prop->type) {
			case P_DEFAULT:
				if ((sym->type == S_STRING || sym->type == S_INT || sym->type == S_HEX) &&
				    prop->expr->type != E_SYMBOL)
					fprintf(stderr, "%s:%d:warning: default must be a single symbol\n",
						prop->file->name, prop->lineno);
				break;
			case P_SELECT:
				sym2 = prop_get_symbol(prop);
				if ((sym->type != S_BOOLEAN) || (sym2->type != S_BOOLEAN))
					fprintf(stderr, "%s:%d:warning: enable is only allowed with booleans\n",
						prop->file->name, prop->lineno);
				break;
			case P_RANGE:
				if (sym->type != S_INT && sym->type != S_HEX)
					fprintf(stderr, "%s:%d:warning: range is only allowed for int or hex symbols\n",
						prop->file->name, prop->lineno);
				if (!sym_string_valid(sym, prop->expr->left.sym->name) ||
				    !sym_string_valid(sym, prop->expr->right.sym->name))
					fprintf(stderr, "%s:%d:warning: range is invalid\n",
						prop->file->name, prop->lineno);
				break;
			default:
				;
			}
		}
		sym->flags |= SYMBOL_WARNED;
	}

	if (sym && !sym_is_optional(sym) && parent->prompt) {
		sym->rev_dep.expr = expr_alloc_or(sym->rev_dep.expr,
				expr_alloc_and(parent->prompt->visible.expr,
					expr_alloc_symbol(&symbol_mod)));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
movq 0x18(%rdi), %rax
leaq 0x10(%rdi), %rsi
cmpq $0x0, 0x10(%rdi)
movq %rax, (%rsp)
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
je 0x583b
testq %rax, %rax
je 0x582c
testb $0x10, 0x44(%rax)
jne 0x585a
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x58a0
movq 0x20(%rax), %rax
jmp 0x58a4
testq %rax, %rax
je 0x5afd
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x59e4
movq 0x20(%rax), %rdi
jmp 0x59e6
movq %rsi, %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x5890
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x585d
movq %r14, 0xec3b(%rip)      # 0x144b0
movl 0x18(%rax), %edi
callq 0x51ca
movq %rbx, 0xec2c(%rip)      # 0x144b0
movq (%rsp), %rax
movl 0x18(%rax), %edi
callq 0x51ca
movq (%rsp), %rdi
callq 0x5567
movq 0x10(%rsp), %rsi
jmp 0x58a4
movq 0x28(%r14), %rax
movq %rax, 0x20(%rsp)
movq %rsi, %r12
movq (%r12), %r12
testq %r12, %r12
je 0x59c6
movq 0x28(%r12), %rdi
callq 0x8ab2
movq %rax, %rbx
movq 0x20(%rsp), %rdi
callq 0x7dc5
movq %rax, %rdi
movq %rbx, %rsi
callq 0x7d87
movq %rax, %rdi
callq 0x87b2
movq %rax, %rbx
movq %rax, 0x28(%r12)
movq 0x18(%r12), %rax
leaq 0x48(%rax), %r13
leaq 0x20(%r12), %rcx
testq %rax, %rax
cmoveq %rcx, %r13
movq %rbx, 0x30(%rsp)
movq (%r13), %r13
testq %r13, %r13
je 0x59bc
cmpq %r12, 0x38(%r13)
jne 0x5905
movq 0x20(%r13), %rdi
callq 0x8ab2
movq %rax, %rbp
movq %rbx, %rdi
callq 0x7dc5
movq %rax, %rdi
movq %rbp, %rsi
callq 0x7d87
movq %rax, %rdi
callq 0x87b2
movq %rax, %rbp
movq %rax, 0x8(%rsp)
movq 0x18(%r12), %rax
testq %rax, %rax
je 0x5964
cmpl $0x2, 0x18(%rax)
je 0x5964
movq %rbp, %rdi
callq 0x8291
movq %rbp, 0x8(%rsp)
movq %rbp, 0x20(%r13)
cmpl $0x6, 0x10(%r13)
jne 0x5905
movq %r13, %rdi
callq 0x7179
movq %rax, %rbx
movq 0x60(%rax), %r15
movq 0x18(%r12), %rdi
callq 0x5567
movq %rax, %r14
movq %rbp, %rdi
callq 0x7dc5
movq %r14, %rdi
movq 0x18(%rsp), %r14
movq %rax, %rsi
callq 0x7d87
movq %r15, %rdi
movq %rax, %rsi
callq 0x7da6
movq %rax, 0x60(%rbx)
movq 0x30(%rsp), %rbx
jmp 0x5905
movq 0x10(%rsp), %rsi
jmp 0x58ac
movq %rsi, %r15
movq (%r15), %r15
testq %r15, %r15
je 0x5afd
movq %r15, %rdi
callq 0x57f3
movq 0x10(%rsp), %rsi
jmp 0x59c9
xorl %edi, %edi
leaq 0xe83b(%rip), %rdx      # 0x14228
pushq $0x5
popq %rsi
callq 0x8fa8
movq %rax, %rdi
callq 0x8ab2
movq %rax, %rdi
callq 0x87b2
movq %rax, %r12
xorl %r15d, %r15d
movq %r14, %rbp
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x5ae2
movq 0x20(%rbp), %rax
leaq 0x20(%rax), %rcx
leaq 0x28(%rbp), %rdx
testq %rax, %rax
cmoveq %rdx, %rcx
movq (%rcx), %r13
movq %r13, 0x8(%rsp)
movq %r13, %rdi
movq (%rsp), %rsi
callq 0x8d08
testl %eax, %eax
je 0x5ae2
movq %r13, %rdi
movq (%rsp), %rsi
callq 0x8d8c
testb %al, %al
jne 0x5ace
movq %r13, %rdi
pushq $0x5
popq %rsi
leaq 0xe7c1(%rip), %rdx      # 0x14228
callq 0x8fa8
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x8ab2
movq %rax, %rdi
callq 0x87b2
movq %rax, 0x8(%rsp)
movq %r12, %rdi
callq 0x7dc5
movq %rax, 0x28(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x7ec0
movq 0x8(%rsp), %rdi
callq 0x7e66
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x6158
movl %eax, %r14d
movq %rbx, %rdi
callq 0x7e66
testl %r14d, %r14d
movq 0x18(%rsp), %r14
je 0x5ae2
movq %rbp, %rdi
callq 0x57f3
movq %r14, 0x8(%rbp)
movq %rbp, %r15
jmp 0x5a0e
testq %r15, %r15
movq 0x10(%rsp), %rsi
je 0x5afd
movq (%r14), %rax
movq %rax, 0x10(%r14)
movq (%r15), %rax
movq %rax, (%r14)
andq $0x0, (%r15)
movq 0xe4f4(%rip), %rbx      # 0x13ff8
pushq $0x5
popq %rbp
pushq $0x6
popq %r12
leaq 0xa26e(%rip), %r15      # 0xfd80
movq (%rsi), %rsi
testq %rsi, %rsi
je 0x5c87
movq (%rsp), %rcx
testq %rcx, %rcx
je 0x5c10
testb $0x10, 0x44(%rcx)
je 0x5c10
movq 0x18(%rsi), %r14
testq %r14, %r14
je 0x5c10
orb $0x20, 0x44(%r14)
cmpq $0x0, 0x20(%rsi)
movq %rsi, %r13
je 0x5c5b
addq $0x48, %r14
movq (%r14), %r14
testq %r14, %r14
je 0x5bbf
movl 0x10(%r14), %eax
cmpl $0x1, %eax
jne 0x5b98
cmpq %rsi, 0x38(%r14)
je 0x5b59
movq (%rbx), %rdi
movq 0x40(%r14), %rax
movq 0x10(%rax), %rdx
movl 0x48(%r14), %ecx
leaq 0xa1b5(%rip), %rsi      # 0xfd3b
xorl %eax, %eax
callq 0x21b0
movq %r13, %rsi
movq (%rsp), %rcx
movl 0x10(%r14), %eax
cmpl $0x4, %eax
jne 0x5b59
movq (%rbx), %rdi
movq 0x40(%r14), %rax
movq 0x10(%rax), %rdx
movl 0x48(%r14), %ecx
movq %r15, %rsi
xorl %eax, %eax
callq 0x21b0
movq %r13, %rsi
movq (%rsp), %rcx
jmp 0x5b59
movq %rsi, 0xe8ea(%rip)      # 0x144b0
movl 0x18(%rcx), %edi
movq %rcx, %r14
callq 0x51ca
movl %ebp, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x526e
movq %r14, %rdi
callq 0x7194
addq $0x30, %rax
movq %rax, %r14
movq (%rax), %rcx
leaq 0x8(%rcx), %rax
testq %rcx, %rcx
jne 0x5be9
movl %r12d, %edi
xorl %esi, %esi
callq 0x5582
movq %rax, (%r14)
movq %r13, %rsi
movq 0x18(%r13), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rsi), %rax
testq %rax, %rax
movq 0x18(%rsp), %r14
je 0x5b12
movq 0x20(%rsi), %rcx
testq %rcx, %rcx
je 0x5c36
cmpq $0x0, 0x18(%rcx)
jne 0x5b12
movq %rax, %rdx
movq %rdx, %rcx
movq %r14, 0x8(%rdx)
movq (%rdx), %rdx
testq %rdx, %rdx
jne 0x5c39
movq (%rsi), %rdx
movq %rdx, (%rcx)
movq %rax, (%rsi)
andq $0x0, 0x10(%rsi)
jmp 0x5b12
movq (%rbx), %rdi
movq 0x38(%rsi), %rax
movq 0x10(%rax), %rdx
movl 0x40(%rsi), %ecx
leaq 0xa09b(%rip), %rsi      # 0xfd0b
xorl %eax, %eax
callq 0x21b0
movq %r13, %rsi
movq (%rsp), %rcx
movq 0x18(%r13), %r14
jmp 0x5b55
movq (%rsp), %rcx
testq %rcx, %rcx
je 0x5e04
movl 0x44(%rcx), %eax
testw %ax, %ax
js 0x5dc4
cmpl $0x0, 0x18(%rcx)
je 0x5e13
testb $0x10, %al
je 0x5cb9
cmpq $0x0, 0x20(%r14)
je 0x5e3c
leaq 0x48(%rcx), %r15
leaq 0xa1f4(%rip), %r14      # 0xfeb8
leaq 0xa17b(%rip), %r13      # 0xfe46
leaq 0xa144(%rip), %rbp      # 0xfe16
movq (%r15), %r15
testq %r15, %r15
je 0x5db4
movl 0x10(%r15), %eax
cmpl $0x7, %eax
je 0x5d2a
cmpl $0x6, %eax
je 0x5d0a
cmpl $0x4, %eax
jne 0x5cd2
movl 0x18(%rcx), %eax
addl $-0x3, %eax
cmpl $0x2, %eax
ja 0x5cd2
movq 0x30(%r15), %rax
cmpl $0x7, (%rax)
movq %rbp, %rsi
je 0x5cd2
jmp 0x5d72
cmpl $0x1, 0x18(%rcx)
movq %r13, %rsi
jne 0x5d72
movq %r15, %rdi
callq 0x7179
movq (%rsp), %rcx
cmpl $0x1, 0x18(%rax)
movq %r13, %rsi
je 0x5cd2
jmp 0x5d72
movl 0x18(%rcx), %eax
addl $-0x3, %eax
cmpl $0x2, %eax
jae 0x5d91
movq 0x30(%r15), %r12
movq 0x8(%r12), %rax
movq 0x8(%rax), %rsi
movq %rcx, %rdi
callq 0x708a
movq (%rsp), %rdi
movq %r14, %rsi
testb %al, %al
je 0x5d72
movq 0x10(%r12), %rax
movq 0x8(%rax), %rsi
callq 0x708a
movq (%rsp), %rcx
movq %r14, %rsi
testb %al, %al
jne 0x5cd2
movq (%rbx), %rdi
movq 0x40(%r15), %rax
movq 0x10(%rax), %rdx
movl 0x48(%r15), %ecx
xorl %eax, %eax
callq 0x21b0
movq (%rsp), %rcx
jmp 0x5cd2
movq (%rbx), %rdi
movq 0x40(%r15), %rax
movq 0x10(%rax), %rdx
movl 0x48(%r15), %ecx
leaq 0xa0d4(%rip), %rsi      # 0xfe7b
xorl %eax, %eax
callq 0x21b0
movq (%rsp), %rcx
jmp 0x5d35
movl $0x8000, %eax           # imm = 0x8000
orl 0x44(%rcx), %eax
movl %eax, 0x44(%rcx)
movq 0x18(%rsp), %r14
btl $0x8, %eax
jb 0x5e04
movq 0x20(%r14), %rax
testq %rax, %rax
je 0x5e04
movq 0x60(%rcx), %rbx
movq 0x20(%rax), %r14
leaq 0xe526(%rip), %rdi      # 0x14308
movq %rcx, %r15
callq 0x5567
movq %r14, %rdi
movq %rax, %rsi
callq 0x7d87
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7da6
movq %rax, 0x60(%r15)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdi
movq 0x38(%r14), %rax
movq 0x10(%rax), %rdx
movl 0x40(%r14), %ecx
leaq 0x9f90(%rip), %rsi      # 0xfdb9
xorl %eax, %eax
callq 0x21b0
movq (%rsp), %rcx
movl 0x44(%rcx), %eax
jmp 0x5caa
movq (%rbx), %rdi
movq 0x38(%r14), %rax
movq 0x10(%rax), %rdx
movl 0x40(%r14), %ecx
leaq 0x9f9a(%rip), %rsi      # 0xfdec
xorl %eax, %eax
callq 0x21b0
movq (%rsp), %rcx
jmp 0x5cb9