#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *get_conf_file();
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int set_conf_value(char *label, char *value) {
  FILE *conf;
  char *in, *temp, *tempbuffer, *file;
  struct stat st;
  file = get_conf_file();
  if (stat(file, &st) >= 0) {
    if ((conf = fopen(file, "r")) == NULL) {
      free(file);
      return -1;
    }
    tempbuffer = malloc(256);
    in = malloc(st.st_size + 1);
    temp = in;
    while (!feof(conf)) {
      if (fgets(tempbuffer, 256, conf) != NULL) {
        if (strncmp(tempbuffer, label, strlen(label)) != 0) {
          memcpy(temp, tempbuffer, strlen(tempbuffer));
          temp += strlen(tempbuffer);
        }
      }
    }
    free(tempbuffer);
    temp[0] = '\0';
    fclose(conf);
    if ((conf = fopen(file, "w")) == NULL) {
      free(file);
      free(tempbuffer);
      free(in);
      return -1;
    }
    fputs(in, conf);
    free(in);
  } else if ((conf = fopen(file, "w")) == NULL) {
    free(file);
    return -1;
  }
  free(file);
  fprintf(conf, "%s: %s\n", label, value);
  fclose(conf);
  return 0;
}


x86 assembly (clang, -O0):
<set_conf_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1030 <get_conf_file@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0x0,%rax
jl     138a <set_conf_value+0x1ba>
mov    -0x40(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1235 <set_conf_value+0x65>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f3 <set_conf_value+0x223>
mov    $0x100,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%edi
add    $0x1,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1278 <set_conf_value+0xa8>
jmp    1311 <set_conf_value+0x141>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x100,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     130c <set_conf_value+0x13c>
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     1307 <set_conf_value+0x137>
mov    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   10d0 <memcpy@plt>
mov    -0x38(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    130c <set_conf_value+0x13c>
jmp    125a <set_conf_value+0x8a>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x40(%rbp),%rdi
lea    0xccd(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    136f <set_conf_value+0x19f>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f3 <set_conf_value+0x223>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <fputs@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
jmp    13c2 <set_conf_value+0x1f2>
mov    -0x40(%rbp),%rdi
lea    0xc6d(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    13bd <set_conf_value+0x1ed>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f3 <set_conf_value+0x223>
jmp    13c2 <set_conf_value+0x1f2>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xc26(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_conf_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r13
xor    %eax,%eax
call   1030 <get_conf_file@plt>
mov    %rax,%r15
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   10c0 <stat@plt>
test   %rax,%rax
js     129d <set_conf_value+0xcd>
lea    0xdf5(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     12e0 <set_conf_value+0x110>
mov    %rax,%rbp
mov    %rbx,0x10(%rsp)
mov    $0x100,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%edi
add    $0x1,%edi
call   10e0 <malloc@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   10b0 <feof@plt>
mov    %r14,%r12
test   %eax,%eax
je     12e8 <set_conf_value+0x118>
mov    %rbx,%rdi
call   1040 <free@plt>
movb   $0x0,(%r12)
mov    %rbp,%rdi
call   1060 <fclose@plt>
lea    0xd93(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1353 <set_conf_value+0x183>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %rax,%rsi
call   1080 <fputs@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    0x10(%rsp),%rbx
jmp    12b4 <set_conf_value+0xe4>
lea    0xd5e(%rip),%rsi
mov    %r15,%rdi
call   10f0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12e0 <set_conf_value+0x110>
mov    %r15,%rdi
call   1040 <free@plt>
lea    0xd41(%rip),%rsi
mov    %rbp,%rdi
mov    %r13,%rdx
mov    %rbx,%rcx
call   10a0 <fprintf@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
jmp    1370 <set_conf_value+0x1a0>
mov    %r15,%rdi
jmp    1366 <set_conf_value+0x196>
mov    %r14,%r12
jmp    1300 <set_conf_value+0x130>
nopl   (%rax)
mov    %rbp,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    1253 <set_conf_value+0x83>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12f0 <set_conf_value+0x120>
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     12f0 <set_conf_value+0x120>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10d0 <memcpy@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
add    %rax,%r12
jmp    12f0 <set_conf_value+0x120>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"%s: %s\0A\00"
define i32 @set_conf_value(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = call i8* (...) @get_conf_file()
store i8* %12, i8** %10
%13 = load i8*, i8** %10
%14 = call i64 @stat(i8* %13, %struct.stat* %11)
%15 = icmp sge i64 %14, 0
br i1 %15, label %16, label %83
16: ; preds = %2
%17 = load i8*, i8** %10
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %10
%22 = call i32 @free(i8* %21)
store i32 -1, i32* %3
br label %100
23: ; preds = %16
%24 = call i8* @malloc(i32 256)
store i8* %24, i8** %9
%25 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
store i8* %29, i8** %8
br label %30
30: ; preds = %59, %23
%31 = load i32*, i32** %6
%32 = call i32 @feof(i32* %31)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
br i1 %34, label %35, label %60
35: ; preds = %30
%36 = load i8*, i8** %9
%37 = load i32*, i32** %6
%38 = call i32* @fgets(i8* %36, i32 256, i32* %37)
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %59
40: ; preds = %35
%41 = load i8*, i8** %9
%42 = load i8*, i8** %4
%43 = load i8*, i8** %4
%44 = call i32 @strlen(i8* %43)
%45 = call i64 @strncmp(i8* %41, i8* %42, i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %58
47: ; preds = %40
%48 = load i8*, i8** %8
%49 = load i8*, i8** %9
%50 = load i8*, i8** %9
%51 = call i32 @strlen(i8* %50)
%52 = call i32 @memcpy(i8* %48, i8* %49, i32 %51)
%53 = load i8*, i8** %9
%54 = call i32 @strlen(i8* %53)
%55 = load i8*, i8** %8
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8, i8* %55, i64 %56
store i8* %57, i8** %8
br label %58
58: ; preds = %47, %40
br label %59
59: ; preds = %58, %35
br label %30
60: ; preds = %30
%61 = load i8*, i8** %9
%62 = call i32 @free(i8* %61)
%63 = load i8*, i8** %8
%64 = getelementptr inbounds i8, i8* %63, i64 0
store i8 0, i8* %64
%65 = load i32*, i32** %6
%66 = call i32 @fclose(i32* %65)
%67 = load i8*, i8** %10
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %68, i32** %6
%69 = icmp eq i32* %68, null
br i1 %69, label %70, label %77
70: ; preds = %60
%71 = load i8*, i8** %10
%72 = call i32 @free(i8* %71)
%73 = load i8*, i8** %9
%74 = call i32 @free(i8* %73)
%75 = load i8*, i8** %7
%76 = call i32 @free(i8* %75)
store i32 -1, i32* %3
br label %100
77: ; preds = %60
%78 = load i8*, i8** %7
%79 = load i32*, i32** %6
%80 = call i32 @fputs(i8* %78, i32* %79)
%81 = load i8*, i8** %7
%82 = call i32 @free(i8* %81)
br label %91
83: ; preds = %2
%84 = load i8*, i8** %10
%85 = call i32* @fopen(i8* %84, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %85, i32** %6
%86 = icmp eq i32* %85, null
br i1 %86, label %87, label %90
87: ; preds = %83
%88 = load i8*, i8** %10
%89 = call i32 @free(i8* %88)
store i32 -1, i32* %3
br label %100
90: ; preds = %83
br label %91
91: ; preds = %90, %77
%92 = load i8*, i8** %10
%93 = call i32 @free(i8* %92)
%94 = load i32*, i32** %6
%95 = load i8*, i8** %4
%96 = load i8*, i8** %5
%97 = call i32 @fprintf(i32* %94, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %95, i8* %96)
%98 = load i32*, i32** %6
%99 = call i32 @fclose(i32* %98)
store i32 0, i32* %3
br label %100
100: ; preds = %91, %87, %70, %20
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [8 x i8] c"%s: %s\0A\00"
define i32 @set_conf_value(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i8* (...) @get_conf_file()
%6 = call i64 @stat(i8* %5, %struct.stat* %3)
%7 = icmp sgt i64 %6, -1
br i1 %7, label %8, label %52
8: ; preds = %2
%9 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @free(i8* %5)
br label %62
13: ; preds = %8
%14 = call dereferenceable_or_null(256) i8* @malloc(i32 256)
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = call i8* @malloc(i32 %17)
%19 = call i32 @feof(i32* %9)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %39
21: ; preds = %13, %35
%22 = phi i8* [ %36, %35 ], [ %18, %13 ]
%23 = call i32* @fgets(i8* %14, i32 256, i32* %9)
%24 = icmp eq i32* %23, null
br i1 %24, label %35, label %25
25: ; preds = %21
%26 = call i32 @strlen(i8* %0)
%27 = call i64 @strncmp(i8* %14, i8* %0, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %25
%30 = call i32 @strlen(i8* %14)
%31 = call i32 @memcpy(i8* %22, i8* %14, i32 %30)
%32 = call i32 @strlen(i8* %14)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %22, i64 %33
br label %35
35: ; preds = %25, %29, %21
%36 = phi i8* [ %34, %29 ], [ %22, %25 ], [ %22, %21 ]
%37 = call i32 @feof(i32* %9)
%38 = icmp eq i32 %37, 0
br i1 %38, label %21, label %39
39: ; preds = %35, %13
%40 = phi i8* [ %18, %13 ], [ %36, %35 ]
%41 = call i32 @free(i8* %14)
store i8 0, i8* %40
%42 = call i32 @fclose(i32* %9)
%43 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %49
45: ; preds = %39
%46 = call i32 @free(i8* %5)
%47 = call i32 @free(i8* %14)
%48 = call i32 @free(i8* %18)
br label %62
49: ; preds = %39
%50 = call i32 @fputs(i8* %18, i32* %43)
%51 = call i32 @free(i8* %18)
br label %57
52: ; preds = %2
%53 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @free(i8* %5)
br label %62
57: ; preds = %52, %49
%58 = phi i32* [ %43, %49 ], [ %53, %52 ]
%59 = call i32 @free(i8* %5)
%60 = call i32 @fprintf(i32* %58, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
%61 = call i32 @fclose(i32* %58)
br label %62
62: ; preds = %57, %55, %45, %11
%63 = phi i32 [ -1, %11 ], [ -1, %45 ], [ 0, %57 ], [ -1, %55 ]
ret i32 %63
}