// File: /workspace/github_c_makefile_star2_O0/ShonFrazier[P]lib6502/run6502.c
// Function: main
int main(int argc, char **argv)
{
  M6502 *mpu= M6502_new(0, 0, 0);
  int bTraps= 0;
  int countCycles = 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, "-c"))	countCycles = 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, "-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, "-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);

  volatile unsigned long isns = 0, cycles = 0;

  if (!setjmp(exit_6502_env)){
    M6502_reset(mpu);
    if (countCycles){
      while (1){
	M6502_step(mpu);
	isns++;
	cycles += mpu->ticks;
	mpu->ticks = 0;
      }
    } else {
      M6502_run(mpu);
    }
  }
  if (countCycles){
    fprintf(stderr, "Instructions: %lu Cycles: %lu\n", isns, cycles);
  }
  M6502_delete(mpu);

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %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 0x24390
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x24fa3(%rip)     # 0x289e8
movl $0x2, %eax
cmpl -0x8(%rbp), %eax
jne 0x3ab4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %ecx
movl $0x2d, %eax
cmpl %ecx, %eax
je 0x3ab4
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %esi, %esi
callq 0x3f70
cmpl $0x0, %eax
jne 0x3aa0
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %esi, %esi
callq 0x4080
cmpl $0x0, %eax
jne 0x3aa0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x33b0
movq -0x18(%rbp), %rdx
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x4140
jmp 0x3ea9
jmp 0x3ab6
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 0x3ea7
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x21541(%rip), %rsi     # 0x2502a
callq 0x3100
cmpl $0x0, %eax
jne 0x3aff
movl $0x1, -0x1c(%rbp)
jmp 0x3e82
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x21520(%rip), %rsi     # 0x2502d
callq 0x3100
cmpl $0x0, %eax
jne 0x3b23
movl $0x1, -0x20(%rbp)
jmp 0x3e80
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x214ff(%rip), %rsi     # 0x25030
callq 0x3100
cmpl $0x0, %eax
jne 0x3b53
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x42d0
movl %eax, -0x24(%rbp)
jmp 0x3e7e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x214d2(%rip), %rsi     # 0x25033
callq 0x3100
cmpl $0x0, %eax
jne 0x3b83
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x44d0
movl %eax, -0x24(%rbp)
jmp 0x3e7c
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x214a5(%rip), %rsi     # 0x25036
callq 0x3100
cmpl $0x0, %eax
jne 0x3bb3
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x4530
movl %eax, -0x24(%rbp)
jmp 0x3e7a
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x21478(%rip), %rsi     # 0x25039
callq 0x3100
cmpl $0x0, %eax
jne 0x3be3
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x4560
movl %eax, -0x24(%rbp)
jmp 0x3e78
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x2144b(%rip), %rsi     # 0x2503c
callq 0x3100
cmpl $0x0, %eax
jne 0x3c13
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x45d0
movl %eax, -0x24(%rbp)
jmp 0x3e76
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x2141e(%rip), %rsi     # 0x2503f
callq 0x3100
cmpl $0x0, %eax
jne 0x3c43
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x4650
movl %eax, -0x24(%rbp)
jmp 0x3e74
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x213f1(%rip), %rsi     # 0x25042
callq 0x3100
cmpl $0x0, %eax
jne 0x3c73
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x46c0
movl %eax, -0x24(%rbp)
jmp 0x3e72
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x213c4(%rip), %rsi     # 0x25045
callq 0x3100
cmpl $0x0, %eax
jne 0x3ca3
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x4740
movl %eax, -0x24(%rbp)
jmp 0x3e70
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x21397(%rip), %rsi     # 0x25048
callq 0x3100
cmpl $0x0, %eax
jne 0x3cd3
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x47c0
movl %eax, -0x24(%rbp)
jmp 0x3e6e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x2136a(%rip), %rsi     # 0x2504b
callq 0x3100
cmpl $0x0, %eax
jne 0x3d03
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x4820
movl %eax, -0x24(%rbp)
jmp 0x3e6c
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x2133d(%rip), %rsi     # 0x2504e
callq 0x3100
cmpl $0x0, %eax
jne 0x3d33
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x48a0
movl %eax, -0x24(%rbp)
jmp 0x3e6a
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x21310(%rip), %rsi     # 0x25051
callq 0x3100
cmpl $0x0, %eax
jne 0x3d63
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x4930
movl %eax, -0x24(%rbp)
jmp 0x3e68
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x212e3(%rip), %rsi     # 0x25054
callq 0x3100
cmpl $0x0, %eax
jne 0x3d93
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x4960
movl %eax, -0x24(%rbp)
jmp 0x3e66
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x212b6(%rip), %rsi     # 0x25057
callq 0x3100
cmpl $0x0, %eax
jne 0x3db2
xorl %edi, %edi
callq 0x31b0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %ecx
movl $0x2d, %eax
cmpl %ecx, %eax
jne 0x3dd4
movl $0x1, %edi
callq 0x49c0
jmp 0x3e62
cmpl $0x0, -0x1c(%rbp)
jne 0x3de4
movl $0x1, %edi
callq 0x49c0
cmpl $0x0, 0x24315(%rip)     # 0x28100
jge 0x3dfb
leaq 0x21266(%rip), %rdi     # 0x2505a
movb $0x0, %al
callq 0x32e0
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movl $0x8000, %esi           # imm = 0x8000
callq 0x4080
cmpl $0x0, %eax
jne 0x3e21
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x33b0
movl 0x242d9(%rip), %eax     # 0x28100
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x242ce(%rip)     # 0x28100
cltq
leaq 0x24bb5(%rip), %rdi     # 0x289f0
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 0x3140
movl $0x1, -0x24(%rbp)
jmp 0x3e64
jmp 0x3e66
jmp 0x3e68
jmp 0x3e6a
jmp 0x3e6c
jmp 0x3e6e
jmp 0x3e70
jmp 0x3e72
jmp 0x3e74
jmp 0x3e76
jmp 0x3e78
jmp 0x3e7a
jmp 0x3e7c
jmp 0x3e7e
jmp 0x3e80
jmp 0x3e82
movl -0x24(%rbp), %ecx
movl -0x8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8(%rbp)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
jmp 0x3ab6
jmp 0x3ea9
cmpl $0x0, -0x1c(%rbp)
je 0x3ebe
movq -0x18(%rbp), %rdx
xorl %edi, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x4140
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
leaq 0x24a4b(%rip), %rdi     # 0x28920
callq 0x30e0
cmpl $0x0, %eax
jne 0x3f2f
movq -0x18(%rbp), %rdi
callq 0x5140
cmpl $0x0, -0x20(%rbp)
je 0x3f24
jmp 0x3ef0
movq -0x18(%rbp), %rdi
callq 0x13f90
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x1c(%rax), %eax
movl %eax, %ecx
movq -0x38(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movb $0x0, 0x1c(%rax)
jmp 0x3ef0
movq -0x18(%rbp), %rdi
callq 0x51a0
jmp 0x3f2f
cmpl $0x0, -0x20(%rbp)
je 0x3f55
movq 0x240bc(%rip), %rax     # 0x27ff8
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x2111c(%rip), %rsi     # 0x2506a
movb $0x0, %al
callq 0x3120
movq -0x18(%rbp), %rdi
callq 0x244c0
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)