#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ isspace(char);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ parse_configuration_option(char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strchrnul(char *, char);
void read_configuration_file() {
  struct stat st;
  if (0 != stat("/etc/log-user-session.conf", &st)) {
    return;
  }
  size_t filesize = (size_t)st.st_size;
  FILE *f = fopen("/etc/log-user-session.conf", "r");
  if (!f) {
    perror("/etc/log-user-session.conf");
    fprintf(stderr, "using default configuration\n");
    return;
  }
  char *data = (char *)malloc(filesize + 1);
  size_t s = fread(data, 1, filesize, f);
  if (0 == s) {
    if (ferror(f)) {
      perror("/etc/log-user-session.conf");
      fprintf(stderr, "using default configuration\n");
    }
    free(data);
    return;
  }
  data[filesize] = '\0';
  fclose(f);
  char *pos = data;
  do {
    if ('#' == *pos) {
      pos = strchrnul(pos, '\n');
    } else if (!isspace(*pos)) {
      char *end = strchrnul(pos, '\n');
      parse_configuration_option(pos, end);
      pos = end;
    } else {
      pos++;
    }
  } while (*pos != '\0');
  free(data);
}


x86 assembly (clang, -O0):
<read_configuration_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe31(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   10b0 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11eb <read_configuration_file+0x2b>
jmp    136c <read_configuration_file+0x1ac>
movslq -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xe06(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123b <read_configuration_file+0x7b>
lea    0xde4(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    136c <read_configuration_file+0x1ac>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fread@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    12b4 <read_configuration_file+0xf4>
mov    -0x18(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     12a6 <read_configuration_file+0xe6>
lea    0xd74(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    136c <read_configuration_file+0x1ac>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1080 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x23,%eax
cmp    %ecx,%eax
jne    12fc <read_configuration_file+0x13c>
mov    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1070 <strchrnul@plt>
mov    %rax,-0x30(%rbp)
jmp    134e <read_configuration_file+0x18e>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1090 <isspace@plt>
cmp    $0x0,%eax
jne    133d <read_configuration_file+0x17d>
mov    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1070 <strchrnul@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <parse_configuration_option@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1349 <read_configuration_file+0x189>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    134e <read_configuration_file+0x18e>
jmp    1353 <read_configuration_file+0x193>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12d1 <read_configuration_file+0x111>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_configuration_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe30(%rip),%rdi
lea    0x8(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
jne    12a2 <read_configuration_file+0xe2>
movslq 0x8(%rsp),%r15
lea    0xe11(%rip),%rdi
lea    0xe25(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     12ac <read_configuration_file+0xec>
mov    %rax,%rbx
lea    0x1(%r15),%rdi
call   10c0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1060 <fread@plt>
test   %rax,%rax
je     128d <read_configuration_file+0xcd>
movb   $0x0,(%r14,%r15,1)
mov    %rbx,%rdi
call   1080 <fclose@plt>
mov    (%r14),%al
mov    %r14,%rbx
jmp    1257 <read_configuration_file+0x97>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <strchrnul@plt>
mov    %rax,%rbx
movzbl (%rbx),%eax
test   %al,%al
je     129a <read_configuration_file+0xda>
cmp    $0x23,%al
je     1240 <read_configuration_file+0x80>
movsbl %al,%edi
call   1090 <isspace@plt>
test   %eax,%eax
je     126d <read_configuration_file+0xad>
add    $0x1,%rbx
jmp    1250 <read_configuration_file+0x90>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1070 <strchrnul@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <parse_configuration_option@plt>
mov    %r15,%rbx
jmp    1250 <read_configuration_file+0x90>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    12cf <read_configuration_file+0x10f>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd4d(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xd55(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    12a2 <read_configuration_file+0xe2>
lea    0xd2a(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xd32(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    129a <read_configuration_file+0xda>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [27 x i8] c"/etc/log-user-session.conf\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"using default configuration\0A\00"
define void @read_configuration_file() {
%1 = alloca %struct.stat
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = call i64 @stat(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%9 = icmp ne i64 0, %8
br i1 %9, label %10, label %11
10: ; preds = %0
br label %84
11: ; preds = %0
%12 = getelementptr inbounds %struct.stat, %struct.stat* %1, i32 0, i32 0
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
store i64 %14, i64* %2
%15 = call i32* @fopen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %3
%16 = load i32*, i32** %3
%17 = icmp ne i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %11
%19 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %84
22: ; preds = %11
%23 = load i64, i64* %2
%24 = add i64 %23, 1
%25 = call i64 @malloc(i64 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = load i64, i64* %2
%29 = load i32*, i32** %3
%30 = call i64 @fread(i8* %27, i32 1, i64 %28, i32* %29)
store i64 %30, i64* %5
%31 = load i64, i64* %5
%32 = icmp eq i64 0, %31
br i1 %32, label %33, label %44
33: ; preds = %22
%34 = load i32*, i32** %3
%35 = call i64 @ferror(i32* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %37, %33
%42 = load i8*, i8** %4
%43 = call i32 @free(i8* %42)
br label %84
44: ; preds = %22
%45 = load i8*, i8** %4
%46 = load i64, i64* %2
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 0, i8* %47
%48 = load i32*, i32** %3
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %4
store i8* %50, i8** %6
br label %51
51: ; preds = %76, %44
%52 = load i8*, i8** %6
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 35, %54
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i8*, i8** %6
%58 = call i8* @strchrnul(i8* %57, i8 signext 10)
store i8* %58, i8** %6
br label %75
59: ; preds = %51
%60 = load i8*, i8** %6
%61 = load i8, i8* %60
%62 = call i32 @isspace(i8 signext %61)
%63 = icmp ne i32 %62, 0
br i1 %63, label %71, label %64
64: ; preds = %59
%65 = load i8*, i8** %6
%66 = call i8* @strchrnul(i8* %65, i8 signext 10)
store i8* %66, i8** %7
%67 = load i8*, i8** %6
%68 = load i8*, i8** %7
%69 = call i32 @parse_configuration_option(i8* %67, i8* %68)
%70 = load i8*, i8** %7
store i8* %70, i8** %6
br label %74
71: ; preds = %59
%72 = load i8*, i8** %6
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %6
br label %74
74: ; preds = %71, %64
br label %75
75: ; preds = %74, %56
br label %76
76: ; preds = %75
%77 = load i8*, i8** %6
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp ne i32 %79, 0
br i1 %80, label %51, label %81
81: ; preds = %76
%82 = load i8*, i8** %4
%83 = call i32 @free(i8* %82)
br label %84
84: ; preds = %81, %41, %18, %10
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [27 x i8] c"/etc/log-user-session.conf\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"using default configuration\0A\00"
define void @read_configuration_file() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i64 @stat(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %54
5: ; preds = %0
%6 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = sext i32 %7 to i64
%9 = call i32* @fopen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %5
%12 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %54
15: ; preds = %5
%16 = add nsw i64 %8, 1
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = call i64 @fread(i8* %18, i32 1, i64 %8, i32* %9)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %15
%22 = call i64 @ferror(i32* %9)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %24, %21
%29 = call i32 @free(i8* %18)
br label %54
30: ; preds = %15
%31 = getelementptr inbounds i8, i8* %18, i64 %8
store i8 0, i8* %31
%32 = call i32 @fclose(i32* %9)
%33 = load i8, i8* %18
br label %34
34: ; preds = %48, %30
%35 = phi i8 [ %50, %48 ], [ %33, %30 ]
%36 = phi i8* [ %49, %48 ], [ %18, %30 ]
%37 = icmp eq i8 %35, 35
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i8* @strchrnul(i8* %36, i8 signext 10)
br label %48
40: ; preds = %34
%41 = call i32 @isspace(i8 signext %35)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i8* @strchrnul(i8* %36, i8 signext 10)
%45 = call i32 @parse_configuration_option(i8* %36, i8* %44)
br label %48
46: ; preds = %40
%47 = getelementptr inbounds i8, i8* %36, i64 1
br label %48
48: ; preds = %38, %46, %43
%49 = phi i8* [ %39, %38 ], [ %47, %46 ], [ %44, %43 ]
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 0
br i1 %51, label %52, label %34
52: ; preds = %48
%53 = call i32 @free(i8* %18)
br label %54
54: ; preds = %11, %52, %28, %0
ret void
}