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

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ parse_config_line(char *, char *);
char *strchr(char *, char);
scalar_t__ write(int /*<<< orphan*/, char *, int);
bool read_config(const char *cfg_file) {
  FILE *f = fopen(cfg_file, "rb");
  if (f == NULL) {
    if (write(STDERR_FILENO, ("Cannot read config file\n"),
              (sizeof("Cannot read config file\n") - 1)) < 0) {
      abort();
    }
    exit(0);
  }
  char buf[4096];
  while (!feof(f)) {
    if (!fgets(buf, sizeof(buf), f))
      continue;
    char *endline = strchr(buf, '\n');
    if (!endline && !feof(f))
      assert(0);
    if (endline)
      *endline = '\0';
    char *comment = strchr(buf, '#');
    if (comment)
      *comment = '\0';
    char *key = buf;
    if (*key == '\0')
      continue;
    char *value = strchr(buf, ' ');
    if (!value)
      assert(0);
    *(value++) = '\0';
    parse_config_line(key, value);
  }
  fclose(f);
  return true;
}


x86 assembly (clang, -O0):
<read_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1200 <read_config+0x60>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    11f9 <read_config+0x59>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    1205 <read_config+0x65>
mov    -0x10(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1223 <read_config+0x83>
jmp    1350 <read_config+0x1b0>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%eax
jne    1246 <read_config+0xa6>
jmp    1205 <read_config+0x65>
lea    -0x1010(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jne    1285 <read_config+0xe5>
mov    -0x10(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
jne    1285 <read_config+0xe5>
xor    %edi,%edi
call   1090 <assert@plt>
cmpq   $0x0,-0x1018(%rbp)
je     129d <read_config+0xfd>
mov    -0x1018(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1010(%rbp),%rdi
mov    $0x23,%esi
call   1060 <strchr@plt>
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1020(%rbp)
je     12cd <read_config+0x12d>
mov    -0x1020(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12f3 <read_config+0x153>
jmp    1205 <read_config+0x65>
lea    -0x1010(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,-0x1030(%rbp)
cmpq   $0x0,-0x1030(%rbp)
jne    1320 <read_config+0x180>
xor    %edi,%edi
call   1090 <assert@plt>
mov    -0x1030(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x1030(%rbp)
movb   $0x0,(%rax)
mov    -0x1028(%rbp),%rdi
mov    -0x1030(%rbp),%rsi
call   1080 <parse_config_line@plt>
jmp    1205 <read_config+0x65>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_config>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
lea    0xe4d(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12a0 <read_config+0x100>
mov    %rax,%r15
mov    %rax,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     11ea <read_config+0x4a>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsp,%r14
jmp    120e <read_config+0x6e>
nop
mov    %rbx,%rsi
add    $0x1,%rsi
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1080 <parse_config_line@plt>
mov    %r15,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    11d0 <read_config+0x30>
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %eax,%eax
je     1202 <read_config+0x62>
mov    %r14,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1240 <read_config+0xa0>
movb   $0x0,(%rax)
jmp    1260 <read_config+0xc0>
nopl   0x0(%rax)
mov    %r15,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1260 <read_config+0xc0>
xor    %edi,%edi
call   1090 <assert@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    $0x23,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1275 <read_config+0xd5>
movb   $0x0,(%rax)
cmpb   $0x0,(%rsp)
je     1202 <read_config+0x62>
mov    %r14,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11f0 <read_config+0x50>
xor    %edi,%edi
call   1090 <assert@plt>
jmp    11f0 <read_config+0x50>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd53(%rip),%rsi
mov    $0x18,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    12c6 <read_config+0x126>
xor    %eax,%eax
call   1030 <abort@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@STDERR_FILENO = global i32 0
@.str.1 = [25 x i8] c"Cannot read config file\0A\00"
define i32 @read_config(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [4096 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %21
13: ; preds = %1
%14 = load i32, i32* @STDERR_FILENO
%15 = call i64 @write(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 24)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %13
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %1
br label %22
22: ; preds = %70, %62, %32, %21
%23 = load i32*, i32** %3
%24 = call i32 @feof(i32* %23)
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br i1 %26, label %27, label %76
27: ; preds = %22
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%29 = load i32*, i32** %3
%30 = call i32 @fgets(i8* %28, i32 4096, i32* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %27
br label %22
33: ; preds = %27
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%35 = call i8* @strchr(i8* %34, i8 signext 10)
store i8* %35, i8** %5
%36 = load i8*, i8** %5
%37 = icmp ne i8* %36, null
br i1 %37, label %44, label %38
38: ; preds = %33
%39 = load i32*, i32** %3
%40 = call i32 @feof(i32* %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 @assert(i32 0)
br label %44
44: ; preds = %42, %38, %33
%45 = load i8*, i8** %5
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = load i8*, i8** %5
store i8 0, i8* %48
br label %49
49: ; preds = %47, %44
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%51 = call i8* @strchr(i8* %50, i8 signext 35)
store i8* %51, i8** %6
%52 = load i8*, i8** %6
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = load i8*, i8** %6
store i8 0, i8* %55
br label %56
56: ; preds = %54, %49
%57 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
store i8* %57, i8** %7
%58 = load i8*, i8** %7
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %56
br label %22
63: ; preds = %56
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%65 = call i8* @strchr(i8* %64, i8 signext 32)
store i8* %65, i8** %8
%66 = load i8*, i8** %8
%67 = icmp ne i8* %66, null
br i1 %67, label %70, label %68
68: ; preds = %63
%69 = call i32 @assert(i32 0)
br label %70
70: ; preds = %68, %63
%71 = load i8*, i8** %8
%72 = getelementptr inbounds i8, i8* %71, i32 1
store i8* %72, i8** %8
store i8 0, i8* %71
%73 = load i8*, i8** %7
%74 = load i8*, i8** %8
%75 = call i32 @parse_config_line(i8* %73, i8* %74)
br label %22
76: ; preds = %22
%77 = load i32*, i32** %3
%78 = call i32 @fclose(i32* %77)
ret i32 1
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@STDERR_FILENO = global i32 0
@.str.1 = [25 x i8] c"Cannot read config file\0A\00"
define i32 @read_config(i8* nocapture %0) {
%2 = alloca [4096 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = load i32, i32* @STDERR_FILENO
%7 = tail call i64 @write(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 24)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 (...) @abort()
unreachable
11: ; preds = %5
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %1
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%15 = call i32 @feof(i32* %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %47
17: ; preds = %13, %20
%18 = call i32 @fgets(i8* %14, i32 4096, i32* %3)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %44, %36, %17
%21 = call i32 @feof(i32* %3)
%22 = icmp eq i32 %21, 0
br i1 %22, label %17, label %47
23: ; preds = %17
%24 = call i8* @strchr(i8* %14, i8 signext 10)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = call i32 @feof(i32* %3)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = call i32 @assert(i32 0)
br label %32
31: ; preds = %23
store i8 0, i8* %24
br label %32
32: ; preds = %26, %29, %31
%33 = call i8* @strchr(i8* %14, i8 signext 35)
%34 = icmp eq i8* %33, null
br i1 %34, label %36, label %35
35: ; preds = %32
store i8 0, i8* %33
br label %36
36: ; preds = %35, %32
%37 = load i8, i8* %14
%38 = icmp eq i8 %37, 0
br i1 %38, label %20, label %39
39: ; preds = %36
%40 = call i8* @strchr(i8* %14, i8 signext 32)
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @assert(i32 0)
br label %44
44: ; preds = %42, %39
%45 = getelementptr inbounds i8, i8* %40, i64 1
store i8 0, i8* %40
%46 = call i32 @parse_config_line(i8* %14, i8* %45)
br label %20
47: ; preds = %20, %13
%48 = call i32 @fclose(i32* %3)
ret i32 1
}