// File: /workspace/github_cpp_makefile_star2_O2/AshOlogn[P]ash-language-interpreter/src/main.cpp
// Function: main
int main(int argc, char** argv) {
  
  //read in source code
  char* sourceFile = argv[1];
  fstream in(sourceFile, fstream::in);

  in.seekg(0, in.end);
  uint32_t length = in.tellg();
  in.seekg(0, in.beg);
  
  char* sourceCode = new char[length+1];
  in.read(sourceCode, length);
  sourceCode[length] = 0;
  in.close();

  //convert source code into array of lines
  vector<char*>* codeLines = getLines(sourceCode);
  
  //generate array of Tokens from source code 
  vector<Token> tokens;
  
  try {
    tokens = lex(sourceCode, codeLines);
  } catch(exception& e) {
    cout << e.what() << endl;
    return 1;
  }
	
  //get list of statements from list of tokens (parse)
  vector<AbstractStatementNode*>* statements;
  
  try {
    statements = parse(&tokens, codeLines); 
  } catch(exception& e) {
    cout << e.what() << endl;
    return 1;
  }
  
  vector<AbstractStatementNode*>::iterator it2;
	
  //execute statements
  for(it2 = statements->begin(); it2 != statements->end(); it2++) {

		try {
			(*it2)->execute();
		}	catch(exception& e) {
			cout << e.what() << endl;
			return 1;
		}	
  }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq 0x8(%rsi), %rsi
leaq -0x258(%rbp), %rbx
pushq $0x8
popq %rdx
movq %rbx, %rdi
callq 0x4270
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4280
leaq -0x258(%rbp), %rdi
callq 0x4320
movq %rax, %r14
leaq -0x258(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4280
leal 0x1(%r14), %edi
callq 0x4030
movq %rax, %rbx
movl %r14d, %r14d
leaq -0x258(%rbp), %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x4220
movb $0x0, (%rbx,%r14)
leaq -0x258(%rbp), %rdi
callq 0x4040
movq %rbx, %rdi
callq 0x4b50
movq %rax, %r14
xorps %xmm0, %xmm0
movaps %xmm0, -0x30(%rbp)
andq $0x0, -0x20(%rbp)
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x5b75
leaq -0x30(%rbp), %rbx
leaq -0x48(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4c8e
movq %r15, %rdi
callq 0x4c7a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a92a
movq %rax, %rbx
movq (%rax), %r14
cmpq 0x8(%rbx), %r14
je 0x4a16
movq (%r14), %rdi
movq (%rdi), %rax
callq *(%rax)
addq $0x8, %r14
jmp 0x4a02
xorl %ebx, %ebx
leaq -0x30(%rbp), %rdi
callq 0x4c7a
leaq -0x258(%rbp), %rdi
callq 0x4070
movl %ebx, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x4b3d
movq %rbx, %rdi
callq 0x40b0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x26567(%rip), %rdi     # 0x2afc8
movq %rax, %rsi
callq 0x41e0
movq %rax, %rdi
callq 0x4100
callq 0x4300
jmp 0x4b28
jmp 0x4b30
movq %rax, %rbx
callq 0x4300
jmp 0x4b3d
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x4b3d
movq %rbx, %rdi
callq 0x40b0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x26517(%rip), %rdi     # 0x2afc8
movq %rax, %rsi
callq 0x41e0
movq %rax, %rdi
callq 0x4100
callq 0x4300
jmp 0x4b28
jmp 0x4b30
movq %rax, %rbx
callq 0x4300
jmp 0x4b3d
jmp 0x4adc
jmp 0x4adc
jmp 0x4adc
jmp 0x4adc
movq %rax, %rbx
leaq -0x258(%rbp), %rdi
callq 0x4070
movq %rbx, %rdi
callq 0x4340
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x4b3d
movq %rbx, %rdi
callq 0x40b0
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x264b5(%rip), %rdi     # 0x2afc8
movq %rax, %rsi
callq 0x41e0
movq %rax, %rdi
callq 0x4100
callq 0x4300
pushq $0x1
popq %rbx
jmp 0x4a18
movq %rax, %rbx
jmp 0x4b3d
movq %rax, %rbx
callq 0x4300
leaq -0x30(%rbp), %rdi
callq 0x4c7a
jmp 0x4adf
movq %rax, %rdi
callq 0x4c48