// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x648, %rsp            # imm = 0x648
movq %rsi, %r13
movl %edi, %ebp
movq (%rsi), %rdi
movq %rdi, 0x10(%rsp)
callq 0x3c35
leaq 0x7d4a(%rip), %rbx      # 0xa200
leaq 0x7d5b(%rip), %r12      # 0xa218
movq %r13, 0x40(%rsp)
movq $0x0, 0x8(%rsp)
cmpl $0x2, %ebp
jl 0x281e
movq %rbx, %r15
movq 0x8(%r13), %rbx
movq %rbx, %rdi
leaq 0x3b53(%rip), %rsi      # 0x6038
callq 0x2040
testl %eax, %eax
je 0x35ac
movq %rbx, %rdi
leaq 0x3b4b(%rip), %rsi      # 0x6047
callq 0x2040
testl %eax, %eax
je 0x25db
movq %rbx, %rdi
leaq 0x3b37(%rip), %rsi      # 0x604a
callq 0x2040
testl %eax, %eax
je 0x25e4
movq %rbx, %rdi
leaq 0x3b23(%rip), %rsi      # 0x604d
callq 0x2040
testl %eax, %eax
je 0x25ed
movq %rbx, %rdi
leaq 0x3b0f(%rip), %rsi      # 0x6050
callq 0x2040
testl %eax, %eax
je 0x25f6
movq %rbx, %rdi
leaq 0x3afb(%rip), %rsi      # 0x6053
callq 0x2040
testl %eax, %eax
je 0x2608
movq %rbx, %rdi
leaq 0x3ae7(%rip), %rsi      # 0x6056
callq 0x2040
testl %eax, %eax
je 0x25ff
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x3adb(%rip), %rsi      # 0x6067
callq 0x2040
testl %eax, %eax
je 0x25ff
leaq 0x8(%r13), %r14
movq %rbx, %rdi
leaq 0x3ac7(%rip), %rsi      # 0x606a
callq 0x2040
cmpl $0x2, %ebp
je 0x2623
testl %eax, %eax
jne 0x2623
cmpq $0x0, 0x7c4f(%rip)      # 0xa208
movq %r15, %rbx
je 0x25cd
movq %rbx, %rdi
leaq 0x4664(%rip), %rsi      # 0x6c2c
callq 0x3faf
decl %ebp
movq 0x10(%r13), %rdx
movq %rbx, %rdi
jmp 0x2660
movb $0x1, 0x7c16(%rip)      # 0xa1f8
jmp 0x260f
movb $0x1, 0x7c0e(%rip)      # 0xa1f9
jmp 0x260f
movb $0x1, 0x7c06(%rip)      # 0xa1fa
jmp 0x260f
movb $0x1, 0x7bfe(%rip)      # 0xa1fb
jmp 0x260f
movb $0x1, 0x7bf7(%rip)      # 0xa1fd
jmp 0x260f
movb $0x1, 0x7bed(%rip)      # 0xa1fc
movq %r13, %r14
movq %r15, %rbx
decl %ebp
addq $0x8, %r14
movq %r14, %r13
jmp 0x24cb
movq %rbx, %rdi
leaq 0x3a41(%rip), %rsi      # 0x606e
callq 0x2040
cmpl $0x2, %ebp
je 0x2670
testl %eax, %eax
jne 0x2670
cmpq $0x0, 0x7bdd(%rip)      # 0xa220
movq %r15, %rbx
je 0x2657
movq %r12, %rdi
leaq 0x45da(%rip), %rsi      # 0x6c2c
callq 0x3faf
decl %ebp
movq 0x10(%r13), %rdx
movq %r12, %rdi
leaq 0x4ab2(%rip), %rsi      # 0x7119
xorl %eax, %eax
callq 0x3e6e
jmp 0x2615
movq %rbx, %rdi
leaq 0x39f8(%rip), %rsi      # 0x6072
callq 0x2040
cmpl $0x2, %ebp
je 0x26a8
testl %eax, %eax
jne 0x26a8
decl %ebp
movq 0x10(%r13), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x21d0
movq %rax, 0x7b91(%rip)      # 0xa230
leaq 0x39dc(%rip), %rdi      # 0x6082
jmp 0x26de
movq %rbx, %rdi
leaq 0x39c3(%rip), %rsi      # 0x6075
callq 0x2040
cmpl $0x2, %ebp
je 0x26ed
testl %eax, %eax
jne 0x26ed
decl %ebp
movq 0x10(%r13), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x21d0
movq %rax, 0x7b61(%rip)      # 0xa238
leaq 0x399e(%rip), %rdi      # 0x607c
movq %rax, %rsi
xorl %eax, %eax
callq 0x3a00
jmp 0x2612
movq %rbx, %rdi
leaq 0x39a7(%rip), %rsi      # 0x609e
callq 0x2040
cmpl $0x2, %ebp
je 0x2766
testl %eax, %eax
jne 0x2766
movq 0x10(%r13), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x21d0
movl %eax, 0x7ac3(%rip)      # 0xa1dc
cmpl $0x9600, %eax           # imm = 0x9600
je 0x27e6
cmpl $0xe100, %eax           # imm = 0xE100
movq %r15, %rbx
je 0x27f8
cmpl $0x1c200, %eax          # imm = 0x1C200
je 0x27a2
cmpl $0x38400, %eax          # imm = 0x38400
je 0x27b3
cmpl $0x70800, %eax          # imm = 0x70800
je 0x27c4
cmpl $0xe1000, %eax          # imm = 0xE1000
jne 0x27d5
movl $0x1007, 0x7a7c(%rip)   # imm = 0x1007
movl $0x1007, %edx           # imm = 0x1007
jmp 0x2807
movq %rbx, %rdi
leaq 0x394c(%rip), %rsi      # 0x60bc
callq 0x2040
testl %eax, %eax
je 0x2795
movq %r13, %r14
cmpq $0x0, 0x8(%rsp)
movq %rbx, 0x8(%rsp)
movq %r15, %rbx
je 0x2615
jmp 0x35bf
pushq $0x3
popq %rdi
callq 0x3c0e
jmp 0x260f
movl $0x1002, 0x7a2c(%rip)   # imm = 0x1002
movl $0x1002, %edx           # imm = 0x1002
jmp 0x2807
movl $0x1003, 0x7a1b(%rip)   # imm = 0x1003
movl $0x1003, %edx           # imm = 0x1003
jmp 0x2807
movl $0x1004, 0x7a0a(%rip)   # imm = 0x1004
movl $0x1004, %edx           # imm = 0x1004
jmp 0x2807
movl 0x79fd(%rip), %edx      # 0xa1d8
movq $0x0, 0x8(%rsp)
jmp 0x2807
movl $0xf, 0x79e8(%rip)      # 0xa1d8
pushq $0xf
popq %rdx
movq %r15, %rbx
jmp 0x2807
movl $0x1001, 0x79d6(%rip)   # imm = 0x1001
movl $0x1001, %edx           # imm = 0x1001
decl %ebp
leaq 0x3891(%rip), %rdi      # 0x60a1
movl %eax, %esi
xorl %eax, %eax
callq 0x3a00
jmp 0x2615
cmpq $0x0, 0x8(%rsp)
je 0x35bf
leaq 0x3f1d(%rip), %rdi      # 0x674e
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3a00
leaq 0x3f13(%rip), %rsi      # 0x675a
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x2070
movq %rbx, %rdi
testl %eax, %eax
je 0x2962
movl $0x902, %esi            # imm = 0x902
xorl %eax, %eax
callq 0x22a0
movl %eax, %ebp
leaq 0x3f15(%rip), %rdi      # 0x6787
movl %eax, %esi
xorl %eax, %eax
callq 0x3a00
testl %ebp, %ebp
jns 0x2890
leaq 0x3f0a(%rip), %rdi      # 0x6790
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3b22
leaq 0x1b0(%rsp), %rsi
movl %ebp, %edi
callq 0x2330
testl %eax, %eax
jns 0x28b4
leaq 0x3efd(%rip), %rdi      # 0x67a7
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3b22
movl $0xf000, %eax           # imm = 0xF000
andl 0x1c8(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
sete 0x7974(%rip)            # 0xa240
je 0x29a2
movl 0x7904(%rip), %esi      # 0xa1dc
leaq 0x3f19(%rip), %rdi      # 0x67f8
xorl %eax, %eax
callq 0x3a00
xorps %xmm0, %xmm0
leaq 0x170(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, 0x20(%rdi)
movups %xmm0, 0x2c(%rdi)
movl 0x78d2(%rip), %esi      # 0xa1d8
callq 0x2170
testl %eax, %eax
jns 0x2923
movl 0x78c7(%rip), %esi      # 0xa1dc
leaq 0x3f16(%rip), %rdi      # 0x6832
xorl %eax, %eax
callq 0x3b22
leaq 0x170(%rsp), %rbx
orl $0x8b0, 0x8(%rbx)       # imm = 0x8B0
orb $0x4, (%rbx)
movw $0x100, 0x16(%rbx)      # imm = 0x100
movl %ebp, %edi
xorl %esi, %esi
callq 0x20e0
movl %ebp, 0x10(%rsp)
movl %ebp, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2290
movb $0x1, 0x78e6(%rip)      # 0xa241
callq 0x35ea
jmp 0x29b4
callq 0x4589
movl %eax, %ebp
leaq 0x3def(%rip), %rdi      # 0x675f
movl %eax, %esi
xorl %eax, %eax
callq 0x3a00
movb $0x1, 0x78c0(%rip)      # 0xa240
testl %ebp, %ebp
jns 0x29a2
leaq 0x3de1(%rip), %rdi      # 0x676c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3b22
testb $0x1, 0x78a4(%rip)      # 0xa240
je 0x28d2
movl %ebp, 0x10(%rsp)
leaq 0x3e16(%rip), %rdi      # 0x67c3
xorl %eax, %eax
callq 0x38f3
leaq 0x3d92(%rip), %r15      # 0x674d
cmpq $0x1, 0x788d(%rip)      # 0xa250
movl $0x0, %r14d
sbbl %r14d, %r14d
movl 0x10(%rsp), %ebx
orl %ebx, %r14d
movl %r14d, %eax
notl %eax
xorl %r13d, %r13d
orl 0x787f(%rip), %eax      # 0xa260
setne %r13b
negl %r13d
movl 0x7842(%rip), %ecx      # 0xa230
movl %ebx, %edi
movl %r13d, %esi
movl %r14d, %edx
callq 0x479b
movl %eax, %ebp
movq 0x782c(%rip), %r8       # 0xa230
leaq 0x3e3f(%rip), %rdi      # 0x684a
movl %ebx, %esi
movl %r13d, %edx
movl %r14d, %ecx
movl %eax, %r9d
xorl %eax, %eax
callq 0x3a00
testb $0x1, %bpl
je 0x2a84
movl $0x400, %edx            # imm = 0x400
movl 0x10(%rsp), %edi
leaq 0x240(%rsp), %rbx
movq %rbx, %rsi
callq 0x21a0
testq %rax, %rax
jle 0x2a55
leaq 0x7820(%rip), %rdi      # 0xa268
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3d57
jmp 0x2a84
js 0x2a67
leaq 0x3e24(%rip), %rdi      # 0x6882
xorl %eax, %eax
callq 0x3b22
jmp 0x2a84
callq 0x2050
movl (%rax), %edi
callq 0x2320
leaq 0x3dee(%rip), %rdi      # 0x6868
movq %rax, %rsi
xorl %eax, %eax
callq 0x3b22
testb $0x2, %bpl
leaq 0x77b9(%rip), %r12      # 0xa248
pushq $0xa
popq %r13
leaq 0x40a0(%rip), %rbx      # 0x6b3a
je 0x2cbe
movl $0x400, %edx            # imm = 0x400
xorl %edi, %edi
leaq 0x240(%rsp), %rsi
callq 0x21a0
testq %rax, %rax
jle 0x2c8a
leaq 0x77bc(%rip), %rdi      # 0xa280
leaq 0x240(%rsp), %rsi
movq %rax, 0x8(%rsp)
movq %rax, %rdx
callq 0x3d57
movq 0x77a0(%rip), %r14      # 0xa280
testq %r14, %r14
movq %r14, %rdi
cmoveq %r15, %rdi
movl %r13d, %esi
callq 0x20f0
testq %rax, %rax
je 0x2c63
movq %rax, %r13
cmpb $0x0, 0x76f5(%rip)      # 0xa1fa
jne 0x2bfa
leaq 0x776e(%rip), %rdi      # 0xa280
leaq 0x48(%rsp), %rsi
callq 0x553e
movl 0x88(%rsp), %edx
cmpl $0x40000, %edx          # imm = 0x40000
setb %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2b71
movzbl 0x8c(%rsp), %ecx
movq %r12, %rdi
leaq 0x3dea(%rip), %rsi      # 0x692f
xorl %eax, %eax
callq 0x3e6e
movzbl 0x8e(%rsp), %edx
cmpb $0x1, 0x76a1(%rip)      # 0xa1fc
jne 0x2bbb
movq %r12, %rdi
leaq 0x8f(%rsp), %rsi
xorl %ecx, %ecx
callq 0x3dae
jmp 0x2bcd
movb 0x8e(%rsp), %r14b
cmpb $0x7, %r14b
setb %al
orb 0x7674(%rip), %al       # 0xa1fa
testb $0x1, %al
jne 0x2bfa
leaq 0x8f(%rsp), %rdi
leaq 0x3db4(%rip), %rsi      # 0x694d
pushq $0x6
popq %rdx
callq 0x2230
testl %eax, %eax
jne 0x2bfa
movzbl %r14b, %edx
movq %r12, %rdi
leaq 0x8f(%rsp), %rsi
callq 0x3d57
jmp 0x2bcd
movq %r12, %rdi
leaq 0x8f(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5af8
movq %r12, %rdi
leaq 0x3e7d(%rip), %rsi      # 0x6a54
xorl %eax, %eax
callq 0x3e6e
movq 0x7663(%rip), %rsi      # 0xa248
testq %rsi, %rsi
cmoveq %r15, %rsi
leaq 0x3d49(%rip), %rdi      # 0x693c
xorl %eax, %eax
callq 0x3a00
cmpb $0x1, 0x75f8(%rip)      # 0xa1f9
jne 0x2c35
movq 0x7676(%rip), %rsi      # 0xa280
testq %rsi, %rsi
cmoveq %r15, %rsi
movq %r13, %rdx
subq %rsi, %rdx
incq %rdx
pushq $0x1
popq %rdi
callq 0x20c0
testq %rax, %rax
jg 0x2c35
leaq 0x3d25(%rip), %rdi      # 0x6953
xorl %eax, %eax
callq 0x3b22
movq 0x7644(%rip), %rax      # 0xa280
testq %rax, %rax
cmoveq %r15, %rax
subq %rax, %r13
incq %r13
leaq 0x7630(%rip), %rdi      # 0xa280
xorl %esi, %esi
movq %r13, %rdx
callq 0x3cfc
pushq $0xa
popq %r13
jmp 0x2ad9
cmpq $0x2c1, 0x761a(%rip) # imm = 0x2C1
movq 0x8(%rsp), %rax
jb 0x2c86
andq $0x0, 0x760b(%rip)      # 0xa288
testq %r14, %r14
je 0x2c86
movb $0x0, (%r14)
pushq $0xa
popq %r13
testq %rax, %rax
js 0x2ca1
jne 0x2cbe
leaq 0x3c12(%rip), %rdi      # 0x68aa
xorl %eax, %eax
callq 0x3b22
jmp 0x2cbe
callq 0x2050
movl (%rax), %edi
callq 0x2320
leaq 0x3bdd(%rip), %rdi      # 0x6891
movq %rax, %rsi
xorl %eax, %eax
callq 0x3b22
shrb $0x2, %bpl
movq 0x7587(%rip), %rdx      # 0xa250
testq %rdx, %rdx
setne %al
andb %bpl, %al
cmpb $0x1, %al
jne 0x2d3c
movq 0x756b(%rip), %rsi      # 0xa248
testq %rsi, %rsi
cmoveq %r15, %rsi
movl 0x10(%rsp), %edi
callq 0x20c0
testq %rax, %rax
jle 0x2d2c
movq %rax, %r14
cmpb $0x1, 0x74ff(%rip)      # 0xa1fb
jne 0x2d1d
movq 0x7543(%rip), %rdx      # 0xa248
testq %rdx, %rdx
cmoveq %r15, %rdx
leaq 0x3ba5(%rip), %rdi      # 0x68b8
movq %r14, %rsi
xorl %eax, %eax
callq 0x38f3
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x3cfc
jmp 0x2d3c
jne 0x2d3c
leaq 0x3b92(%rip), %rdi      # 0x68c7
xorl %eax, %eax
callq 0x3b22
movq 0x752d(%rip), %rsi      # 0xa270
testq %rsi, %rsi
je 0x350e
movl $0x0, 0x1c(%rsp)
leaq 0x3b7b(%rip), %rdi      # 0x68d6
xorl %eax, %eax
callq 0x3a00
movq 0x7507(%rip), %rsi      # 0xa270
leaq 0x3d1f(%rip), %rdi      # 0x6a8f
xorl %eax, %eax
callq 0x3a00
movb $0x1, %al
movl %eax, 0x8(%rsp)
leaq 0x74e4(%rip), %r12      # 0xa268
movq %r12, %rdi
movl %r13d, %esi
callq 0x44c0
testq %rax, %rax
je 0x34d0
movq %rax, %rbp
movq 0x74c6(%rip), %r14      # 0xa268
testq %r14, %r14
cmoveq %r15, %r14
movq %rax, %rsi
subq %r14, %rsi
cmpq $0x8, %rsi
jb 0x2e9d
movzbl (%r14), %eax
cmpl $0x24, %eax
je 0x2dcb
cmpl $0x21, %eax
jne 0x2e9d
leaq 0x3cd8(%rip), %rdi      # 0x6aaa
xorl %eax, %eax
callq 0x3a00
movl $0x128, %edx            # imm = 0x128
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x2160
movb $0x0, (%rbp)
leaq 0x1(%r14), %rax
cmpq %rax, %rbp
jbe 0x2e01
cmpb $0xd, -0x1(%rbp)
jne 0x2e01
movb $0x0, -0x1(%rbp)
leaq 0x3cca(%rip), %rdi      # 0x6ad2
movq %r14, %rsi
xorl %eax, %eax
callq 0x3a00
cmpb $0x0, 0x73df(%rip)      # 0xa1f8
jne 0x33cf
movq 0x7442(%rip), %rax      # 0xa268
testq %rax, %rax
cmoveq %r15, %rax
movq %rax, (%rsp)
movq %rsp, %rbx
movq %rbx, %rdi
leaq 0x3d11(%rip), %rsi      # 0x6b4f
callq 0x49e9
testb %al, %al
je 0x3262
movq %rbx, %rdi
leaq 0x3d01(%rip), %rsi      # 0x6b56
callq 0x49e9
testb %al, %al
je 0x2ed0
movq (%rsp), %rsi
leaq 0x3cf3(%rip), %rdi      # 0x6b5c
xorl %eax, %eax
callq 0x38f3
cmpl $0xd, 0x73e9(%rip)      # 0xa260
leaq 0x3cbc(%rip), %rbx      # 0x6b3a
jne 0x2eea
movl $0xc, 0x73d6(%rip)      # 0xa260
leaq 0x3cdc(%rip), %rdi      # 0x6b6d
pushq $0xc
popq %rsi
xorl %eax, %eax
callq 0x3a00
jmp 0x2eea
incq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3a00
movq 0x73b7(%rip), %rax      # 0xa268
testq %rax, %rax
cmoveq %r15, %rax
subq %rax, %rbp
incq %rbp
movq %r12, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x3cfc
jmp 0x2d84
cmpl $0xd, 0x7389(%rip)      # 0xa260
leaq 0x3c5c(%rip), %rbx      # 0x6b3a
jne 0x2f1f
movl $0xe, 0x7376(%rip)      # 0xa260
movq 0x7377(%rip), %rsi      # 0xa268
testq %rsi, %rsi
cmoveq %r15, %rsi
leaq 0x3be2(%rip), %rdi      # 0x6ae1
xorl %eax, %eax
callq 0x3a00
testb $0x1, 0x8(%rsp)
je 0x2f12
callq 0x3607
movl $0x0, 0x8(%rsp)
jmp 0x33cf
movq %rsp, %r14
movq %r14, %rdi
leaq 0x3c68(%rip), %rsi      # 0x6b94
callq 0x49e9
testb %al, %al
je 0x2f52
cmpb $0x1, 0x72bf(%rip)      # 0xa1fb
jne 0x2eea
movq (%rsp), %rsi
leaq 0x3c58(%rip), %rdi      # 0x6ba1
xorl %eax, %eax
callq 0x38f3
jmp 0x2eea
movq %r14, %rdi
leaq 0x3c64(%rip), %rsi      # 0x6bc0
callq 0x49e9
testb %al, %al
je 0x2fa5
cmpb $0x1, 0x728f(%rip)      # 0xa1fb
jne 0x2f80
movq (%rsp), %rsi
leaq 0x3c54(%rip), %rdi      # 0x6bcd
xorl %eax, %eax
callq 0x38f3
cmpl $0x5, 0x72d9(%rip)      # 0xa260
jne 0x2eea
movl $0x4, 0x72c9(%rip)      # 0xa260
leaq 0x3bcf(%rip), %rdi      # 0x6b6d
pushq $0x4
jmp 0x2e93
movq %r14, %rdi
leaq 0x3c3e(%rip), %rsi      # 0x6bed
callq 0x49e9
testb %al, %al
je 0x3001
cmpb $0x1, 0x723c(%rip)      # 0xa1fb
jne 0x2fd3
movq (%rsp), %rsi
leaq 0x3c26(%rip), %rdi      # 0x6bf2
xorl %eax, %eax
callq 0x38f3
movl 0x7287(%rip), %esi      # 0xa260
testl %esi, %esi
setle %al
testb $0x1, %sil
sete %cl
orb %al, %cl
jne 0x2eea
decl %esi
movl %esi, 0x726b(%rip)      # 0xa260
leaq 0x3b71(%rip), %rdi      # 0x6b6d
jmp 0x2e94
movq %r14, %rdi
leaq 0x3c03(%rip), %rsi      # 0x6c0e
callq 0x49e9
movq %r14, %rdi
testb %al, %al
je 0x3054
leaq 0x2c(%rsp), %rsi
pushq $-0x1
popq %rdx
callq 0x4997
testb %al, %al
je 0x2eea
cmpb $0x1, 0x71c8(%rip)      # 0xa1fb
jne 0x2eea
movl 0x2c(%rsp), %esi
movq (%rsp), %rdx
leaq 0x3bcb(%rip), %rdi      # 0x6c13
xorl %eax, %eax
callq 0x38f3
jmp 0x2eea
leaq 0x28(%rsp), %rsi
pushq $-0x1
popq %rdx
callq 0x4997
movq (%rsp), %rsi
testb %al, %al
je 0x3243
cmpl $0x0, 0x28(%rsp)
jne 0x3243
movq %rsi, %rdi
leaq 0x3ba6(%rip), %rsi      # 0x6c28
callq 0x21b0
testl %eax, %eax
je 0x34a0
movl $0x40100, 0x88(%rsp) # imm = 0x40100
movb $0x7, 0x84(%rsp)
movw $0xff, 0x8c(%rsp)
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x3859
movb $0xf, 0x8e(%rsp)
leaq 0x8f(%rsp), %rax
orq $-0x1, 0x7(%rax)
orq $-0x1, (%rax)
movq %rsp, %rdi
leaq 0x24(%rsp), %rsi
movl $0xff, %edx
callq 0x4997
testb %al, %al
je 0x310a
movl 0x24(%rsp), %esi
movb %sil, 0x8f(%rsp)
cmpb $0x1, 0x7101(%rip)      # 0xa1fb
jne 0x310a
leaq 0x3b45(%rip), %rdi      # 0x6c48
xorl %eax, %eax
callq 0x38f3
movq %rsp, %rdi
leaq 0x34(%rsp), %rsi
pushq $-0x1
popq %rdx
callq 0x4997
testb %al, %al
je 0x3140
movl 0x34(%rsp), %esi
movl %esi, 0x90(%rsp)
cmpb $0x1, 0x70cb(%rip)      # 0xa1fb
jne 0x3140
leaq 0x3b22(%rip), %rdi      # 0x6c5b
xorl %eax, %eax
callq 0x38f3
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
callq 0x4997
movl 0x30(%rsp), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x317e
movb %sil, 0x94(%rsp)
cmpb $0x1, 0x708d(%rip)      # 0xa1fb
jne 0x317e
leaq 0x3af7(%rip), %rdi      # 0x6c6e
xorl %eax, %eax
callq 0x38f3
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x4997
movl 0x20(%rsp), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x31bb
movl %esi, 0x95(%rsp)
cmpb $0x1, 0x7050(%rip)      # 0xa1fb
jne 0x31bb
leaq 0x3acf(%rip), %rdi      # 0x6c83
xorl %eax, %eax
callq 0x38f3
movq %rsp, %rdi
leaq 0x3c(%rsp), %rsi
xorl %edx, %edx
callq 0x4997
movl 0x3c(%rsp), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x31f9
movb %sil, 0x99(%rsp)
cmpb $0x1, 0x7012(%rip)      # 0xa1fb
jne 0x31f9
leaq 0x3aa6(%rip), %rdi      # 0x6c98
xorl %eax, %eax
callq 0x38f3
movq %rsp, %rdi
leaq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0x4997
movl 0x38(%rsp), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2eea
movl %esi, 0x9a(%rsp)
cmpb $0x1, 0x6fd1(%rip)      # 0xa1fb
jne 0x2eea
leaq 0x3a76(%rip), %rdi      # 0x6cad
xorl %eax, %eax
callq 0x38f3
jmp 0x2eea
leaq 0x3a8d(%rip), %rdi      # 0x6cd7
xorl %eax, %eax
callq 0x3a91
cmpl $0x0, 0x7008(%rip)      # 0xa260
movq %rsp, %rbx
jle 0x3262
callq 0x35ea
movq 0x6fff(%rip), %r14      # 0xa268
testq %r14, %r14
cmoveq %r15, %r14
movq %r14, %rdi
callq 0x20d0
movq %rax, %r13
subq $0x8, %rsp
movq %r14, %rdi
leaq 0x3a6c(%rip), %rsi      # 0x6cf5
movq %rbx, %rdx
leaq 0x34(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x2c(%rsp), %r9
xorl %eax, %eax
leaq 0x28(%rsp), %r10
pushq %r10
leaq 0x40(%rsp), %r10
pushq %r10
leaq 0x4c(%rsp), %r10
pushq %r10
callq 0x2220
addq $0x20, %rsp
cmpl $0x6, %eax
jne 0x331a
movb 0x2c(%rsp), %al
movb %al, 0x84(%rsp)
movl (%rsp), %eax
movl %eax, 0x88(%rsp)
movb 0x28(%rsp), %al
movb %al, 0x8d(%rsp)
movb 0x24(%rsp), %al
movb %al, 0x8c(%rsp)
movslq 0x20(%rsp), %rax
addq %rax, %r14
subq %rax, %r13
cmpb $0x1, 0x6eff(%rip)      # 0xa1fc
leaq 0x3836(%rip), %rbx      # 0x6b3a
leaq 0x6f95(%rip), %rdi      # 0xa2a0
movq %r14, %rsi
movq %r13, %rdx
jne 0x3346
callq 0x3ef2
jmp 0x334d
movq 0x6f47(%rip), %rsi      # 0xa268
testq %rsi, %rsi
cmoveq %r15, %rsi
leaq 0x37ce(%rip), %rdi      # 0x6afd
xorl %eax, %eax
callq 0x3a91
pushq $0xa
popq %r13
leaq 0x37f9(%rip), %rbx      # 0x6b3a
jmp 0x33cf
xorl %ecx, %ecx
callq 0x5caa
movq 0x6f54(%rip), %rdx      # 0xa2a8
movl $0xdf, %eax
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movb %dl, 0x8e(%rsp)
movq 0x6f32(%rip), %r14      # 0xa2a0
testq %r14, %r14
movq %r14, %rsi
cmoveq %r15, %rsi
leaq 0x8f(%rsp), %rdi
callq 0x21e0
andq $0x0, 0x6f1b(%rip)      # 0xa2a8
testq %r14, %r14
pushq $0xa
popq %r13
je 0x339a
movb $0x0, (%r14)
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x3859
andl $0x0, 0x6f0b(%rip)      # 0xa2b8
cmpl $0x0, 0x6eac(%rip)      # 0xa260
jle 0x33c9
movb $0x0, 0x8e(%rsp)
movb $0x1, %al
movl %eax, 0x1c(%rsp)
jmp 0x2eaa
movb $0x1, %al
movl %eax, 0x1c(%rsp)
movzbl 0x8e(%rsp), %r10d
testl %r10d, %r10d
je 0x2eaa
movzbl 0x84(%rsp), %ecx
movl 0x88(%rsp), %r8d
movzbl 0x8d(%rsp), %r9d
movzbl 0x8c(%rsp), %r11d
leaq 0x6e96(%rip), %r14      # 0xa2a0
movq %r14, %rdi
leaq 0x3713(%rip), %rsi      # 0x6b27
leaq 0x48(%rsp), %rdx
xorl %eax, %eax
pushq %r10
pushq %r11
callq 0x3e6e
popq %rax
popq %rcx
movzbl 0x8e(%rsp), %edx
movq %r14, %rdi
leaq 0x8f(%rsp), %rsi
pushq $0x2c
popq %rcx
callq 0x3dae
movq %r14, %rdi
leaq 0x3301(%rip), %rsi      # 0x674c
callq 0x3faf
movq 0x6e49(%rip), %rsi      # 0xa2a0
testq %rsi, %rsi
cmoveq %r15, %rsi
movq 0x6e43(%rip), %rdx      # 0xa2a8
pushq $0x1
popq %rdi
callq 0x20c0
testq %rax, %rax
jg 0x3480
leaq 0x34da(%rip), %rdi      # 0x6953
xorl %eax, %eax
callq 0x3b22
andq $0x0, 0x6e20(%rip)      # 0xa2a8
movq 0x6e11(%rip), %rax      # 0xa2a0
testq %rax, %rax
je 0x2eaa
movb $0x0, (%rax)
jmp 0x2eaa
leaq 0x3787(%rip), %rdi      # 0x6c2e
xorl %eax, %eax
callq 0x3a00
movl 0x6e04(%rip), %eax      # 0xa2b8
leal 0x1(%rax), %ecx
movl %ecx, 0x6dfb(%rip)      # 0xa2b8
cmpl $0xa, %eax
jl 0x2eea
callq 0x35ea
jmp 0x2eea
cmpq $0x0, 0x6d98(%rip)      # 0xa270
je 0x3508
movq 0x6d87(%rip), %rax      # 0xa268
testq %rax, %rax
movq %rax, %rcx
cmoveq %r15, %rcx
movzbl (%rcx), %ecx
cmpl $0x21, %ecx
je 0x3508
cmpl $0x24, %ecx
je 0x3508
andq $0x0, 0x6d70(%rip)      # 0xa270
testq %rax, %rax
je 0x3508
movb $0x0, (%rax)
movl 0x1c(%rsp), %ebx
jmp 0x3510
xorl %ebx, %ebx
cmpl $0x0, 0x6d49(%rip)      # 0xa260
jne 0x29bb
cmpq $0x0, 0x6d13(%rip)      # 0xa238
jle 0x29bb
callq 0x380c
movq %rax, %r14
movq 0x6d5e(%rip), %rax      # 0xa298
testq %rax, %rax
sete %cl
orb %bl, %cl
testb $0x1, %cl
je 0x3551
movq %r14, 0x6d4a(%rip)      # 0xa298
movq %r14, %rax
imulq $-0x3e8, 0x6cdc(%rip), %rcx # imm = 0xFC18
addq %r14, %rcx
cmpq %rcx, %rax
jae 0x29bb
movl 0x10(%rsp), %edi
callq 0x2180
movq 0x6d20(%rip), %rax      # 0xa298
subq %rax, %r14
leaq 0x3368(%rip), %rdi      # 0x68ea
movq %r14, %rsi
xorl %eax, %eax
callq 0x3a91
leaq 0x337b(%rip), %rdi      # 0x690e
xorl %eax, %eax
callq 0x3a91
movq 0x40(%rsp), %rsi
movq (%rsi), %rdi
callq 0x22d0
jmp 0x29bb
leaq 0x2a8e(%rip), %rdi      # 0x6041
callq 0x20a0
xorl %edi, %edi
callq 0x22f0
movq 0x6a32(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2aef(%rip), %rsi      # 0x60bf
movq 0x10(%rsp), %rcx
movq %rcx, %rdx
movq %rcx, %r8
xorl %eax, %eax
callq 0x21c0
pushq $0x1
popq %rdi
callq 0x22f0