#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 *, char *);
int /*<<< orphan*/ parse_config_line(char *);
int load_config(char *fname) {
  FILE *fp = fopen(fname, "r");
  char buf[4096];
  if (!fp)
    return (-1);
  while (fgets(buf, 4095, fp))
    parse_config_line(buf);
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<load_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117a <load_config+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <load_config+0x7f>
jmp    117f <load_config+0x3f>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xfff,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11af <load_config+0x6f>
lea    -0x1020(%rbp),%rdi
call   1050 <parse_config_line@plt>
jmp    117f <load_config+0x3f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_config>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a9 <load_config+0x69>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0xfff,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     119d <load_config+0x5d>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <parse_config_line@plt>
mov    %rbx,%rdi
mov    $0xfff,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1180 <load_config+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11ae <load_config+0x6e>
mov    $0xffffffff,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @load_config(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [4096 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 -1, i32* %2
br label %23
11: ; preds = %1
br label %12
12: ; preds = %17, %11
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i64 @fgets(i8* %13, i32 4095, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%19 = call i32 @parse_config_line(i8* %18)
br label %12
20: ; preds = %12
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
store i32 0, i32* %2
br label %23
23: ; preds = %20, %10
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @load_config(i8* nocapture %0) {
%2 = alloca [4096 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = icmp eq i32* %3, null
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %4, i32 4095, i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6, %9
%10 = call i32 @parse_config_line(i8* %4)
%11 = call i64 @fgets(i8* %4, i32 4095, i32* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %9
13: ; preds = %9, %6
%14 = call i32 @fclose(i32* %3)
br label %15
15: ; preds = %1, %13
%16 = phi i32 [ 0, %13 ], [ -1, %1 ]
ret i32 %16
}