#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ parseConfigFile(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void loadConfigfile() {
  int len;
  FILE *file;
  char *filename;
  filename = "~/.arnold";
  fprintf(stderr, "Opening %s\n", filename);
  file = fopen(filename, "r");
  if (file == NULL) {
    perror("Could not open ~/.arnold");
    filename = "/etc/arnold";
    fprintf(stderr, "Opening %s\n", filename);
    file = fopen(filename, "r");
    if (file == NULL) {
      perror("Could not open /etc/arnold");
      return;
    }
  }
  fprintf(stderr, "Parsing %s\n", filename);
  if (parseConfigFile(file) < 0) {
    perror("Could not parse configfile");
    return;
  }
}


x86 assembly (clang, -O0):
<loadConfigfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe99(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f0 <loadConfigfile+0xb0>
lea    0xe7c(%rip),%rdi
call   1060 <perror@plt>
lea    0xe98(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe4a(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11eb <loadConfigfile+0xab>
lea    0xe46(%rip),%rdi
call   1060 <perror@plt>
jmp    1228 <loadConfigfile+0xe8>
jmp    11f0 <loadConfigfile+0xb0>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe3e(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <parseConfigFile@plt>
cmp    $0x0,%rax
jge    1228 <loadConfigfile+0xe8>
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadConfigfile>:
push   %r15
push   %r14
push   %rbx
mov    0x2e94(%rip),%r15
mov    (%r15),%edi
lea    0xeaa(%rip),%rsi
lea    0xec0(%rip),%r14
mov    %r14,%rdx
call   1030 <fprintf@plt>
lea    0xea0(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a1 <loadConfigfile+0x61>
mov    (%r15),%edi
lea    0xebc(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <parseConfigFile@plt>
test   %rax,%rax
js     11e6 <loadConfigfile+0xa6>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe66(%rip),%rdi
call   1060 <perror@plt>
mov    (%r15),%edi
lea    0xe49(%rip),%rsi
lea    0xe78(%rip),%r14
mov    %r14,%rdx
call   1030 <fprintf@plt>
lea    0xe3f(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117c <loadConfigfile+0x3c>
lea    0xe43(%rip),%rdi
jmp    11ed <loadConfigfile+0xad>
lea    0xe61(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <perror@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"~/.arnold\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"Opening %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"Could not open ~/.arnold\00"
@.str.4 = [12 x i8] c"/etc/arnold\00"
@.str.5 = [27 x i8] c"Could not open /etc/arnold\00"
@.str.6 = [12 x i8] c"Parsing %s\0A\00"
@.str.7 = [27 x i8] c"Could not parse configfile\00"
define void @loadConfigfile() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = load i32, i32* @stderr
%5 = load i8*, i8** %3
%6 = call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %23
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8** %3
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %3
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %2
%18 = load i32*, i32** %2
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %32
22: ; preds = %11
br label %23
23: ; preds = %22, %0
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %3
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %25)
%27 = load i32*, i32** %2
%28 = call i64 @parseConfigFile(i32* %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %20, %30, %23
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"~/.arnold\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"Opening %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"Could not open ~/.arnold\00"
@.str.4 = [12 x i8] c"/etc/arnold\00"
@.str.5 = [27 x i8] c"Could not open /etc/arnold\00"
@.str.6 = [12 x i8] c"Parsing %s\0A\00"
@.str.7 = [27 x i8] c"Could not parse configfile\00"
define void @loadConfigfile() {
%1 = load i32, i32* @stderr
%2 = tail call i32 @fprintf(i32 %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %18, label %11
11: ; preds = %5, %0
%12 = phi i32* [ %9, %5 ], [ %3, %0 ]
%13 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %5 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %0 ]
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %13)
%16 = tail call i64 @parseConfigFile(i32* %12)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11, %5
%19 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), %5 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), %11 ]
%20 = tail call i32 @perror(i8* %19)
br label %21
21: ; preds = %18, %11
ret void
}