// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rsi, %rbx
cmpl $0x1, %edi
jne 0x2548
movq (%rbx), %rsi
leaq 0x1b9b(%rip), %rdi      # 0x40d7
xorl %eax, %eax
callq 0x2030
jmp 0x26f9
movl %edi, %r14d
leaq -0x73(%rip), %r15       # 0x24df
pushq $0x2
popq %rdi
movq %r15, %rsi
callq 0x21a0
pushq $0xa
popq %rbp
movl %ebp, %edi
movq %r15, %rsi
callq 0x21a0
andl $0x0, 0x4c1b(%rip)      # 0x718c
movl $0x3d090, 0x4c15(%rip)  # imm = 0x3D090
xorl %eax, %eax
movb %al, 0x4c11(%rip)       # 0x7194
movb %al, 0x4c0c(%rip)       # 0x7195
decl %r14d
movslq %r14d, %r15
pushq $0x1
popq %r14
movq %r14, %r12
cmpq %r15, %r12
jge 0x262b
testb $0x1, %al
je 0x25a7
xorl %eax, %eax
jmp 0x2623
movq (%rbx,%r12,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x2742
xorl %eax, %eax
movq %r14, %r13
movzbl (%rdx,%r13), %ecx
cmpl $0x54, %ecx
je 0x25f7
cmpl $0x61, %ecx
je 0x25ee
cmpl $0x64, %ecx
je 0x2600
cmpl $0x77, %ecx
jne 0x261f
movq 0x8(%rbx,%r12,8), %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x2200
imull $0x3e8, %eax, %eax      # imm = 0x3E8
movl %eax, 0x4ba4(%rip)      # 0x7190
jmp 0x2614
movb $0x1, 0x4b9f(%rip)      # 0x7194
jmp 0x2616
movb $0x1, 0x4b97(%rip)      # 0x7195
jmp 0x2616
movq 0x8(%rbx,%r12,8), %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x2200
movl %eax, 0x4b78(%rip)      # 0x718c
movb $0x1, %al
incq %r13
movq (%rbx,%r12,8), %rdx
jmp 0x25b9
testl %ecx, %ecx
jne 0x269b
incq %r12
jmp 0x2596
movq (%rbx,%r15,8), %rax
cmpb $0x2d, (%rax)
jne 0x263a
cmpb $0x0, 0x1(%rax)
je 0x26b8
movq %rsp, %r14
movq %r14, %rdi
callq 0x2170
movq (%rbx,%r15,8), %rsi
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x20f0
leaq 0x78(%rsp), %rdi
callq 0x2060
movl %eax, %ebp
testb %al, %al
je 0x270d
pushq $0x58
popq %rdi
callq 0x2130
movq %rax, %r14
movq %rsp, %rsi
movq %rax, %rdi
callq 0x27e6
movq %r14, 0x4b13(%rip)      # 0x7198
movq %rsp, %rdi
callq 0x2070
testb %bpl, %bpl
je 0x26f9
movq 0x4aff(%rip), %r14      # 0x7198
jmp 0x26d2
movsbl %cl, %edx
movq 0x492b(%rip), %rax      # 0x6fd0
movq (%rax), %rdi
leaq 0x1c47(%rip), %rsi      # 0x42f6
xorl %eax, %eax
callq 0x2220
jmp 0x26f9
pushq $0x58
popq %rdi
callq 0x2130
movq %rax, %r14
movq %rax, %rdi
callq 0x2790
movq %r14, 0x4ac6(%rip)      # 0x7198
movq %r14, %rdi
callq 0x2906
movq 0x4ab7(%rip), %rbx      # 0x7198
testq %rbx, %rbx
je 0x26ee
movq %rbx, %rdi
callq 0x29d8
pushq $0x58
popq %rsi
movq %rbx, %rdi
callq 0x2140
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x48bc(%rip), %r14      # 0x6fd0
movq (%r14), %rdi
movq (%rbx,%r15,8), %rdx
leaq 0x1c06(%rip), %rsi      # 0x4328
xorl %eax, %eax
callq 0x2220
movq (%r14), %rdi
movq (%rbx), %rdx
leaq 0x1c0c(%rip), %rsi      # 0x4342
xorl %eax, %eax
callq 0x2220
jmp 0x2685
movq 0x4887(%rip), %rax      # 0x6fd0
movq (%rax), %rdi
leaq 0x1bbb(%rip), %rsi      # 0x430e
xorl %eax, %eax
callq 0x2220
jmp 0x26f9
movq %rax, %rbx
pushq $0x58
popq %rsi
movq %r14, %rdi
callq 0x2140
jmp 0x2787
movq %rax, %rbx
pushq $0x58
popq %rsi
movq %r14, %rdi
callq 0x2140
jmp 0x277f
movq %rax, %rbx
movq %rsp, %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x22a0
nop