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

/* Variables and functions */
int STDIN_FILENO;
int /*<<< orphan*/ arrange_funeral();
int /*<<< orphan*/ close_aux(int);
int /*<<< orphan*/ error(char *, ...);
scalar_t__ gc_alloc(int, char *);
int /*<<< orphan*/ gc_free(char *);
int open_read_error_aux(char *);
scalar_t__ parse_file(int, char **, int *);
void do_file(char *fname, int do_error) {
  int file = STDIN_FILENO;
  int len = 256;
  char *buff = (char *)gc_alloc(sizeof(char) * len, "do_file");
  if (fname) {
    file = open_read_error_aux(fname);
  }
  if (file < 0) {
    if (do_error) {
      if (fname) {
        error("esh: could not load script file \"%s\".", fname);
      } else {
        error("esh: could not load script file from stdin.");
      }
    }
    gc_free(buff);
    return;
  }
  while (parse_file(file, &buff, &len)) {
    arrange_funeral();
  }
  close_aux(file);
  gc_free(buff);
}


x86 assembly (clang, -O0):
<do_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movl   $0x100,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
lea    0xe5d(%rip),%rsi
call   1060 <gc_alloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c3 <do_file+0x53>
mov    -0x8(%rbp),%rdi
call   1050 <open_read_error_aux@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    121a <do_file+0xaa>
cmpl   $0x0,-0xc(%rbp)
je     120c <do_file+0x9c>
cmpq   $0x0,-0x8(%rbp)
je     11f9 <do_file+0x89>
mov    -0x8(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1070 <error@plt>
jmp    1207 <do_file+0x97>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1070 <error@plt>
jmp    120c <do_file+0x9c>
mov    -0x20(%rbp),%rdi
call   1090 <gc_free@plt>
jmp    1256 <do_file+0xe6>
jmp    121f <do_file+0xaf>
mov    -0x10(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1080 <parse_file@plt>
cmp    $0x0,%rax
je     1245 <do_file+0xd5>
mov    $0x0,%al
call   1040 <arrange_funeral@plt>
jmp    121f <do_file+0xaf>
mov    -0x10(%rbp),%edi
call   1030 <close_aux@plt>
mov    -0x20(%rbp),%rdi
call   1090 <gc_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r15
mov    0x2e5a(%rip),%rax
mov    (%rax),%ebx
movl   $0x100,0xc(%rsp)
lea    0xe69(%rip),%rsi
mov    $0x100,%edi
call   1060 <gc_alloc@plt>
mov    %rax,%r14
mov    %rax,0x10(%rsp)
test   %r15,%r15
je     11b8 <do_file+0x48>
mov    %r15,%rdi
call   1050 <open_read_error_aux@plt>
mov    %eax,%ebx
test   %ebx,%ebx
js     1215 <do_file+0xa5>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1080 <parse_file@plt>
test   %rax,%rax
je     11f9 <do_file+0x89>
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%rbp
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <arrange_funeral@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1080 <parse_file@plt>
test   %rax,%rax
jne    11e0 <do_file+0x70>
mov    %ebx,%edi
call   1030 <close_aux@plt>
mov    0x10(%rsp),%rdi
call   1090 <gc_free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
je     123f <do_file+0xcf>
test   %r15,%r15
je     1231 <do_file+0xc1>
lea    0xde3(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <error@plt>
jmp    123f <do_file+0xcf>
lea    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1070 <error@plt>
mov    %r14,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <gc_free@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [8 x i8] c"do_file\00"
@.str.1 = [38 x i8] c"esh: could not load script file \22%s\22.\00"
@.str.2 = [44 x i8] c"esh: could not load script file from stdin.\00"
define void @do_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* @STDIN_FILENO
store i32 %8, i32* %5
store i32 256, i32* %6
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = mul i64 1, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @gc_alloc(i32 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
%15 = load i8*, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = call i32 @open_read_error_aux(i8* %18)
store i32 %19, i32* %5
br label %20
20: ; preds = %17, %2
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %38
23: ; preds = %20
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i8*, i8** %3
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %34
32: ; preds = %26
%33 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
br label %35
35: ; preds = %34, %23
%36 = load i8*, i8** %7
%37 = call i32 @gc_free(i8* %36)
br label %50
38: ; preds = %20
br label %39
39: ; preds = %43, %38
%40 = load i32, i32* %5
%41 = call i64 @parse_file(i32 %40, i8** %7, i32* %6)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 (...) @arrange_funeral()
br label %39
45: ; preds = %39
%46 = load i32, i32* %5
%47 = call i32 @close_aux(i32 %46)
%48 = load i8*, i8** %7
%49 = call i32 @gc_free(i8* %48)
br label %50
50: ; preds = %45, %35
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [8 x i8] c"do_file\00"
@.str.1 = [38 x i8] c"esh: could not load script file \22%s\22.\00"
@.str.2 = [44 x i8] c"esh: could not load script file from stdin.\00"
define void @do_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = load i32, i32* @STDIN_FILENO
%6 = bitcast i32* %3 to i8*
store i32 256, i32* %3
%7 = bitcast i8** %4 to i8*
%8 = tail call i64 @gc_alloc(i32 256, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = icmp eq i8* %0, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @open_read_error_aux(i8* %0)
br label %13
13: ; preds = %11, %2
%14 = phi i32 [ %12, %11 ], [ %5, %2 ]
%15 = icmp slt i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i64 @parse_file(i32 %14, i8** %4, i32* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %32, label %28
19: ; preds = %13
%20 = icmp eq i32 %1, 0
br i1 %20, label %26, label %21
21: ; preds = %19
br i1 %10, label %24, label %22
22: ; preds = %21
%23 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %26
24: ; preds = %21
%25 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %22, %24, %19
%27 = tail call i32 @gc_free(i8* %9)
br label %36
28: ; preds = %16, %28
%29 = call i32 (...) @arrange_funeral()
%30 = call i64 @parse_file(i32 %14, i8** %4, i32* %3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %28
32: ; preds = %28, %16
%33 = call i32 @close_aux(i32 %14)
%34 = load i8*, i8** %4
%35 = call i32 @gc_free(i8* %34)
br label %36
36: ; preds = %32, %26
ret void
}