// File: /workspace/github_c_makefile_star2_O2/saltyJeff[P]uClibcpp/extra/config/./confdata.c
// Function: conf_write
int conf_write(const char *name)
{
	FILE *out, *out_h;
	struct symbol *sym;
	struct menu *menu;
	const char *basename;
	char dirname[128], tmpname[128], newname[128];
	int type, l;
	const char *str;

	dirname[0] = 0;
	if (name && name[0]) {
		char *slash = strrchr(name, '/');
		if (slash) {
			int size = slash - name + 1;
			memcpy(dirname, name, size);
			dirname[size] = 0;
			if (slash[1])
				basename = slash + 1;
			else
				basename = conf_def_filename;
		} else
			basename = name;
	} else
		basename = conf_def_filename;

	sprintf(newname, "%s.tmpconfig.%d", dirname, getpid());
	out = fopen(newname, "w");
	if (!out)
		return 1;
	out_h = NULL;
	if (!name) {
		out_h = fopen(".tmpconfig.h", "w");
		if (!out_h)
			return 1;
	}
	fprintf(out, "#\n"
		     "# Automatically generated make config: don't edit\n"
		     "#\n");
	if (out_h)
		fprintf(out_h, "/*\n"
			     " * Automatically generated C config: don't edit\n"
			     " */\n"
			     "/*\n"
			     " * Version Number\n"
			     " */\n"
			     "#define __UCLIBCXX_MAJOR__ %s\n"
			     "#define __UCLIBCXX_MINOR__ %s\n"
			     "#define __UCLIBCXX_SUBLEVEL__ %s\n",
			     getenv("MAJOR_VERSION"),
			     getenv("MINOR_VERSION"),
			     getenv("SUBLEVEL"));

	if (!sym_change_count)
		sym_clear_all_valid();

	menu = rootmenu.list;
	while (menu) {
		sym = menu->sym;
		if (!sym) {
			if (!menu_is_visible(menu))
				goto next;
			str = menu_get_prompt(menu);
			fprintf(out, "\n"
				     "#\n"
				     "# %s\n"
				     "#\n", str);
			if (out_h)
				fprintf(out_h, "\n"
					       "/*\n"
					       " * %s\n"
					       " */\n", str);
		} else if (!(sym->flags & SYMBOL_CHOICE)) {
			sym_calc_value(sym);
			if (!(sym->flags & SYMBOL_WRITE))
				goto next;
			sym->flags &= ~SYMBOL_WRITE;
			type = sym->type;
			if (type == S_TRISTATE) {
				sym_calc_value(modules_sym);
				if (modules_sym->curr.tri == no)
					type = S_BOOLEAN;
			}
			switch (type) {
			case S_BOOLEAN:
			case S_TRISTATE:
				switch (sym_get_tristate_value(sym)) {
				case no:
					fprintf(out, "# %s is not set\n", sym->name);
					if (out_h)
						fprintf(out_h, "#undef __%s__\n", sym->name);
					break;
				case mod:
					fprintf(out, "%s=m\n", sym->name);
					if (out_h)
						fprintf(out_h, "#define %s_MODULE 1\n", sym->name);
					break;
				case yes:
					fprintf(out, "%s=y\n", sym->name);
					if (out_h)
						fprintf(out_h, "#define __%s__ 1\n", sym->name);
					break;
				}
				break;
			case S_STRING:
				// fix me
				str = sym_get_string_value(sym);
				fprintf(out, "%s=\"", sym->name);
				if (out_h)
					fprintf(out_h, "#define __%s__ \"", sym->name);
				do {
					l = strcspn(str, "\"\\");
					if (l) {
						fwrite(str, l, 1, out);
						if (out_h)
							fwrite(str, l, 1, out_h);
					}
					str += l;
					while (*str == '\\' || *str == '"') {
						fprintf(out, "\\%c", *str);
						if (out_h)
							fprintf(out_h, "\\%c", *str);
						str++;
					}
				} while (*str);
				fputs("\"\n", out);
				if (out_h)
					fputs("\"\n", out_h);
				break;
			case S_HEX:
				str = sym_get_string_value(sym);
				if (str[0] != '0' || (str[1] != 'x' && str[1] != 'X')) {
					fprintf(out, "%s=%s\n", sym->name, str);
					if (out_h)
						fprintf(out_h, "#define __%s__ 0x%s\n", sym->name, str);
					break;
				}
			case S_INT:
				str = sym_get_string_value(sym);
				fprintf(out, "%s=%s\n", sym->name, str);
				if (out_h)
					fprintf(out_h, "#define __%s__ %s\n", sym->name, str);
				break;
			}
		}

	next:
		if (menu->list) {
			menu = menu->list;
			continue;
		}
		if (menu->next)
			menu = menu->next;
		else while ((menu = menu->parent)) {
			if (menu->next) {
				menu = menu->next;
				break;
			}
		}
	}
	fclose(out);
	if (out_h) {
		fclose(out_h);
		rename(".tmpconfig.h", "include/system_configuration.h");
		file_write_dep(NULL);
	}
	if (!name || basename != conf_def_filename) {
		if (!name)
			name = conf_def_filename;
		sprintf(tmpname, "%s.old", name);
		rename(name, tmpname);
	}
	sprintf(tmpname, "%s%s", dirname, basename);
	if (rename(newname, tmpname))
		return 1;

	sym_change_count = 0;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdi, %r13
movb $0x0, 0x20(%rsp)
leaq 0x7b9e(%rip), %rbp      # 0xf216
testq %rdi, %rdi
je 0x76cd
cmpb $0x0, (%r13)
je 0x76cd
pushq $0x2f
popq %rsi
movq %r13, %rdi
callq 0x2110
movq %r13, %rbp
testq %rax, %rax
je 0x76cd
movq %rax, %rbx
subl %r13d, %eax
incl %eax
movslq %eax, %r14
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x21f0
movb $0x0, 0x20(%rsp,%r14)
movq %rbx, %rax
incq %rax
cmpb $0x0, 0x1(%rbx)
leaq 0x7b4d(%rip), %rbp      # 0xf216
cmovneq %rax, %rbp
callq 0x20c0
leaq 0x8275(%rip), %rsi      # 0xf94e
leaq 0xa0(%rsp), %rbx
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x22e0
leaq 0x8c43(%rip), %rsi      # 0x1033c
movq %rbx, %rdi
callq 0x2290
movq %rax, %rcx
pushq $0x1
popq %rax
movq %rcx, 0x8(%rsp)
testq %rcx, %rcx
je 0x7bc0
testq %r13, %r13
je 0x771f
xorl %r12d, %r12d
jmp 0x773e
leaq 0x8238(%rip), %rdi      # 0xf95e
leaq 0x8c0f(%rip), %rsi      # 0x1033c
callq 0x2290
movq %rax, %r12
testq %rax, %rax
je 0x7bbd
leaq 0x8226(%rip), %rdi      # 0xf96b
pushq $0x36
popq %rsi
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rcx
callq 0x2300
testq %r12, %r12
je 0x779e
leaq 0x82ef(%rip), %rdi      # 0xfa50
callq 0x2030
movq %rax, %rbx
leaq 0x82ee(%rip), %rdi      # 0xfa5e
callq 0x2030
movq %rax, %r14
leaq 0x82ed(%rip), %rdi      # 0xfa6c
callq 0x2030
leaq 0x8217(%rip), %rsi      # 0xf9a2
movq %r12, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x21b0
movq %rbp, 0x10(%rsp)
movq %r13, 0x18(%rsp)
cmpl $0x0, 0xd579(%rip)      # 0x14d28
jne 0x77b6
callq 0x7bd2
movq 0xcd1b(%rip), %rax      # 0x144d8
leaq 0x8334(%rip), %r15      # 0xfaf8
pushq $0x1
popq %rbp
testq %rax, %rax
je 0x7af9
movq %rax, %r13
movq 0x18(%rax), %r14
testq %r14, %r14
je 0x787f
testb $0x10, 0x44(%r14)
jne 0x78d9
movq %r14, %rdi
callq 0x71aa
movl 0x44(%r14), %eax
btl $0x9, %eax
jae 0x78d9
andl $0xfffffdff, %eax       # imm = 0xFFFFFDFF
movl %eax, 0x44(%r14)
movl 0x18(%r14), %eax
decl %eax
cmpl $0x4, %eax
ja 0x78d9
leaq 0x2d08(%rip), %rcx      # 0xa528
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xcc90(%rip), %rdi      # 0x144c0
callq 0x71aa
movl 0x28(%r14), %eax
cmpl $0x2, %eax
je 0x7ac6
cmpl $0x1, %eax
je 0x7a93
testl %eax, %eax
jne 0x78d9
movq 0x8(%r14), %rdx
movq 0x8(%rsp), %rdi
leaq 0x822c(%rip), %rsi      # 0xfa8f
xorl %eax, %eax
callq 0x21b0
testq %r12, %r12
je 0x78d9
movq 0x8(%r14), %rdx
movq %r12, %rdi
leaq 0x8223(%rip), %rsi      # 0xfaa0
jmp 0x78d2
movq %r13, %rdi
callq 0x7c07
testb %al, %al
je 0x78d9
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x789a
addq $0x18, %rax
jmp 0x78a7
movq 0x18(%r13), %rax
testq %rax, %rax
je 0x7903
addq $0x8, %rax
movq (%rax), %rbx
movq 0x8(%rsp), %rdi
leaq 0x81bf(%rip), %rsi      # 0xfa75
movq %rbx, %rdx
xorl %eax, %eax
callq 0x21b0
testq %r12, %r12
je 0x78d9
movq %r12, %rdi
leaq 0x81b1(%rip), %rsi      # 0xfa80
movq %rbx, %rdx
xorl %eax, %eax
callq 0x21b0
movq 0x10(%r13), %rax
testq %rax, %rax
jne 0x77c7
movq (%r13), %rax
testq %rax, %rax
jne 0x77c7
movq 0x8(%r13), %r13
testq %r13, %r13
jne 0x78e6
xorl %eax, %eax
jmp 0x77c7
xorl %ebx, %ebx
jmp 0x78aa
movq %r14, %rdi
callq 0x7c9f
movq %rax, %rbx
movq 0x8(%r14), %rdx
movq 0x8(%rsp), %rdi
leaq 0x81c0(%rip), %rsi      # 0xfae2
xorl %eax, %eax
callq 0x21b0
testq %r12, %r12
je 0x7943
movq 0x8(%r14), %rdx
movq %r12, %rdi
leaq 0x81ab(%rip), %rsi      # 0xfae7
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
leaq 0x7fb8(%rip), %rsi      # 0xf905
callq 0x2150
testl %eax, %eax
je 0x7984
movslq %eax, %r14
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq 0x8(%rsp), %rcx
callq 0x2300
testq %r12, %r12
je 0x7987
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
movq %r12, %rcx
callq 0x2300
jmp 0x7987
xorl %r14d, %r14d
addq %r14, %rbx
movq %r15, %r14
movzbl (%rbx), %edx
cmpl $0x22, %edx
je 0x799a
cmpl $0x5c, %edx
jne 0x79c3
movq 0x8(%rsp), %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x21b0
testq %r12, %r12
je 0x79be
movsbl (%rbx), %edx
movq %r12, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x21b0
incq %rbx
jmp 0x798d
testl %edx, %edx
jne 0x7943
leaq 0x7e9d(%rip), %rdi      # 0xf86f
movq 0x8(%rsp), %rsi
callq 0x2120
testq %r12, %r12
je 0x78d9
leaq 0x7e83(%rip), %rdi      # 0xf86f
movq %r12, %rsi
callq 0x2120
jmp 0x78d9
movq %r14, %rdi
callq 0x7c9f
movq %rax, %rbx
cmpb $0x30, (%rax)
jne 0x7a53
movzbl 0x1(%rbx), %eax
orl $0x20, %eax
cmpl $0x78, %eax
jne 0x7a53
movq %r14, %rdi
callq 0x7c9f
movq %rax, %rbx
movq 0x8(%r14), %rdx
movq 0x8(%rsp), %rdi
leaq 0x80cc(%rip), %rsi      # 0xfafc
movq %rax, %rcx
xorl %eax, %eax
callq 0x21b0
testq %r12, %r12
je 0x78d9
movq 0x8(%r14), %rdx
movq %r12, %rdi
leaq 0x80c7(%rip), %rsi      # 0xfb18
jmp 0x7a84
movq 0x8(%r14), %rdx
movq 0x8(%rsp), %rdi
leaq 0x8099(%rip), %rsi      # 0xfafc
movq %rbx, %rcx
xorl %eax, %eax
callq 0x21b0
testq %r12, %r12
je 0x78d9
movq 0x8(%r14), %rdx
movq %r12, %rdi
leaq 0x807f(%rip), %rsi      # 0xfb03
movq %rbx, %rcx
xorl %eax, %eax
callq 0x21b0
jmp 0x78d9
movq 0x8(%r14), %rdx
movq 0x8(%rsp), %rdi
leaq 0x800c(%rip), %rsi      # 0xfaaf
xorl %eax, %eax
callq 0x21b0
testq %r12, %r12
je 0x78d9
movq 0x8(%r14), %rdx
movq %r12, %rdi
leaq 0x7ff4(%rip), %rsi      # 0xfab5
jmp 0x78d2
movq 0x8(%r14), %rdx
movq 0x8(%rsp), %rdi
leaq 0x7ff4(%rip), %rsi      # 0xfaca
xorl %eax, %eax
callq 0x21b0
testq %r12, %r12
je 0x78d9
movq 0x8(%r14), %rdx
movq %r12, %rdi
leaq 0x7fdc(%rip), %rsi      # 0xfad0
jmp 0x78d2
movq 0x8(%rsp), %rdi
callq 0x20d0
testq %r12, %r12
je 0x7b2a
movq %r12, %rdi
callq 0x20d0
leaq 0x7e47(%rip), %rdi      # 0xf95e
leaq 0x800d(%rip), %rsi      # 0xfb2b
callq 0x22a0
xorl %edi, %edi
callq 0x7cc7
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
movq 0x10(%rsp), %r15
je 0x7b45
leaq 0x76d6(%rip), %rax      # 0xf216
cmpq %rax, %r15
je 0x7b7a
testq %rcx, %rcx
leaq 0x76c7(%rip), %rbx      # 0xf216
cmovneq %rcx, %rbx
leaq 0x7ff0(%rip), %rsi      # 0xfb4a
leaq 0x120(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x22e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
leaq 0x7fd0(%rip), %rsi      # 0xfb51
leaq 0x120(%rsp), %rbx
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x22e0
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x22a0
testl %eax, %eax
pushq $0x1
popq %rax
jne 0x7bc0
andl $0x0, 0xd16f(%rip)      # 0x14d28
xorl %eax, %eax
jmp 0x7bc0
pushq $0x1
popq %rax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq