// File: zerolfx[P]P-Machine/main.cpp
// Function: main
int main(int argc, char *argv[])
{
	try
	{
		if(argc < 2)
		{
			usage(); 
			exit(0);
		}
				
		for(int i = 0; i < argc; ++i)
		{
			if(argv[i][0] == '-')
			{
				switch(argv[i][1])
				{
					case 's':
					{
						if(argv[i+1] == 0)
						{
							cerr << "switch -s expects a numeric value" << endl;
							usage();
							exit(0);
						}
						
						Pmachine.setStepSize(atoi(argv[i+1]));
						break;
					}
					case 't': 
					{
						if(argv[i+1] == 0)
						{
							cerr << "switch -t expects a numeric value" << endl;
							usage();
							exit(0);
						}
						
						Pmachine.setStackSize(atoi(argv[i+1]));
						break;
					}
					case 'h':
					{
						Pmachine.setShowHeap();
						break;
					}
					default:
					{
						cerr << "unrecognized switch" << endl;
						usage();
						exit(0);
					}
				}
			}
		}

		
		
		FILE *file = fopen(argv[1], "r");
		if(file != NULL)
		{
			yyin = file;
		}
		else
		{
			cerr << "File " << argv[1] << " niet beschikbaar" << endl;
			usage();
			exit(0);
		}
		
		yyparse();
		
		fclose(file);
		
		Pmachine.run();
	}
	catch(ExecutionError e)
	{
		cerr << e.getMsg() << endl;
	}
	catch(CompileTimeError e)
	{
		cerr << e.getMsg() << endl;
	}
	catch(...)
	{
		cerr << "unknown error" << endl;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x2e169
callq 0x2def0
jmp 0x2dfca
xorl %edi, %edi
callq 0x7360
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0xac(%rbp)
movl $0x3, %ecx
cmpl %ecx, %eax
jne 0x2e08f
movq -0x18(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x73a0
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x2e4d0
jmp 0x2e014
movq -0xb8(%rbp), %rdi
callq 0x70d0
leaq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x28420
jmp 0x2e035
movq 0x1cfb4(%rip), %rdi     # 0x4aff0
leaq -0xa8(%rbp), %rsi
callq 0x7240
movq %rax, -0xc0(%rbp)
jmp 0x2e051
movq -0xc0(%rbp), %rdi
movq 0x1cf49(%rip), %rsi     # 0x4afa8
callq 0x72b0
jmp 0x2e066
leaq -0xa8(%rbp), %rdi
callq 0x7170
leaq -0x88(%rbp), %rdi
callq 0x28400
callq 0x7480
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movl -0xac(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x2e125
movq -0x18(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x73a0
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x2e4a0
jmp 0x2e0c0
movq -0xc8(%rbp), %rdi
callq 0x70d0
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x284a0
jmp 0x2e0db
movq 0x1cf0e(%rip), %rdi     # 0x4aff0
leaq -0x68(%rbp), %rsi
callq 0x7240
movq %rax, -0xd0(%rbp)
jmp 0x2e0f4
movq -0xd0(%rbp), %rdi
movq 0x1cea6(%rip), %rsi     # 0x4afa8
callq 0x72b0
jmp 0x2e109
leaq -0x68(%rbp), %rdi
callq 0x7170
leaq -0x48(%rbp), %rdi
callq 0x28480
callq 0x7480
jmp 0x2e083
movq -0x18(%rbp), %rdi
callq 0x70d0
movq 0x1cebb(%rip), %rdi     # 0x4aff0
leaq 0xc909(%rip), %rsi      # 0x3aa45
callq 0x7250
movq %rax, -0xd8(%rbp)
jmp 0x2e14a
movq -0xd8(%rbp), %rdi
movq 0x1ce50(%rip), %rsi     # 0x4afa8
callq 0x72b0
jmp 0x2e15f
callq 0x7480
jmp 0x2e083
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x2e324
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x2e314
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
movl %eax, -0xdc(%rbp)
subl $0x68, %eax
je 0x2e2c3
jmp 0x2e1b5
movl -0xdc(%rbp), %eax
subl $0x73, %eax
je 0x2e1d2
jmp 0x2e1c2
movl -0xdc(%rbp), %eax
subl $0x74, %eax
je 0x2e24c
jmp 0x2e2d3
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x2e225
movq 0x1ce03(%rip), %rdi     # 0x4aff0
leaq 0xc7e1(%rip), %rsi      # 0x3a9d5
callq 0x7250
movq %rax, -0xe8(%rbp)
jmp 0x2e202
movq -0xe8(%rbp), %rdi
movq 0x1cd98(%rip), %rsi     # 0x4afa8
callq 0x72b0
jmp 0x2e217
callq 0x2def0
jmp 0x2e21e
xorl %edi, %edi
callq 0x7360
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x7450
movl %eax, %esi
leaq 0x1d170(%rip), %rdi     # 0x4b3b0
callq 0x2d020
jmp 0x2e247
jmp 0x2e312
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x2e29f
movq 0x1cd89(%rip), %rdi     # 0x4aff0
leaq 0xc789(%rip), %rsi      # 0x3a9f7
callq 0x7250
movq %rax, -0xf0(%rbp)
jmp 0x2e27c
movq -0xf0(%rbp), %rdi
movq 0x1cd1e(%rip), %rsi     # 0x4afa8
callq 0x72b0
jmp 0x2e291
callq 0x2def0
jmp 0x2e298
xorl %edi, %edi
callq 0x7360
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x7450
movl %eax, %esi
leaq 0x1d0f6(%rip), %rdi     # 0x4b3b0
callq 0x2cff0
jmp 0x2e2c1
jmp 0x2e312
leaq 0x1d0e6(%rip), %rdi     # 0x4b3b0
callq 0x2cfc0
jmp 0x2e2d1
jmp 0x2e312
movq 0x1cd16(%rip), %rdi     # 0x4aff0
leaq 0xc738(%rip), %rsi      # 0x3aa19
callq 0x7250
movq %rax, -0xf8(%rbp)
jmp 0x2e2ef
movq -0xf8(%rbp), %rdi
movq 0x1ccab(%rip), %rsi     # 0x4afa8
callq 0x72b0
jmp 0x2e304
callq 0x2def0
jmp 0x2e30b
xorl %edi, %edi
callq 0x7360
jmp 0x2e314
jmp 0x2e316
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2e170
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xc710(%rip), %rsi      # 0x3aa43
callq 0x7340
movq %rax, -0x100(%rbp)
jmp 0x2e341
movq -0x100(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2e363
movq -0x28(%rbp), %rcx
leaq 0x1cfe2(%rip), %rax     # 0x4b340
movq %rcx, (%rax)
jmp 0x2e3db
movq 0x1cc86(%rip), %rdi     # 0x4aff0
leaq 0xc6bc(%rip), %rsi      # 0x3aa2d
callq 0x7250
movq %rax, -0x108(%rbp)
jmp 0x2e37f
movq -0x108(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x7250
movq %rax, -0x110(%rbp)
jmp 0x2e39c
movq -0x110(%rbp), %rdi
leaq 0xc689(%rip), %rsi      # 0x3aa33
callq 0x7250
movq %rax, -0x118(%rbp)
jmp 0x2e3b8
movq -0x118(%rbp), %rdi
movq 0x1cbe2(%rip), %rsi     # 0x4afa8
callq 0x72b0
jmp 0x2e3cd
callq 0x2def0
jmp 0x2e3d4
xorl %edi, %edi
callq 0x7360
callq 0x30620
jmp 0x2e3e2
movq -0x28(%rbp), %rdi
callq 0x7260
jmp 0x2e3ed
leaq 0x1cfbc(%rip), %rdi     # 0x4b3b0
callq 0x2c900
jmp 0x2e3fb
jmp 0x2e083
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x7480
jmp 0x2e413
jmp 0x2e485
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x2e438
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x7170
leaq -0x48(%rbp), %rdi
callq 0x28480
callq 0x7480
jmp 0x2e448
jmp 0x2e485
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x2e470
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x7170
leaq -0x88(%rbp), %rdi
callq 0x28400
callq 0x7480
jmp 0x2e483
jmp 0x2e485
movq -0x18(%rbp), %rdi
callq 0x74e0
movq %rax, %rdi
callq 0x8c50
nopw %cs:(%rax,%rax)