#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 */
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ __getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ config_free();
int /*<<< orphan*/ config_write_int(char *, int);
int /*<<< orphan*/ config_write_string(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strchr(char *, char);
int strtol(char *, char **, int /*<<< orphan*/);
int config_load(const char *filename) {
  FILE *fd;
  char *line;
  size_t n;
  ssize_t readbytes;
  char *c;
  config_free();
  fd = fopen(filename, "r");
  if (fd == NULL)
    return 0;
  line = NULL;
  while (!feof(fd)) {
    readbytes = __getline(&line, &n, fd);
    if (readbytes <= 0)
      break;
    c = strchr(line, '\r');
    if (c)
      *c = 0;
    c = strchr(line, '\n');
    if (c)
      *c = 0;
    c = strchr(line, '=');
    if (c == NULL) {
      printf("malformed line: '%s'\n", line);
      continue;
    }
    *c = 0;
    c++;
    if (*c == 's') {
      c++;
      config_write_string(line, c);
    } else if (*c == 'i') {
      int val;
      char *err;
      c++;
      val = strtol(c, &err, 0);
      config_write_int(line, val);
    } else {
      printf("unknown data type %c\n", *c);
      continue;
    }
  }
  free(line);
  fclose(fd);
  return 1;
}


x86 assembly (clang, -O0):
<config_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   10b0 <config_free@plt>
mov    -0x10(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ee <config_load+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    1372 <config_load+0x1c2>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1214 <config_load+0x64>
jmp    1359 <config_load+0x1a9>
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10c0 <__getline@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jg     1239 <config_load+0x89>
jmp    1359 <config_load+0x1a9>
mov    -0x20(%rbp),%rdi
mov    $0xd,%esi
call   1070 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     125d <config_load+0xad>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1281 <config_load+0xd1>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x3d,%esi
call   1070 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12b5 <config_load+0x105>
mov    -0x20(%rbp),%rsi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    11f6 <config_load+0x46>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x73,%eax
jne    12f6 <config_load+0x146>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <config_write_string@plt>
jmp    1354 <config_load+0x1a4>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x69,%eax
jne    1335 <config_load+0x185>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   10a0 <strtol@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x3c(%rbp),%esi
call   1050 <config_write_int@plt>
jmp    134f <config_load+0x19f>
mov    -0x38(%rbp),%rax
movsbl (%rax),%esi
lea    0xcd5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    11f6 <config_load+0x46>
jmp    1354 <config_load+0x1a4>
jmp    11f6 <config_load+0x46>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <config_free@plt>
lea    0xe2f(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1325 <config_load+0x175>
mov    %rax,%rbx
movq   $0x0,(%rsp)
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1200 <config_load+0x50>
xor    %edi,%edi
jmp    1313 <config_load+0x163>
mov    %rsp,%r14
lea    0x10(%rsp),%r15
lea    0xdf3(%rip),%r12
lea    0xe02(%rip),%rbp
jmp    123d <config_load+0x8d>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    130f <config_load+0x15f>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   10c0 <__getline@plt>
test   %rax,%rax
jle    130f <config_load+0x15f>
mov    (%rsp),%r13
mov    %r13,%rdi
mov    $0xd,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1271 <config_load+0xc1>
movb   $0x0,(%rax)
mov    (%rsp),%r13
mov    %r13,%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     128a <config_load+0xda>
movb   $0x0,(%rax)
mov    (%rsp),%r13
mov    %r13,%rdi
mov    $0x3d,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     1220 <config_load+0x70>
movb   $0x0,(%rax)
movsbl 0x1(%rax),%esi
cmp    $0x69,%esi
je     12d0 <config_load+0x120>
cmp    $0x73,%sil
jne    1300 <config_load+0x150>
add    $0x2,%rax
mov    (%rsp),%rdi
mov    %rax,%rsi
call   1030 <config_write_string@plt>
jmp    122d <config_load+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x2,%rax
mov    %rax,%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   10a0 <strtol@plt>
mov    (%rsp),%rdi
mov    %eax,%esi
call   1050 <config_write_int@plt>
jmp    122d <config_load+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    122d <config_load+0x7d>
mov    (%rsp),%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"malformed line: '%s'\0A\00"
@.str.2 = [22 x i8] c"unknown data type %c\0A\00"
define i32 @config_load(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %3
%11 = call i32 (...) @config_free()
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 0, i32* %2
br label %90
17: ; preds = %1
store i8* null, i8** %5
br label %18
18: ; preds = %84, %78, %48, %17
%19 = load i32*, i32** %4
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %85
23: ; preds = %18
%24 = load i32*, i32** %4
%25 = call i64 @__getline(i8** %5, i64* %6, i32* %24)
store i64 %25, i64* %7
%26 = load i64, i64* %7
%27 = icmp sle i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
br label %85
29: ; preds = %23
%30 = load i8*, i8** %5
%31 = call i8* @strchr(i8* %30, i8 signext 13)
store i8* %31, i8** %8
%32 = load i8*, i8** %8
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i8*, i8** %8
store i8 0, i8* %35
br label %36
36: ; preds = %34, %29
%37 = load i8*, i8** %5
%38 = call i8* @strchr(i8* %37, i8 signext 10)
store i8* %38, i8** %8
%39 = load i8*, i8** %8
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = load i8*, i8** %8
store i8 0, i8* %42
br label %43
43: ; preds = %41, %36
%44 = load i8*, i8** %5
%45 = call i8* @strchr(i8* %44, i8 signext 61)
store i8* %45, i8** %8
%46 = load i8*, i8** %8
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i8*, i8** %5
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %49)
br label %18
51: ; preds = %43
%52 = load i8*, i8** %8
store i8 0, i8* %52
%53 = load i8*, i8** %8
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %8
%55 = load i8*, i8** %8
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 115
br i1 %58, label %59, label %65
59: ; preds = %51
%60 = load i8*, i8** %8
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %8
%62 = load i8*, i8** %5
%63 = load i8*, i8** %8
%64 = call i32 @config_write_string(i8* %62, i8* %63)
br label %84
65: ; preds = %51
%66 = load i8*, i8** %8
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 105
br i1 %69, label %70, label %78
70: ; preds = %65
%71 = load i8*, i8** %8
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %8
%73 = load i8*, i8** %8
%74 = call i32 @strtol(i8* %73, i8** %10, i32 0)
store i32 %74, i32* %9
%75 = load i8*, i8** %5
%76 = load i32, i32* %9
%77 = call i32 @config_write_int(i8* %75, i32 %76)
br label %83
78: ; preds = %65
%79 = load i8*, i8** %8
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %81)
br label %18
83: ; preds = %70
br label %84
84: ; preds = %83, %59
br label %18
85: ; preds = %28, %18
%86 = load i8*, i8** %5
%87 = call i32 @free(i8* %86)
%88 = load i32*, i32** %4
%89 = call i32 @fclose(i32* %88)
store i32 1, i32* %2
br label %90
90: ; preds = %85, %16
%91 = load i32, i32* %2
ret i32 %91
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"malformed line: '%s'\0A\00"
@.str.2 = [22 x i8] c"unknown data type %c\0A\00"
define i32 @config_load(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = bitcast i8** %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = tail call i32 (...) @config_free()
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %60, label %10
10: ; preds = %1
store i8* null, i8** %2
%11 = call i32 @feof(i32* %8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %56
13: ; preds = %10
%14 = bitcast i8** %4 to i8*
br label %15
15: ; preds = %13, %36
%16 = call i64 @__getline(i8** %2, i64* %3, i32* %8)
%17 = icmp slt i64 %16, 1
br i1 %17, label %54, label %18
18: ; preds = %15
%19 = load i8*, i8** %2
%20 = call i8* @strchr(i8* dereferenceable(1) %19, i8 signext 13)
%21 = icmp eq i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %18
store i8 0, i8* %20
%23 = load i8*, i8** %2
br label %24
24: ; preds = %22, %18
%25 = phi i8* [ %23, %22 ], [ %19, %18 ]
%26 = call i8* @strchr(i8* dereferenceable(1) %25, i8 signext 10)
%27 = icmp eq i8* %26, null
br i1 %27, label %30, label %28
28: ; preds = %24
store i8 0, i8* %26
%29 = load i8*, i8** %2
br label %30
30: ; preds = %28, %24
%31 = phi i8* [ %29, %28 ], [ %25, %24 ]
%32 = call i8* @strchr(i8* dereferenceable(1) %31, i8 signext 61)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %36
36: ; preds = %42, %46, %34, %51
%37 = call i32 @feof(i32* %8)
%38 = icmp eq i32 %37, 0
br i1 %38, label %15, label %54
39: ; preds = %30
store i8 0, i8* %32
%40 = getelementptr inbounds i8, i8* %32, i64 1
%41 = load i8, i8* %40
switch i8 %41, label %51 [
i8 115, label %42
i8 105, label %46
]
42: ; preds = %39
%43 = getelementptr inbounds i8, i8* %32, i64 2
%44 = load i8*, i8** %2
%45 = call i32 @config_write_string(i8* %44, i8* %43)
br label %36
46: ; preds = %39
%47 = getelementptr inbounds i8, i8* %32, i64 2
%48 = call i32 @strtol(i8* %47, i8** %4, i32 0)
%49 = load i8*, i8** %2
%50 = call i32 @config_write_int(i8* %49, i32 %48)
br label %36
51: ; preds = %39
%52 = sext i8 %41 to i32
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %52)
br label %36
54: ; preds = %15, %36
%55 = load i8*, i8** %2
br label %56
56: ; preds = %54, %10
%57 = phi i8* [ %55, %54 ], [ null, %10 ]
%58 = call i32 @free(i8* %57)
%59 = call i32 @fclose(i32* %8)
br label %60
60: ; preds = %1, %56
%61 = phi i32 [ 1, %56 ], [ 0, %1 ]
ret i32 %61
}