// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/ikonvert-serial/ikonvert-serial.c
// Function: main
int main(int argc, char **argv)
{
  int            handle;
  struct termios attr;
  char          *name   = argv[0];
  char          *device = 0;
  struct stat    statbuf;
  int            ac = argc;
  char         **av = argv;

  setProgName(av[0]);
  while (ac > 1)
  {
    if (strcasecmp(av[1], "-version") == 0)
    {
      printf("%s\n", VERSION);
      exit(0);
    }
    else if (strcasecmp(av[1], "-w") == 0)
    {
      writeonly = true;
    }
    else if (strcasecmp(av[1], "-p") == 0)
    {
      passthru = true;
    }
    else if (strcasecmp(av[1], "-r") == 0)
    {
      readonly = true;
    }
    else if (strcasecmp(av[1], "-v") == 0)
    {
      verbose = true;
    }
    else if (strcasecmp(av[1], "-x") == 0)
    {
      hexMode = true;
    }
    else if (strcasecmp(av[1], "--rate-limit-off") == 0 || strcasecmp(argv[1], "-l") == 0)
    {
      rate_limit_off = true;
    }
    else if (strcasecmp(av[1], "-rx") == 0 && ac > 2)
    {
      ac--;
      av++;
      if (sbGetLength(&rxList) > 0)
      {
        sbAppendString(&rxList, ",");
      }
      sbAppendFormat(&rxList, "%s", av[1]);
    }
    else if (strcasecmp(av[1], "-tx") == 0 && ac > 2)
    {
      ac--;
      av++;
      if (sbGetLength(&txList) > 0)
      {
        sbAppendString(&txList, ",");
      }
      sbAppendFormat(&txList, "%s", av[1]);
    }
    else if (strcasecmp(av[1], "-t") == 0 && ac > 2)
    {
      ac--;
      av++;
      timeout = strtol(av[1], 0, 10);
      logDebug("timeout set to %ld seconds\n", timeout);
    }
    else if (strcasecmp(av[1], "-reset") == 0 && ac > 2)
    {
      ac--;
      av++;
      resetTimeout = strtol(av[1], 0, 10);
      logDebug("reset timeout set to %ld seconds\n", resetTimeout);
    }
    else if (strcasecmp(av[1], "-s") == 0 && ac > 2)
    {
      ac--;
      av++;
      speed = strtol(av[1], 0, 10);
      switch (speed)
      {
        case 38400:
          baudRate = B38400;
          break;
        case 57600:
          baudRate = B57600;
          break;
        case 115200:
          baudRate = B115200;
          break;
        case 230400:
          baudRate = B230400;
          break;
#ifdef B460800
        case 460800:
          baudRate = B460800;
          break;
#endif
#ifdef B921600
        case 921600:
          baudRate = B921600;
          break;
#endif
        default:
          device = 0;
          break;
      }
      logDebug("speed set to %d (%d) baud\n", speed, baudRate);
    }
    else if (strcasecmp(av[1], "-d") == 0)
    {
      setLogLevel(LOGLEVEL_DEBUG);
    }
    else if (!device)
    {
      device = av[1];
    }
    else
    {
      device = 0;
      break;
    }
    ac--;
    av++;
  }

  if (!device)
  {
    fprintf(stderr,
            "Usage: %s [-w] -[-p] [-r] [-v] [-d] [-s <n>] [-t <n>] device\n"
            "\n"
            "Options:\n"
            "  -w                    writeonly mode, data from device is not sent to stdout\n"
            "  -r                    readonly mode, data from stdin is not sent to device\n"
            "  -p                    passthru mode, data from stdin is also sent to stdout\n"
            "  -v                    verbose\n"
            "  -d                    debug\n"
            "  -rx <list>            Set PGN receive list\n"
            "  -tx <list>            Set PGN transmit list\n"
            "  -l | --rate-limit-off Disable TX rate limits (use at own risk)\n"
            "  -s <n>                set baudrate to 38400, 57600, 115200, 230400"
#ifdef B460800
            ", 460800"
#endif
#ifdef B921600
            ", 921600"
#endif
            " (default 230400)\n"
            "  -t <n>                timeout, if no message is received after <n> seconds the program quits\n"
            "  -x                    hex instead of base64 mode"
            "  <device> can be a serial device, a normal file containing a raw log,\n"
            "  or the address of a TCP server in the format tcp://<host>[:<port>]\n"
            "\n"
            "  Examples: %s /dev/ttyUSB0\n"
            "            %s tcp://192.168.1.1:10001\n"
            "\n" COPYRIGHT,
            name,
            name,
            name);
    exit(1);
  }

  logDebug("Opening %s\n", device);
  if (strncmp(device, "tcp:", STRSIZE("tcp:")) == 0)
  {
    handle = open_socket_stream(device);
    logDebug("socket = %d\n", handle);
    isFile = true;
    if (handle < 0)
    {
      logAbort("Cannot open TCP stream %s\n", device);
    }
  }
  else
  {
    handle = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
    logDebug("fd = %d\n", handle);
    if (handle < 0)
    {
      logAbort("Cannot open device %s\n", device);
    }
    if (fstat(handle, &statbuf) < 0)
    {
      logAbort("Cannot determine device %s\n", device);
    }
    isFile = S_ISREG(statbuf.st_mode);
  }

  if (isFile)
  {
    logInfo("Device is a normal file, do not set the attributes.\n");
  }
  else
  {
    logDebug("Device is a serial port, set the attributes for %d baud.\n", speed);

    memset(&attr, 0, sizeof(attr));
    if (cfsetspeed(&attr, baudRate) < 0)
    {
      logAbort("Cannot set baudrate %d\n", speed);
    }

    attr.c_cflag |= CS8 | CLOCAL | CREAD;

    attr.c_iflag |= IGNPAR;
    attr.c_cc[VMIN]  = 1;
    attr.c_cc[VTIME] = 0;
    tcflush(handle, TCIFLUSH);
    tcsetattr(handle, TCSANOW, &attr);

    isSerialDevice = true;
    initializeDevice();
  }

  for (;;)
  {
    uint8_t data[1024];
    ssize_t r;
    bool    receivedSomething = false;

    int     writeHandle = (sbGetLength(&writeBuffer) > 0) ? handle : INVALID_SOCKET;
    int     inHandle    = (sendInitState == 0 && writeHandle == INVALID_SOCKET) ? STDIN : INVALID_SOCKET;

    int rd = isReady(handle, inHandle, writeHandle, timeout);

    logDebug("isReady(%d, %d, %d, %d) = %d\n", handle, inHandle, writeHandle, timeout, rd);

    if ((rd & FD1_ReadReady) > 0)
    {
      r = read(handle, data, sizeof data);
      if (r > 0)
      {
        sbAppendData(&readBuffer, data, r);
      }
      if (r < 0)
      {
        logAbort("Error reading device: %s\n", strerror(errno));
      }
      if (r == 0)
      {
        logAbort("EOF on device\n");
      }
    }

    if ((rd & FD2_ReadReady) > 0)
    {
      r = read(STDIN, data, sizeof data);
      if (r > 0)
      {
        sbAppendData(&inBuffer, data, r);
        processInBuffer(&inBuffer, &writeBuffer);
      }
      if (r < 0)
      {
        logAbort("Error reading stdin: %s\n", strerror(errno));
      }
      if (r == 0)
      {
        logAbort("EOF on stdin\n");
      }
    }

    if ((rd & FD3_WriteReady) > 0 && sbGetLength(&writeBuffer) > 0)
    {
      r = write(handle, sbGet(&writeBuffer), sbGetLength(&writeBuffer));
      if (r > 0)
      {
        if (verbose)
        {
          logInfo("Sent [%-1.*s]\n", r, sbGet(&writeBuffer));
        }
        sbDelete(&writeBuffer, 0, (size_t) r); // Eliminate written bytes from buffer
      }
      if (r == 0)
      {
        logAbort("EOF on stdout\n");
      }
    }

    if (sbGetLength(&readBuffer) > 0)
    {
      logDebug("readBuffer len=%zu\n", sbGetLength(&readBuffer));
      receivedSomething = processReadBuffer(&readBuffer, STDOUT);
    }

    // The isReady() function already aborted the program
    // where nothing at all was received from the iKonvert, for instance
    // when there is no N2K bus power.
    // However, we may also want reinitialize when there was no actual data
    // received from the iKonvert, e.g. no PGN was received. A reset of the
    // iKonvert is enough for that, so initializeDevices() suffices.
    if (sendInitState == 0 && resetTimeout > 0)
    {
      uint64_t now = getNow();

      if (debugReset > 0)
      {
        debugReset--;
      }

      if (lastNow == 0 || receivedSomething)
      {
        lastNow = now;
      }
      if (lastNow < now - 1000 * resetTimeout || debugReset == 0)
      {
        close(handle);
        logError("Last received N2K data %"PRIu64" ms ago.\n", now - lastNow);
        logError("Restart process to reset device\n");
        execvp(argv[0], argv);
      }
    }
  }

  close(handle);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x550, %rsp            # imm = 0x550
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0xf4(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq (%rax), %rdi
callq 0x4970
cmpl $0x1, -0xf4(%rbp)
jle 0x29df
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6b5a(%rip), %rsi      # 0x9038
callq 0x2040
cmpl $0x0, %eax
jne 0x2504
leaq 0x7ac6(%rip), %rdi      # 0x9fb5
leaq 0x6b4b(%rip), %rsi      # 0x9041
movb $0x0, %al
callq 0x20e0
xorl %edi, %edi
callq 0x22d0
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6b31(%rip), %rsi      # 0x9047
callq 0x2040
cmpl $0x0, %eax
jne 0x252c
movb $0x1, 0xa4f1(%rip)      # 0xca18
jmp 0x29b7
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6b0c(%rip), %rsi      # 0x904a
callq 0x2040
cmpl $0x0, %eax
jne 0x2554
movb $0x1, 0xa4ca(%rip)      # 0xca19
jmp 0x29b5
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6ae7(%rip), %rsi      # 0x904d
callq 0x2040
cmpl $0x0, %eax
jne 0x257c
movb $0x1, 0xa4a3(%rip)      # 0xca1a
jmp 0x29b3
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6ac2(%rip), %rsi      # 0x9050
callq 0x2040
cmpl $0x0, %eax
jne 0x25a4
movb $0x1, 0xa47c(%rip)      # 0xca1b
jmp 0x29b1
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6a9d(%rip), %rsi      # 0x9053
callq 0x2040
cmpl $0x0, %eax
jne 0x25cc
movb $0x1, 0xa455(%rip)      # 0xca1c
jmp 0x29af
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6a78(%rip), %rsi      # 0x9056
callq 0x2040
cmpl $0x0, %eax
je 0x2601
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6a70(%rip), %rsi      # 0x9067
callq 0x2040
cmpl $0x0, %eax
jne 0x260d
movb $0x1, 0xa415(%rip)      # 0xca1d
jmp 0x29ad
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6a4b(%rip), %rsi      # 0x906a
callq 0x2040
cmpl $0x0, %eax
jne 0x2695
cmpl $0x2, -0xf4(%rbp)
jle 0x2695
movl -0xf4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xf4(%rbp)
movq -0x100(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, 0xa3cd(%rip)      # 0xca28
jbe 0x2670
leaq 0xa3bc(%rip), %rdi      # 0xca20
leaq 0x75c1(%rip), %rsi      # 0x9c2c
callq 0x5060
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0xa39e(%rip), %rdi      # 0xca20
leaq 0x7ac3(%rip), %rsi      # 0xa14c
movb $0x0, %al
callq 0x4e10
jmp 0x29ab
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x69c7(%rip), %rsi      # 0x906e
callq 0x2040
cmpl $0x0, %eax
jne 0x271d
cmpl $0x2, -0xf4(%rbp)
jle 0x271d
movl -0xf4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xf4(%rbp)
movq -0x100(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x100(%rbp)
cmpq $0x0, 0xa35d(%rip)      # 0xca40
jbe 0x26f8
leaq 0xa34c(%rip), %rdi      # 0xca38
leaq 0x7539(%rip), %rsi      # 0x9c2c
callq 0x5060
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0xa32e(%rip), %rdi      # 0xca38
leaq 0x7a3b(%rip), %rsi      # 0xa14c
movb $0x0, %al
callq 0x4e10
jmp 0x29a9
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6943(%rip), %rsi      # 0x9072
callq 0x2040
cmpl $0x0, %eax
jne 0x279d
cmpl $0x2, -0xf4(%rbp)
jle 0x279d
movl -0xf4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xf4(%rbp)
movq -0x100(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x21c0
movq %rax, 0xa2cd(%rip)      # 0xca50
movq 0xa2c6(%rip), %rsi      # 0xca50
leaq 0x68f1(%rip), %rdi      # 0x9082
movb $0x0, %al
callq 0x4640
jmp 0x29a7
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x68c6(%rip), %rsi      # 0x9075
callq 0x2040
cmpl $0x0, %eax
jne 0x281d
cmpl $0x2, -0xf4(%rbp)
jle 0x281d
movl -0xf4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xf4(%rbp)
movq -0x100(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x21c0
movq %rax, 0xa255(%rip)      # 0xca58
movq 0xa24e(%rip), %rsi      # 0xca58
leaq 0x686b(%rip), %rdi      # 0x907c
movb $0x0, %al
callq 0x4640
jmp 0x29a5
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x686f(%rip), %rsi      # 0x909e
callq 0x2040
cmpl $0x0, %eax
jne 0x2955
cmpl $0x2, -0xf4(%rbp)
jle 0x2955
movl -0xf4(%rbp), %eax
decl %eax
movl %eax, -0xf4(%rbp)
movq -0x100(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x21c0
movl %eax, 0x994b(%rip)      # 0xc1d4
movl 0x9945(%rip), %eax      # 0xc1d4
movl %eax, -0x524(%rbp)
subl $0x9600, %eax           # imm = 0x9600
je 0x28e9
jmp 0x289e
movl -0x524(%rbp), %eax
subl $0xe100, %eax           # imm = 0xE100
je 0x28f5
jmp 0x28ad
movl -0x524(%rbp), %eax
subl $0x1c200, %eax          # imm = 0x1C200
je 0x2901
jmp 0x28bc
movl -0x524(%rbp), %eax
subl $0x38400, %eax          # imm = 0x38400
je 0x290d
jmp 0x28cb
movl -0x524(%rbp), %eax
subl $0x70800, %eax          # imm = 0x70800
je 0x2919
jmp 0x28da
movl -0x524(%rbp), %eax
subl $0xe1000, %eax          # imm = 0xE1000
je 0x2925
jmp 0x2931
movl $0xf, 0x98dd(%rip)      # 0xc1d0
jmp 0x2939
movl $0x1001, 0x98d1(%rip)   # imm = 0x1001
jmp 0x2939
movl $0x1002, 0x98c5(%rip)   # imm = 0x1002
jmp 0x2939
movl $0x1003, 0x98b9(%rip)   # imm = 0x1003
jmp 0x2939
movl $0x1004, 0x98ad(%rip)   # imm = 0x1004
jmp 0x2939
movl $0x1007, 0x98a1(%rip)   # imm = 0x1007
jmp 0x2939
movq $0x0, -0x60(%rbp)
movl 0x9895(%rip), %esi      # 0xc1d4
movl 0x988b(%rip), %edx      # 0xc1d0
leaq 0x6755(%rip), %rdi      # 0x90a1
movb $0x0, %al
callq 0x4640
jmp 0x29a3
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x6755(%rip), %rsi      # 0x90bc
callq 0x2040
cmpl $0x0, %eax
jne 0x297d
movl $0x3, %edi
callq 0x48d0
jmp 0x29a1
cmpq $0x0, -0x60(%rbp)
jne 0x2995
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x299f
movq $0x0, -0x60(%rbp)
jmp 0x29df
jmp 0x29a1
jmp 0x29a3
jmp 0x29a5
jmp 0x29a7
jmp 0x29a9
jmp 0x29ab
jmp 0x29ad
jmp 0x29af
jmp 0x29b1
jmp 0x29b3
jmp 0x29b5
jmp 0x29b7
jmp 0x29b9
movl -0xf4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xf4(%rbp)
movq -0x100(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x100(%rbp)
jmp 0x24bf
cmpq $0x0, -0x60(%rbp)
jne 0x2a14
movq 0x960b(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x58(%rbp), %r8
leaq 0x66bc(%rip), %rsi      # 0x90bf
movb $0x0, %al
callq 0x21b0
movl $0x1, %edi
callq 0x22d0
movq -0x60(%rbp), %rsi
leaq 0x6d2f(%rip), %rdi      # 0x974e
movb $0x0, %al
callq 0x4640
movq -0x60(%rbp), %rdi
leaq 0x6d29(%rip), %rsi      # 0x975a
movl $0x4, %edx
callq 0x2070
cmpl $0x0, %eax
jne 0x2a7e
movq -0x60(%rbp), %rdi
callq 0x5ae0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %esi
leaq 0x6d09(%rip), %rdi      # 0x975f
movb $0x0, %al
callq 0x4640
movb $0x1, 0x9ffc(%rip)      # 0xca60
cmpl $0x0, -0x14(%rbp)
jge 0x2a7c
movq -0x60(%rbp), %rsi
leaq 0x6cf7(%rip), %rdi      # 0x976c
movb $0x0, %al
callq 0x47a0
jmp 0x2afb
movq -0x60(%rbp), %rdi
movl $0x902, %esi            # imm = 0x902
movb $0x0, %al
callq 0x2280
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %esi
leaq 0x6cec(%rip), %rdi      # 0x9787
movb $0x0, %al
callq 0x4640
cmpl $0x0, -0x14(%rbp)
jge 0x2aba
movq -0x60(%rbp), %rsi
leaq 0x6cdd(%rip), %rdi      # 0x9790
movb $0x0, %al
callq 0x47a0
movl -0x14(%rbp), %edi
leaq -0xf0(%rbp), %rsi
callq 0x2310
cmpl $0x0, %eax
jge 0x2ae0
movq -0x60(%rbp), %rsi
leaq 0x6cce(%rip), %rdi      # 0x97a7
movb $0x0, %al
callq 0x47a0
movl -0xd8(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
sete %al
andb $0x1, %al
movb %al, 0x9f65(%rip)       # 0xca60
testb $0x1, 0x9f5e(%rip)      # 0xca60
je 0x2b17
leaq 0x6cb8(%rip), %rdi      # 0x97c3
movb $0x0, %al
callq 0x44f0
jmp 0x2ba3
movl 0x96b7(%rip), %esi      # 0xc1d4
leaq 0x6cd4(%rip), %rdi      # 0x97f8
movb $0x0, %al
callq 0x4640
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x3c, %edx
callq 0x2140
movl 0x968f(%rip), %esi      # 0xc1d0
leaq -0x50(%rbp), %rdi
callq 0x2150
cmpl $0x0, %eax
jge 0x2b63
movl 0x967f(%rip), %esi      # 0xc1d4
leaq 0x6cd6(%rip), %rdi      # 0x9832
movb $0x0, %al
callq 0x47a0
movl -0x48(%rbp), %eax
orl $0x8b0, %eax            # imm = 0x8B0
movl %eax, -0x48(%rbp)
movl -0x50(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x50(%rbp)
movb $0x1, -0x39(%rbp)
movb $0x0, -0x3a(%rbp)
movl -0x14(%rbp), %edi
xorl %esi, %esi
callq 0x20c0
movl -0x14(%rbp), %edi
xorl %esi, %esi
leaq -0x50(%rbp), %rdx
callq 0x2270
movb $0x1, 0x9ec3(%rip)      # 0xca61
callq 0x2fb0
jmp 0x2ba5
movb $0x0, -0x509(%rbp)
cmpq $0x0, 0x9ebc(%rip)      # 0xca70
jbe 0x2bc1
movl -0x14(%rbp), %eax
movl %eax, -0x528(%rbp)
jmp 0x2bce
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x528(%rbp)
jmp 0x2bce
movl -0x528(%rbp), %eax
movl %eax, -0x510(%rbp)
xorl %eax, %eax
cmpl $0x0, 0x9e9d(%rip)      # 0xca80
movb %al, -0x529(%rbp)
jne 0x2bfb
cmpl $-0x1, -0x510(%rbp)
sete %al
movb %al, -0x529(%rbp)
movb -0x529(%rbp), %dl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x514(%rbp)
movl -0x14(%rbp), %edi
movl -0x514(%rbp), %esi
movl -0x510(%rbp), %edx
movq 0x9e26(%rip), %rax      # 0xca50
movl %eax, %ecx
callq 0x5eb0
movl %eax, -0x518(%rbp)
movl -0x14(%rbp), %esi
movl -0x514(%rbp), %edx
movl -0x510(%rbp), %ecx
movq 0x9e03(%rip), %r8       # 0xca50
movl -0x518(%rbp), %r9d
leaq 0x6bef(%rip), %rdi      # 0x984a
movb $0x0, %al
callq 0x4640
movl -0x518(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jle 0x2cf4
movl -0x14(%rbp), %edi
leaq -0x500(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x2180
movq %rax, -0x508(%rbp)
cmpq $0x0, -0x508(%rbp)
jle 0x2cb3
leaq -0x500(%rbp), %rsi
movq -0x508(%rbp), %rdx
leaq 0x9dda(%rip), %rdi      # 0xca88
callq 0x4c90
cmpq $0x0, -0x508(%rbp)
jge 0x2cda
callq 0x2050
movl (%rax), %edi
callq 0x2300
movq %rax, %rsi
leaq 0x6b95(%rip), %rdi      # 0x9868
movb $0x0, %al
callq 0x47a0
cmpq $0x0, -0x508(%rbp)
jne 0x2cf2
leaq 0x6b97(%rip), %rdi      # 0x9882
movb $0x0, %al
callq 0x47a0
jmp 0x2cf4
movl -0x518(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jle 0x2d98
leaq -0x500(%rbp), %rsi
xorl %edi, %edi
movl $0x400, %edx            # imm = 0x400
callq 0x2180
movq %rax, -0x508(%rbp)
cmpq $0x0, -0x508(%rbp)
jle 0x2d57
leaq -0x500(%rbp), %rsi
movq -0x508(%rbp), %rdx
leaq 0x9d61(%rip), %rdi      # 0xcaa0
callq 0x4c90
leaq 0x9d55(%rip), %rdi      # 0xcaa0
leaq 0x9d16(%rip), %rsi      # 0xca68
callq 0x2fe0
cmpq $0x0, -0x508(%rbp)
jge 0x2d7e
callq 0x2050
movl (%rax), %edi
callq 0x2300
movq %rax, %rsi
leaq 0x6b1a(%rip), %rdi      # 0x9891
movb $0x0, %al
callq 0x47a0
cmpq $0x0, -0x508(%rbp)
jne 0x2d96
leaq 0x6b1b(%rip), %rdi      # 0x98aa
movb $0x0, %al
callq 0x47a0
jmp 0x2d98
movl -0x518(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jle 0x2ea3
cmpq $0x0, 0x9cbe(%rip)      # 0xca70
jbe 0x2ea3
movl -0x14(%rbp), %eax
movl %eax, -0x530(%rbp)
cmpq $0x0, 0x9c9f(%rip)      # 0xca68
je 0x2ddb
movq 0x9c96(%rip), %rax      # 0xca68
movq %rax, -0x538(%rbp)
jmp 0x2deb
leaq 0x696b(%rip), %rax      # 0x974d
movq %rax, -0x538(%rbp)
jmp 0x2deb
movl -0x530(%rbp), %edi
movq -0x538(%rbp), %rsi
movq 0x9c71(%rip), %rdx      # 0xca70
callq 0x20a0
movq %rax, -0x508(%rbp)
cmpq $0x0, -0x508(%rbp)
jle 0x2e89
testb $0x1, 0x9bff(%rip)      # 0xca1b
je 0x2e72
movq -0x508(%rbp), %rax
movq %rax, -0x540(%rbp)
cmpq $0x0, 0x9c34(%rip)      # 0xca68
je 0x2e46
movq 0x9c2b(%rip), %rax      # 0xca68
movq %rax, -0x548(%rbp)
jmp 0x2e56
leaq 0x6900(%rip), %rax      # 0x974d
movq %rax, -0x548(%rbp)
jmp 0x2e56
movq -0x540(%rbp), %rsi
movq -0x548(%rbp), %rdx
leaq 0x6a4d(%rip), %rdi      # 0x98b8
movb $0x0, %al
callq 0x44f0
movq -0x508(%rbp), %rdx
leaq 0x9be8(%rip), %rdi      # 0xca68
xorl %eax, %eax
movl %eax, %esi
callq 0x4b50
cmpq $0x0, -0x508(%rbp)
jne 0x2ea1
leaq 0x6a2d(%rip), %rdi      # 0x98c7
movb $0x0, %al
callq 0x47a0
jmp 0x2ea3
cmpq $0x0, 0x9be5(%rip)      # 0xca90
jbe 0x2edb
movq 0x9bdc(%rip), %rsi      # 0xca90
leaq 0x6a1b(%rip), %rdi      # 0x98d6
movb $0x0, %al
callq 0x4640
leaq 0x9bbf(%rip), %rdi      # 0xca88
movl $0x1, %esi
callq 0x3390
andb $0x1, %al
movb %al, -0x509(%rbp)
cmpl $0x0, 0x9b9e(%rip)      # 0xca80
jne 0x2fa9
cmpq $0x0, 0x9b68(%rip)      # 0xca58
jle 0x2fa9
callq 0x4380
movq %rax, -0x520(%rbp)
cmpl $0x0, 0x92cf(%rip)      # 0xc1d8
jle 0x2f1a
movl 0x92c7(%rip), %eax      # 0xc1d8
addl $-0x1, %eax
movl %eax, 0x92be(%rip)      # 0xc1d8
cmpq $0x0, 0x9b96(%rip)      # 0xcab8
je 0x2f2d
testb $0x1, -0x509(%rbp)
je 0x2f3b
movq -0x520(%rbp), %rax
movq %rax, 0x9b7d(%rip)      # 0xcab8
movq 0x9b76(%rip), %rax      # 0xcab8
movq -0x520(%rbp), %rcx
imulq $0x3e8, 0x9b04(%rip), %rdx # imm = 0x3E8
subq %rdx, %rcx
cmpq %rcx, %rax
jb 0x2f65
cmpl $0x0, 0x9275(%rip)      # 0xc1d8
jne 0x2fa7
movl -0x14(%rbp), %edi
callq 0x2160
movq -0x520(%rbp), %rsi
subq 0x9b3d(%rip), %rsi      # 0xcab8
leaq 0x6968(%rip), %rdi      # 0x98ea
movb $0x0, %al
callq 0x46f0
leaq 0x697e(%rip), %rdi      # 0x990e
movb $0x0, %al
callq 0x46f0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x22b0
jmp 0x2fa9
jmp 0x2ba5
nop