// File: tomsmeding[P]MarioLANG/mariolang.cpp
// Function: main
int main(int argc,char **argv){
	if(argc==1){
		printf(
		 "Usage: %s [-a] [-d level] <file>\n"
		 "\t-a        Turn on \x1B[46ma\x1B[0mnimation mode.\n"
		 "\t-d level  Set \x1B[46md\x1B[0mebug level to 'level', where 'level' can be:\n"
		 "\t            -1: No fatal errors.\n"
		 "\t             0: No debug output. Default.\n"
		 "\t             1: Show errors.\n"
		 "\t             2: Plus one debug line per command.\n"
		 "\t             3: Frantic. Useless. Adds even more shit per executed command.\n"
		 "\t-T        Show the \x1B[46mT\x1B[0mape in animation mode.\n"
		 "\t-w msecs  Sets the time to \x1B[46mw\x1B[0mait between commands in milliseconds if animating. Useless otherwise.\n"
		 ,argv[0]);
		return 0;
	}
	signal(SIGINT,signalhandler);
	signal(SIGUSR1,signalhandler);
	debuglevel=0;
	animatedelay=250000;
	animate=false;
	animateShowTape=false;
	int i,j;
	bool skipNextArg=false;
	for(i=1;i<argc-1;i++){
		if(skipNextArg){skipNextArg=false;continue;}
		if(argv[i][0]=='-'){
			for(j=1;argv[i][j]!='\0';j++){
				if(argv[i][j]=='a')animate=true;
				else if(argv[i][j]=='d'){debuglevel=strtol(argv[i+1],NULL,10);skipNextArg=true;}
				else if(argv[i][j]=='T')animateShowTape=true;
				else if(argv[i][j]=='w'){animatedelay=strtol(argv[i+1],NULL,10)*1000;skipNextArg=true;}
				else {fprintf(stderr,"Unrecognised option %c\n",argv[i][j]);return 0;}
			}
		} else {
			fprintf(stderr,"Unrecognised argument %s\n",argv[i]);
			return 0;
		}
	}
	if(strcmp(argv[argc-1],"-")==0){
		L=new Level();
	} else {
		ifstream cf; //CodeFile
		cf.open(argv[argc-1]);
		if(!cf.is_open()){
			fprintf(stderr,"Could not open file '%s'\n",argv[argc-1]);
			fprintf(stderr,"Run %s without arguments for usage information.\n",argv[0]);
			return 0;
		}
		L=new Level(cf);
	}
	L->play();
	delete L;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
jne 0x2650
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x4b8a(%rip), %rdi      # 0x71c7
movb $0x0, %al
callq 0x2030
movl $0x0, -0x4(%rbp)
jmp 0x2a66
movl $0x2, %edi
leaq -0xcc(%rip), %rsi       # 0x2590
callq 0x21d0
movl $0xa, %edi
leaq -0xdd(%rip), %rsi       # 0x2590
callq 0x21d0
movl $0x0, 0x8b30(%rip)      # 0xb1ac
movl $0x3d090, 0x8b2a(%rip)  # imm = 0x3D090
movb $0x0, 0x8b27(%rip)      # 0xb1b4
movb $0x0, 0x8b21(%rip)      # 0xb1b5
movb $0x0, -0x19(%rbp)
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2867
testb $0x1, -0x19(%rbp)
je 0x26bf
movb $0x0, -0x19(%rbp)
jmp 0x2859
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x2827
movl $0x1, -0x18(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x2825
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x61, %eax
jne 0x2720
movb $0x1, 0x8a99(%rip)      # 0xb1b4
jmp 0x2815
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x64, %eax
jne 0x2767
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x2230
movl %eax, 0x8a4e(%rip)      # 0xb1ac
movb $0x1, -0x19(%rbp)
jmp 0x2813
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x54, %eax
jne 0x278c
movb $0x1, 0x8a2e(%rip)      # 0xb1b5
jmp 0x2811
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x77, %eax
jne 0x27d7
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x2230
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
movl %eax, 0x89df(%rip)      # 0xb1b0
movb $0x1, -0x19(%rbp)
jmp 0x280f
movq 0x87f2(%rip), %rax      # 0xafd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %edx
leaq 0x4bea(%rip), %rsi      # 0x73e6
movb $0x0, %al
callq 0x2250
movl $0x0, -0x4(%rbp)
jmp 0x2a66
jmp 0x2811
jmp 0x2813
jmp 0x2815
jmp 0x2817
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x26de
jmp 0x2857
movq 0x87a2(%rip), %rax      # 0xafd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x4bba(%rip), %rsi      # 0x73fe
movb $0x0, %al
callq 0x2250
movl $0x0, -0x4(%rbp)
jmp 0x2a66
jmp 0x2859
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x269f
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4b99(%rip), %rsi      # 0x7418
callq 0x2220
cmpl $0x0, %eax
jne 0x28dc
movl $0x58, %edi
callq 0x2170
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x248(%rbp)
callq 0x2ac0
jmp 0x28a7
movq -0x248(%rbp), %rax
movq %rax, 0x8903(%rip)      # 0xb1b8
jmp 0x2a22
movq -0x248(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x58, %esi
callq 0x2180
jmp 0x2a72
leaq -0x238(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x21a0
movq -0x250(%rbp), %rdi
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
decl %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
movl $0x8, %edx
callq 0x2120
jmp 0x2912
leaq -0x238(%rbp), %rdi
callq 0x22a0
movb %al, -0x251(%rbp)
jmp 0x2926
movb -0x251(%rbp), %al
testb $0x1, %al
jne 0x299b
jmp 0x2932
movq 0x8697(%rip), %rax      # 0xafd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x4ac6(%rip), %rsi      # 0x741a
movb $0x0, %al
callq 0x2250
movq 0x866e(%rip), %rax      # 0xafd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x4ac1(%rip), %rsi      # 0x7434
movb $0x0, %al
callq 0x2250
movl $0x0, -0x4(%rbp)
movl $0x1, -0x23c(%rbp)
jmp 0x29db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x2a14
movl $0x58, %edi
callq 0x2170
movq %rax, -0x260(%rbp)
jmp 0x29ae
movq -0x260(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x2b40
jmp 0x29c3
movq -0x260(%rbp), %rax
movq %rax, 0x87e7(%rip)      # 0xb1b8
movl $0x0, -0x23c(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x2060
movl -0x23c(%rbp), %eax
testl %eax, %eax
je 0x29f5
jmp 0x29f3
jmp 0x2a66
jmp 0x2a22
movq -0x260(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x58, %esi
callq 0x2180
leaq -0x238(%rbp), %rdi
callq 0x2060
jmp 0x2a72
movq 0x878f(%rip), %rdi      # 0xb1b8
callq 0x2d20
movq 0x8783(%rip), %rax      # 0xb1b8
movq %rax, -0x268(%rbp)
cmpq $0x0, %rax
je 0x2a5f
movq -0x268(%rbp), %rdi
callq 0x2e70
movq -0x268(%rbp), %rdi
movl $0x58, %esi
callq 0x2180
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x22e0
nopl (%rax,%rax)