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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ line_empty(char *);
int parse_line(char *, struct config_prof *);
int /*<<< orphan*/ perror(char *);
int config_read(const char *path, struct config_prof *prof) {
  FILE *fp;
  char buf[64];
  if ((fp = fopen(path, "r")) == NULL) {
    perror("fopen");
    return -1;
  }
  while (fgets(buf, 64, fp)) {
    if (!line_empty(buf) && parse_line(buf, prof) == -1) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<config_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1196 <config_read+0x46>
lea    0xe7d(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <config_read+0xa7>
jmp    119b <config_read+0x4b>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x40,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11f0 <config_read+0xa0>
lea    -0x60(%rbp),%rdi
call   1040 <line_empty@plt>
cmp    $0x0,%eax
jne    11eb <config_read+0x9b>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <parse_line@plt>
cmp    $0xffffffff,%eax
jne    11eb <config_read+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <config_read+0xa7>
jmp    119b <config_read+0x4b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c3 <config_read+0x73>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1030 <fgets@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     11d5 <config_read+0x85>
mov    %rsp,%rbp
jmp    11a5 <config_read+0x55>
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11d5 <config_read+0x85>
mov    %rbp,%rdi
call   1040 <line_empty@plt>
test   %eax,%eax
jne    1190 <config_read+0x40>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <parse_line@plt>
cmp    $0xffffffff,%eax
jne    1190 <config_read+0x40>
jmp    11cf <config_read+0x7f>
lea    0xe38(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.config_prof = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fopen\00"
define i32 @config_read(i8* %0, %struct.config_prof* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.config_prof*
%6 = alloca i32*
%7 = alloca [64 x i8]
store i8* %0, i8** %4
store %struct.config_prof* %1, %struct.config_prof** %5
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %31
13: ; preds = %2
br label %14
14: ; preds = %29, %13
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i64 @fgets(i8* %15, i32 64, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%21 = call i32 @line_empty(i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%25 = load %struct.config_prof*, %struct.config_prof** %5
%26 = call i32 @parse_line(i8* %24, %struct.config_prof* %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -1, i32* %3
br label %31
29: ; preds = %23, %19
br label %14
30: ; preds = %14
store i32 0, i32* %3
br label %31
31: ; preds = %30, %28, %11
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.config_prof = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"fopen\00"
define i32 @config_read(i8* nocapture %0, %struct.config_prof* %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i64 @fgets(i8* %4, i32 64, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %21, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %21
12: ; preds = %7, %18
%13 = call i32 @line_empty(i8* %4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @parse_line(i8* %4, %struct.config_prof* %1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %21, label %18
18: ; preds = %15, %12
%19 = call i64 @fgets(i8* %4, i32 64, i32* %5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %12
21: ; preds = %15, %18, %7, %10
%22 = phi i32 [ -1, %10 ], [ 0, %7 ], [ -1, %15 ], [ 0, %18 ]
ret i32 %22
}