// File: /workspace/github_c_makefile_star2_O3/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
movl %edi, %r15d
movq %rsi, 0x30(%rsp)
movq (%rsi), %rdi
movq %rdi, 0x20(%rsp)
callq 0x3d26
cmpl $0x2, %r15d
jl 0x3690
leaq 0x8d3d(%rip), %rbx      # 0xb1f0
leaq 0x8d4e(%rip), %r13      # 0xb208
movq $0x0, (%rsp)
movq 0x30(%rsp), %r14
movq %rbx, %r12
movq 0x8(%r14), %rbx
movq %rbx, %rdi
leaq 0x4b60(%rip), %rsi      # 0x7038
callq 0x2040
testl %eax, %eax
je 0x367d
movq %rbx, %rdi
leaq 0x4b58(%rip), %rsi      # 0x7047
callq 0x2040
testl %eax, %eax
je 0x25d8
movq %rbx, %rdi
leaq 0x4b44(%rip), %rsi      # 0x704a
callq 0x2040
testl %eax, %eax
je 0x25e1
movq %rbx, %rdi
leaq 0x4b30(%rip), %rsi      # 0x704d
callq 0x2040
testl %eax, %eax
je 0x25ea
movq %rbx, %rdi
leaq 0x4b1c(%rip), %rsi      # 0x7050
callq 0x2040
testl %eax, %eax
je 0x25f3
movq %rbx, %rdi
leaq 0x4b08(%rip), %rsi      # 0x7053
callq 0x2040
testl %eax, %eax
je 0x2605
movq %rbx, %rdi
leaq 0x4af4(%rip), %rsi      # 0x7056
callq 0x2040
testl %eax, %eax
je 0x25fc
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4ae8(%rip), %rsi      # 0x7067
callq 0x2040
testl %eax, %eax
je 0x25fc
leaq 0x8(%r14), %rbp
movq %rbx, %rdi
leaq 0x4ad4(%rip), %rsi      # 0x706a
callq 0x2040
cmpl $0x2, %r15d
je 0x262f
testl %eax, %eax
jne 0x262f
cmpq $0x0, 0x8c43(%rip)      # 0xb1f8
movq %r12, %rbx
je 0x25c9
movq %rbx, %rdi
leaq 0x5668(%rip), %rsi      # 0x7c2c
callq 0x40c9
decl %r15d
movq 0x10(%r14), %rdx
movq %rbx, %rdi
jmp 0x266e
movb $0x1, 0x8c09(%rip)      # 0xb1e8
jmp 0x260c
movb $0x1, 0x8c01(%rip)      # 0xb1e9
jmp 0x260c
movb $0x1, 0x8bf9(%rip)      # 0xb1ea
jmp 0x260c
movb $0x1, 0x8bf1(%rip)      # 0xb1eb
jmp 0x260c
movb $0x1, 0x8bea(%rip)      # 0xb1ed
jmp 0x260c
movb $0x1, 0x8be0(%rip)      # 0xb1ec
movq %r14, %rbp
movq %r12, %rbx
leal -0x1(%r15), %eax
addq $0x8, %rbp
movq %rbp, %r14
cmpl $0x2, %r15d
movl %eax, %r15d
jg 0x24c7
jmp 0x2840
movq %rbx, %rdi
leaq 0x4a35(%rip), %rsi      # 0x706e
callq 0x2040
cmpl $0x2, %r15d
je 0x267e
testl %eax, %eax
jne 0x267e
cmpq $0x0, 0x8bc0(%rip)      # 0xb210
movq %r12, %rbx
je 0x2664
movq %r13, %rdi
leaq 0x55cd(%rip), %rsi      # 0x7c2c
callq 0x40c9
decl %r15d
movq 0x10(%r14), %rdx
movq %r13, %rdi
leaq 0x5aa4(%rip), %rsi      # 0x8119
xorl %eax, %eax
callq 0x3f95
jmp 0x2612
movq %rbx, %rdi
leaq 0x49ea(%rip), %rsi      # 0x7072
callq 0x2040
cmpl $0x2, %r15d
je 0x26ba
testl %eax, %eax
jne 0x26ba
decl %r15d
movq 0x10(%r14), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x21d0
movq %rax, 0x8b6f(%rip)      # 0xb220
leaq 0x49ca(%rip), %rdi      # 0x7082
jmp 0x26f4
movq %rbx, %rdi
leaq 0x49b1(%rip), %rsi      # 0x7075
callq 0x2040
cmpl $0x2, %r15d
je 0x2703
testl %eax, %eax
jne 0x2703
decl %r15d
movq 0x10(%r14), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x21d0
movq %rax, 0x8b3b(%rip)      # 0xb228
leaq 0x4988(%rip), %rdi      # 0x707c
movq %rax, %rsi
xorl %eax, %eax
callq 0x3ae9
jmp 0x260f
movq %rbx, %rdi
leaq 0x4991(%rip), %rsi      # 0x709e
callq 0x2040
cmpl $0x2, %r15d
je 0x2771
testl %eax, %eax
jne 0x2771
movq 0x10(%r14), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x21d0
movl %eax, 0x8aa2(%rip)      # 0xb1d4
cmpl $0x383ff, %eax          # imm = 0x383FF
jg 0x279e
cmpl $0x9600, %eax           # imm = 0x9600
movq %r12, %rbx
je 0x27d6
cmpl $0xe100, %eax           # imm = 0xE100
je 0x2808
cmpl $0x1c200, %eax          # imm = 0x1C200
jne 0x27f8
movl $0x1002, 0x8a69(%rip)   # imm = 0x1002
movl $0x1002, %edx           # imm = 0x1002
jmp 0x2828
movq %rbx, %rdi
leaq 0x4941(%rip), %rsi      # 0x70bc
callq 0x2040
testl %eax, %eax
je 0x27c7
movq %r14, %rbp
cmpq $0x0, (%rsp)
movq %rbx, (%rsp)
movq %r12, %rbx
je 0x2612
jmp 0x3690
cmpl $0x38400, %eax          # imm = 0x38400
movq %r12, %rbx
je 0x27e7
cmpl $0x70800, %eax          # imm = 0x70800
je 0x2819
cmpl $0xe1000, %eax          # imm = 0xE1000
jne 0x27f8
movl $0x1007, 0x8a10(%rip)   # imm = 0x1007
movl $0x1007, %edx           # imm = 0x1007
jmp 0x2828
movl $0x3, %edi
callq 0x3cfd
jmp 0x260c
movl $0xf, 0x89f0(%rip)      # 0xb1d0
movl $0xf, %edx
jmp 0x2828
movl $0x1003, 0x89df(%rip)   # imm = 0x1003
movl $0x1003, %edx           # imm = 0x1003
jmp 0x2828
movl 0x89d2(%rip), %edx      # 0xb1d0
movq $0x0, (%rsp)
jmp 0x2828
movl $0x1001, 0x89be(%rip)   # imm = 0x1001
movl $0x1001, %edx           # imm = 0x1001
jmp 0x2828
movl $0x1004, 0x89ad(%rip)   # imm = 0x1004
movl $0x1004, %edx           # imm = 0x1004
decl %r15d
leaq 0x486f(%rip), %rdi      # 0x70a1
movl %eax, %esi
xorl %eax, %eax
callq 0x3ae9
jmp 0x2612
cmpq $0x0, (%rsp)
je 0x3690
leaq 0x4efc(%rip), %rdi      # 0x774e
movq (%rsp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3ae9
leaq 0x4ef3(%rip), %rsi      # 0x775a
movl $0x4, %edx
movq %rbx, %rdi
callq 0x2070
movq %rbx, %rdi
testl %eax, %eax
je 0x298f
movl $0x902, %esi            # imm = 0x902
xorl %eax, %eax
callq 0x2290
movl %eax, %r15d
leaq 0x4ef2(%rip), %rdi      # 0x7787
movl %eax, %esi
xorl %eax, %eax
callq 0x3ae9
testl %r15d, %r15d
jns 0x28b4
leaq 0x4ee6(%rip), %rdi      # 0x7790
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3c0f
leaq 0x1b0(%rsp), %rsi
movl %r15d, %edi
callq 0x2320
testl %eax, %eax
jns 0x28d9
leaq 0x4ed8(%rip), %rdi      # 0x77a7
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3c0f
movl $0xf000, %eax           # imm = 0xF000
andl 0x1c8(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
sete 0x893f(%rip)            # 0xb230
je 0x29d1
movl 0x88d7(%rip), %esi      # 0xb1d4
leaq 0x4ef4(%rip), %rdi      # 0x77f8
xorl %eax, %eax
callq 0x3ae9
xorps %xmm0, %xmm0
leaq 0x170(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, 0x20(%rdi)
movups %xmm0, 0x2c(%rdi)
movl 0x88a5(%rip), %esi      # 0xb1d0
callq 0x2170
testl %eax, %eax
jns 0x2948
movl 0x889a(%rip), %esi      # 0xb1d4
leaq 0x4ef1(%rip), %rdi      # 0x7832
xorl %eax, %eax
callq 0x3c0f
leaq 0x170(%rsp), %rbx
orl $0x8b0, 0x8(%rbx)       # imm = 0x8B0
orb $0x4, (%rbx)
movw $0x100, 0x16(%rbx)      # imm = 0x100
movl %r15d, %edi
xorl %esi, %esi
callq 0x20e0
movl %r15d, %edi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2280
movb $0x1, 0x88b3(%rip)      # 0xb231
movl $0xe, 0x88c8(%rip)      # 0xb250
callq 0x36bd
jmp 0x29df
callq 0x4720
movl %eax, %r15d
leaq 0x4dc1(%rip), %rdi      # 0x775f
movl %eax, %esi
xorl %eax, %eax
callq 0x3ae9
movb $0x1, 0x8882(%rip)      # 0xb230
testl %r15d, %r15d
jns 0x29d1
leaq 0x4db2(%rip), %rdi      # 0x776c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3c0f
testb $0x1, 0x8865(%rip)      # 0xb230
je 0x28f7
leaq 0x4deb(%rip), %rdi      # 0x77c3
xorl %eax, %eax
callq 0x39d8
leaq 0x4d67(%rip), %r13      # 0x774d
leaq 0x886b(%rip), %r12      # 0xb258
movl %r15d, 0x3c(%rsp)
cmpq $0x1, 0x8846(%rip)      # 0xb240
movl $0x0, %ebx
sbbl %ebx, %ebx
orl %r15d, %ebx
movl %ebx, %eax
notl %eax
xorl %r14d, %r14d
orl 0x883f(%rip), %eax      # 0xb250
setne %r14b
negl %r14d
movl 0x8802(%rip), %ecx      # 0xb220
movl %r15d, %edi
movl %r14d, %esi
movl %ebx, %edx
callq 0x493d
movl %eax, %ebp
movq 0x87ec(%rip), %r8       # 0xb220
leaq 0x4e0f(%rip), %rdi      # 0x784a
movl %r15d, %esi
movl %r14d, %edx
movl %ebx, %ecx
movl %eax, %r9d
xorl %eax, %eax
callq 0x3ae9
testb $0x1, %bpl
je 0x2aaf
movl $0x400, %edx            # imm = 0x400
movl %r15d, %edi
leaq 0x240(%rsp), %rbx
movq %rbx, %rsi
callq 0x21a0
testq %rax, %rax
jle 0x2a80
movq %r12, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3e50
jmp 0x2aaf
js 0x2a92
leaq 0x4df9(%rip), %rdi      # 0x7882
xorl %eax, %eax
callq 0x3c0f
jmp 0x2aaf
callq 0x2050
movl (%rax), %edi
callq 0x2310
leaq 0x4dc3(%rip), %rdi      # 0x7868
movq %rax, %rsi
xorl %eax, %eax
callq 0x3c0f
testb $0x2, %bpl
leaq 0x8(%rsp), %r14
je 0x2d10
movl $0x400, %edx            # imm = 0x400
xorl %edi, %edi
leaq 0x240(%rsp), %rsi
callq 0x21a0
testq %rax, %rax
jle 0x2cdc
leaq 0x878e(%rip), %rdi      # 0xb270
leaq 0x240(%rsp), %rsi
movq %rax, (%rsp)
movq %rax, %rdx
callq 0x3e50
movq 0x8773(%rip), %r15      # 0xb270
testq %r15, %r15
sete %bl
movq %r15, %rdi
cmoveq %r13, %rdi
movl $0xa, %esi
callq 0x20f0
testq %rax, %rax
je 0x2cae
movq %rax, %r14
cmpb $0x0, 0x86c3(%rip)      # 0xb1ea
leaq 0x870a(%rip), %rbx      # 0xb238
jne 0x2c22
leaq 0x8735(%rip), %rdi      # 0xb270
leaq 0x48(%rsp), %rsi
callq 0x57c7
movl 0x88(%rsp), %edx
cmpl $0x40000, %edx          # imm = 0x40000
setb %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2b9a
movzbl 0x8c(%rsp), %ecx
movq %rbx, %rdi
leaq 0x4dc1(%rip), %rsi      # 0x792f
xorl %eax, %eax
callq 0x3f95
movzbl 0x8e(%rsp), %edx
cmpb $0x1, 0x8668(%rip)      # 0xb1ec
jne 0x2be3
movq %rbx, %rdi
leaq 0x8f(%rsp), %rsi
xorl %ecx, %ecx
callq 0x3ea7
jmp 0x2bf5
movb 0x8e(%rsp), %al
cmpb $0x7, %al
setb %cl
orb 0x863e(%rip), %cl       # 0xb1ea
testb $0x1, %cl
jne 0x2c22
movl 0x8f(%rsp), %ecx
movl $0x47445024, %edx       # imm = 0x47445024
xorl %edx, %ecx
movzwl 0x93(%rsp), %edx
xorl $0x59, %edx
orl %ecx, %edx
jne 0x2c22
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x8f(%rsp), %rsi
callq 0x3e50
jmp 0x2bf5
movq %rbx, %rdi
leaq 0x8f(%rsp), %rsi
xorl %ecx, %ecx
callq 0x5d9c
movq %rbx, %rdi
leaq 0x4e55(%rip), %rsi      # 0x7a54
xorl %eax, %eax
callq 0x3f95
movq 0x862b(%rip), %rsi      # 0xb238
testq %rsi, %rsi
cmoveq %r13, %rsi
leaq 0x4d21(%rip), %rdi      # 0x793c
xorl %eax, %eax
callq 0x3ae9
cmpb $0x1, 0x85c0(%rip)      # 0xb1e9
jne 0x2c5f
movq 0x863e(%rip), %rsi      # 0xb270
testq %rsi, %rsi
cmoveq %r13, %rsi
movq %r14, %rdx
subq %rsi, %rdx
incq %rdx
movl $0x1, %edi
callq 0x20c0
testq %rax, %rax
jg 0x2c5f
leaq 0x4cfb(%rip), %rdi      # 0x7953
xorl %eax, %eax
callq 0x3c0f
movq 0x860a(%rip), %rax      # 0xb270
testq %rax, %rax
cmoveq %r13, %rax
subq %rax, %r14
incq %r14
leaq 0x85f6(%rip), %rdi      # 0xb270
xorl %esi, %esi
movq %r14, %rdx
callq 0x3df5
movq 0x85e5(%rip), %r15      # 0xb270
testq %r15, %r15
sete %bl
movq %r15, %rdi
cmoveq %r13, %rdi
movl $0xa, %esi
callq 0x20f0
movq %rax, %r14
testq %rax, %rax
jne 0x2b20
cmpq $0x2c1, 0x85bf(%rip) # imm = 0x2C1
jb 0x2cce
movq $0x0, 0x85b2(%rip) # 0xb278
testb %bl, %bl
jne 0x2cce
movb $0x0, (%r15)
movl 0x3c(%rsp), %r15d
leaq 0x8(%rsp), %r14
movq (%rsp), %rax
testq %rax, %rax
js 0x2cf3
jne 0x2d10
leaq 0x4bc0(%rip), %rdi      # 0x78aa
xorl %eax, %eax
callq 0x3c0f
jmp 0x2d10
callq 0x2050
movl (%rax), %edi
callq 0x2310
leaq 0x4b8b(%rip), %rdi      # 0x7891
movq %rax, %rsi
xorl %eax, %eax
callq 0x3c0f
shrb $0x2, %bpl
movq 0x8525(%rip), %rdx      # 0xb240
testq %rdx, %rdx
setne %al
andb %bpl, %al
cmpb $0x1, %al
jne 0x2d91
movq 0x8509(%rip), %rsi      # 0xb238
testq %rsi, %rsi
cmoveq %r13, %rsi
movl %r15d, %edi
callq 0x20c0
testq %rax, %rax
jle 0x2d81
movq %rax, %rbx
cmpb $0x1, 0x849e(%rip)      # 0xb1eb
jne 0x2d6e
movq 0x84e2(%rip), %rdx      # 0xb238
testq %rdx, %rdx
cmoveq %r13, %rdx
leaq 0x4b54(%rip), %rdi      # 0x78b8
movq %rbx, %rsi
xorl %eax, %eax
callq 0x39d8
leaq 0x84c3(%rip), %rdi      # 0xb238
xorl %esi, %esi
movq %rbx, %rdx
callq 0x3df5
jmp 0x2d91
jne 0x2d91
leaq 0x4b3d(%rip), %rdi      # 0x78c7
xorl %eax, %eax
callq 0x3c0f
movq 0x84c8(%rip), %rsi      # 0xb260
testq %rsi, %rsi
je 0x35df
movl $0x0, 0x20(%rsp)
leaq 0x4b26(%rip), %rdi      # 0x78d6
xorl %eax, %eax
callq 0x3ae9
movq 0x84a2(%rip), %rsi      # 0xb260
leaq 0x4cca(%rip), %rdi      # 0x7a8f
xorl %eax, %eax
callq 0x3ae9
movq %r12, %rdi
movl $0xa, %esi
callq 0x4654
testq %rax, %rax
je 0x359e
movq %rax, %rbp
movb $0x1, %al
movl %eax, (%rsp)
movl $0x0, 0x20(%rsp)
movq 0x845f(%rip), %rbx      # 0xb258
testq %rbx, %rbx
cmoveq %r13, %rbx
movq %rbp, %rsi
subq %rbx, %rsi
cmpq $0x8, %rsi
jb 0x2ef5
movzbl (%rbx), %eax
cmpl $0x24, %eax
je 0x2e21
cmpl $0x21, %eax
jne 0x2ef5
leaq 0x4c82(%rip), %rdi      # 0x7aaa
xorl %eax, %eax
callq 0x3ae9
movl $0x128, %edx            # imm = 0x128
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x2160
movb $0x0, (%rbp)
leaq 0x1(%rbx), %rax
cmpq %rax, %rbp
jbe 0x2e57
cmpb $0xd, -0x1(%rbp)
jne 0x2e57
movb $0x0, -0x1(%rbp)
leaq 0x4c74(%rip), %rdi      # 0x7ad2
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3ae9
cmpb $0x0, 0x8379(%rip)      # 0xb1e8
jne 0x34b5
movq 0x83dc(%rip), %rax      # 0xb258
testq %rax, %rax
cmoveq %r13, %rax
movq %rax, 0x8(%rsp)
movq %r14, %rdi
leaq 0x4cbd(%rip), %rsi      # 0x7b4f
callq 0x4bd7
testb %al, %al
je 0x3341
movq %r14, %rdi
leaq 0x4cad(%rip), %rsi      # 0x7b56
callq 0x4bd7
testb %al, %al
je 0x2f45
movq 0x8(%rsp), %rsi
leaq 0x4c9a(%rip), %rdi      # 0x7b5c
xorl %eax, %eax
callq 0x39d8
cmpl $0xd, 0x8380(%rip)      # 0xb250
jne 0x2f58
movl $0xc, 0x8370(%rip)      # 0xb250
leaq 0x4c86(%rip), %rdi      # 0x7b6d
movl $0xc, %esi
xorl %eax, %eax
callq 0x3ae9
jmp 0x2f58
incq %rsi
leaq 0x4c3b(%rip), %rdi      # 0x7b3a
xorl %eax, %eax
callq 0x3ae9
movq 0x834b(%rip), %rax      # 0xb258
testq %rax, %rax
cmoveq %r13, %rax
subq %rax, %rbp
incq %rbp
movq %r12, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x3df5
movq %r12, %rdi
movl $0xa, %esi
callq 0x4654
movq %rax, %rbp
testq %rax, %rax
jne 0x2df2
jmp 0x359e
cmpl $0xd, 0x8304(%rip)      # 0xb250
jne 0x2f8b
movl $0xe, 0x82f8(%rip)      # 0xb250
movq 0x82f9(%rip), %rsi      # 0xb258
testq %rsi, %rsi
cmoveq %r13, %rsi
leaq 0x4b74(%rip), %rdi      # 0x7ae1
xorl %eax, %eax
callq 0x3ae9
testb $0x1, (%rsp)
je 0x2f7f
callq 0x36bd
movl $0x0, (%rsp)
jmp 0x34b5
movq %r14, %rdi
leaq 0x4bff(%rip), %rsi      # 0x7b94
callq 0x4bd7
testb %al, %al
je 0x2fbc
cmpb $0x1, 0x8246(%rip)      # 0xb1eb
jne 0x2f58
movq 0x8(%rsp), %rsi
leaq 0x4bee(%rip), %rdi      # 0x7ba1
xorl %eax, %eax
callq 0x39d8
jmp 0x2f58
movq %r14, %rdi
leaq 0x4bfa(%rip), %rsi      # 0x7bc0
callq 0x4bd7
testb %al, %al
je 0x3013
cmpb $0x1, 0x8215(%rip)      # 0xb1eb
jne 0x2feb
movq 0x8(%rsp), %rsi
leaq 0x4be9(%rip), %rdi      # 0x7bcd
xorl %eax, %eax
callq 0x39d8
cmpl $0x5, 0x825e(%rip)      # 0xb250
jne 0x2f58
movl $0x4, 0x824e(%rip)      # 0xb250
leaq 0x4b64(%rip), %rdi      # 0x7b6d
movl $0x4, %esi
jmp 0x2eec
movq %r14, %rdi
leaq 0x4bd0(%rip), %rsi      # 0x7bed
callq 0x4bd7
testb %al, %al
je 0x3070
cmpb $0x1, 0x81be(%rip)      # 0xb1eb
jne 0x3042
movq 0x8(%rsp), %rsi
leaq 0x4bb7(%rip), %rdi      # 0x7bf2
xorl %eax, %eax
callq 0x39d8
movl 0x8208(%rip), %esi      # 0xb250
testl %esi, %esi
setle %al
testb $0x1, %sil
sete %cl
orb %al, %cl
jne 0x2f58
decl %esi
movl %esi, 0x81ec(%rip)      # 0xb250
leaq 0x4b02(%rip), %rdi      # 0x7b6d
jmp 0x2eec
movq %r14, %rdi
leaq 0x4b94(%rip), %rsi      # 0x7c0e
callq 0x4bd7
movq %r14, %rdi
testb %al, %al
je 0x30c6
leaq 0x1c(%rsp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4b83
testb %al, %al
je 0x2f58
cmpb $0x1, 0x8147(%rip)      # 0xb1eb
jne 0x2f58
movl 0x1c(%rsp), %esi
movq 0x8(%rsp), %rdx
leaq 0x4b59(%rip), %rdi      # 0x7c13
xorl %eax, %eax
callq 0x39d8
jmp 0x2f58
leaq 0x18(%rsp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4b83
movq 0x8(%rsp), %rsi
testb %al, %al
je 0x32bf
cmpl $0x0, 0x18(%rsp)
jne 0x32bf
movq %rsi, %rdi
leaq 0x4b31(%rip), %rsi      # 0x7c28
callq 0x21b0
testl %eax, %eax
je 0x32f0
movl $0x40100, 0x88(%rsp) # imm = 0x40100
movb $0x7, 0x84(%rsp)
movw $0xff, 0x8c(%rsp)
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x3923
movb $0xf, 0x8e(%rsp)
leaq 0x8f(%rsp), %rax
movq $-0x1, %rcx
movq %rcx, 0x7(%rax)
movq %rcx, (%rax)
movq %r14, %rdi
leaq 0x14(%rsp), %rsi
movl $0xff, %edx
callq 0x4b83
testb %al, %al
je 0x3184
movl 0x14(%rsp), %esi
movb %sil, 0x8f(%rsp)
cmpb $0x1, 0x8077(%rip)      # 0xb1eb
jne 0x3184
leaq 0x4acb(%rip), %rdi      # 0x7c48
xorl %eax, %eax
callq 0x39d8
movq %r14, %rdi
leaq 0x2c(%rsp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4b83
testb %al, %al
je 0x31bc
movl 0x2c(%rsp), %esi
movl %esi, 0x90(%rsp)
cmpb $0x1, 0x803f(%rip)      # 0xb1eb
jne 0x31bc
leaq 0x4aa6(%rip), %rdi      # 0x7c5b
xorl %eax, %eax
callq 0x39d8
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x4b83
movl 0x28(%rsp), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x31fa
movb %sil, 0x94(%rsp)
cmpb $0x1, 0x8001(%rip)      # 0xb1eb
jne 0x31fa
leaq 0x4a7b(%rip), %rdi      # 0x7c6e
xorl %eax, %eax
callq 0x39d8
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
xorl %edx, %edx
callq 0x4b83
movl 0x10(%rsp), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3237
movl %esi, 0x95(%rsp)
cmpb $0x1, 0x7fc4(%rip)      # 0xb1eb
jne 0x3237
leaq 0x4a53(%rip), %rdi      # 0x7c83
xorl %eax, %eax
callq 0x39d8
movq %r14, %rdi
leaq 0x44(%rsp), %rsi
xorl %edx, %edx
callq 0x4b83
movl 0x44(%rsp), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3275
movb %sil, 0x99(%rsp)
cmpb $0x1, 0x7f86(%rip)      # 0xb1eb
jne 0x3275
leaq 0x4a2a(%rip), %rdi      # 0x7c98
xorl %eax, %eax
callq 0x39d8
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
xorl %edx, %edx
callq 0x4b83
movl 0x40(%rsp), %esi
testl %esi, %esi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2f58
movl %esi, 0x9a(%rsp)
cmpb $0x1, 0x7f45(%rip)      # 0xb1eb
jne 0x2f58
leaq 0x49fa(%rip), %rdi      # 0x7cad
xorl %eax, %eax
callq 0x39d8
jmp 0x2f58
leaq 0x4a11(%rip), %rdi      # 0x7cd7
xorl %eax, %eax
callq 0x3b7c
cmpl $0x0, 0x7f7c(%rip)      # 0xb250
jle 0x3341
cmpb $0x1, 0x7f54(%rip)      # 0xb231
jne 0x3337
movl $0xe, 0x7f67(%rip)      # 0xb250
callq 0x36bd
jmp 0x3341
leaq 0x4937(%rip), %rdi      # 0x7c2e
xorl %eax, %eax
callq 0x3ae9
movl 0x7fa4(%rip), %eax      # 0xb2a8
leal 0x1(%rax), %ecx
movl %ecx, 0x7f9b(%rip)      # 0xb2a8
cmpl $0xa, %eax
jl 0x2f58
cmpb $0x1, 0x7f14(%rip)      # 0xb231
jne 0x358f
movl $0xe, 0x7f23(%rip)      # 0xb250
callq 0x36bd
jmp 0x2f58
movl $0x0, 0x7f0f(%rip)      # 0xb250
movq 0x7f10(%rip), %rbx      # 0xb258
testq %rbx, %rbx
cmoveq %r13, %rbx
movq %rbx, %rdi
callq 0x20d0
movq %r14, %rdx
movq %rax, %r14
subq $0x8, %rsp
movq %rbx, %rdi
leaq 0x498a(%rip), %rsi      # 0x7cf5
leaq 0x24(%rsp), %rcx
leaq 0x20(%rsp), %r8
leaq 0x1c(%rsp), %r9
xorl %eax, %eax
leaq 0x18(%rsp), %r10
pushq %r10
leaq 0x38(%rsp), %r10
pushq %r10
leaq 0x44(%rsp), %r10
pushq %r10
callq 0x2220
addq $0x20, %rsp
cmpl $0x6, %eax
jne 0x33f3
movb 0x1c(%rsp), %al
movb %al, 0x84(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x88(%rsp)
movb 0x18(%rsp), %al
movb %al, 0x8d(%rsp)
movb 0x14(%rsp), %al
movb %al, 0x8c(%rsp)
movslq 0x10(%rsp), %rax
addq %rax, %rbx
subq %rax, %r14
cmpb $0x1, 0x7e0f(%rip)      # 0xb1ec
jne 0x3419
leaq 0x7eaa(%rip), %rdi      # 0xb290
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4019
jmp 0x342d
movq 0x7e5e(%rip), %rsi      # 0xb258
testq %rsi, %rsi
cmoveq %r13, %rsi
leaq 0x46f5(%rip), %rdi      # 0x7afd
xorl %eax, %eax
callq 0x3b7c
leaq 0x8(%rsp), %r14
jmp 0x34b5
leaq 0x7e70(%rip), %rdi      # 0xb290
movq %rbx, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x5f39
movq 0x7e64(%rip), %rdx      # 0xb298
movl $0xdf, %eax
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movb %dl, 0x8e(%rsp)
movq 0x7e42(%rip), %rbx      # 0xb290
testq %rbx, %rbx
movq %rbx, %rsi
cmoveq %r13, %rsi
leaq 0x8f(%rsp), %rdi
callq 0x21e0
movq $0x0, 0x7e28(%rip) # 0xb298
testq %rbx, %rbx
leaq 0x8(%rsp), %r14
je 0x347d
movb $0x0, (%rbx)
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x3923
movl $0x0, 0x7e15(%rip)      # 0xb2a8
cmpl $0x0, 0x7db6(%rip)      # 0xb250
jle 0x34af
movb $0x0, 0x8e(%rsp)
movb $0x1, %al
movl %eax, 0x20(%rsp)
jmp 0x2f06
movb $0x1, %al
movl %eax, 0x20(%rsp)
movzbl 0x8e(%rsp), %r10d
testl %r10d, %r10d
je 0x2f06
movzbl 0x84(%rsp), %ecx
movl 0x88(%rsp), %r8d
movzbl 0x8d(%rsp), %r9d
movzbl 0x8c(%rsp), %r11d
leaq 0x7da0(%rip), %rbx      # 0xb290
movq %rbx, %rdi
leaq 0x462d(%rip), %rsi      # 0x7b27
leaq 0x48(%rsp), %rdx
xorl %eax, %eax
pushq %r10
pushq %r11
callq 0x3f95
addq $0x10, %rsp
movzbl 0x8e(%rsp), %edx
movq %rbx, %rdi
leaq 0x8f(%rsp), %rsi
movl $0x2c, %ecx
callq 0x3ea7
movq %rbx, %rdi
leaq 0x4217(%rip), %rsi      # 0x774c
callq 0x40c9
movq 0x7d4f(%rip), %rsi      # 0xb290
testq %rsi, %rsi
cmoveq %r13, %rsi
movq 0x7d49(%rip), %rdx      # 0xb298
movl $0x1, %edi
callq 0x20c0
testq %rax, %rax
jg 0x356c
leaq 0x43ee(%rip), %rdi      # 0x7953
xorl %eax, %eax
callq 0x3c0f
movq $0x0, 0x7d21(%rip) # 0xb298
movq 0x7d12(%rip), %rax      # 0xb290
testq %rax, %rax
je 0x2f06
movb $0x0, (%rax)
jmp 0x2f06
movl $0x0, 0x7cb7(%rip)      # 0xb250
jmp 0x2f58
cmpq $0x0, 0x7cba(%rip)      # 0xb260
je 0x35d9
movq 0x7ca9(%rip), %rax      # 0xb258
testq %rax, %rax
movq %rax, %rcx
cmoveq %r13, %rcx
movzbl (%rcx), %ecx
cmpl $0x21, %ecx
je 0x35d9
cmpl $0x24, %ecx
je 0x35d9
movq $0x0, 0x7c8f(%rip) # 0xb260
testq %rax, %rax
je 0x35d9
movb $0x0, (%rax)
movl 0x20(%rsp), %ebp
jmp 0x35e1
xorl %ebp, %ebp
cmpl $0x0, 0x7c68(%rip)      # 0xb250
jne 0x29f2
cmpq $0x0, 0x7c32(%rip)      # 0xb228
jle 0x29f2
callq 0x38c8
movq %rax, %rbx
movq 0x7c7d(%rip), %rax      # 0xb288
testq %rax, %rax
sete %cl
orb %bpl, %cl
testb $0x1, %cl
je 0x3623
movq %rbx, 0x7c68(%rip)      # 0xb288
movq %rbx, %rax
imulq $-0x3e8, 0x7bfa(%rip), %rcx # imm = 0xFC18
addq %rbx, %rcx
cmpq %rcx, %rax
jae 0x29f2
movl %r15d, %edi
callq 0x2180
movq 0x7c3f(%rip), %rax      # 0xb288
subq %rax, %rbx
leaq 0x4297(%rip), %rdi      # 0x78ea
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3b7c
leaq 0x42aa(%rip), %rdi      # 0x790e
xorl %eax, %eax
callq 0x3b7c
movq 0x30(%rsp), %rsi
movq (%rsi), %rdi
callq 0x22c0
jmp 0x29f2
leaq 0x39bd(%rip), %rdi      # 0x7041
callq 0x20a0
xorl %edi, %edi
callq 0x22e0
movq 0x7961(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x3a1e(%rip), %rsi      # 0x70bf
movq 0x20(%rsp), %rcx
movq %rcx, %rdx
movq %rcx, %r8
xorl %eax, %eax
callq 0x21c0
movl $0x1, %edi
callq 0x22e0