int main(int argc, char **argv) {
  if (argc != 2) {
    printf("To use the Expression Parser, type the command \"mathp \",\n");
    printf("then the mathematical expression you want to evaluate, then press "
           "enter.\n");
    printf("You can use \"pi\" to represent the constant pi, \"e\" to "
           "represent e and\n");
    printf(
        "\"sqrt( [expression] )\" to calculate the square root of a number\n");
    printf(" or a mathematical expression. You can use \"123.4567!\" to "
           "calculate the\n");
    printf("factorial of a number, or \"( [expression] )!\" to calculate the "
           "factorial\n");
    printf("of a mathematical expression. You may need to surround your "
           "mathematical\n");
    printf("expression with \" and \".\n");
    printf("Example: \n");
    printf("'mathp \"3.5 * 7 + 23 / pi\"'   this evaluates to (3.5 * 7) + (23 "
           "/ 3.14159...).\n");
    return 0;
  }
  char **tokens = (char **)malloc(strlen(argv[1]) * sizeof(char *));
  int tokenIndex = tokenize(argv[1], tokens);
  double result = parse(tokens, 0, tokenIndex - 1, tokenIndex);
  printf("Result: %f\n", result);
  for (int i = 0; i < tokenIndex; i++) {
    free(tokens[i]);
  }
  free(tokens);
}


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)
je     1218 <main+0xb8>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xfc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0x1000(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0x100c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0x1009(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b8 <main+0x158>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
shl    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1070 <tokenize@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
mov    -0x1c(%rbp),%ecx
xor    %esi,%esi
mov    $0x0,%al
call   1080 <parse@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xfe8(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12af <main+0x14f>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1284 <main+0x124>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11fc <main+0x8c>
mov    0x8(%rsi),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x0(,%rax,8),%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <tokenize@plt>
mov    %eax,%r14d
lea    -0x1(%r14),%edx
mov    %r15,%rdi
xor    %esi,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   1090 <parse@plt>
cvtsi2sd %eax,%xmm0
lea    0xe39(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
test   %r14d,%r14d
jle    11f2 <main+0x82>
mov    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11e0 <main+0x70>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1274 <main+0x104>
lea    0xe09(%rip),%rdi
call   1040 <puts@plt>
lea    0xe36(%rip),%rdi
call   1040 <puts@plt>
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
lea    0xee1(%rip),%rdi
call   1040 <puts@plt>
lea    0xf1d(%rip),%rdi
call   1040 <puts@plt>
lea    0xf5a(%rip),%rdi
call   1040 <puts@plt>
lea    0xf97(%rip),%rdi
call   1040 <puts@plt>
lea    0xfa4(%rip),%rdi
call   1040 <puts@plt>
lea    0xfa2(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [58 x i8] c"To use the Expression Parser, type the command \22mathp \22,\0A\00"
@.str.1 = [74 x i8] c"then the mathematical expression you want to evaluate, then press enter.\0A\00"
@.str.2 = [71 x i8] c"You can use \22pi\22 to represent the constant pi, \22e\22 to represent e and\0A\00"
@.str.3 = [65 x i8] c"\22sqrt( [expression] )\22 to calculate the square root of a number\0A\00"
@.str.4 = [73 x i8] c" or a mathematical expression. You can use \22123.4567!\22 to calculate the\0A\00"
@.str.5 = [74 x i8] c"factorial of a number, or \22( [expression] )!\22 to calculate the factorial\0A\00"
@.str.6 = [74 x i8] c"of a mathematical expression. You may need to surround your mathematical\0A\00"
@.str.7 = [26 x i8] c"expression with \22 and \22.\0A\00"
@.str.8 = [11 x i8] c"Example: \0A\00"
@.str.9 = [80 x i8] c"'mathp \223.5 * 7 + 23 / pi\22' this evaluates to (3.5 * 7) + (23 / 3.14159...).\0A\00"
@.str.10 = [12 x i8] c"Result: %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %23
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.6, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %60
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strlen(i8* %26)
%28 = mul i64 %27, 8
%29 = call i8* @malloc(i64 %28)
%30 = bitcast i8* %29 to i8**
store i8** %30, i8*** %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %6
%35 = call i32 (i8*, i8**, ...) bitcast (i32 (...)* @tokenize to i32 (i8*, i8**, ...)*)(i8* %33, i8** %34)
store i32 %35, i32* %7
%36 = load i8**, i8*** %6
%37 = load i32, i32* %7
%38 = sub nsw i32 %37, 1
%39 = load i32, i32* %7
%40 = call i32 (i8**, i32, i32, i32, ...) bitcast (i32 (...)* @parse to i32 (i8**, i32, i32, i32, ...)*)(i8** %36, i32 0, i32 %38, i32 %39)
%41 = sitofp i32 %40 to double
store double %41, double* %8
%42 = load double, double* %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), double %42)
store i32 0, i32* %9
br label %44
44: ; preds = %54, %23
%45 = load i32, i32* %9
%46 = load i32, i32* %7
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %57
48: ; preds = %44
%49 = load i8**, i8*** %6
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
br label %54
54: ; preds = %48
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %44
57: ; preds = %44
%58 = load i8**, i8*** %6
%59 = bitcast i8** %58 to i8*
br label %60
60: ; preds = %57, %12
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str.10 = [12 x i8] c"Result: %f\0A\00"
@str = [57 x i8] c"To use the Expression Parser, type the command \22mathp \22,\00"
@str.11 = [73 x i8] c"then the mathematical expression you want to evaluate, then press enter.\00"
@str.12 = [70 x i8] c"You can use \22pi\22 to represent the constant pi, \22e\22 to represent e and\00"
@str.13 = [64 x i8] c"\22sqrt( [expression] )\22 to calculate the square root of a number\00"
@str.14 = [72 x i8] c" or a mathematical expression. You can use \22123.4567!\22 to calculate the\00"
@str.15 = [73 x i8] c"factorial of a number, or \22( [expression] )!\22 to calculate the factorial\00"
@str.16 = [73 x i8] c"of a mathematical expression. You may need to surround your mathematical\00"
@str.17 = [25 x i8] c"expression with \22 and \22.\00"
@str.18 = [10 x i8] c"Example: \00"
@str.19 = [79 x i8] c"'mathp \223.5 * 7 + 23 / pi\22' this evaluates to (3.5 * 7) + (23 / 3.14159...).\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.11, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.12, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.13, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str.14, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.15, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.16, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.17, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.18, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str.19, i64 0, i64 0))
br label %37
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i64 @strlen(i8* dereferenceable(1) %17)
%19 = shl i64 %18, 3
%20 = tail call i8* @malloc(i64 %19)
%21 = bitcast i8* %20 to i8**
%22 = tail call i32 (i8*, i8**, ...) bitcast (i32 (...)* @tokenize to i32 (i8*, i8**, ...)*)(i8* %17, i8** %21)
%23 = add nsw i32 %22, -1
%24 = tail call i32 (i8**, i32, i32, i32, ...) bitcast (i32 (...)* @parse to i32 (i8**, i32, i32, i32, ...)*)(i8** %21, i32 0, i32 %23, i32 %22)
%25 = sitofp i32 %24 to double
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), double %25)
%27 = icmp sgt i32 %22, 0
br i1 %27, label %28, label %30
28: ; preds = %15
%29 = zext i32 %22 to i64
br label %31
30: ; preds = %31, %15
tail call void @free(i8* %20)
br label %37
31: ; preds = %28, %31
%32 = phi i64 [ 0, %28 ], [ %35, %31 ]
%33 = getelementptr inbounds i8*, i8** %21, i64 %32
%34 = load i8*, i8** %33
tail call void @free(i8* %34)
%35 = add nuw nsw i64 %32, 1
%36 = icmp eq i64 %35, %29
br i1 %36, label %30, label %31
37: ; preds = %30, %4
ret i32 0
}