#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 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 1;
  c = fgetc(f);
  ungetc(c, f);
  status = (c == 27) ? luaI_undump(f) : do_protectedmain();
  lua_closefile();
  return status;
}


x86 assembly (clang, -O0):
<lua_dofile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <lua_openfile@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <lua_dofile+0x30>
movl   $0x1,-0x4(%rbp)
jmp    11e0 <lua_dofile+0x80>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <ungetc@plt>
cmpl   $0x1b,-0x18(%rbp)
jne    11c3 <lua_dofile+0x63>
mov    -0x20(%rbp),%rdi
call   1060 <luaI_undump@plt>
mov    %eax,-0x24(%rbp)
jmp    11cd <lua_dofile+0x6d>
mov    $0x0,%al
call   1070 <do_protectedmain@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1080 <lua_closefile@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lua_dofile>:
push   %rbp
push   %rbx
push   %rax
call   1030 <lua_openfile@plt>
test   %rax,%rax
je     1193 <lua_dofile+0x33>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <ungetc@plt>
cmp    $0x1b,%ebp
jne    119a <lua_dofile+0x3a>
mov    %rbx,%rdi
call   1060 <luaI_undump@plt>
jmp    11a1 <lua_dofile+0x41>
mov    $0x1,%ebx
jmp    11aa <lua_dofile+0x4a>
xor    %eax,%eax
call   1070 <do_protectedmain@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <lua_closefile@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
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 1, i32* %2
br label %29
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 %23
20: ; preds = %12
%21 = load i32*, i32** %6
%22 = call i32 @luaI_undump(i32* %21)
br label %25
23: ; preds = %12
%24 = call i32 (...) @do_protectedmain()
br label %25
25: ; preds = %23, %20
%26 = phi i32 [ %22, %20 ], [ %24, %23 ]
store i32 %26, i32* %4
%27 = call i32 (...) @lua_closefile()
%28 = load i32, i32* %4
store i32 %28, i32* %2
br label %29
29: ; preds = %25, %11
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @lua_dofile(i8* %0) {
%2 = tail call i32* @lua_openfile(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = tail call i32 @fgetc(i32* %2)
%6 = tail call i32 @ungetc(i32 %5, i32* %2)
%7 = icmp eq i32 %5, 27
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @luaI_undump(i32* %2)
br label %12
10: ; preds = %4
%11 = tail call i32 (...) @do_protectedmain()
br label %12
12: ; preds = %10, %8
%13 = phi i32 [ %9, %8 ], [ %11, %10 ]
%14 = tail call i32 (...) @lua_closefile()
br label %15
15: ; preds = %1, %12
%16 = phi i32 [ %13, %12 ], [ 1, %1 ]
ret i32 %16
}