// File: /workspace/github_c_makefile_star2_O0/mrdudz[P]run6502/run6502.c
// Function: main
int main(int argc, char **argv)
{
  M6502 *mpu= M6502_new(0, 0, 0);
  int bTraps= 0;

  program= argv[0];

  if ((2 == argc) && ('-' != *argv[1]))
    {
      if ((!loadInterpreter(mpu, 0, argv[1])) && (!load(mpu, 0, argv[1])))
	pfail(argv[1]);
      doBtraps(0, 0, mpu);
    }
  else
    while (++argv, --argc > 0)
      {
	int n= 0;
	if      (!strcmp(*argv, "-B"))  bTraps= 1;
	else if (!strcmp(*argv, "-d"))	n= doDisassemble(argc, argv, mpu);
	else if (!strcmp(*argv, "-G"))	n= doGtrap(argc, argv, mpu);
	else if (!strcmp(*argv, "-E"))	n= doEtrap(argc, argv, mpu);
	else if (!strcmp(*argv, "-h"))	n= doHelp(argc, argv, mpu);
	else if (!strcmp(*argv, "-i"))	n= doLoadInterpreter(argc, argv, mpu);
	else if (!strcmp(*argv, "-I"))	n= doIRQ(argc, argv, mpu);
	else if (!strcmp(*argv, "-l"))	n= doLoad(argc, argv, mpu);
	else if (!strcmp(*argv, "-M"))	n= doMtrap(argc, argv, mpu);
	else if (!strcmp(*argv, "-N"))	n= doNMI(argc, argv, mpu);
	else if (!strcmp(*argv, "-P"))	n= doPtrap(argc, argv, mpu);
	else if (!strcmp(*argv, "-R"))	n= doRST(argc, argv, mpu);
	else if (!strcmp(*argv, "-s"))	n= doSave(argc, argv, mpu);
	else if (!strcmp(*argv, "-v"))	n= doVersion(argc, argv, mpu);
	else if (!strcmp(*argv, "-X"))	n= doXtrap(argc, argv, mpu);
	else if (!strcmp(*argv, "-t"))	mpu->flags|=M6502_TraceExecution;
	else if (!strcmp(*argv, "-x"))	exit(0);
	else if ('-' == **argv)		usage(1);
	else
	  {
	    /* doBtraps() left 0x8000+0x4000 in bank 0, so load */
	    /* additional images starting at 15 and work down */
	    static int bankSel= 0x0F;
	    if (!bTraps)			usage(1);
	    if (bankSel < 0)			fail("too many images");
	    if (!load(mpu, 0x8000, argv[0]))	pfail(argv[0]);
	    memcpy(bank[bankSel--],
		   0x8000 + mpu->memory,
		   0x4000);
	    n= 1;
	  }
	argc -= n;
	argv += n;
      }

  if (bTraps)
    doBtraps(0, 0, mpu);

  M6502_reset(mpu);
  M6502_run(mpu);
  M6502_delete(mpu);

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rdi
movq %rdx, %rsi
callq 0x140a0
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x166f2(%rip)     # 0x18110
movl $0x2, %eax
cmpl -0x8(%rbp), %eax
jne 0x1a8d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %ecx
movl $0x2d, %eax
cmpl %ecx, %eax
je 0x1a8d
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %esi, %esi
callq 0x1f00
cmpl $0x0, %eax
jne 0x1a79
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %esi, %esi
callq 0x2010
cmpl $0x0, %eax
jne 0x1a79
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x13a0
movq -0x18(%rbp), %rdx
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x20d0
jmp 0x1eba
jmp 0x1a8f
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x0, %eax
jle 0x1eb8
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x13568(%rip), %rsi     # 0x1502a
callq 0x1100
cmpl $0x0, %eax
jne 0x1ad8
movl $0x1, -0x1c(%rbp)
jmp 0x1e93
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x13547(%rip), %rsi     # 0x1502d
callq 0x1100
cmpl $0x0, %eax
jne 0x1b08
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2260
movl %eax, -0x20(%rbp)
jmp 0x1e91
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x1351a(%rip), %rsi     # 0x15030
callq 0x1100
cmpl $0x0, %eax
jne 0x1b38
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2460
movl %eax, -0x20(%rbp)
jmp 0x1e8f
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x134ed(%rip), %rsi     # 0x15033
callq 0x1100
cmpl $0x0, %eax
jne 0x1b68
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x24c0
movl %eax, -0x20(%rbp)
jmp 0x1e8d
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x134c0(%rip), %rsi     # 0x15036
callq 0x1100
cmpl $0x0, %eax
jne 0x1b98
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2520
movl %eax, -0x20(%rbp)
jmp 0x1e8b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x13493(%rip), %rsi     # 0x15039
callq 0x1100
cmpl $0x0, %eax
jne 0x1bc8
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2550
movl %eax, -0x20(%rbp)
jmp 0x1e89
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x13466(%rip), %rsi     # 0x1503c
callq 0x1100
cmpl $0x0, %eax
jne 0x1bf8
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x25c0
movl %eax, -0x20(%rbp)
jmp 0x1e87
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x13439(%rip), %rsi     # 0x1503f
callq 0x1100
cmpl $0x0, %eax
jne 0x1c28
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2640
movl %eax, -0x20(%rbp)
jmp 0x1e85
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x1340c(%rip), %rsi     # 0x15042
callq 0x1100
cmpl $0x0, %eax
jne 0x1c58
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x26b0
movl %eax, -0x20(%rbp)
jmp 0x1e83
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x133df(%rip), %rsi     # 0x15045
callq 0x1100
cmpl $0x0, %eax
jne 0x1c88
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2730
movl %eax, -0x20(%rbp)
jmp 0x1e81
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x133b2(%rip), %rsi     # 0x15048
callq 0x1100
cmpl $0x0, %eax
jne 0x1cb8
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x27b0
movl %eax, -0x20(%rbp)
jmp 0x1e7f
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x13385(%rip), %rsi     # 0x1504b
callq 0x1100
cmpl $0x0, %eax
jne 0x1ce8
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2810
movl %eax, -0x20(%rbp)
jmp 0x1e7d
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x13358(%rip), %rsi     # 0x1504e
callq 0x1100
cmpl $0x0, %eax
jne 0x1d18
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2890
movl %eax, -0x20(%rbp)
jmp 0x1e7b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x1332b(%rip), %rsi     # 0x15051
callq 0x1100
cmpl $0x0, %eax
jne 0x1d48
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2920
movl %eax, -0x20(%rbp)
jmp 0x1e79
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x132fe(%rip), %rsi     # 0x15054
callq 0x1100
cmpl $0x0, %eax
jne 0x1d78
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x2950
movl %eax, -0x20(%rbp)
jmp 0x1e77
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x132d1(%rip), %rsi     # 0x15057
callq 0x1100
cmpl $0x0, %eax
jne 0x1da2
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rax)
jmp 0x1e75
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x132aa(%rip), %rsi     # 0x1505a
callq 0x1100
cmpl $0x0, %eax
jne 0x1dc1
xorl %edi, %edi
callq 0x11a0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %ecx
movl $0x2d, %eax
cmpl %ecx, %eax
jne 0x1de3
movl $0x1, %edi
callq 0x29b0
jmp 0x1e71
cmpl $0x0, -0x1c(%rbp)
jne 0x1df3
movl $0x1, %edi
callq 0x29b0
cmpl $0x0, 0x162fe(%rip)     # 0x180f8
jge 0x1e0a
leaq 0x1325a(%rip), %rdi     # 0x1505d
movb $0x0, %al
callq 0x12d0
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movl $0x8000, %esi           # imm = 0x8000
callq 0x2010
cmpl $0x0, %eax
jne 0x1e30
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x13a0
movl 0x162c2(%rip), %eax     # 0x180f8
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x162b7(%rip)     # 0x180f8
cltq
leaq 0x162d6(%rip), %rdi     # 0x18120
shlq $0xe, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x8000, %rsi           # imm = 0x8000
movl $0x4000, %edx           # imm = 0x4000
callq 0x1140
movl $0x1, -0x20(%rbp)
jmp 0x1e73
jmp 0x1e75
jmp 0x1e77
jmp 0x1e79
jmp 0x1e7b
jmp 0x1e7d
jmp 0x1e7f
jmp 0x1e81
jmp 0x1e83
jmp 0x1e85
jmp 0x1e87
jmp 0x1e89
jmp 0x1e8b
jmp 0x1e8d
jmp 0x1e8f
jmp 0x1e91
jmp 0x1e93
movl -0x20(%rbp), %ecx
movl -0x8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8(%rbp)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
jmp 0x1a8f
jmp 0x1eba
cmpl $0x0, -0x1c(%rbp)
je 0x1ecf
movq -0x18(%rbp), %rdx
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x20d0
movq -0x18(%rbp), %rdi
callq 0x7b90
movq -0x18(%rbp), %rdi
callq 0x7bf0
movq -0x18(%rbp), %rdi
callq 0x141c0
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)