// File: philpoore[P]Math/main.cpp
// Function: main
int main(int argc, char** argv) {
    bool repl = argc == 1;

    if (repl) {
        runRepl();
    }

    string input;
    string firstArg = string(argv[1]);

    if (firstArg == "-f") {
        // Use a file as input.
        // E.g "./math -f examples/example-1.math"
        if (argc < 3) {
            cerr << "Runtime Error: Too few arguments\n";
            cerr << "-f flag missing filename" << endl;
            exit(1);
        }
        string filename = string(argv[2]);
        // Read file for input
        input = readFile(filename);
    } else {
        // Default to running from firstArg.
        // E.g "./math 10+10"
        input = string(firstArg);
    }

    run(input);
    exit(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
sete %al
andb $0x1, %al
movb %al, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
je 0xaf00
callq 0xac50
leaq -0x38(%rbp), %rdi
callq 0x43f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x128(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x4500
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0xbcf0
jmp 0xaf41
leaq -0x59(%rbp), %rdi
callq 0x4340
leaq 0xb57e(%rip), %rsi      # 0x164cf
leaq -0x58(%rbp), %rdi
callq 0xcb90
movb %al, -0x129(%rbp)
jmp 0xaf62
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0xaf71
jmp 0xb0ed
cmpl $0x3, -0x8(%rbp)
jge 0xaff2
movq 0x15072(%rip), %rdi     # 0x1fff0
leaq 0xb54d(%rip), %rsi      # 0x164d2
callq 0x42e0
jmp 0xaf8c
movq 0x1505d(%rip), %rdi     # 0x1fff0
leaq 0xb55a(%rip), %rsi      # 0x164f4
callq 0x42e0
movq %rax, -0x138(%rbp)
jmp 0xafa8
movq -0x138(%rbp), %rdi
movq 0x14f4a(%rip), %rsi     # 0x1ff00
callq 0x4320
jmp 0xafbd
movl $0x1, %edi
callq 0x4390
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x4340
jmp 0xb16f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xb166
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x148(%rbp)
leaq -0x91(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x4500
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdx
leaq -0x90(%rbp), %rdi
callq 0xbcf0
jmp 0xb030
leaq -0x91(%rbp), %rdi
callq 0x4340
leaq -0xd8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x4160
jmp 0xb051
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xad20
jmp 0xb066
leaq -0x38(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x43a0
leaq -0xb8(%rbp), %rdi
callq 0x4200
leaq -0xd8(%rbp), %rdi
callq 0x4200
leaq -0x90(%rbp), %rdi
callq 0x4200
jmp 0xb11b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x4340
jmp 0xb166
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xb0df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x4200
leaq -0x90(%rbp), %rdi
callq 0x4200
jmp 0xb166
leaq -0xf8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x4160
jmp 0xb0ff
leaq -0x38(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x43a0
leaq -0xf8(%rbp), %rdi
callq 0x4200
leaq -0x118(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4160
jmp 0xb12d
leaq -0x118(%rbp), %rdi
callq 0xa8c0
jmp 0xb13b
leaq -0x118(%rbp), %rdi
callq 0x4200
xorl %edi, %edi
callq 0x4390
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x4200
leaq -0x58(%rbp), %rdi
callq 0x4200
leaq -0x38(%rbp), %rdi
callq 0x4200
movq -0x68(%rbp), %rdi
callq 0x44f0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)