// File: mikeakohn[P]cloudtari/build/../src/cloudtari.cxx
// Function: main
int main(int argc, char *argv[])
{
  int cycles;
  bool debug = false;
  bool step = false;
  int step_address = -1;
  int port = 5900;
  Television *television;

  // Used to see how many CPU cycles a set of instructions takes.
  DebugTimer debug_timer;

  if (argc < 3 || argc > 5)
  {
    printf(
      "Usage: %s <gamefile.bin> <null/sdl/vnc/debug/break/timer/step>\n"
      "          null\n"
#ifdef USE_SDL
      "          sdl\n"
#endif
      "          vnc <port>\n"
      "          http <port>\n"
      "          debug\n"
      "          break <address>\n"
      "          timer <start_address> <end_address>\n"
      "          step <start_address>\n",
      argv[0]);
    exit(0);
  }

  M6502 *m6502 = new M6502();
  MemoryBus *memory_bus = new MemoryBus();
  ROM *rom = new ROM();

  if (rom->load(argv[1]) != 0) { exit(-1); }

  memory_bus->init();
  memory_bus->set_rom(rom);
  m6502->set_memory_bus(memory_bus);
  m6502->reset();

#ifdef USE_SDL
  if (strcmp(argv[2], "sdl") == 0)
  {
    television = new TelevisionSDL();
  }
    else
#endif
  if (strcmp(argv[2], "vnc") == 0)
  {
    television = new TelevisionVNC();

    if (argc > 3) { port = atoi(argv[3]); }

    television->set_port(port);
  }
    else
  if (strcmp(argv[2], "http") == 0)
  {
    television = new TelevisionHttp();

    port = 8080;
    if (argc > 3) { port = atoi(argv[3]); }

    television->set_port(port);
  }
    else
  if (strcmp(argv[2], "debug") == 0)
  {
    television = new TelevisionNull();
    debug = true;
    m6502->set_debug();
  }
    else
  if (strcmp(argv[2], "break") == 0)
  {
    television = new TelevisionNull();

    int address = 0xf000;
    if (argc > 3) { address = strtol(argv[3], NULL, 0); }
    debug = true;
    m6502->set_breakpoint(address);
  }
    else
  if (strcmp(argv[2], "timer") == 0)
  {
    television = new TelevisionNull();
    debug = true;
    m6502->set_debug();

    int address_start = -1, address_end = -1;

    if (argc > 3) { address_start = strtol(argv[3], NULL, 0); }
    if (argc > 4) { address_end = strtol(argv[4], NULL, 0); }

    debug_timer.set(address_start, address_end);
  }
    else
  if (strcmp(argv[2], "step") == 0)
  {
    television = new TelevisionNull();
    debug = true;
    m6502->set_debug();

    step_address = 0xf000;
    if (argc > 3) { step_address = strtol(argv[3], NULL, 0); }
  }
    else
  if (strcmp(argv[2], "null") == 0)
  {
    television = new TelevisionNull();
  }
    else
  {
    printf("Unknown mode %s\n", argv[2]);
    exit(1);
  }

  if (television->init() != 0)
  {
    delete m6502;
    delete rom;
    delete memory_bus;
    delete television;

    printf("Display init error.\n");
    return -1;
  }

  RIOT *riot = memory_bus->get_riot();
  TIA *tia = memory_bus->get_tia();
  tia->set_television(television);

  // memory_bus->dump(0xf000, 0xffff);

  while (m6502->is_running())
  {
    if (m6502->get_pc() == step_address)
    {
      step = true;
    }

    if (tia->wait_for_hsync())
    {
      cycles = 1;
      m6502->clock();
    }
      else
    {
      //int address = m6502->get_pc();
      cycles = m6502->step();
      //debug_timer.compute(address, cycles);
    }

    memory_bus->clock(cycles);

    if (debug)
    {
      printf("  cycles=%d\n", cycles);
      m6502->dump();
      tia->dump();
      memory_bus->dump(0x80, 0xff);

      if (!tia->wait_for_hsync())
      {
        //sleep(1);
        usleep(1000);
      }
    }

    if (tia->need_check_events())
    {
      int event_code = television->handle_events();

      if (event_code == Television::KEY_QUIT) { break; }

      switch (event_code)
      {
        case Television::KEY_SELECT_DOWN:
          riot->set_switch_select();
          break;
        case Television::KEY_SELECT_UP:
          riot->clear_switch_select();
          break;
        case Television::KEY_RESET_DOWN:
          riot->set_switch_reset();
          break;
        case Television::KEY_RESET_UP:
          riot->clear_switch_reset();
          break;
        case Television::KEY_LEFT_DOWN:
          riot->set_joystick_0_left();
          break;
        case Television::KEY_LEFT_UP:
          riot->clear_joystick_0_left();
          break;
        case Television::KEY_RIGHT_DOWN:
          riot->set_joystick_0_right();
          break;
        case Television::KEY_RIGHT_UP:
          riot->clear_joystick_0_right();
          break;
        case Television::KEY_UP_DOWN:
          riot->set_joystick_0_up();
          break;
        case Television::KEY_UP_UP:
          riot->clear_joystick_0_up();
          break;
        case Television::KEY_DOWN_DOWN:
          riot->set_joystick_0_down();
          break;
        case Television::KEY_DOWN_UP:
          riot->clear_joystick_0_down();
          break;
        case Television::KEY_FIRE_DOWN:
          tia->set_joystick_0_fire();
          break;
        case Television::KEY_FIRE_UP:
          tia->clear_joystick_0_fire();
          break;
      }
    }

    if (step)
    {
      getchar();
    }
  }

#if 0
   m6502->dump();
   tia->dump();
   memory_bus->dump(0x80, 0xff);
#endif

  delete m6502;
  delete rom;
  delete memory_bus;
  delete television;

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x15(%rbp)
movb $0x0, -0x16(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl $0x170c, -0x20(%rbp)    # imm = 0x170C
leaq -0x38(%rbp), %rdi
callq 0x5040
cmpl $0x3, -0x8(%rbp)
jl 0x4564
cmpl $0x5, -0x8(%rbp)
jle 0x4593
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0xaaca(%rip), %rdi      # 0xf03c
xorl %eax, %eax
callq 0x4050
jmp 0x457b
xorl %edi, %edi
callq 0x42f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5026
movl $0x30, %edi
callq 0x4260
movq %rax, -0x90(%rbp)
jmp 0x45a6
movq -0x90(%rbp), %rdi
callq 0x6460
jmp 0x45b4
movq -0x90(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x18, %edi
callq 0x4260
movq %rax, -0x98(%rbp)
jmp 0x45d2
movq -0x98(%rbp), %rdi
callq 0x95d0
jmp 0x45e0
movq -0x98(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x3004, %edi           # imm = 0x3004
callq 0x4260
movq %rax, -0xa0(%rbp)
jmp 0x45fe
movq -0xa0(%rbp), %rdi
callq 0xa420
jmp 0x460c
movq -0xa0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xa460
movl %eax, -0xa4(%rbp)
jmp 0x4630
movl -0xa4(%rbp), %eax
cmpl $0x0, %eax
je 0x46ab
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42f0
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x30, %esi
callq 0x4270
jmp 0x5026
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x18, %esi
callq 0x4270
jmp 0x5026
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x3004, %esi           # imm = 0x3004
callq 0x4270
jmp 0x5026
movq -0x58(%rbp), %rdi
callq 0x96f0
jmp 0x46b6
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x5070
jmp 0x46c5
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x5090
jmp 0x46d4
movq -0x50(%rbp), %rdi
callq 0x64d0
jmp 0x46df
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0xaa4d(%rip), %rsi      # 0xf13b
callq 0x4360
cmpl $0x0, %eax
jne 0x474b
movl $0x58, %edi
callq 0x4260
movq %rax, -0xb0(%rbp)
jmp 0x470b
movq -0xb0(%rbp), %rdi
callq 0xe980
jmp 0x4719
movq -0xb0(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x4bb9
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x58, %esi
callq 0x4270
jmp 0x5026
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0xa9e5(%rip), %rsi      # 0xf13f
callq 0x4360
cmpl $0x0, %eax
jne 0x47e1
movl $0x60, %edi
callq 0x4260
movq %rax, -0xb8(%rbp)
jmp 0x4777
movq -0xb8(%rbp), %rdi
callq 0xd5c0
jmp 0x4785
movq -0xb8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x3, -0x8(%rbp)
jle 0x47ca
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x43b0
movl %eax, -0x20(%rbp)
jmp 0x47ca
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x60, %esi
callq 0x4270
jmp 0x5026
movq -0x28(%rbp), %rdi
movl -0x20(%rbp), %esi
movq (%rdi), %rax
movq 0x38(%rax), %rax
callq *%rax
jmp 0x47dc
jmp 0x4bb7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0xa953(%rip), %rsi      # 0xf143
callq 0x4360
cmpl $0x0, %eax
jne 0x4882
movl $0x180, %edi            # imm = 0x180
callq 0x4260
movq %rax, -0xc0(%rbp)
jmp 0x4811
movq -0xc0(%rbp), %rdi
callq 0xbf00
jmp 0x481f
movq -0xc0(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x1f90, -0x20(%rbp)    # imm = 0x1F90
cmpl $0x3, -0x8(%rbp)
jle 0x486b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x43b0
movl %eax, -0x20(%rbp)
jmp 0x486b
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x180, %esi            # imm = 0x180
callq 0x4270
jmp 0x5026
movq -0x28(%rbp), %rdi
movl -0x20(%rbp), %esi
movq (%rdi), %rax
movq 0x38(%rax), %rax
callq *%rax
jmp 0x487d
jmp 0x4bb5
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0xa8b7(%rip), %rsi      # 0xf148
callq 0x4360
cmpl $0x0, %eax
jne 0x48fd
movl $0x28, %edi
callq 0x4260
movq %rax, -0xc8(%rbp)
jmp 0x48ae
movq -0xc8(%rbp), %rdi
callq 0xd4a0
jmp 0x48bc
movq -0xc8(%rbp), %rax
movq %rax, -0x28(%rbp)
movb $0x1, -0x15(%rbp)
movq -0x50(%rbp), %rdi
callq 0x50b0
jmp 0x48d6
jmp 0x4bb3
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x28, %esi
callq 0x4270
jmp 0x5026
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0xa842(%rip), %rsi      # 0xf14e
callq 0x4360
cmpl $0x0, %eax
jne 0x49a4
movl $0x28, %edi
callq 0x4260
movq %rax, -0xd0(%rbp)
jmp 0x492d
movq -0xd0(%rbp), %rdi
callq 0xd4a0
jmp 0x493b
movq -0xd0(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0xf000, -0x64(%rbp)    # imm = 0xF000
cmpl $0x3, -0x8(%rbp)
jle 0x498d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x4370
movl %eax, -0x64(%rbp)
jmp 0x498d
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x28, %esi
callq 0x4270
jmp 0x5026
movb $0x1, -0x15(%rbp)
movq -0x50(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x50d0
jmp 0x499f
jmp 0x4bb1
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0xa7a1(%rip), %rsi      # 0xf154
callq 0x4360
cmpl $0x0, %eax
jne 0x4a7c
movl $0x28, %edi
callq 0x4260
movq %rax, -0xd8(%rbp)
jmp 0x49d4
movq -0xd8(%rbp), %rdi
callq 0xd4a0
jmp 0x49e2
movq -0xd8(%rbp), %rax
movq %rax, -0x28(%rbp)
movb $0x1, -0x15(%rbp)
movq -0x50(%rbp), %rdi
callq 0x50b0
jmp 0x49fc
movl $0xffffffff, -0x68(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x6c(%rbp) # imm = 0xFFFFFFFF
cmpl $0x3, -0x8(%rbp)
jle 0x4a4a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x4370
movl %eax, -0x68(%rbp)
jmp 0x4a4a
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x28, %esi
callq 0x4270
jmp 0x5026
cmpl $0x4, -0x8(%rbp)
jle 0x4a66
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x4370
movl %eax, -0x6c(%rbp)
movl -0x68(%rbp), %esi
movl -0x6c(%rbp), %edx
leaq -0x38(%rbp), %rdi
callq 0x50f0
jmp 0x4a77
jmp 0x4baf
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0xa6cf(%rip), %rsi      # 0xf15a
callq 0x4360
cmpl $0x0, %eax
jne 0x4b20
movl $0x28, %edi
callq 0x4260
movq %rax, -0xe0(%rbp)
jmp 0x4aac
movq -0xe0(%rbp), %rdi
callq 0xd4a0
jmp 0x4aba
movq -0xe0(%rbp), %rax
movq %rax, -0x28(%rbp)
movb $0x1, -0x15(%rbp)
movq -0x50(%rbp), %rdi
callq 0x50b0
jmp 0x4ad4
movl $0xf000, -0x1c(%rbp)    # imm = 0xF000
cmpl $0x3, -0x8(%rbp)
jle 0x4b1b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x4370
movl %eax, -0x1c(%rbp)
jmp 0x4b1b
movq -0xe0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x28, %esi
callq 0x4270
jmp 0x5026
jmp 0x4bad
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0xa630(%rip), %rsi      # 0xf15f
callq 0x4360
cmpl $0x0, %eax
jne 0x4b89
movl $0x28, %edi
callq 0x4260
movq %rax, -0xe8(%rbp)
jmp 0x4b4c
movq -0xe8(%rbp), %rdi
callq 0xd4a0
jmp 0x4b5a
movq -0xe8(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x4bab
movq -0xe8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x28, %esi
callq 0x4270
jmp 0x5026
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq 0xa5cc(%rip), %rdi      # 0xf164
xorl %eax, %eax
callq 0x4050
jmp 0x4ba1
movl $0x1, %edi
callq 0x42f0
jmp 0x4bad
jmp 0x4baf
jmp 0x4bb1
jmp 0x4bb3
jmp 0x4bb5
jmp 0x4bb7
jmp 0x4bb9
movq -0x28(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, -0xec(%rbp)
jmp 0x4bce
movl -0xec(%rbp), %eax
cmpl $0x0, %eax
je 0x4ca8
movq -0x50(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, %rax
je 0x4c0b
movq -0xf8(%rbp), %rdi
callq 0x64c0
movq -0xf8(%rbp), %rdi
movl $0x30, %esi
callq 0x4270
movq -0x60(%rbp), %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, %rax
je 0x4c39
movq -0x100(%rbp), %rdi
callq 0xa450
movq -0x100(%rbp), %rdi
movl $0x3004, %esi           # imm = 0x3004
callq 0x4270
movq -0x58(%rbp), %rax
movq %rax, -0x108(%rbp)
cmpq $0x0, %rax
je 0x4c67
movq -0x108(%rbp), %rdi
callq 0x9680
movq -0x108(%rbp), %rdi
movl $0x18, %esi
callq 0x4270
movq -0x28(%rbp), %rax
movq %rax, -0x110(%rbp)
cmpq $0x0, %rax
je 0x4c85
movq -0x110(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0xa4e9(%rip), %rdi      # 0xf175
xorl %eax, %eax
callq 0x4050
jmp 0x4c95
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x70(%rbp)
jmp 0x5011
movq -0x58(%rbp), %rdi
callq 0x5110
movq %rax, -0x118(%rbp)
jmp 0x4cba
movq -0x118(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rdi
callq 0x5130
movq %rax, -0x120(%rbp)
jmp 0x4cd7
movq -0x120(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x5150
jmp 0x4cf1
jmp 0x4cf3
movq -0x50(%rbp), %rdi
callq 0x5190
movb %al, -0x121(%rbp)
jmp 0x4d04
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x4d13
jmp 0x4f5b
movq -0x50(%rbp), %rdi
callq 0x51b0
movl %eax, -0x128(%rbp)
jmp 0x4d24
movl -0x128(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x4d33
movb $0x1, -0x16(%rbp)
movq -0x80(%rbp), %rdi
callq 0x51d0
movb %al, -0x129(%rbp)
jmp 0x4d44
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x4d50
jmp 0x4d69
movl $0x1, -0x14(%rbp)
movq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x51f0
jmp 0x4d67
jmp 0x4d83
movq -0x50(%rbp), %rdi
callq 0x6670
movl %eax, -0x130(%rbp)
jmp 0x4d7a
movl -0x130(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x58(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x9940
jmp 0x4d91
testb $0x1, -0x15(%rbp)
je 0x4e02
movl -0x14(%rbp), %esi
leaq 0xa3e9(%rip), %rdi      # 0xf18a
xorl %eax, %eax
callq 0x4050
jmp 0x4daa
movq -0x50(%rbp), %rdi
callq 0x6530
jmp 0x4db5
movq -0x80(%rbp), %rdi
callq 0xb610
jmp 0x4dc0
movq -0x58(%rbp), %rdi
movl $0x80, %esi
movl $0xff, %edx
callq 0x9860
jmp 0x4dd5
movq -0x80(%rbp), %rdi
callq 0x51d0
movb %al, -0x131(%rbp)
jmp 0x4de6
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x4e00
jmp 0x4df2
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x4380
jmp 0x4dfe
jmp 0x4e00
jmp 0x4e02
movq -0x80(%rbp), %rdi
callq 0x5210
movb %al, -0x132(%rbp)
jmp 0x4e13
movb -0x132(%rbp), %al
testb $0x1, %al
jne 0x4e22
jmp 0x4f47
movq -0x28(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movl %eax, -0x138(%rbp)
jmp 0x4e37
movl -0x138(%rbp), %eax
movl %eax, -0x84(%rbp)
cmpl $0x1, -0x84(%rbp)
jne 0x4e51
jmp 0x4f5b
movl -0x84(%rbp), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x140(%rbp)
subl $0xd, %eax
ja 0x4f45
movq -0x140(%rbp), %rax
leaq 0xa18a(%rip), %rcx      # 0xf004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x78(%rbp), %rdi
callq 0x5240
jmp 0x4e8e
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x5270
jmp 0x4e9e
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x52a0
jmp 0x4eae
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x52d0
jmp 0x4ebe
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x5300
jmp 0x4ece
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x5330
jmp 0x4edb
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x5360
jmp 0x4ee8
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x5390
jmp 0x4ef5
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x53c0
jmp 0x4f02
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x53f0
jmp 0x4f0f
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x5420
jmp 0x4f1c
jmp 0x4f45
movq -0x78(%rbp), %rdi
callq 0x5450
jmp 0x4f29
jmp 0x4f45
movq -0x80(%rbp), %rdi
callq 0x5480
jmp 0x4f36
jmp 0x4f45
movq -0x80(%rbp), %rdi
callq 0x54a0
jmp 0x4f43
jmp 0x4f45
jmp 0x4f47
testb $0x1, -0x16(%rbp)
je 0x4f56
callq 0x4350
jmp 0x4f54
jmp 0x4f56
jmp 0x4cf3
movq -0x50(%rbp), %rax
movq %rax, -0x148(%rbp)
cmpq $0x0, %rax
je 0x4f89
movq -0x148(%rbp), %rdi
callq 0x64c0
movq -0x148(%rbp), %rdi
movl $0x30, %esi
callq 0x4270
movq -0x60(%rbp), %rax
movq %rax, -0x150(%rbp)
cmpq $0x0, %rax
je 0x4fb7
movq -0x150(%rbp), %rdi
callq 0xa450
movq -0x150(%rbp), %rdi
movl $0x3004, %esi           # imm = 0x3004
callq 0x4270
movq -0x58(%rbp), %rax
movq %rax, -0x158(%rbp)
cmpq $0x0, %rax
je 0x4fe5
movq -0x158(%rbp), %rdi
callq 0x9680
movq -0x158(%rbp), %rdi
movl $0x18, %esi
callq 0x4270
movq -0x28(%rbp), %rax
movq %rax, -0x160(%rbp)
cmpq $0x0, %rax
je 0x5003
movq -0x160(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x0, -0x4(%rbp)
movl $0x1, -0x70(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x54d0
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x54d0
movq -0x40(%rbp), %rdi
callq 0x43d0
nopl (%rax,%rax)