#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 /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int interpret(int /*<<< orphan*/);
char *malloc(long);
int /*<<< orphan*/ panic(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ tokenize(char *);
int main(int argc, char *argv[]) {
  FILE *program_file;
  char *program;
  long length;
  if (argc < 2)
    panic("Not enough arguments", 0);
  if ((program_file = fopen(argv[1], "rb")) == NULL) {
    panic("Cannot open file", 0);
  }
  fseek(program_file, 0, SEEK_END);
  length = ftell(program_file);
  fseek(program_file, 0, SEEK_SET);
  program = malloc(length);
  if (program) {
    fread(program, 1, length, program_file);
  }
  fclose(program_file);
  printf("Program: %s", program);
  return interpret(tokenize(program));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ce <main+0x2e>
lea    0xe39(%rip),%rdi
xor    %esi,%esi
call   1060 <panic@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe38(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11fe <main+0x5e>
lea    0xe21(%rip),%rdi
xor    %esi,%esi
call   1060 <panic@plt>
mov    -0x18(%rbp),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1261 <main+0xc1>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rsi
lea    0xdb4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <tokenize@plt>
mov    %eax,%edi
call   10c0 <interpret@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11bb <main+0x1b>
lea    0xe4c(%rip),%rdi
xor    %esi,%esi
call   1060 <panic@plt>
mov    0x8(%rbx),%rdi
lea    0xe4f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11e1 <main+0x41>
lea    0xe3e(%rip),%rdi
xor    %esi,%esi
call   1060 <panic@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r14,%rdi
call   1070 <ftell@plt>
mov    %rax,%r15
mov    0x2dd2(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1235 <main+0x95>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xde5(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1090 <tokenize@plt>
mov    %eax,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    10c0 <interpret@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Not enough arguments\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [17 x i8] c"Cannot open file\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"Program: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 0)
br label %13
13: ; preds = %11, %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @panic(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %21
21: ; preds = %19, %13
%22 = load i32*, i32** %6
%23 = load i32, i32* @SEEK_END
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i32*, i32** %6
%26 = call i64 @ftell(i32* %25)
store i64 %26, i64* %8
%27 = load i32*, i32** %6
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %27, i32 0, i32 %28)
%30 = load i64, i64* %8
%31 = call i8* @malloc(i64 %30)
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %39
34: ; preds = %21
%35 = load i8*, i8** %7
%36 = load i64, i64* %8
%37 = load i32*, i32** %6
%38 = call i32 @fread(i8* %35, i32 1, i64 %36, i32* %37)
br label %39
39: ; preds = %34, %21
%40 = load i32*, i32** %6
%41 = call i32 @fclose(i32* %40)
%42 = load i8*, i8** %7
%43 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %7
%45 = call i32 @tokenize(i8* %44)
%46 = call i32 @interpret(i32 %45)
ret i32 %46
}

LLVM IR (-O2):
@.str = [21 x i8] c"Not enough arguments\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [17 x i8] c"Cannot open file\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [12 x i8] c"Program: %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 0)
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @panic(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 0)
br label %13
13: ; preds = %11, %6
%14 = load i32, i32* @SEEK_END
%15 = tail call i32 @fseek(i32* %9, i32 0, i32 %14)
%16 = tail call i64 @ftell(i32* %9)
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @fseek(i32* %9, i32 0, i32 %17)
%19 = tail call i8* @malloc(i64 %16)
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %13
%22 = tail call i32 @fread(i8* %19, i32 1, i64 %16, i32* %9)
br label %23
23: ; preds = %21, %13
%24 = tail call i32 @fclose(i32* %9)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%26 = tail call i32 @tokenize(i8* %19)
%27 = tail call i32 @interpret(i32 %26)
ret i32 %27
}