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

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ load_config_line(struct bbootimg_info *, char *);
int load_config(struct bbootimg_info *i, const char *src, int *error_line) {
  FILE *f;
  int res = 0;
  int line_num = 0;
  char line[1024];
  f = fopen(src, "r");
  if (!f)
    return -errno;
  while (fgets(line, sizeof(line), f)) {
    if (load_config_line(i, line) < 0) {
      res = -1;
      if (error_line)
        *error_line = line_num;
      goto exit;
    }
    ++line_num;
  }
exit:
  fclose(f);
  return res;
}


x86 assembly (clang, -O0):
<load_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1197 <load_config+0x57>
xor    %eax,%eax
mov    0x2e53(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1217 <load_config+0xd7>
jmp    119c <load_config+0x5c>
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1203 <load_config+0xc3>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1050 <load_config_line@plt>
cmp    $0x0,%rax
jge    11f5 <load_config+0xb5>
movl   $0xffffffff,-0x2c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f0 <load_config+0xb0>
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1208 <load_config+0xc8>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    119c <load_config+0x5c>
jmp    1208 <load_config+0xc8>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_config>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%r14
mov    %rsi,%rax
mov    %rdi,%r15
lea    0xea1(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bc <load_config+0x7c>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11b8 <load_config+0x78>
xor    %ebx,%ebx
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbp,%rsi
call   1050 <load_config_line@plt>
test   %rax,%rax
js     11c9 <load_config+0x89>
add    $0x1,%ebx
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1190 <load_config+0x50>
xor    %ebp,%ebp
jmp    11d6 <load_config+0x96>
mov    0x2e1d(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    11de <load_config+0x9e>
mov    $0xffffffff,%ebp
test   %r14,%r14
je     11d6 <load_config+0x96>
mov    %ebx,(%r14)
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bbootimg_info = type { i32 }
@.str = [2 x i8] c"r\00"
@errno = global i32 0
define i32 @load_config(%struct.bbootimg_info* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.bbootimg_info*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
store %struct.bbootimg_info* %0, %struct.bbootimg_info** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 0, i32* %9
store i32 0, i32* %10
%12 = load i8*, i8** %6
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %3
%17 = load i32, i32* @errno
%18 = sub nsw i32 0, %17
store i32 %18, i32* %4
br label %45
19: ; preds = %3
br label %20
20: ; preds = %37, %19
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%22 = load i32*, i32** %8
%23 = call i64 @fgets(i8* %21, i32 1024, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %40
25: ; preds = %20
%26 = load %struct.bbootimg_info*, %struct.bbootimg_info** %5
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%28 = call i64 @load_config_line(%struct.bbootimg_info* %26, i8* %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %25
store i32 -1, i32* %9
%31 = load i32*, i32** %7
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %10
%35 = load i32*, i32** %7
store i32 %34, i32* %35
br label %36
36: ; preds = %33, %30
br label %41
37: ; preds = %25
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %20
40: ; preds = %20
br label %41
41: ; preds = %40, %36
%42 = load i32*, i32** %8
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %9
store i32 %44, i32* %4
br label %45
45: ; preds = %41, %16
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
%struct.bbootimg_info = type { i32 }
@.str = [2 x i8] c"r\00"
@errno = global i32 0
define i32 @load_config(%struct.bbootimg_info* %0, i8* nocapture %1, i32* writeonly %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %25, label %14
11: ; preds = %3
%12 = load i32, i32* @errno
%13 = sub nsw i32 0, %12
br label %28
14: ; preds = %8, %21
%15 = phi i32 [ %22, %21 ], [ 0, %8 ]
%16 = call i64 @load_config_line(%struct.bbootimg_info* %0, i8* %5)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = icmp eq i32* %2, null
br i1 %19, label %25, label %20
20: ; preds = %18
store i32 %15, i32* %2
br label %25
21: ; preds = %14
%22 = add nuw nsw i32 %15, 1
%23 = call i64 @fgets(i8* %5, i32 1024, i32* %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %14
25: ; preds = %21, %8, %18, %20
%26 = phi i32 [ -1, %20 ], [ -1, %18 ], [ 0, %8 ], [ 0, %21 ]
%27 = call i32 @fclose(i32* %6)
br label %28
28: ; preds = %25, %11
%29 = phi i32 [ %26, %25 ], [ %13, %11 ]
ret i32 %29
}