#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
int strlen(char const *);
scalar_t__ strncmp(char *, char const *, int);
int read_conf(const char *config_file, const char *key, char **value) {
  FILE *fp;
  char line[100];
  int end;
  int retVal = 0;
  int keyLen = strlen(key);
  if (!(fp = fopen(config_file, "r"))) {
    return (-1);
  }
  while (fgets(line, 100, fp)) {
    if (strncmp(line, key, keyLen) == 0) {
      if (*value != NULL)
        free(*value);
      end = strlen(line);
      if (line[end - 1] == '\n')
        line[end - 1] = 0;
      *value = strdup(line + keyLen + 1);
      if (fp != NULL)
        fclose(fp);
      return (1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_conf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x98(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x9c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ca <read_conf+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b9 <read_conf+0x149>
jmp    11cf <read_conf+0x5f>
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12b2 <read_conf+0x142>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x9c(%rbp),%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12ad <read_conf+0x13d>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1228 <read_conf+0xb8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
lea    -0x90(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1269 <read_conf+0xf9>
mov    -0x94(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rdi
movslq -0x9c(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     12a1 <read_conf+0x131>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b9 <read_conf+0x149>
jmp    11cf <read_conf+0x5f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_conf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     121d <read_conf+0xad>
mov    %rax,%r12
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1224 <read_conf+0xb4>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11b0 <read_conf+0x40>
mov    (%r14),%rdi
test   %rdi,%rdi
je     11e5 <read_conf+0x75>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11fb <read_conf+0x8b>
movb   $0x0,-0x1(%rsp,%rax,1)
movslq %r15d,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x1,%rdi
call   1090 <strdup@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
jmp    1226 <read_conf+0xb6>
mov    $0xffffffff,%eax
jmp    1226 <read_conf+0xb6>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @read_conf(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca [100 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i32 0, i32* %11
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %12
%15 = load i8*, i8** %5
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %8
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %3
store i32 -1, i32* %4
br label %70
19: ; preds = %3
br label %20
20: ; preds = %68, %19
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%22 = load i32*, i32** %8
%23 = call i64 @fgets(i8* %21, i32 100, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %69
25: ; preds = %20
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = load i32, i32* %12
%29 = call i64 @strncmp(i8* %26, i8* %27, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %68
31: ; preds = %25
%32 = load i8**, i8*** %7
%33 = load i8*, i8** %32
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i8**, i8*** %7
%37 = load i8*, i8** %36
%38 = call i32 @free(i8* %37)
br label %39
39: ; preds = %35, %31
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 10
br i1 %48, label %49, label %54
49: ; preds = %39
%50 = load i32, i32* %10
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %52
store i8 0, i8* %53
br label %54
54: ; preds = %49, %39
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%56 = load i32, i32* %12
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = call i8* @strdup(i8* %59)
%61 = load i8**, i8*** %7
store i8* %60, i8** %61
%62 = load i32*, i32** %8
%63 = icmp ne i32* %62, null
br i1 %63, label %64, label %67
64: ; preds = %54
%65 = load i32*, i32** %8
%66 = call i32 @fclose(i32* %65)
br label %67
67: ; preds = %64, %54
store i32 1, i32* %4
br label %70
68: ; preds = %25
br label %20
69: ; preds = %20
store i32 0, i32* %4
br label %70
70: ; preds = %69, %67, %18
%71 = load i32, i32* %4
ret i32 %71
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @read_conf(i8* nocapture %0, i8* %1, i8** nocapture %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %1)
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %34, label %9
9: ; preds = %3, %12
%10 = call i64 @fgets(i8* %5, i32 100, i32* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %34, label %12
12: ; preds = %9
%13 = call i64 @strncmp(i8* %5, i8* %1, i32 %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %9
15: ; preds = %12
%16 = load i8*, i8** %2
%17 = icmp eq i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = call i32 @free(i8* %16)
br label %20
20: ; preds = %18, %15
%21 = call i32 @strlen(i8* %5)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 10
br i1 %26, label %27, label %28
27: ; preds = %20
store i8 0, i8* %24
br label %28
28: ; preds = %27, %20
%29 = sext i32 %6 to i64
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %29
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = call i8* @strdup(i8* %31)
store i8* %32, i8** %2
%33 = call i32 @fclose(i32* %7)
br label %34
34: ; preds = %9, %3, %28
%35 = phi i32 [ 1, %28 ], [ -1, %3 ], [ 0, %9 ]
ret i32 %35
}