int main(int argc, char **argv) {
  printf("%f\n", 3.5 * 7 / 23 + 3.14159);
  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);
  for (int i = 0; i < tokenIndex; i++) {
    printf("%s, ", tokens[i]);
  }
  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)
lea    0x10f6(%rip),%rdi
movsd  0xe7b(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     122e <main+0xce>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xfb6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xff2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xffe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xffb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1309 <main+0x1a9>
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)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    129c <main+0x13c>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xfdf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1268 <main+0x108>
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    0xfa4(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1300 <main+0x1a0>
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    12d5 <main+0x175>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe91(%rip),%rdi
movsd  0xe74(%rip),%xmm0
mov    $0x1,%al
call   1060 <printf@plt>
cmp    $0x2,%ebp
jne    1247 <main+0xd7>
mov    0x8(%rbx),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x0(,%rax,8),%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <tokenize@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    12c1 <main+0x151>
mov    %r14d,%ebp
lea    0xe2e(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11e0 <main+0x70>
lea    -0x1(%r14),%edx
mov    %r12,%rdi
xor    %esi,%esi
mov    %r14d,%ecx
xor    %eax,%eax
call   1090 <parse@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xdf5(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
test   %r14d,%r14d
jle    12eb <main+0x17b>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1230 <main+0xc0>
jmp    12eb <main+0x17b>
lea    0xdcb(%rip),%rdi
call   1040 <puts@plt>
lea    0xdf8(%rip),%rdi
call   1040 <puts@plt>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
lea    0xea3(%rip),%rdi
call   1040 <puts@plt>
lea    0xedf(%rip),%rdi
call   1040 <puts@plt>
lea    0xf1c(%rip),%rdi
call   1040 <puts@plt>
lea    0xf59(%rip),%rdi
call   1040 <puts@plt>
lea    0xf66(%rip),%rdi
call   1040 <puts@plt>
lea    0xf64(%rip),%rdi
call   1040 <puts@plt>
jmp    12f3 <main+0x183>
mov    %r14d,%edx
add    $0xffffffff,%edx
mov    %r12,%rdi
xor    %esi,%esi
mov    %r14d,%ecx
xor    %eax,%eax
call   1090 <parse@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xd29(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%f\0A\00"
@.str.11 = [5 x i8] c"%s, \00"
@.str.12 = [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.13 = [73 x i8] c"then the mathematical expression you want to evaluate, then press enter.\00"
@str.14 = [70 x i8] c"You can use \22pi\22 to represent the constant pi, \22e\22 to represent e and\00"
@str.15 = [64 x i8] c"\22sqrt( [expression] )\22 to calculate the square root of a number\00"
@str.16 = [72 x i8] c" or a mathematical expression. You can use \22123.4567!\22 to calculate the\00"
@str.17 = [73 x i8] c"factorial of a number, or \22( [expression] )!\22 to calculate the factorial\00"
@str.18 = [73 x i8] c"of a mathematical expression. You may need to surround your mathematical\00"
@str.19 = [25 x i8] c"expression with \22 and \22.\00"
@str.20 = [10 x i8] c"Example: \00"
@str.21 = [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 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double 0x4010D3C55118E49B)
%4 = icmp eq i32 %0, 2
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.13, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str.14, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.15, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str.16, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.17, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.18, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.19, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.20, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str.21, i64 0, i64 0))
br label %53
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i64 @strlen(i8* dereferenceable(1) %18)
%20 = shl i64 %19, 3
%21 = tail call i8* @malloc(i64 %20)
%22 = bitcast i8* %21 to i8**
%23 = tail call i32 (i8*, i8**, ...) bitcast (i32 (...)* @tokenize to i32 (i8*, i8**, ...)*)(i8* %18, i8** %22)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %41
25: ; preds = %16
%26 = zext i32 %23 to i64
br label %34
27: ; preds = %34
%28 = add nsw i32 %23, -1
%29 = tail call i32 (i8**, i32, i32, i32, ...) bitcast (i32 (...)* @parse to i32 (i8**, i32, i32, i32, ...)*)(i8** %22, i32 0, i32 %28, i32 %23)
%30 = sitofp i32 %29 to double
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), double %30)
br i1 %24, label %32, label %46
32: ; preds = %27
%33 = zext i32 %23 to i64
br label %47
34: ; preds = %25, %34
%35 = phi i64 [ 0, %25 ], [ %39, %34 ]
%36 = getelementptr inbounds i8*, i8** %22, i64 %35
%37 = load i8*, i8** %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i8* %37)
%39 = add nuw nsw i64 %35, 1
%40 = icmp eq i64 %39, %26
br i1 %40, label %27, label %34
41: ; preds = %16
%42 = add nsw i32 %23, -1
%43 = tail call i32 (i8**, i32, i32, i32, ...) bitcast (i32 (...)* @parse to i32 (i8**, i32, i32, i32, ...)*)(i8** %22, i32 0, i32 %42, i32 %23)
%44 = sitofp i32 %43 to double
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), double %44)
br label %46
46: ; preds = %47, %41, %27
tail call void @free(i8* %21)
br label %53
47: ; preds = %32, %47
%48 = phi i64 [ 0, %32 ], [ %51, %47 ]
%49 = getelementptr inbounds i8*, i8** %22, i64 %48
%50 = load i8*, i8** %49
tail call void @free(i8* %50)
%51 = add nuw nsw i64 %48, 1
%52 = icmp eq i64 %51, %33
br i1 %52, label %46, label %47
53: ; preds = %46, %5
ret i32 0
}