#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ handle_config_line(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char const *);
void read_config(const char *fn) {
  FILE *fp;
  int line = 1;
  char buf[512];
  fp = fopen(fn, "r");
  if (!fp) {
    perror(fn);
    exit(1);
  }
  while (!feof(fp)) {
    if (fgets(buf, sizeof(buf), fp))
      handle_config_line(buf, fn, line++);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<read_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b8 <read_config+0x48>
mov    -0x8(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11bd <read_config+0x4d>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11db <read_config+0x6b>
jmp    121a <read_config+0xaa>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1215 <read_config+0xa5>
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
call   1030 <handle_config_line@plt>
jmp    11bd <read_config+0x4d>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_config>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
lea    0xe77(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1205 <read_config+0x95>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11ba <read_config+0x4a>
mov    %r12,%rdi
call   1040 <fclose@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebx
mov    %rsp,%r15
jmp    11dc <read_config+0x6c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11a2 <read_config+0x32>
mov    %r15,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d0 <read_config+0x60>
lea    0x1(%rbx),%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <handle_config_line@plt>
mov    %ebp,%ebx
jmp    11d0 <read_config+0x60>
mov    %r14,%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define void @read_config(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [512 x i8]
store i8* %0, i8** %2
store i32 1, i32* %4
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @perror(i8* %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
br label %15
15: ; preds = %31, %14
%16 = load i32*, i32** %3
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %32
20: ; preds = %15
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%22 = load i32*, i32** %3
%23 = call i64 @fgets(i8* %21, i32 512, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%27 = load i8*, i8** %2
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
%30 = call i32 @handle_config_line(i8* %26, i8* %27, i32 %28)
br label %31
31: ; preds = %25, %20
br label %15
32: ; preds = %15
%33 = load i32*, i32** %3
%34 = call i32 @fclose(i32* %33)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @read_config(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %23
9: ; preds = %1
%10 = tail call i32 @perror(i8* %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6, %19
%13 = phi i32 [ %20, %19 ], [ 1, %6 ]
%14 = call i64 @fgets(i8* %3, i32 512, i32* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = add nsw i32 %13, 1
%18 = call i32 @handle_config_line(i8* %3, i8* %0, i32 %13)
br label %19
19: ; preds = %16, %12
%20 = phi i32 [ %17, %16 ], [ %13, %12 ]
%21 = call i32 @feof(i32* %4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %12, label %23
23: ; preds = %19, %6
%24 = call i32 @fclose(i32* %4)
ret void
}