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

/* Variables and functions */
int /*<<< orphan*/ apply_config_opt(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ strip(char *);
int strlen(char *);
char *strtok(char *, char *);
int parse_config(const char *filename) {
  printf("reading %s\n", filename);
  FILE *fp;
  char line[100];
  if ((fp = fopen(filename, "r")) != NULL) {
    char *key;
    char *val;
    while (fgets(line, 100, fp)) {
      if (line[0] == '#')
        continue;
      int ln = strlen(line) - 1;
      if (line[ln] == '\n')
        line[ln--] = 0;
      if (line[ln] == '\r')
        line[ln--] = 0;
      if (ln < 0)
        continue;
      key = strtok(line, "=");
      val = strtok(NULL, "=");
      if (val != NULL) {
        strip(key);
        strip(val);
        apply_config_opt(key, val);
      } else {
        printf("config: Invalid line, ignoring: %s\n", line);
      }
    }
    fclose(fp);
    return 1;
  } else {
    perror("Error reading configuration file");
    return 0;
  }
}


x86 assembly (clang, -O0):
<parse_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1314 <parse_config+0x184>
jmp    11d2 <parse_config+0x42>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12ff <parse_config+0x16f>
movsbl -0x80(%rbp),%eax
cmp    $0x23,%eax
jne    1200 <parse_config+0x70>
jmp    11d2 <parse_config+0x42>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x94(%rbp)
movslq -0x94(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    123f <parse_config+0xaf>
mov    -0x94(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x94(%rbp)
cltq
movb   $0x0,-0x80(%rbp,%rax,1)
movslq -0x94(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0xd,%eax
jne    126c <parse_config+0xdc>
mov    -0x94(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x94(%rbp)
cltq
movb   $0x0,-0x80(%rbp,%rax,1)
cmpl   $0x0,-0x94(%rbp)
jge    127e <parse_config+0xee>
jmp    11d2 <parse_config+0x42>
lea    -0x80(%rbp),%rdi
lea    0xd85(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x88(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd6e(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
je     12ea <parse_config+0x15a>
mov    -0x88(%rbp),%rdi
call   1060 <strip@plt>
mov    -0x90(%rbp),%rdi
call   1060 <strip@plt>
mov    -0x88(%rbp),%rdi
mov    -0x90(%rbp),%rsi
call   10b0 <apply_config_opt@plt>
jmp    12fa <parse_config+0x16a>
lea    -0x80(%rbp),%rsi
lea    0xd1b(%rip),%rdi
call   1050 <printf@plt>
jmp    11d2 <parse_config+0x42>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1327 <parse_config+0x197>
lea    0xd19(%rip),%rdi
call   1090 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_config>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rbx
lea    0xe58(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12cf <parse_config+0x13f>
mov    %rax,%r13
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12b3 <parse_config+0x123>
mov    %rsp,%r14
lea    0xe20(%rip),%r15
lea    0xe1b(%rip),%r12
jmp    1235 <parse_config+0xa5>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <strip@plt>
mov    %rbp,%rdi
call   1060 <strip@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <apply_config_opt@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    $0x64,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12b3 <parse_config+0x123>
cmpb   $0x23,(%rsp)
je     1220 <parse_config+0x90>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
lea    -0x1(%rax),%rcx
movzbl -0x1(%rsp,%rax,1),%edx
cmp    $0xa,%dl
jne    1270 <parse_config+0xe0>
movb   $0x0,(%rsp,%rcx,1)
movzbl -0x2(%rsp,%rax,1),%edx
add    $0xfffffffffffffffe,%rax
mov    %rax,%rcx
cmp    $0xd,%dl
je     1277 <parse_config+0xe7>
jmp    127e <parse_config+0xee>
nopw   0x0(%rax,%rax,1)
mov    %ecx,%eax
cmp    $0xd,%dl
jne    127e <parse_config+0xee>
add    $0xffffffff,%eax
movb   $0x0,(%rsp,%rcx,1)
test   %eax,%eax
js     1220 <parse_config+0x90>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <strtok@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
jne    11f7 <parse_config+0x67>
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
jmp    1220 <parse_config+0x90>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5e(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
jmp    12c0 <parse_config+0x130>

LLVM IR (-O0):
@.str = [12 x i8] c"reading %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [36 x i8] c"config: Invalid line, ignoring: %s\0A\00"
@.str.4 = [33 x i8] c"Error reading configuration file\00"
define i32 @parse_config(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [100 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %78
14: ; preds = %1
br label %15
15: ; preds = %74, %56, %25, %14
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %4
%18 = call i64 @fgets(i8* %16, i32 100, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %75
20: ; preds = %15
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 35
br i1 %24, label %25, label %26
25: ; preds = %20
br label %15
26: ; preds = %20
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 10
br i1 %35, label %36, label %41
36: ; preds = %26
%37 = load i32, i32* %8
%38 = add nsw i32 %37, -1
store i32 %38, i32* %8
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %36, %26
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 13
br i1 %47, label %48, label %53
48: ; preds = %41
%49 = load i32, i32* %8
%50 = add nsw i32 %49, -1
store i32 %50, i32* %8
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %51
store i8 0, i8* %52
br label %53
53: ; preds = %48, %41
%54 = load i32, i32* %8
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %53
br label %15
57: ; preds = %53
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%59 = call i8* @strtok(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %59, i8** %6
%60 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %60, i8** %7
%61 = load i8*, i8** %7
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %71
63: ; preds = %57
%64 = load i8*, i8** %6
%65 = call i32 @strip(i8* %64)
%66 = load i8*, i8** %7
%67 = call i32 @strip(i8* %66)
%68 = load i8*, i8** %6
%69 = load i8*, i8** %7
%70 = call i32 @apply_config_opt(i8* %68, i8* %69)
br label %74
71: ; preds = %57
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%73 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %71, %63
br label %15
75: ; preds = %15
%76 = load i32*, i32** %4
%77 = call i32 @fclose(i32* %76)
store i32 1, i32* %2
br label %80
78: ; preds = %1
%79 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %80
80: ; preds = %78, %75
%81 = load i32, i32* %2
ret i32 %81
}

LLVM IR (-O2):
@.str = [12 x i8] c"reading %s\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"=\00"
@.str.3 = [36 x i8] c"config: Invalid line, ignoring: %s\0A\00"
@.str.4 = [33 x i8] c"Error reading configuration file\00"
define i32 @parse_config(i8* %0) {
%2 = alloca [100 x i8]
%3 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %51, label %7
7: ; preds = %1
%8 = call i64 @fgets(i8* %4, i32 100, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %49, label %10
10: ; preds = %7, %13
%11 = load i8, i8* %4
%12 = icmp eq i8 %11, 35
br i1 %12, label %13, label %16
13: ; preds = %36, %47, %43, %10
%14 = call i64 @fgets(i8* %4, i32 100, i32* %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %49, label %10
16: ; preds = %10
%17 = call i32 @strlen(i8* %4)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = add nsw i32 %17, -2
store i8 0, i8* %20
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
br label %28
28: ; preds = %23, %16
%29 = phi i8 [ %27, %23 ], [ %21, %16 ]
%30 = phi i64 [ %25, %23 ], [ %19, %16 ]
%31 = phi i32 [ %24, %23 ], [ %18, %16 ]
%32 = icmp eq i8 %29, 13
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %30
%35 = add nsw i32 %31, -1
store i8 0, i8* %34
br label %36
36: ; preds = %33, %28
%37 = phi i32 [ %35, %33 ], [ %31, %28 ]
%38 = icmp slt i32 %37, 0
br i1 %38, label %13, label %39
39: ; preds = %36
%40 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i8* %41, null
br i1 %42, label %47, label %43
43: ; preds = %39
%44 = call i32 @strip(i8* %40)
%45 = call i32 @strip(i8* %41)
%46 = call i32 @apply_config_opt(i8* %40, i8* %41)
br label %13
47: ; preds = %39
%48 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %13
49: ; preds = %13, %7
%50 = call i32 @fclose(i32* %5)
br label %53
51: ; preds = %1
%52 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %49
%54 = phi i32 [ 1, %49 ], [ 0, %51 ]
ret i32 %54
}