#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int interp_line(char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int load(const char *str) {
  FILE *f;
  char s[1024];
  char *p;
  int err;
  f = fopen(str, "r");
  if (f == NULL) {
    fprintf(stderr, "cannot open file %s\n", str);
    return 1;
  }
  while ((p = fgets(s, 1024, f))) {
    char *eol;
    eol = strchr(p, '\n');
    if (eol == NULL) {
      continue;
    }
    *eol = 0;
    if (*p == 0) {
      continue;
    }
    err = interp_line(p);
    if (err) {
      fprintf(stderr, "error indicated\n");
      break;
    }
  }
  fclose(f);
  return err;
}


x86 assembly (clang, -O0):
<load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b5 <load+0x55>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127f <load+0x11f>
jmp    11ba <load+0x5a>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
je     126d <load+0x10d>
mov    -0x428(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    120b <load+0xab>
jmp    11ba <load+0x5a>
mov    -0x438(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    122d <load+0xcd>
jmp    11ba <load+0x5a>
mov    -0x428(%rbp),%rdi
call   1070 <interp_line@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
je     1268 <load+0x108>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    126d <load+0x10d>
jmp    11ba <load+0x5a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x42c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbp
lea    0xe8b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     120a <load+0xaa>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     122f <load+0xcf>
mov    %rax,%rbp
mov    %rsp,%r14
jmp    11c8 <load+0x68>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rax,%rbp
test   %rax,%rax
je     122b <load+0xcb>
mov    %rbp,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b0 <load+0x50>
movb   $0x0,(%rax)
cmpb   $0x0,0x0(%rbp)
je     11b0 <load+0x50>
mov    %rbp,%rdi
call   1070 <interp_line@plt>
test   %eax,%eax
je     11b0 <load+0x50>
mov    %eax,%ebp
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    122f <load+0xcf>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
jmp    1237 <load+0xd7>
xor    %ebp,%ebp
jmp    122f <load+0xcf>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"cannot open file %s\0A\00"
@.str.2 = [17 x i8] c"error indicated\0A\00"
define i32 @load(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 1, i32* %2
br label %49
17: ; preds = %1
br label %18
18: ; preds = %44, %35, %28, %17
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i8* @fgets(i8* %19, i32 1024, i32* %20)
store i8* %21, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %45
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = call i8* @strchr(i8* %24, i8 signext 10)
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %23
br label %18
29: ; preds = %23
%30 = load i8*, i8** %8
store i8 0, i8* %30
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
br label %18
36: ; preds = %29
%37 = load i8*, i8** %6
%38 = call i32 @interp_line(i8* %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %45
44: ; preds = %36
br label %18
45: ; preds = %41, %18
%46 = load i32*, i32** %4
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* %7
store i32 %48, i32* %2
br label %49
49: ; preds = %45, %13
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"cannot open file %s\0A\00"
@.str.2 = [17 x i8] c"error indicated\0A\00"
define i32 @load(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 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 i8* @fgets(i8* %3, i32 1024, i32* %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %28, label %12
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %31
12: ; preds = %6, %25
%13 = phi i8* [ %26, %25 ], [ %7, %6 ]
%14 = call i8* @strchr(i8* %13, i8 signext 10)
%15 = icmp eq i8* %14, null
br i1 %15, label %25, label %16
16: ; preds = %12
store i8 0, i8* %14
%17 = load i8, i8* %13
%18 = icmp eq i8 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = call i32 @interp_line(i8* %13)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %28
25: ; preds = %19, %16, %12
%26 = call i8* @fgets(i8* %3, i32 1024, i32* %4)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %12
28: ; preds = %25, %6, %22
%29 = phi i32 [ %20, %22 ], [ undef, %6 ], [ 0, %25 ]
%30 = call i32 @fclose(i32* %4)
br label %31
31: ; preds = %28, %9
%32 = phi i32 [ 1, %9 ], [ %29, %28 ]
ret i32 %32
}