#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 config {
  int dummy;
};
typedef int /*<<< orphan*/ linebuffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ clean_up();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ parse_configline(struct config *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void parse_configfile(struct config *cfg, char *file) {
  FILE *filp;
  char linebuffer[2048];
  filp = fopen(file, "r");
  if (!filp) {
    fprintf(stderr, "Opening configuration file failed: %s\n", strerror(errno));
    clean_up();
  }
  while (fgets(linebuffer, sizeof(linebuffer) - 1, filp) != NULL)
    parse_configline(cfg, linebuffer);
}


x86 assembly (clang, -O0):
<parse_configfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cb <parse_configfile+0x6b>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x824(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x824(%rbp),%edi
mov    %rax,%rdx
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1040 <clean_up@plt>
jmp    11d0 <parse_configfile+0x70>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x7ff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1204 <parse_configfile+0xa4>
mov    -0x8(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1030 <parse_configline@plt>
jmp    11d0 <parse_configfile+0x70>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_configfile>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe87(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11b8 <parse_configfile+0x58>
mov    0x2e50(%rip),%rax
mov    (%rax),%ebx
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe5b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1040 <clean_up@plt>
mov    %rsp,%rdi
mov    $0x7ff,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f0 <parse_configfile+0x90>
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <parse_configline@plt>
mov    %rbx,%rdi
mov    $0x7ff,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11d0 <parse_configfile+0x70>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.config = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"Opening configuration file failed: %s\0A\00"
@errno = global i32 0
define void @parse_configfile(%struct.config* %0, i8* %1) {
%3 = alloca %struct.config*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [2048 x i8]
store %struct.config* %0, %struct.config** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 (...) @clean_up()
br label %17
17: ; preds = %11, %2
br label %18
18: ; preds = %23, %17
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32* @fgets(i8* %19, i32 2047, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load %struct.config*, %struct.config** %3
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%26 = call i32 @parse_configline(%struct.config* %24, i8* %25)
br label %18
27: ; preds = %18
ret void
}

LLVM IR (-O2):
%struct.config = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"Opening configuration file failed: %s\0A\00"
@errno = global i32 0
define void @parse_configfile(%struct.config* %0, i8* nocapture %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 (...) @clean_up()
br label %13
13: ; preds = %7, %2
%14 = call i32* @fgets(i8* %4, i32 2047, i32* %5)
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %13, %16
%17 = call i32 @parse_configline(%struct.config* %0, i8* %4)
%18 = call i32* @fgets(i8* %4, i32 2047, i32* %5)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %16
20: ; preds = %16, %13
ret void
}