// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x210, %rsp            # imm = 0x210
movq %rsi, %rbx
cmpl $0x1, %edi
jne 0x2c7c
movq (%rbx), %rsi
leaq 0x2467(%rip), %rdi      # 0x50d7
xorl %eax, %eax
callq 0x2030
jmp 0x2e96
movl %edi, %r14d
leaq -0x73(%rip), %r15       # 0x2c13
movl $0x2, %edi
movq %r15, %rsi
callq 0x2170
movl $0xa, %edi
movq %r15, %rsi
callq 0x2170
movl $0x0, 0x54c2(%rip)      # 0x816c
movl $0x3d090, 0x54bc(%rip)  # imm = 0x3D090
xorl %eax, %eax
movb %al, 0x54b8(%rip)       # 0x8174
movb %al, 0x54b3(%rip)       # 0x8175
leal -0x1(%r14), %ebp
cmpl $0x3, %r14d
jl 0x2d82
movl %ebp, %r14d
movl $0x1, %r15d
xorl %eax, %eax
testb $0x1, %al
je 0x2ce6
xorl %eax, %eax
jmp 0x2d76
movq (%rbx,%r15,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x2eb8
movl $0x1, %r12d
movq (%rbx,%r15,8), %rcx
movzbl (%rcx,%r12), %ecx
cmpl $0x63, %ecx
jg 0x2d1a
cmpl $0x54, %ecx
je 0x2d62
cmpl $0x61, %ecx
jne 0x2d6e
movb $0x1, 0x545c(%rip)      # 0x8174
jmp 0x2d69
cmpl $0x64, %ecx
je 0x2d47
cmpl $0x77, %ecx
jne 0x2e7b
movq 0x8(%rbx,%r15,8), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x21d0
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movl %eax, 0x542b(%rip)      # 0x8170
jmp 0x2d5e
movq 0x8(%rbx,%r15,8), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x21d0
movl %eax, 0x540e(%rip)      # 0x816c
movb $0x1, %al
jmp 0x2d69
movb $0x1, 0x540c(%rip)      # 0x8175
incq %r12
jmp 0x2cf9
testl %ecx, %ecx
jne 0x2e7b
incq %r15
cmpq %r14, %r15
jne 0x2cdb
movslq %ebp, %r14
movq (%rbx,%r14,8), %rdi
leaq 0x2598(%rip), %rsi      # 0x5328
callq 0x21c0
testl %eax, %eax
je 0x2e06
leaq (%rbx,%r14,8), %r14
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x2140
movq (%r14), %rsi
movq %r15, %rdi
movl $0x8, %edx
callq 0x20b0
leaq 0x80(%rsp), %rdi
callq 0x2050
movl %eax, %ebp
testb %al, %al
je 0x2ea8
movl $0x58, %edi
callq 0x2100
movq %rax, %r14
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x2f96
movq %r14, 0x5386(%rip)      # 0x8178
leaq 0x8(%rsp), %rdi
callq 0x2060
testb %bpl, %bpl
jne 0x2e22
jmp 0x2e96
movl $0x58, %edi
callq 0x2100
movq %rax, %r14
movq %rax, %rdi
callq 0x2f0c
movq %r14, 0x5356(%rip)      # 0x8178
movq 0x534f(%rip), %rdi      # 0x8178
callq 0x3104
movq 0x5343(%rip), %rbx      # 0x8178
testq %rbx, %rbx
je 0x2e96
leaq 0x30(%rbx), %rdi
callq 0x324a
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x2e58
movq 0x28(%rbx), %rsi
subq %rdi, %rsi
callq 0x2110
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x2e6c
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x2110
movl $0x58, %esi
movq %rbx, %rdi
callq 0x2110
jmp 0x2e96
movsbl %cl, %edx
movq 0x514b(%rip), %rax      # 0x7fd0
movq (%rax), %rdi
leaq 0x2467(%rip), %rsi      # 0x52f6
xorl %eax, %eax
callq 0x21f0
xorl %eax, %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2290
jmp 0x2df2
movq 0x5111(%rip), %rax      # 0x7fd0
movq (%rax), %rdi
leaq 0x2445(%rip), %rsi      # 0x530e
xorl %eax, %eax
callq 0x21f0
jmp 0x2e96
movq %rax, %rbx
movl $0x58, %esi
movq %r14, %rdi
callq 0x2110
jmp 0x2f03
movq %rax, %rbx
movl $0x58, %esi
movq %r14, %rdi
callq 0x2110
jmp 0x2ef9
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2250
nop