#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 char wchar_t;
struct Context {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
char *calloc(scalar_t__, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ lisp_silent_execute(char *);
char *malloc(long);
char *pop();
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ swprintf(char *, long, char *, char *);
scalar_t__ wcslen(char *);
void builtin_load(struct Context *ctx, unsigned int stack_track) {
  if (stack_track != 1)
    return;
  wchar_t *wide_filename = pop();
  char *filename = calloc(wcslen(wide_filename) + 1, sizeof(char));
  sprintf(filename, "%ls", wide_filename);
  FILE *input_file = fopen(filename, "rb");
  free(filename);
  if (input_file == NULL)
    return;
  fseek(input_file, 0, SEEK_END);
  long input_file_size = ftell(input_file);
  rewind(input_file);
  char *file_contents = malloc((input_file_size + 1) * (sizeof(char)));
  fread(file_contents, sizeof(char), input_file_size, input_file);
  file_contents[input_file_size] = 0;
  fclose(input_file);
  wchar_t *wide_file = malloc((input_file_size + 1) * (sizeof(wchar_t)));
  swprintf(wide_file, input_file_size + 1, L"%s", file_contents);
  free(file_contents);
  lisp_silent_execute(wide_file);
  free(wide_file);
}


x86 assembly (clang, -O0):
<builtin_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     11fe <builtin_load+0x1e>
jmp    131e <builtin_load+0x13e>
mov    $0x0,%al
call   1090 <pop@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <wcslen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdca(%rip),%rsi
call   1100 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdbe(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1268 <builtin_load+0x88>
jmp    131e <builtin_load+0x13e>
mov    -0x28(%rbp),%rdi
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   10d0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   10d0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
mov    -0x38(%rbp),%rcx
lea    0xd0a(%rip),%rdx
call   10c0 <swprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <lisp_silent_execute@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_load>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x1,%esi
jne    12e2 <builtin_load+0x102>
xor    %eax,%eax
call   1090 <pop@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <wcslen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
lea    0xde4(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1100 <sprintf@plt>
lea    0xdd6(%rip),%rsi
mov    %rbx,%rdi
call   10f0 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     12e2 <builtin_load+0x102>
mov    0x2d97(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %r14,%rdi
call   10b0 <ftell@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1070 <rewind@plt>
lea    0x1(%r12),%r15
mov    %r15,%rdi
call   10d0 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r14,%rcx
call   1050 <fread@plt>
movb   $0x0,0x0(%r13,%r12,1)
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   10d0 <malloc@plt>
mov    %rax,%rbx
lea    0xd55(%rip),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r13,%rcx
call   10c0 <swprintf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <lisp_silent_execute@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.Context = type { i32 }
@.str = [4 x i8] c"%ls\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.2 = [3 x i32] [i32 37, i32 115, i32 0]
define void @builtin_load(%struct.Context* %0, i32 %1) {
%3 = alloca %struct.Context*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
store %struct.Context* %0, %struct.Context** %3
store i32 %1, i32* %4
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
br label %66
14: ; preds = %2
%15 = call i8* (...) @pop()
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = call i64 @wcslen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = call i8* @calloc(i64 %18, i32 1)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = load i8*, i8** %5
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %6
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %7
%25 = load i8*, i8** %6
%26 = call i32 @free(i8* %25)
%27 = load i32*, i32** %7
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %14
br label %66
30: ; preds = %14
%31 = load i32*, i32** %7
%32 = load i32, i32* @SEEK_END
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
%34 = load i32*, i32** %7
%35 = call i64 @ftell(i32* %34)
store i64 %35, i64* %8
%36 = load i32*, i32** %7
%37 = call i32 @rewind(i32* %36)
%38 = load i64, i64* %8
%39 = add nsw i64 %38, 1
%40 = mul i64 %39, 1
%41 = call i8* @malloc(i64 %40)
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = load i64, i64* %8
%44 = load i32*, i32** %7
%45 = call i32 @fread(i8* %42, i32 1, i64 %43, i32* %44)
%46 = load i8*, i8** %9
%47 = load i64, i64* %8
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8 0, i8* %48
%49 = load i32*, i32** %7
%50 = call i32 @fclose(i32* %49)
%51 = load i64, i64* %8
%52 = add nsw i64 %51, 1
%53 = mul i64 %52, 1
%54 = call i8* @malloc(i64 %53)
store i8* %54, i8** %10
%55 = load i8*, i8** %10
%56 = load i64, i64* %8
%57 = add nsw i64 %56, 1
%58 = load i8*, i8** %9
%59 = call i32 @swprintf(i8* %55, i64 %57, i8* bitcast ([3 x i32]* @.str.2 to i8*), i8* %58)
%60 = load i8*, i8** %9
%61 = call i32 @free(i8* %60)
%62 = load i8*, i8** %10
%63 = call i32 @lisp_silent_execute(i8* %62)
%64 = load i8*, i8** %10
%65 = call i32 @free(i8* %64)
br label %66
66: ; preds = %30, %29, %13
ret void
}

LLVM IR (-O2):
%struct.Context = type { i32 }
@.str = [4 x i8] c"%ls\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.2 = [3 x i32] [i32 37, i32 115, i32 0]
define void @builtin_load(%struct.Context* nocapture readnone %0, i32 %1) {
%3 = icmp eq i32 %1, 1
br i1 %3, label %4, label %28
4: ; preds = %2
%5 = tail call i8* (...) @pop()
%6 = tail call i64 @wcslen(i8* %5)
%7 = add nsw i64 %6, 1
%8 = tail call i8* @calloc(i64 %7, i32 1)
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @free(i8* %8)
%12 = icmp eq i32* %10, null
br i1 %12, label %28, label %13
13: ; preds = %4
%14 = load i32, i32* @SEEK_END
%15 = tail call i32 @fseek(i32* %10, i32 0, i32 %14)
%16 = tail call i64 @ftell(i32* %10)
%17 = tail call i32 @rewind(i32* %10)
%18 = add nsw i64 %16, 1
%19 = tail call i8* @malloc(i64 %18)
%20 = tail call i32 @fread(i8* %19, i32 1, i64 %16, i32* %10)
%21 = getelementptr inbounds i8, i8* %19, i64 %16
store i8 0, i8* %21
%22 = tail call i32 @fclose(i32* %10)
%23 = tail call i8* @malloc(i64 %18)
%24 = tail call i32 @swprintf(i8* %23, i64 %18, i8* bitcast ([3 x i32]* @.str.2 to i8*), i8* %19)
%25 = tail call i32 @free(i8* %19)
%26 = tail call i32 @lisp_silent_execute(i8* %23)
%27 = tail call i32 @free(i8* %23)
br label %28
28: ; preds = %13, %4, %2
ret void
}