// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r13
movl %edi, %ebp
xorl %eax, %eax
movl %eax, %edi
movq %rdi, %rsi
movq %rdi, %rdx
callq 0xd62e
movq %rax, %rbx
movq (%r13), %rax
movq %rax, 0x9ba4(%rip)      # 0x121e8
cmpl $0x2, %ebp
jne 0x8656
movq 0x8(%r13), %rdx
cmpb $0x2d, (%rdx)
jne 0x8d1a
movb $0x1, %al
movl %eax, %ecx
cmpl $0x2, %ebp
jl 0x8d4a
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
movl %r12d, %r14d
movl %r12d, %esi
movl %esi, (%rsp)
leaq 0x8(%r13), %rax
movq %rax, 0x8(%rsp)
movl %ebp, %eax
decl %eax
movl %eax, 0x1c(%rsp)
movq %r13, 0x10(%rsp)
movq 0x8(%r13), %r13
movq %r13, %rdi
leaq 0x59c2(%rip), %rsi      # 0xe05a
callq 0x3110
testl %eax, %eax
je 0x8882
movl %r14d, 0x4(%rsp)
movq %r13, %rdi
leaq 0x59a9(%rip), %rsi      # 0xe05d
callq 0x3110
testl %eax, %eax
je 0x888c
movq %r13, %rdi
leaq 0x5995(%rip), %rsi      # 0xe060
callq 0x3110
testl %eax, %eax
je 0x889c
movq %r13, %rdi
leaq 0x5981(%rip), %rsi      # 0xe063
callq 0x3110
testl %eax, %eax
je 0x88d0
movq %r13, %rdi
leaq 0x596d(%rip), %rsi      # 0xe066
callq 0x3110
testl %eax, %eax
je 0x8df1
movq %r13, %rdi
leaq 0x5959(%rip), %rsi      # 0xe069
callq 0x3110
testl %eax, %eax
je 0x8a8f
movq %r13, %rdi
leaq 0x5945(%rip), %rsi      # 0xe06c
callq 0x3110
testl %eax, %eax
je 0x8ab7
movq %r13, %rdi
leaq 0x5931(%rip), %rsi      # 0xe06f
callq 0x3110
testl %eax, %eax
je 0x8ae9
movq %r13, %rdi
leaq 0x591d(%rip), %rsi      # 0xe072
callq 0x3110
testl %eax, %eax
je 0x8b2d
movq %r13, %rdi
leaq 0x5909(%rip), %rsi      # 0xe075
callq 0x3110
testl %eax, %eax
je 0x8b71
movq %r13, %rdi
leaq 0x58f5(%rip), %rsi      # 0xe078
callq 0x3110
testl %eax, %eax
je 0x8ba0
movq %r13, %rdi
leaq 0x58e1(%rip), %rsi      # 0xe07b
callq 0x3110
testl %eax, %eax
je 0x8bc9
movq %r13, %rdi
leaq 0x58cd(%rip), %rsi      # 0xe07e
callq 0x3110
testl %eax, %eax
je 0x8c2b
movq %r13, %rdi
leaq 0x58b9(%rip), %rsi      # 0xe081
callq 0x3110
testl %eax, %eax
je 0x8e0a
movq %r13, %rdi
leaq 0x58a5(%rip), %rsi      # 0xe084
callq 0x3110
testl %eax, %eax
movl 0x4(%rsp), %ebp
je 0x8ceb
movq %r13, %rdi
leaq 0x588d(%rip), %rsi      # 0xe087
callq 0x3110
testl %eax, %eax
je 0x8e16
cmpb $0x2d, (%r13)
je 0x8de7
cmpl $0x0, (%rsp)
movq 0x8(%rsp), %r13
je 0x8de7
cmpl $0x0, 0x98e0(%rip)      # 0x12108
js 0x8e1d
movq (%r13), %rdx
movq %rbx, %rdi
movl $0x8000, %esi           # imm = 0x8000
callq 0x8ed4
testl %eax, %eax
je 0x8e2b
movslq 0x98ba(%rip), %rax      # 0x12108
movq %rax, %rdi
decl %eax
movl %eax, 0x98af(%rip)      # 0x12108
shlq $0xe, %rdi
leaq 0x998c(%rip), %rax      # 0x121f0
addq %rax, %rdi
movq 0x8(%rbx), %rsi
movl $0x8000, %eax           # imm = 0x8000
addq %rax, %rsi
movl $0x4000, %edx           # imm = 0x4000
callq 0x3150
jmp 0x8cff
movl $0x1, %ecx
movl %r14d, %edx
jmp 0x8894
movl $0x1, %edx
movl (%rsp), %ecx
movl %r12d, %esi
jmp 0x8c02
cmpl $0x3, %ebp
jle 0x8de7
movq 0x10(%rsp), %r14
movq 0x10(%r14), %rdi
callq 0x92dc
movq %rax, %r13
movq 0x18(%r14), %rdi
cmpb $0x2b, (%rdi)
movl 0x4(%rsp), %ebp
jne 0x8901
incq %rdi
callq 0x92dc
addq %r13, %rax
jmp 0x8906
cmpl $0x2, %ebp
je 0x8de7
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x92dc
movq 0x10(%rbx), %rcx
movl %eax, %eax
leaq 0xa20(%rip), %rdx       # 0x9314
movq %rdx, 0x100000(%rcx,%rax,8)
jmp 0x8bf6
callq 0x92dc
movq %rax, %rcx
movl $0x2, %esi
movl %ecx, 0x24(%rsp)
cmpl %ecx, %r13d
jae 0x8a85
movl %r13d, %ebp
movzwl %bp, %esi
movq %rbx, %rdi
movq %r15, %rdx
callq 0xc633
movl %eax, %r13d
movl %r12d, %eax
leaq 0x5780(%rip), %rdi      # 0xe0b9
movl %ebp, %esi
callq 0x30a0
movl %r13d, %eax
testl %r13d, %r13d
movl %ebp, 0x18(%rsp)
movl %eax, 0x20(%rsp)
jle 0x8992
movl %eax, %ecx
movl %ebp, %eax
xorl %r14d, %r14d
leaq 0x6435(%rip), %rbp      # 0xed93
movq %rcx, %r15
movl %eax, %r12d
movq 0x8(%rbx), %rax
movl %r12d, %ecx
movzbl (%rax,%rcx), %esi
movl %r14d, %eax
movq %rbp, %rdi
callq 0x30a0
incl %r12d
movl %r12d, %eax
decq %r15
movq %r15, %rcx
jne 0x895e
movl %r13d, %eax
incl %eax
xorl %r12d, %r12d
jmp 0x8997
movl $0x1, %eax
cmpl $0x3, %eax
leaq 0x571e(%rip), %r14      # 0xe0bf
movl $0x20, %ebp
ja 0x89cb
testl %r13d, %r13d
movl %r12d, %eax
cmovgl %r13d, %eax
addl $-0x3, %eax
movl %eax, %r15d
movl %r12d, %eax
movq %r14, %rdi
callq 0x30a0
incl %r15d
movl %r15d, %eax
jne 0x89b5
movl %ebp, %edi
callq 0x3040
testl %r13d, %r13d
jle 0x8a21
callq 0x31e0
movq %rax, %r12
movl 0x20(%rsp), %eax
movl %eax, %r14d
movl 0x18(%rsp), %r15d
movq (%r12), %rcx
movq 0x8(%rbx), %rax
movl %r15d, %edx
movzbl (%rax,%rdx), %eax
movl %eax, %edx
cmpw $0x0, (%rcx,%rdx,2)
movl $0x20, %edi
jns 0x8a0a
movl %eax, %edi
callq 0x3040
incl %r15d
decq %r14
jne 0x89eb
movl %r13d, %eax
incl %eax
xorl %r12d, %r12d
jmp 0x8a26
movl $0x1, %eax
cmpl $0x3, %eax
leaq 0x30(%rsp), %r15
ja 0x8a4f
testl %r13d, %r13d
movl %r12d, %eax
cmovgl %r13d, %eax
addl $-0x3, %eax
movl %eax, %r14d
movl %ebp, %edi
callq 0x3040
incl %r14d
movl %r14d, %eax
jne 0x8a3d
movl %r12d, %eax
leaq 0x56f2(%rip), %rdi      # 0xe14b
movq %r15, %rsi
callq 0x30a0
addl 0x18(%rsp), %r13d
movl %r13d, %ebp
cmpl 0x24(%rsp), %r13d
jb 0x891e
movl (%rsp), %ecx
movl 0x4(%rsp), %edx
movl $0x2, %esi
jmp 0x8c02
movl (%rsp), %ecx
movl %ebp, %edx
jmp 0x8c02
cmpl $0x3, %ebp
jle 0x8de7
movq 0x10(%rsp), %r14
movq 0x10(%r14), %rdi
callq 0x92dc
movq 0x18(%r14), %rdx
movzwl %ax, %esi
movq %rbx, %rdi
callq 0x8e3d
jmp 0x8b0f
cmpl $0x2, %ebp
je 0x8de7
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x92dc
movl %eax, %ecx
movq 0x8(%rbx), %rdx
movb %al, 0xfffe(%rdx)
movq 0x8(%rbx), %rax
movb %ch, 0xffff(%rax)
jmp 0x8bf6
cmpl $0x3, %ebp
jle 0x8de7
movq 0x10(%rsp), %r14
movq 0x10(%r14), %rdi
callq 0x92dc
movq 0x18(%r14), %rdx
movzwl %ax, %esi
movq %rbx, %rdi
callq 0x8ed4
movl $0x2, %esi
movl (%rsp), %ecx
movl 0x4(%rsp), %edx
testl %eax, %eax
movq 0x8(%rsp), %r13
jne 0x8c07
jmp 0x8df8
cmpl $0x2, %ebp
je 0x8de7
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x92dc
movq 0x10(%rbx), %rcx
movl %eax, %eax
shlq $0x3, %rax
leaq 0x801(%rip), %rdx       # 0x9356
movq %rdx, (%rcx,%rax)
movq 0x10(%rbx), %rcx
leaq 0x7f7(%rip), %rdx       # 0x935b
movq %rdx, 0x80000(%rcx,%rax)
jmp 0x8bf6
cmpl $0x2, %ebp
je 0x8de7
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x92dc
movl %eax, %ecx
movq 0x8(%rbx), %rdx
movb %al, 0xfffa(%rdx)
movq 0x8(%rbx), %rax
movb %ch, 0xfffb(%rax)
jmp 0x8bf6
cmpl $0x2, %ebp
je 0x8de7
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x92dc
movq 0x10(%rbx), %rcx
movl %eax, %eax
leaq 0x79e(%rip), %rdx       # 0x9362
jmp 0x88f4
cmpl $0x2, %ebp
je 0x8de7
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x92dc
movl %eax, %ecx
movq 0x8(%rbx), %rdx
movb %al, 0xfffc(%rdx)
movq 0x8(%rbx), %rax
movb %ch, 0xfffd(%rax)
movl $0x1, %esi
movl (%rsp), %ecx
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %r13
movl 0x1c(%rsp), %edi
subl %esi, %edi
movl %esi, %esi
movl %esi, %eax
leaq (%r13,%rax,8), %r13
movl %edx, %r14d
movl %ecx, %esi
movl %edi, %ebp
cmpl $0x1, %edi
jg 0x8671
jmp 0x8d0e
cmpl $0x4, %ebp
jle 0x8de7
movq 0x10(%rsp), %r14
movq 0x10(%r14), %rdi
callq 0x92dc
movq %rax, %r12
movq 0x18(%r14), %rdi
callq 0x92dc
movq %rax, %r13
movq 0x20(%r14), %rdi
leaq 0x5479(%rip), %rsi      # 0xe0d5
callq 0x3180
testq %rax, %rax
movl $0x1, %esi
je 0x8e34
movq %r12, %r14
movq %r13, %rbp
movq %rax, %r13
movzwl %r14w, %eax
movl %eax, %edi
addq 0x8(%rbx), %rdi
movl %ebp, %eax
movl %eax, %edx
movq %r13, %rcx
callq 0x31d0
testl %eax, %eax
movl $0x1, %r12d
je 0x8ccf
movl %r14d, %esi
movq %rax, %rcx
movl %ebp, %edx
movl %edx, %ebp
subl %eax, %ebp
movl %ecx, %eax
movl %esi, %ecx
addl %eax, %ecx
movl %ecx, %r14d
movzwl %cx, %eax
movl %eax, %edi
addq 0x8(%rbx), %rdi
movl %ebp, %edx
movq %r12, %rsi
movq %r13, %rcx
callq 0x31d0
movq %rax, %rcx
movl %ebp, %edx
movl %r14d, %esi
testl %eax, %eax
jne 0x8ca0
movq %r13, %rdi
callq 0x3080
movl $0x3, %esi
movl (%rsp), %ecx
movl 0x4(%rsp), %edx
xorl %r12d, %r12d
jmp 0x8c02
movl 0x1c(%rsp), %edi
movq 0x8(%rsp), %r13
movq %r13, %rsi
movq %rbx, %rdx
callq 0x9033
movl $0x1, %esi
movl (%rsp), %ecx
movl %ebp, %edx
jmp 0x8c07
testl %ecx, %ecx
sete %al
testl %edx, %edx
sete %cl
jmp 0x8d4a
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8e3d
testl %eax, %eax
jne 0x8d3e
movq 0x8(%r13), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8ed4
testl %eax, %eax
je 0x8e01
movq %rbx, %rdi
callq 0x8f48
movb $0x1, %al
movl %eax, %ecx
movl %ecx, %ebp
testb %al, %al
jne 0x8d58
movq %rbx, %rdi
callq 0x8f48
xorl %eax, %eax
movq %rax, 0x30(%rsp)
movq %rax, 0x28(%rsp)
leaq 0x93b5(%rip), %rdi      # 0x12120
callq 0x30f0
testl %eax, %eax
jne 0x8d89
movq %rbx, %rdi
callq 0x94ae
testb %bpl, %bpl
je 0x8da7
movq %rbx, %rdi
callq 0x328e
testb %bpl, %bpl
je 0x8dc3
movq %rbx, %rdi
callq 0xd712
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x94dd
incq 0x30(%rsp)
movzbl 0x1c(%rbx), %eax
addq %rax, 0x28(%rsp)
movb $0x0, 0x1c(%rbx)
jmp 0x8da7
movq 0x922e(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq 0x30(%rsp), %rdx
movq 0x28(%rsp), %rcx
leaq 0x52bc(%rip), %rsi      # 0xe09a
xorl %eax, %eax
callq 0x3130
jmp 0x8d8e
movl $0x1, %edi
callq 0x9066
xorl %edi, %edi
callq 0x9066
movq 0x18(%r14), %rdi
callq 0x8355
movq 0x8(%r13), %rdi
callq 0x8355
leaq 0x52c6(%rip), %rdi      # 0xe0d7
callq 0x3060
xorl %edi, %edi
callq 0x31c0
leaq 0x5266(%rip), %rdi      # 0xe08a
xorl %eax, %eax
callq 0x829c
movq (%r13), %rdi
callq 0x8355
movq 0x20(%r14), %rdi
callq 0x8355