#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*/ close();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ init(int /*<<< orphan*/, int);
int is_done();
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ run(char *);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  printf("Alphabetti Spaghetti\nInterpreter by Philip Picard\n");
  init(0, 1);
  if (argc == 1) {
    char line[100];
    while (1) {
      printf(">");
      fgets(line, 100, stdin);
      run(line);
      if (is_done() == 1)
        break;
    }
  } else if (argc == 2) {
    FILE *f = fopen(argv[1], "r");
    if (f == NULL) {
      printf("Error: Failed to open the passed in file.");
      return 0;
    }
    fseek(f, 0L, SEEK_END);
    int len = ftell(f);
    rewind(f);
    char *source = malloc(len);
    fread(source, 1, len, f);
    source[len - 1] = '\0';
    run(source);
    free(source);
    fclose(f);
  }
  close();
  printf("Done.");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe00(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   10c0 <init@plt>
cmpl   $0x1,-0x8(%rbp)
jne    126b <main+0x8b>
jmp    1220 <main+0x40>
lea    0xe0c(%rip),%rdi
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10a0 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1060 <run@plt>
mov    $0x0,%al
call   1100 <is_done@plt>
cmp    $0x1,%eax
jne    1261 <main+0x81>
jmp    1266 <main+0x86>
jmp    1220 <main+0x40>
jmp    135d <main+0x17d>
cmpl   $0x2,-0x8(%rbp)
jne    1358 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb1(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    12b6 <main+0xd6>
lea    0xd92(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1377 <main+0x197>
mov    -0x88(%rbp),%rdi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <fseek@plt>
mov    -0x88(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x88(%rbp),%rdi
call   1080 <rewind@plt>
mov    -0x8c(%rbp),%edi
call   10d0 <malloc@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0x8c(%rbp),%edx
mov    -0x88(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x98(%rbp),%rax
mov    -0x8c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x98(%rbp),%rdi
call   1060 <run@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
mov    -0x88(%rbp),%rdi
call   1050 <fclose@plt>
jmp    135d <main+0x17d>
mov    $0x0,%al
call   1090 <close@plt>
lea    0xcf6(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe1e(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   10e0 <init@plt>
cmp    $0x2,%ebp
je     1273 <main+0x73>
cmp    $0x1,%ebp
jne    12f3 <main+0xf3>
mov    0x2da6(%rip),%rbp
mov    %rsp,%rbx
nopl   (%rax)
mov    $0x3e,%edi
call   1040 <putchar@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
call   1080 <run@plt>
xor    %eax,%eax
call   1120 <is_done@plt>
cmp    $0x1,%eax
jne    1240 <main+0x40>
jmp    12f3 <main+0xf3>
mov    0x8(%rbx),%rdi
lea    0xd82(%rip),%rsi
call   1110 <fopen@plt>
test   %rax,%rax
je     1311 <main+0x111>
mov    %rax,%rbx
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1100 <fseek@plt>
mov    %rbx,%rdi
call   10d0 <ftell@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   10a0 <rewind@plt>
mov    %r14d,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1060 <fread@plt>
movslq %r14d,%rax
movb   $0x0,-0x1(%rax,%rbp,1)
mov    %rbp,%rdi
call   1080 <run@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
call   10b0 <close@plt>
lea    0xd2b(%rip),%rdi
call   1090 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xcea(%rip),%rdi
jmp    1301 <main+0x101>

LLVM IR (-O0):
@.str = [51 x i8] c"Alphabetti Spaghetti\0AInterpreter by Philip Picard\0A\00"
@.str.1 = [2 x i8] c">\00"
@stdin = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [42 x i8] c"Error: Failed to open the passed in file.\00"
@SEEK_END = global i32 0
@.str.4 = [6 x i8] c"Done.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @init(i32 0, i32 1)
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %27
14: ; preds = %2
br label %15
15: ; preds = %14, %25
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 100, i32 %18)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%21 = call i32 @run(i8* %20)
%22 = call i32 (...) @is_done()
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %15
br label %26
25: ; preds = %15
br label %15
26: ; preds = %24
br label %65
27: ; preds = %2
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 2
br i1 %29, label %30, label %64
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %7
%35 = load i32*, i32** %7
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %68
39: ; preds = %30
%40 = load i32*, i32** %7
%41 = load i32, i32* @SEEK_END
%42 = call i32 @fseek(i32* %40, i64 0, i32 %41)
%43 = load i32*, i32** %7
%44 = call i32 @ftell(i32* %43)
store i32 %44, i32* %8
%45 = load i32*, i32** %7
%46 = call i32 @rewind(i32* %45)
%47 = load i32, i32* %8
%48 = call i8* @malloc(i32 %47)
store i8* %48, i8** %9
%49 = load i8*, i8** %9
%50 = load i32, i32* %8
%51 = load i32*, i32** %7
%52 = call i32 @fread(i8* %49, i32 1, i32 %50, i32* %51)
%53 = load i8*, i8** %9
%54 = load i32, i32* %8
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 0, i8* %57
%58 = load i8*, i8** %9
%59 = call i32 @run(i8* %58)
%60 = load i8*, i8** %9
%61 = call i32 @free(i8* %60)
%62 = load i32*, i32** %7
%63 = call i32 @fclose(i32* %62)
br label %64
64: ; preds = %39, %27
br label %65
65: ; preds = %64, %26
%66 = call i32 (...) @close()
%67 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %68
68: ; preds = %65, %37
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [42 x i8] c"Error: Failed to open the passed in file.\00"
@SEEK_END = global i32 0
@.str.4 = [6 x i8] c"Done.\00"
@str = [50 x i8] c"Alphabetti Spaghetti\0AInterpreter by Philip Picard\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @init(i32 0, i32 1)
switch i32 %0, label %36 [
i32 1, label %6
i32 2, label %16
]
6: ; preds = %2
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
br label %8
8: ; preds = %8, %6
%9 = call i32 @putchar(i32 62)
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %7, i32 100, i32 %10)
%12 = call i32 @run(i8* %7)
%13 = call i32 (...) @is_done()
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %8
15: ; preds = %8
br label %36
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %34, label %21
21: ; preds = %16
%22 = load i32, i32* @SEEK_END
%23 = tail call i32 @fseek(i32* %19, i64 0, i32 %22)
%24 = tail call i32 @ftell(i32* %19)
%25 = tail call i32 @rewind(i32* %19)
%26 = tail call i8* @malloc(i32 %24)
%27 = tail call i32 @fread(i8* %26, i32 1, i32 %24, i32* %19)
%28 = add nsw i32 %24, -1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 0, i8* %30
%31 = tail call i32 @run(i8* %26)
%32 = tail call i32 @free(i8* %26)
%33 = tail call i32 @fclose(i32* %19)
br label %36
34: ; preds = %16
%35 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %39
36: ; preds = %21, %2, %15
%37 = call i32 (...) @close()
%38 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %34, %36
ret i32 0
}