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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int, int);
int parse_line(struct STATE_DATA *, char *);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int load_data(struct STATE_DATA *sd, const char *fname) {
  FILE *in;
  int lno = 0;
  int r = 0;
  char buf[1024];
  in = fopen(fname, "rt");
  if (!in) {
    perror(fname);
    return -1;
  }
  while (fgets(buf, sizeof(buf), in)) {
    int l;
    ++lno;
    l = strlen(buf);
    if (l && buf[l - 1] == '\n')
      buf[--l] = 0;
    r = parse_line(sd, buf);
    if (r) {
      fprintf(stderr, "%s: error parsing line %i: %i\n", fname, lno, r);
      break;
    }
  }
  fclose(in);
  return r;
}


x86 assembly (clang, -O0):
<load_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c5 <load_data+0x55>
mov    -0x18(%rbp),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129c <load_data+0x12c>
jmp    11ca <load_data+0x5a>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     128d <load_data+0x11d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
je     1246 <load_data+0xd6>
mov    -0x434(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x430(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1246 <load_data+0xd6>
mov    -0x434(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x434(%rbp)
cltq
movb   $0x0,-0x430(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1070 <parse_line@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1288 <load_data+0x118>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xd85(%rip),%rsi
call   1060 <fprintf@plt>
jmp    128d <load_data+0x11d>
jmp    11ca <load_data+0x5a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0xe72(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1245 <load_data+0xd5>
mov    %rax,%r12
mov    %rbx,0x8(%rsp)
xor    %r14d,%r14d
lea    0x10(%rsp),%rbp
xor    %ebx,%ebx
jmp    11d2 <load_data+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <parse_line@plt>
add    $0x1,%ebx
test   %eax,%eax
jne    1203 <load_data+0x93>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1228 <load_data+0xb8>
mov    %rbp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11c0 <load_data+0x50>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    11c0 <load_data+0x50>
movb   $0x0,0xf(%rsp,%rax,1)
jmp    11c0 <load_data+0x50>
mov    %eax,%r15d
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    0x8(%rsp),%rdx
mov    %ebx,%ecx
mov    %r15d,%r8d
call   1060 <fprintf@plt>
mov    %r15d,%r14d
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1230 <load_data+0xc0>

LLVM IR (-O0):
%struct.STATE_DATA = type { i32 }
@.str = [3 x i8] c"rt\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"%s: error parsing line %i: %i\0A\00"
define i32 @load_data(%struct.STATE_DATA* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.STATE_DATA*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca i32
store %struct.STATE_DATA* %0, %struct.STATE_DATA** %4
store i8* %1, i8** %5
store i32 0, i32* %7
store i32 0, i32* %8
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i32 @perror(i8* %16)
store i32 -1, i32* %3
br label %61
18: ; preds = %2
br label %19
19: ; preds = %56, %18
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%21 = load i32*, i32** %6
%22 = call i64 @fgets(i8* %20, i32 1024, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %57
24: ; preds = %19
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %44
31: ; preds = %24
%32 = load i32, i32* %10
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %44
39: ; preds = %31
%40 = load i32, i32* %10
%41 = add nsw i32 %40, -1
store i32 %41, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %42
store i8 0, i8* %43
br label %44
44: ; preds = %39, %31, %24
%45 = load %struct.STATE_DATA*, %struct.STATE_DATA** %4
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%47 = call i32 @parse_line(%struct.STATE_DATA* %45, i8* %46)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %5
%53 = load i32, i32* %7
%54 = load i32, i32* %8
%55 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %52, i32 %53, i32 %54)
br label %57
56: ; preds = %44
br label %19
57: ; preds = %50, %19
%58 = load i32*, i32** %6
%59 = call i32 @fclose(i32* %58)
%60 = load i32, i32* %8
store i32 %60, i32* %3
br label %61
61: ; preds = %57, %15
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
%struct.STATE_DATA = type { i32 }
@.str = [3 x i8] c"rt\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"%s: error parsing line %i: %i\0A\00"
define i32 @load_data(%struct.STATE_DATA* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* %1)
br label %33
9: ; preds = %2, %24
%10 = phi i32 [ %14, %24 ], [ 0, %2 ]
%11 = call i64 @fgets(i8* %4, i32 1024, i32* %5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %30, label %13
13: ; preds = %9
%14 = add nuw nsw i32 %10, 1
%15 = call i32 @strlen(i8* %4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %13
%18 = add nsw i32 %15, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %17
store i8 0, i8* %20
br label %24
24: ; preds = %23, %17, %13
%25 = call i32 @parse_line(%struct.STATE_DATA* %0, i8* %4)
%26 = icmp eq i32 %25, 0
br i1 %26, label %9, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %14, i32 %25)
br label %30
30: ; preds = %9, %27
%31 = phi i32 [ %25, %27 ], [ 0, %9 ]
%32 = call i32 @fclose(i32* %5)
br label %33
33: ; preds = %30, %7
%34 = phi i32 [ %31, %30 ], [ -1, %7 ]
ret i32 %34
}