// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq 0x6234(%rip), %rax      # 0xf58a
movq %rax, -0x54(%rbp)
movl 0x6232(%rip), %eax      # 0xf592
movl %eax, -0x4c(%rbp)
callq 0x8860
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x937e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x979e
movq -0x40(%rbp), %rdi
leaq 0x620d(%rip), %rsi      # 0xf596
callq 0x23b0
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
jne 0x93fa
callq 0x2060
cmpl $0x2, (%rax)
jne 0x93fa
movq -0x40(%rbp), %rdi
leaq 0x61ec(%rip), %rsi      # 0xf599
callq 0x23b0
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
jne 0x93e3
movq -0x40(%rbp), %rsi
leaq 0x6178(%rip), %rdi      # 0xf53f
movb $0x0, %al
callq 0x2120
movq -0x40(%rbp), %rdi
callq 0x23d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x979e
movq -0x60(%rbp), %rdi
callq 0x22d0
movl %eax, %edi
movl $0x180, %esi            # imm = 0x180
callq 0x2170
jmp 0x942a
cmpq $0x0, -0x60(%rbp)
jne 0x9428
movq -0x40(%rbp), %rsi
leaq 0x6133(%rip), %rdi      # 0xf53f
movb $0x0, %al
callq 0x2120
movq -0x40(%rbp), %rdi
callq 0x23d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x979e
jmp 0x942a
movq -0x40(%rbp), %rdi
callq 0x23d0
leaq -0x54(%rbp), %rdi
callq 0x2110
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
jne 0x9467
leaq 0x6151(%rip), %rdi      # 0xf59c
movb $0x0, %al
callq 0x2120
movq -0x60(%rbp), %rdi
callq 0x22a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x979e
movl -0x18(%rbp), %edi
leaq 0x6125(%rip), %rsi      # 0xf596
callq 0x22e0
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
jne 0x94ab
leaq 0x611f(%rip), %rdi      # 0xf5a6
movb $0x0, %al
callq 0x2120
movq -0x60(%rbp), %rdi
callq 0x22a0
movl -0x18(%rbp), %edi
callq 0x25d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x979e
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
cmpq $0x5, %rax
jae 0x94d3
movslq -0x14(%rbp), %rax
movl $0x0, -0x30(%rbp,%rax,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x94b2
movq -0x60(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2330
movq -0x60(%rbp), %rdi
callq 0x8bd0
movq %rax, %rcx
movq %rcx, -0x48(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x71(%rbp)
je 0x9515
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x9170
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x951e
jmp 0x952d
movq -0x48(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x2360
jmp 0x94e2
cmpq $0x0, -0x48(%rbp)
jne 0x954f
movq -0x68(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x606c(%rip), %rsi      # 0xf5af
movb $0x0, %al
callq 0x24a0
jmp 0x9698
movq -0x48(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x2360
movq -0x60(%rbp), %rdi
callq 0x8bd0
movq %rax, %rcx
movq %rcx, -0x48(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x72(%rbp)
je 0x9596
movq -0x48(%rbp), %rdi
callq 0x8c00
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
testb $0x1, %al
jne 0x95a2
jmp 0x9696
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
callq 0x2300
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x95da
jmp 0x95cc
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x95aa
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x95f2
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x9604
movq -0x48(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x2360
jmp 0x9691
movq -0x38(%rbp), %rdi
leaq 0x5fa6(%rip), %rsi      # 0xf5b5
callq 0x20b0
movl %eax, -0x1c(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x97b0
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
jne 0x963d
movq -0x48(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x2360
jmp 0x968f
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
cmpq $0x5, %rax
jae 0x9682
movq -0x70(%rbp), %rax
movslq -0x14(%rbp), %rdx
leaq 0x8cb3(%rip), %rcx      # 0x12310
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jne 0x9675
movslq -0x14(%rbp), %rax
movl $0x1, -0x30(%rbp,%rax,4)
jmp 0x9677
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x9644
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x9830
jmp 0x9691
jmp 0x955c
jmp 0x9698
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
cmpq $0x5, %rax
jae 0x96dc
movslq -0x14(%rbp), %rax
cmpl $0x0, -0x30(%rbp,%rax,4)
jne 0x96cf
movslq -0x14(%rbp), %rax
leaq 0x8c51(%rip), %rdi      # 0x12310
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x68(%rbp), %rsi
callq 0x9830
jmp 0x96d1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x969f
jmp 0x96de
cmpq $0x0, -0x48(%rbp)
je 0x9701
movq -0x48(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x2360
movq -0x60(%rbp), %rdi
callq 0x8bd0
movq %rax, -0x48(%rbp)
jmp 0x96de
movq -0x68(%rbp), %rdi
callq 0x23a0
movq -0x60(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2330
movq -0x68(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2330
movq -0x68(%rbp), %rdi
callq 0x8bd0
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x974a
movq -0x48(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x2360
jmp 0x9728
movq -0x68(%rbp), %rdi
callq 0x22a0
leaq -0x54(%rbp), %rdi
callq 0x2570
movq -0x60(%rbp), %rdi
callq 0x23a0
movq -0x60(%rbp), %rdi
callq 0x22d0
movl %eax, -0x78(%rbp)
movq -0x60(%rbp), %rdi
callq 0x2030
movl -0x78(%rbp), %edi
movq %rax, %rsi
callq 0x2440
movq -0x60(%rbp), %rdi
callq 0x22a0
movq -0x48(%rbp), %rdi
callq 0x23d0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)