#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 */

/* Variables and functions */
int /*<<< orphan*/ getLine(char *, int);
int /*<<< orphan*/ loadCodeFromFile(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ runProgram();
int /*<<< orphan*/ strcpy2(char *, char *);
int strlen2(char *);
int main(int argc, char *argv[]) {
  char filename[100] = "undefined";
  if (argc > 1) {
    if (argv[1][0] == '-' && strlen2(argv[1]) > 1) {
      switch (argv[1][1]) {
      case 'h':
        printf("Runs SML programs from the commandline\n");
        printf("Usage: RunSML [-h]|[-f <filename.sml>]\n");
        return 0;
      case 'f':
        if (argc > 2) {
          strcpy2(filename, argv[2]);
        } else {
          printf("Runs SML programs from the commandline\n");
          printf("Usage: RunSML [-h]|[-f <filename.sml>]\n");
          return 0;
        }
        break;
      default:
        printf("Runs SML programs from the commandline\n");
        printf("Usage: RunSML [-h]|[-f <filename.sml>]\n");
        return 0;
      }
    } else {
      printf("Runs SML programs from the commandline\n");
      printf("Usage: RunSML [-h]|[-f <filename.sml>]\n");
      return 0;
    }
  } else {
    printf("Enter name of file to load: ");
    getLine(filename, 100);
  }
  loadCodeFromFile(filename);
  runProgram();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe6c(%rip),%rsi
mov    $0x64,%edx
call   1050 <memcpy@plt>
cmpl   $0x1,-0x8(%rbp)
jle    12c5 <main+0x155>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    129c <main+0x12c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen2@plt>
cmp    $0x1,%eax
jle    129c <main+0x12c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x84(%rbp)
sub    $0x66,%eax
je     122a <main+0xba>
jmp    11f2 <main+0x82>
mov    -0x84(%rbp),%eax
sub    $0x68,%eax
jne    1273 <main+0x103>
jmp    1206 <main+0x96>
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f6 <main+0x186>
cmpl   $0x2,-0x8(%rbp)
jle    124a <main+0xda>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <strcpy2@plt>
jmp    126e <main+0xfe>
lea    0xe13(%rip),%rdi
call   1040 <printf@plt>
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f6 <main+0x186>
jmp    1297 <main+0x127>
lea    0xdea(%rip),%rdi
call   1040 <printf@plt>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f6 <main+0x186>
jmp    12c0 <main+0x150>
lea    0xdc1(%rip),%rdi
call   1040 <printf@plt>
lea    0xddd(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12f6 <main+0x186>
jmp    12df <main+0x16f>
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x64,%esi
call   1080 <getLine@plt>
lea    -0x80(%rbp),%rdi
call   1070 <loadCodeFromFile@plt>
mov    $0x0,%al
call   1030 <runProgram@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
movaps 0xed3(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeb7(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe9b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe7f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe63(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe47(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
cmp    $0x2,%edi
jl     120c <main+0x9c>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    11f2 <main+0x82>
call   1060 <strlen2@plt>
cmp    $0x2,%eax
jl     11f2 <main+0x82>
mov    0x8(%rbx),%rax
movsbl 0x1(%rax),%eax
cmp    $0x66,%eax
je     123d <main+0xcd>
cmp    $0x68,%eax
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
lea    0xea3(%rip),%rdi
call   1040 <puts@plt>
jmp    1234 <main+0xc4>
lea    0xe51(%rip),%rdi
call   1050 <printf@plt>
mov    %rsp,%rdi
mov    $0x64,%esi
call   1080 <getLine@plt>
mov    %rsp,%rdi
call   1070 <loadCodeFromFile@plt>
xor    %eax,%eax
call   1030 <runProgram@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0x3,%ebp
jb     11f2 <main+0x82>
mov    0x10(%rbx),%rsi
mov    %rsp,%rdi
call   1090 <strcpy2@plt>
jmp    1225 <main+0xb5>

LLVM IR (-O0):
@__const.main.filename = [100 x i8] c"undefined\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [40 x i8] c"Runs SML programs from the commandline\0A\00"
@.str.1 = [40 x i8] c"Usage: RunSML [-h]|[-f <filename.sml>]\0A\00"
@.str.2 = [29 x i8] c"Enter name of file to load: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [100 x i8]* %6 to i8*
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %55
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 45
br i1 %17, label %18, label %51
18: ; preds = %10
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strlen2(i8* %21)
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %51
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
switch i32 %30, label %47 [
i32 104, label %31
i32 102, label %34
]
31: ; preds = %24
%32 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %63
34: ; preds = %24
%35 = load i32, i32* %4
%36 = icmp sgt i32 %35, 2
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @strcpy2(i8* %38, i8* %41)
br label %46
43: ; preds = %34
%44 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%45 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %63
46: ; preds = %37
br label %50
47: ; preds = %24
%48 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%49 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %63
50: ; preds = %46
br label %54
51: ; preds = %18, %10
%52 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%53 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %63
54: ; preds = %50
br label %59
55: ; preds = %2
%56 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%58 = call i32 @getLine(i8* %57, i32 100)
br label %59
59: ; preds = %55, %54
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%61 = call i32 @loadCodeFromFile(i8* %60)
%62 = call i32 (...) @runProgram()
store i32 0, i32* %3
br label %63
63: ; preds = %59, %51, %47, %43, %31
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@__const.main.filename = [100 x i8] c"undefined\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [29 x i8] c"Enter name of file to load: \00"
@str.8 = [39 x i8] c"Runs SML programs from the commandline\00"
@str.9 = [39 x i8] c"Usage: RunSML [-h]|[-f <filename.sml>]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %37
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 45
br i1 %10, label %11, label %34
11: ; preds = %6
%12 = tail call i32 @strlen2(i8* %8)
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %34
14: ; preds = %11
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
switch i32 %18, label %31 [
i32 104, label %19
i32 102, label %22
]
19: ; preds = %14
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.8, i64 0, i64 0))
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.9, i64 0, i64 0))
br label %43
22: ; preds = %14
%23 = icmp ugt i32 %0, 2
br i1 %23, label %24, label %28
24: ; preds = %22
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @strcpy2(i8* %4, i8* %26)
br label %40
28: ; preds = %22
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.8, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.9, i64 0, i64 0))
br label %43
31: ; preds = %14
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.8, i64 0, i64 0))
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.9, i64 0, i64 0))
br label %43
34: ; preds = %11, %6
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.8, i64 0, i64 0))
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.9, i64 0, i64 0))
br label %43
37: ; preds = %2
%38 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @getLine(i8* %4, i32 100)
br label %40
40: ; preds = %37, %24
%41 = call i32 @loadCodeFromFile(i8* %4)
%42 = call i32 (...) @runProgram()
br label %43
43: ; preds = %40, %34, %31, %28, %19
ret i32 0
}