#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 */
scalar_t__ calloc(size_t, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
size_t lengthoffile(int /*<<< orphan*/ *);
char *default_lua_loadscriptfile(const char *name, int *len) {
  size_t locallen, readcount;
  char *sc;
  FILE *f;
  f = fopen(name, "rb");
  if (!f)
    return NULL;
  locallen = lengthoffile(f);
  sc = (char *)calloc(locallen + 1, 1);
  readcount = fread(sc, 1, locallen, f);
  fclose(f);
  sc[locallen] = '\0';
  if (len)
    *len = locallen;
  return sc;
}


x86 assembly (clang, -O0):
<default_lua_loadscriptfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    118c <default_lua_loadscriptfile+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    11fd <default_lua_loadscriptfile+0xad>
mov    -0x38(%rbp),%rdi
call   1060 <lengthoffile@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x18(%rbp)
je     11f5 <default_lua_loadscriptfile+0xa5>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<default_lua_loadscriptfile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b5 <default_lua_loadscriptfile+0x65>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <lengthoffile@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
movb   $0x0,(%r12,%r15,1)
test   %r14,%r14
je     11b8 <default_lua_loadscriptfile+0x68>
mov    %r15d,(%r14)
jmp    11b8 <default_lua_loadscriptfile+0x68>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i8* @default_lua_loadscriptfile(i8* nocapture %0, i32* writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = tail call i64 @lengthoffile(i32* %3)
%7 = add i64 %6, 1
%8 = tail call i64 @calloc(i64 %7, i32 1)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i64 @fread(i8* %9, i32 1, i64 %6, i32* %3)
%11 = tail call i32 @fclose(i32* %3)
%12 = getelementptr inbounds i8, i8* %9, i64 %6
store i8 0, i8* %12
%13 = icmp eq i32* %1, null
br i1 %13, label %16, label %14
14: ; preds = %5
%15 = trunc i64 %6 to i32
store i32 %15, i32* %1
br label %16
16: ; preds = %5, %14, %2
%17 = phi i8* [ null, %2 ], [ %9, %14 ], [ %9, %5 ]
ret i8* %17
}