#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 do_protectedmain();
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/ *);
int luaI_undump(int /*<<< orphan*/ *);
int /*<<< orphan*/ lua_closefile();
int /*<<< orphan*/ *lua_openfile(char *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int lua_dofile(char *filename) {
  int status;
  int c;
  FILE *f = lua_openfile(filename);
  if (f == 0)
    return 2;
  c = fgetc(f);
  ungetc(c, f);
  if (c == 27) {
    f = freopen(filename, "rb", f);
    status = luaI_undump(f);
  } else {
    if (c == '#')
      while ((c = fgetc(f)) != '\n')
        ;
    status = do_protectedmain();
  }
  lua_closefile();
  return status;
}


x86 assembly (clang, -O0):
<lua_dofile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <lua_openfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a0 <lua_dofile+0x30>
movl   $0x2,-0x4(%rbp)
jmp    1230 <lua_dofile+0xc0>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <ungetc@plt>
cmpl   $0x1b,-0x18(%rbp)
jne    11eb <lua_dofile+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe2f(%rip),%rsi
call   1040 <freopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <luaI_undump@plt>
mov    %eax,-0x14(%rbp)
jmp    1223 <lua_dofile+0xb3>
cmpl   $0x23,-0x18(%rbp)
jne    1219 <lua_dofile+0xa9>
jmp    11fa <lua_dofile+0x8a>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xa,%eax
je     1214 <lua_dofile+0xa4>
jmp    11fa <lua_dofile+0x8a>
jmp    1219 <lua_dofile+0xa9>
mov    $0x0,%al
call   1080 <do_protectedmain@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1090 <lua_closefile@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lua_dofile>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <lua_openfile@plt>
test   %rax,%rax
je     11c6 <lua_dofile+0x56>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <ungetc@plt>
cmp    $0x1b,%ebp
je     11cd <lua_dofile+0x5d>
cmp    $0x23,%ebp
jne    11bd <lua_dofile+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%eax
jne    11b0 <lua_dofile+0x40>
xor    %eax,%eax
call   1080 <do_protectedmain@plt>
jmp    11e7 <lua_dofile+0x77>
mov    $0x2,%ebx
jmp    11f0 <lua_dofile+0x80>
lea    0xe2c(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <freopen@plt>
mov    %rax,%rdi
call   1070 <luaI_undump@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <lua_closefile@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @lua_dofile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @lua_openfile(i8* %7)
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 2, i32* %2
br label %41
12: ; preds = %1
%13 = load i32*, i32** %6
%14 = call i32 @fgetc(i32* %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = load i32*, i32** %6
%17 = call i32 @ungetc(i32 %15, i32* %16)
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 27
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = load i8*, i8** %3
%22 = load i32*, i32** %6
%23 = call i32* @freopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %22)
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = call i32 @luaI_undump(i32* %24)
store i32 %25, i32* %4
br label %38
26: ; preds = %12
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 35
br i1 %28, label %29, label %36
29: ; preds = %26
br label %30
30: ; preds = %34, %29
%31 = load i32*, i32** %6
%32 = call i32 @fgetc(i32* %31)
store i32 %32, i32* %5
%33 = icmp ne i32 %32, 10
br i1 %33, label %34, label %35
34: ; preds = %30
br label %30
35: ; preds = %30
br label %36
36: ; preds = %35, %26
%37 = call i32 (...) @do_protectedmain()
store i32 %37, i32* %4
br label %38
38: ; preds = %36, %20
%39 = call i32 (...) @lua_closefile()
%40 = load i32, i32* %4
store i32 %40, i32* %2
br label %41
41: ; preds = %38, %11
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @lua_dofile(i8* %0) {
%2 = tail call i32* @lua_openfile(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = tail call i32 @fgetc(i32* %2)
%6 = tail call i32 @ungetc(i32 %5, i32* %2)
switch i32 %5, label %13 [
i32 27, label %7
i32 35, label %10
]
7: ; preds = %4
%8 = tail call i32* @freopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = tail call i32 @luaI_undump(i32* %8)
br label %15
10: ; preds = %4, %10
%11 = tail call i32 @fgetc(i32* %2)
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %10
13: ; preds = %10, %4
%14 = tail call i32 (...) @do_protectedmain()
br label %15
15: ; preds = %13, %7
%16 = phi i32 [ %9, %7 ], [ %14, %13 ]
%17 = tail call i32 (...) @lua_closefile()
br label %18
18: ; preds = %1, %15
%19 = phi i32 [ %16, %15 ], [ 2, %1 ]
ret i32 %19
}