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

/* Variables and functions */
scalar_t__ EOF;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ perror(char *);
scalar_t__ set_conf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
char *strtok(char *, char *);
char *strtrim(char *);
int parse_conf(const char *conf) {
  FILE *fd;
  char line[255];
  char *key, *val;
  int ret = 0;
  if ((fd = fopen(conf, "r")) == NULL) {
    (void)fprintf(stderr, "Cannot read file %s", conf);
    perror(" ");
    return -1;
  }
  while ((fgets(line, (int)sizeof(line), fd)) != NULL) {
    if (!strlen(strtrim(line)) || line[0] == '#')
      continue;
    key = strtok(line, "=");
    val = strtok(NULL, "");
    key = strtrim(key);
    if ((val = strtrim(val)) == NULL) {
      (void)fprintf(stderr,
                    "Error: no value for %s in "
                    "configuration file\n",
                    key);
      if (fclose(fd) == EOF)
        perror("Could not close configuration file ");
      return -1;
    }
    ret += set_conf(key, val);
  }
  if (fclose(fd) == EOF)
    perror("Could not close configuration file ");
  if (ret < 0)
    return -1;
  return ret;
}


x86 assembly (clang, -O0):
<parse_conf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x134(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f8 <parse_conf+0x68>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe27(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe81(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136e <parse_conf+0x1de>
jmp    11fd <parse_conf+0x6d>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1327 <parse_conf+0x197>
lea    -0x120(%rbp),%rdi
call   1080 <strtrim@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
je     1249 <parse_conf+0xb9>
movsbl -0x120(%rbp),%eax
cmp    $0x23,%eax
jne    124e <parse_conf+0xbe>
jmp    11fd <parse_conf+0x6d>
lea    -0x120(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x128(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd2(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x130(%rbp)
mov    -0x128(%rbp),%rdi
call   1080 <strtrim@plt>
mov    %rax,-0x128(%rbp)
mov    -0x130(%rbp),%rdi
call   1080 <strtrim@plt>
mov    %rax,-0x130(%rbp)
cmp    $0x0,%rax
jne    12fc <parse_conf+0x16c>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
mov    -0x128(%rbp),%rdx
lea    0xd52(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d0d(%rip),%rcx
cmp    (%rcx),%rax
jne    12f0 <parse_conf+0x160>
lea    0xd5b(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136e <parse_conf+0x1de>
mov    -0x128(%rbp),%rdi
mov    -0x130(%rbp),%rsi
call   1070 <set_conf@plt>
mov    %rax,%rcx
movslq -0x134(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x134(%rbp)
jmp    11fd <parse_conf+0x6d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2cb1(%rip),%rcx
cmp    (%rcx),%rax
jne    134c <parse_conf+0x1bc>
lea    0xcff(%rip),%rdi
call   10a0 <perror@plt>
cmpl   $0x0,-0x134(%rbp)
jge    1365 <parse_conf+0x1d5>
movl   $0xffffffff,-0x4(%rbp)
jmp    136e <parse_conf+0x1de>
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_conf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rbx
lea    0xe55(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1298 <parse_conf+0x108>
mov    %rax,%r14
xor    %r15d,%r15d
lea    0x10(%rsp),%rbx
lea    0xe4b(%rip),%r13
lea    0xe73(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1264 <parse_conf+0xd4>
mov    %rbx,%rdi
call   1080 <strtrim@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11e0 <parse_conf+0x50>
cmpb   $0x23,0x10(%rsp)
je     11e0 <parse_conf+0x50>
mov    %rbx,%rdi
mov    %r13,%rbp
mov    %r13,%rsi
call   10b0 <strtok@plt>
mov    %rax,%r13
xor    %edi,%edi
mov    %r12,%rsi
call   10b0 <strtok@plt>
mov    %rax,0x8(%rsp)
mov    %r13,%rdi
call   1080 <strtrim@plt>
mov    %rax,%r13
mov    0x8(%rsp),%rdi
call   1080 <strtrim@plt>
test   %rax,%rax
je     12d1 <parse_conf+0x141>
mov    %r13,%rdi
mov    %rax,%rsi
call   1070 <set_conf@plt>
add    %eax,%r15d
mov    %rbp,%r13
jmp    11e0 <parse_conf+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2d75(%rip),%rcx
cmp    (%rcx),%rax
je     12c3 <parse_conf+0x133>
test   %r15d,%r15d
mov    $0xffffffff,%ebx
cmovns %r15d,%ebx
mov    %ebx,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
lea    0xdb1(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1284 <parse_conf+0xf4>
lea    0xd7c(%rip),%rdi
call   10a0 <perror@plt>
jmp    1278 <parse_conf+0xe8>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
mov    %r13,%rdx
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2cf0(%rip),%rcx
mov    $0xffffffff,%ebx
cmp    (%rcx),%rax
jne    1284 <parse_conf+0xf4>
lea    0xd3d(%rip),%rdi
call   10a0 <perror@plt>
jmp    1284 <parse_conf+0xf4>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Cannot read file %s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"=\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [46 x i8] c"Error: no value for %s in configuration file\0A\00"
@EOF = global i64 0
@.str.6 = [36 x i8] c"Could not close configuration file \00"
define i32 @parse_conf(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [255 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %8
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %75
17: ; preds = %1
br label %18
18: ; preds = %54, %33, %17
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32* @fgets(i8* %19, i32 255, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %62
23: ; preds = %18
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%25 = call i8* @strtrim(i8* %24)
%26 = call i32 @strlen(i8* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 35
br i1 %32, label %33, label %34
33: ; preds = %28, %23
br label %18
34: ; preds = %28
%35 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%36 = call i8* @strtok(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %36, i8** %6
%37 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
store i8* %37, i8** %7
%38 = load i8*, i8** %6
%39 = call i8* @strtrim(i8* %38)
store i8* %39, i8** %6
%40 = load i8*, i8** %7
%41 = call i8* @strtrim(i8* %40)
store i8* %41, i8** %7
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %54
43: ; preds = %34
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %6
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %4
%48 = call i64 @fclose(i32* %47)
%49 = load i64, i64* @EOF
%50 = icmp eq i64 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %43
%52 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
br label %53
53: ; preds = %51, %43
store i32 -1, i32* %2
br label %75
54: ; preds = %34
%55 = load i8*, i8** %6
%56 = load i8*, i8** %7
%57 = call i64 @set_conf(i8* %55, i8* %56)
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = add nsw i64 %59, %57
%61 = trunc i64 %60 to i32
store i32 %61, i32* %8
br label %18
62: ; preds = %18
%63 = load i32*, i32** %4
%64 = call i64 @fclose(i32* %63)
%65 = load i64, i64* @EOF
%66 = icmp eq i64 %64, %65
br i1 %66, label %67, label %69
67: ; preds = %62
%68 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
br label %69
69: ; preds = %67, %62
%70 = load i32, i32* %8
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %69
store i32 -1, i32* %2
br label %75
73: ; preds = %69
%74 = load i32, i32* %8
store i32 %74, i32* %2
br label %75
75: ; preds = %73, %72, %53, %12
%76 = load i32, i32* %2
ret i32 %76
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Cannot read file %s\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"=\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [46 x i8] c"Error: no value for %s in configuration file\0A\00"
@EOF = global i64 0
@.str.6 = [36 x i8] c"Could not close configuration file \00"
define i32 @parse_conf(i8* %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %38
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @perror(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %49
10: ; preds = %38, %13
%11 = call i32* @fgets(i8* %3, i32 255, i32* %4)
%12 = icmp eq i32* %11, null
br i1 %12, label %40, label %13
13: ; preds = %10
%14 = call i8* @strtrim(i8* %3)
%15 = call i32 @strlen(i8* %14)
%16 = icmp eq i32 %15, 0
%17 = load i8, i8* %3
%18 = icmp eq i8 %17, 35
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %10, label %20
20: ; preds = %13
%21 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%23 = call i8* @strtrim(i8* %21)
%24 = call i8* @strtrim(i8* %22)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %34
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i8* %23)
%29 = call i64 @fclose(i32* %4)
%30 = load i64, i64* @EOF
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %49
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
br label %49
34: ; preds = %20
%35 = call i64 @set_conf(i8* %23, i8* %24)
%36 = trunc i64 %35 to i32
%37 = add i32 %39, %36
br label %38
38: ; preds = %1, %34
%39 = phi i32 [ %37, %34 ], [ 0, %1 ]
br label %10
40: ; preds = %10
%41 = call i64 @fclose(i32* %4)
%42 = load i64, i64* @EOF
%43 = icmp eq i64 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
%47 = icmp sgt i32 %39, -1
%48 = select i1 %47, i32 %39, i32 -1
br label %49
49: ; preds = %46, %26, %32, %6
%50 = phi i32 [ -1, %6 ], [ -1, %32 ], [ -1, %26 ], [ %48, %46 ]
ret i32 %50
}