// File: /workspace/github_c_makefile_star2_O2/tomka[P]cliaspora/config.c
// Function: write_config
int
write_config(const char *label)
{
	int   i, fd, varlen;
	bool  var_written[NVARS];
	char  *p, *path, *ln, tmpl[] = "/tmp/XXXXXX";
	FILE  *fp, *tmpfp;
	var_t *var;

	if ((path = cfgpath()) == NULL)
		return (-1);
	if ((fp = fopen(path, "r+")) == NULL && errno == ENOENT) {
		if ((fp = fopen(path, "w+")) == NULL) {
			warn("fopen(%s)", path); free(path);
			return (-1);
		}
		(void)fchmod(fileno(fp), S_IRUSR|S_IWUSR);
	} else if (fp == NULL) {
		warn("fopen(%s)", path); free(path); return (-1);
	}
	free(path);

	if ((fd = mkstemp(tmpl)) == -1) {
		warn("mkstemp()"); (void)fclose(fp); return (-1);
	}
	if ((tmpfp = fdopen(fd, "r+")) == NULL) {
		warn("fdopen()"); (void)fclose(fp); (void)close(fd);
		return (-1);
	}
	for (i = 0; i < NVARS; i++)
		var_written[i] = false;
	(void)fseek(fp, 0, SEEK_SET);
	/* Just copy all global variables, etc. */
	while ((ln = readln(fp)) != NULL && !cmp_label(ln, label))
		(void)fputs(ln, tmpfp);
	if (ln == NULL)
		/* Label doesn't exist yet. */
		(void)fprintf(tmpfp, "\n%s:\n", label);
	else {
		/* Write label. */
		(void)fputs(ln, tmpfp);
		/* Write variables in section as they appear in config file. */
		while ((ln = readln(fp)) != NULL && !is_label(ln) != 0) {
			for (p = ln; isspace(*p); p++)
				;
			if (*p == '\0' || *p == '#')
				(void)fputs(ln, tmpfp);
			else {
				varlen = strcspn(p, " =\t");
				if ((var = find_var(p, varlen)) == NULL)
					(void)fputs(ln, tmpfp);
				else {
					for (i = 0; i < NVARS; i++) {
						if (var == &vars[i])
							var_written[i] = true;
					}
					(void)write_var(var, tmpfp);
				}
			}
		}
	}
	/* Write remaining variables. */
	for (i = 0; i < NVARS; i++) {
		if (!var_written[i])
			(void)write_var(&vars[i], tmpfp);
	}
	/* Copy the remaining lines. */ 
	while (ln != NULL) {
		(void)fputs(ln, tmpfp); ln = readln(fp);
	}
	(void)fflush(tmpfp);
	(void)fseek(fp, 0, SEEK_SET); (void)fseek(tmpfp, 0, SEEK_SET);

	while ((ln = readln(tmpfp)) != NULL)
		(void)fputs(ln, fp);
	(void)fclose(tmpfp); (void)remove(tmpl);

	(void)fflush(fp);
        (void)ftruncate(fileno(fp), ftell(fp));
        (void)fclose(fp); free(ln);

	return (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r12
movabsq $0x5858582f706d742f, %rax # imm = 0x5858582F706D742F
movq %rax, 0x10(%rsp)
movl $0x585858, 0x18(%rsp)   # imm = 0x585858
callq 0x63b4
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x6d7a
movq %rax, %r14
leaq 0x4a80(%rip), %rsi      # 0xb4f2
movq %rax, %rdi
callq 0x23b0
movq %rax, %rbx
testq %rax, %rax
je 0x6acc
movq %r14, %rdi
callq 0x23d0
leaq 0x10(%rsp), %rdi
callq 0x2100
cmpl $-0x1, %eax
je 0x6c3d
movl %eax, %r15d
leaq 0x4a4b(%rip), %rsi      # 0xb4f2
movl %eax, %edi
callq 0x22d0
testq %rax, %rax
je 0x6c76
movq %rax, %r14
xorl %eax, %eax
cmpq $0x5, %rax
je 0x6b0e
andl $0x0, 0x20(%rsp,%rax,4)
incq %rax
jmp 0x6abc
callq 0x2060
cmpl $0x2, (%rax)
jne 0x6c58
leaq 0x4a14(%rip), %rsi      # 0xb4f5
movq %r14, %rdi
callq 0x23b0
testq %rax, %rax
je 0x6c58
movq %rax, %rbx
movq %rax, %rdi
callq 0x22c0
movl %eax, %edi
movl $0x180, %esi            # imm = 0x180
callq 0x2160
jmp 0x6a82
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2320
movq %rbx, (%rsp)
movq %rbx, %rdi
callq 0x65f5
testq %rax, %rax
je 0x6c99
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
callq 0x6964
movl %eax, %ebp
movq %r15, %rdi
movq %r14, %rsi
callq 0x2360
testl %ebp, %ebp
je 0x6b1e
movq %r14, 0x8(%rsp)
movq %rbx, %rdi
callq 0x65f5
testq %rax, %rax
je 0x6cb2
movq %rax, %r15
movq %rax, %rdi
callq 0x6609
testl %eax, %eax
jne 0x6cb5
callq 0x22f0
movq (%rax), %rax
movq %r15, %r13
decq %r13
movsbq 0x1(%r13), %rcx
incq %r13
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x6b85
movzbl %cl, %eax
cmpl $0x23, %eax
je 0x6ba0
testl %eax, %eax
jne 0x6bad
movq %r15, %rdi
movq %r14, %rsi
callq 0x2360
jmp 0x6b53
movq %r13, %rdi
leaq 0x495a(%rip), %rsi      # 0xb511
callq 0x20a0
movslq %eax, %r12
xorl %ecx, %ecx
leaq 0x8730(%rip), %rbp      # 0xf2f8
pushq $-0x1
popq %rbx
cmpq $0x4, %rbx
je 0x6c0b
movq %rcx, %r14
movq 0x18(%rbp), %rdi
addq $0x18, %rbp
movq %r13, %rsi
movq %r12, %rdx
callq 0x2170
incq %rbx
leaq 0x1(%r14), %rcx
testl %eax, %eax
jne 0x6bcb
pushq $0x5
popq %rax
subq $0x1, %rax
jb 0x6c24
subq $0x1, %r14
jae 0x6bf5
movl $0x1, 0x20(%rsp,%rbx,4)
jmp 0x6bf5
movq %r15, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2360
movq (%rsp), %rbx
jmp 0x6b53
movq %rbp, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x6d8b
movq (%rsp), %rbx
jmp 0x6b53
leaq 0x48b4(%rip), %rdi      # 0xb4f8
xorl %eax, %eax
callq 0x2110
movq %rbx, %rdi
callq 0x2280
jmp 0x6d7a
leaq 0x483c(%rip), %rdi      # 0xb49b
movq %r14, %rsi
xorl %eax, %eax
callq 0x2110
movq %r14, %rdi
callq 0x23d0
jmp 0x6d7a
leaq 0x4885(%rip), %rdi      # 0xb502
xorl %eax, %eax
callq 0x2110
movq %rbx, %rdi
callq 0x2280
movl %r15d, %edi
callq 0x25d0
jmp 0x6d7a
leaq 0x486b(%rip), %rsi      # 0xb50b
xorl %r15d, %r15d
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x24a0
jmp 0x6cb5
xorl %r15d, %r15d
leaq 0x8654(%rip), %r12      # 0xf310
xorl %ebx, %ebx
cmpq $0x5, %rbx
je 0x6cdf
cmpl $0x0, 0x20(%rsp,%rbx,4)
jne 0x6cd6
movq %r12, %rdi
movq %r14, %rsi
callq 0x6d8b
incq %rbx
addq $0x18, %r12
jmp 0x6cbe
movq (%rsp), %rbx
testq %r15, %r15
je 0x6d00
movq %r15, %rdi
movq %r14, %rsi
callq 0x2360
movq %rbx, %rdi
callq 0x65f5
movq %rax, %r15
jmp 0x6ce3
movq %r14, %rdi
callq 0x23a0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2320
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2320
movq %r14, %rdi
callq 0x65f5
testq %rax, %rax
je 0x6d3a
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2360
jmp 0x6d20
movq %r14, %rdi
callq 0x2280
leaq 0x10(%rsp), %rdi
callq 0x2570
movq %rbx, %rdi
callq 0x23a0
movq %rbx, %rdi
callq 0x22c0
movl %eax, %ebp
movq %rbx, %rdi
callq 0x2030
movl %ebp, %edi
movq %rax, %rsi
callq 0x2440
movq %rbx, %rdi
callq 0x2280
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq