// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/ikonvert-serial/ikonvert-serial.c
// Function: parseIKonvertAsciiMessage
static bool parseIKonvertAsciiMessage(const char *msg, RawMessage *n2k)
{
  int error;
  int pgn;

  if (!parseConst(&msg, IKONVERT_ASCII_PREFIX))
  {
    return false;
  }

  if (parseConst(&msg, RX_TEXT_MSG))
  {
    logInfo("Connected to %s\n", msg);
    if (sendInitState == 13)
    {
      sendInitState--;
      logDebug("iKonvert initialization next phase %d\n", sendInitState);
    }
    return true;
  }
  if (sendInitState == 13)
  {
    sendInitState++;
    // Send message again on next loop
    return true;
  }

  if (parseConst(&msg, RX_SHOW_RX_LIST_MSG))
  {
    if (verbose)
    {
      logInfo("iKonvert will receive PGNs %s\n", msg);
    }
    return true;
  }

  if (parseConst(&msg, RX_SHOW_TX_LIST_MSG))
  {
    if (verbose)
    {
      logInfo("iKonvert will transmit PGNs %s\n", msg);
    }
    if (sendInitState == 5)
    {
      sendInitState--;
      logDebug("iKonvert initialization next phase %d\n", sendInitState);
    }
    return true;
  }

  if (parseConst(&msg, RX_ACK_MSG))
  {
    if (verbose)
    {
      logInfo("iKonvert acknowledge of %s\n", msg);
    }
    if ((sendInitState > 0) && (sendInitState % 2 == 1))
    {
      sendInitState--;
      logDebug("iKonvert initialization next phase %d\n", sendInitState);
    }
    return true;
  }

  if (parseConst(&msg, RX_NAK_MSG))
  {
    if (parseInt(&msg, &error, -1) && verbose)
    {
      logInfo("iKonvert NAK %d: %s\n", error, msg);
    }
    return true;
  }
  if (parseInt(&msg, &pgn, -1) && pgn == 0)
  {
    if (strcmp(msg, ",,,,,") == 0)
    {
      logDebug("iKonvert keep-alive seen\n");
      sequentialStatusMessages++;
      if (sequentialStatusMessages > 10)
      {
        initializeDevice();
      }
      return true;
    }

    n2k->pgn  = IKONVERT_BEM;
    n2k->prio = 7;
    n2k->src  = 0;
    n2k->dst  = 255;
    fmtTimestamp(n2k->timestamp, UINT64_C(0));

    int load, errors, count, uptime, addr, rejected;

    n2k->len = 15;
    memset(n2k->data, 0xff, n2k->len);

    if (parseInt(&msg, &load, 0xff))
    {
      n2k->data[0] = (uint8_t) load;
      if (verbose)
      {
        logInfo("CAN Bus load %d%%\n", load);
      }
    }
    if (parseInt(&msg, &errors, -1))
    {
      n2k->data[1] = (uint8_t) (errors >> 0);
      n2k->data[2] = (uint8_t) (errors >> 8);
      n2k->data[3] = (uint8_t) (errors >> 16);
      n2k->data[4] = (uint8_t) (errors >> 24);
      if (verbose)
      {
        logInfo("CAN Bus errors %d\n", errors);
      }
    }
    if (parseInt(&msg, &count, 0) && count != 0)
    {
      n2k->data[5] = (uint8_t) count;
      if (verbose)
      {
        logInfo("CAN device count %d\n", count);
      }
    }
    if (parseInt(&msg, &uptime, 0) && uptime != 0)
    {
      n2k->data[6] = (uint8_t) (uptime >> 0);
      n2k->data[7] = (uint8_t) (uptime >> 8);
      n2k->data[8] = (uint8_t) (uptime >> 16);
      n2k->data[9] = (uint8_t) (uptime >> 24);
      if (verbose)
      {
        logInfo("iKonvert uptime %ds\n", uptime);
      }
    }
    if (parseInt(&msg, &addr, 0) && addr != 0)
    {
      n2k->data[10] = (uint8_t) addr;
      if (verbose)
      {
        logInfo("iKonvert address %d\n", addr);
      }
    }
    if (parseInt(&msg, &rejected, 0) && rejected != 0)
    {
      n2k->data[11] = (uint8_t) (rejected >> 0);
      n2k->data[12] = (uint8_t) (rejected >> 8);
      n2k->data[13] = (uint8_t) (rejected >> 16);
      n2k->data[14] = (uint8_t) (rejected >> 24);
      if (verbose)
      {
        logInfo("iKonvert rejected %d TX message requests\n", rejected);
      }
    }

    return true;
  }
  logError("Unknown iKonvert message: %s\n", msg);
  if (sendInitState > 0)
  {
    initializeDevice();
  }

  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq 0x5f64(%rip), %rsi      # 0x9b4f
callq 0x63f0
testb $0x1, %al
jne 0x3bfd
movb $0x0, -0x1(%rbp)
jmp 0x40f1
leaq -0x10(%rbp), %rdi
leaq 0x5f4e(%rip), %rsi      # 0x9b56
callq 0x63f0
testb $0x1, %al
jne 0x3c13
jmp 0x3c5a
movq -0x10(%rbp), %rsi
leaq 0x5f3e(%rip), %rdi      # 0x9b5c
movb $0x0, %al
callq 0x44f0
cmpl $0xd, 0x8e54(%rip)      # 0xca80
jne 0x3c51
movl 0x8e4c(%rip), %eax      # 0xca80
addl $-0x1, %eax
movl %eax, 0x8e43(%rip)      # 0xca80
movl 0x8e3d(%rip), %esi      # 0xca80
leaq 0x5f23(%rip), %rdi      # 0x9b6d
movb $0x0, %al
callq 0x4640
movb $0x1, -0x1(%rbp)
jmp 0x40f1
cmpl $0xd, 0x8e1f(%rip)      # 0xca80
jne 0x3c7b
movl 0x8e17(%rip), %eax      # 0xca80
addl $0x1, %eax
movl %eax, 0x8e0e(%rip)      # 0xca80
movb $0x1, -0x1(%rbp)
jmp 0x40f1
leaq -0x10(%rbp), %rdi
leaq 0x5f0e(%rip), %rsi      # 0x9b94
callq 0x63f0
testb $0x1, %al
jne 0x3c91
jmp 0x3cb5
testb $0x1, 0x8d83(%rip)      # 0xca1b
je 0x3cac
movq -0x10(%rbp), %rsi
leaq 0x5efc(%rip), %rdi      # 0x9ba1
movb $0x0, %al
callq 0x44f0
movb $0x1, -0x1(%rbp)
jmp 0x40f1
leaq -0x10(%rbp), %rdi
leaq 0x5f00(%rip), %rsi      # 0x9bc0
callq 0x63f0
testb $0x1, %al
jne 0x3ccb
jmp 0x3d1b
testb $0x1, 0x8d49(%rip)      # 0xca1b
je 0x3ce6
movq -0x10(%rbp), %rsi
leaq 0x5eee(%rip), %rdi      # 0x9bcd
movb $0x0, %al
callq 0x44f0
cmpl $0x5, 0x8d93(%rip)      # 0xca80
jne 0x3d12
movl 0x8d8b(%rip), %eax      # 0xca80
addl $-0x1, %eax
movl %eax, 0x8d82(%rip)      # 0xca80
movl 0x8d7c(%rip), %esi      # 0xca80
leaq 0x5e62(%rip), %rdi      # 0x9b6d
movb $0x0, %al
callq 0x4640
movb $0x1, -0x1(%rbp)
jmp 0x40f1
leaq -0x10(%rbp), %rdi
leaq 0x5ec7(%rip), %rsi      # 0x9bed
callq 0x63f0
testb $0x1, %al
jne 0x3d31
jmp 0x3d94
testb $0x1, 0x8ce3(%rip)      # 0xca1b
je 0x3d4c
movq -0x10(%rbp), %rsi
leaq 0x5ead(%rip), %rdi      # 0x9bf2
movb $0x0, %al
callq 0x44f0
cmpl $0x0, 0x8d2d(%rip)      # 0xca80
jle 0x3d8b
movl 0x8d25(%rip), %eax      # 0xca80
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x3d8b
movl 0x8d12(%rip), %eax      # 0xca80
addl $-0x1, %eax
movl %eax, 0x8d09(%rip)      # 0xca80
movl 0x8d03(%rip), %esi      # 0xca80
leaq 0x5de9(%rip), %rdi      # 0x9b6d
movb $0x0, %al
callq 0x4640
movb $0x1, -0x1(%rbp)
jmp 0x40f1
leaq -0x10(%rbp), %rdi
leaq 0x5e6f(%rip), %rsi      # 0x9c0e
callq 0x63f0
testb $0x1, %al
jne 0x3daa
jmp 0x3de9
leaq -0x10(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6350
testb $0x1, %al
jne 0x3dc2
jmp 0x3de0
testb $0x1, 0x8c52(%rip)      # 0xca1b
je 0x3de0
movl -0x1c(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x5e3a(%rip), %rdi      # 0x9c13
movb $0x0, %al
callq 0x44f0
movb $0x1, -0x1(%rbp)
jmp 0x40f1
leaq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6350
testb $0x1, %al
jne 0x3e04
jmp 0x40cd
cmpl $0x0, -0x20(%rbp)
jne 0x40cd
movq -0x10(%rbp), %rdi
leaq 0x5e0f(%rip), %rsi      # 0x9c28
callq 0x21a0
cmpl $0x0, %eax
jne 0x3e57
leaq 0x5e04(%rip), %rdi      # 0x9c2e
movb $0x0, %al
callq 0x4640
movl 0x8ca1(%rip), %eax      # 0xcad8
addl $0x1, %eax
movl %eax, 0x8c98(%rip)      # 0xcad8
cmpl $0xa, 0x8c91(%rip)      # 0xcad8
jle 0x3e4e
callq 0x2fb0
movb $0x1, -0x1(%rbp)
jmp 0x40f1
movq -0x18(%rbp), %rax
movl $0x40100, 0x40(%rax)    # imm = 0x40100
movq -0x18(%rbp), %rax
movb $0x7, 0x3c(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x45(%rax)
movq -0x18(%rbp), %rax
movb $-0x1, 0x44(%rax)
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4400
movq -0x18(%rbp), %rax
movb $0xf, 0x46(%rax)
movq -0x18(%rbp), %rdi
addq $0x47, %rdi
movq -0x18(%rbp), %rax
movzbl 0x46(%rax), %eax
movl %eax, %edx
movl $0xff, %esi
callq 0x2140
leaq -0x10(%rbp), %rdi
leaq -0x24(%rbp), %rsi
movl $0xff, %edx
callq 0x6350
testb $0x1, %al
jne 0x3ec3
jmp 0x3eeb
movl -0x24(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x47(%rax)
testb $0x1, 0x8b45(%rip)      # 0xca1b
je 0x3ee9
movl -0x24(%rbp), %esi
leaq 0x5d66(%rip), %rdi      # 0x9c48
movb $0x0, %al
callq 0x44f0
jmp 0x3eeb
leaq -0x10(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6350
testb $0x1, %al
jne 0x3f03
jmp 0x3f5b
movl -0x28(%rbp), %eax
sarl $0x0, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x48(%rax)
movl -0x28(%rbp), %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x49(%rax)
movl -0x28(%rbp), %eax
sarl $0x10, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4a(%rax)
movl -0x28(%rbp), %eax
sarl $0x18, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4b(%rax)
testb $0x1, 0x8ad5(%rip)      # 0xca1b
je 0x3f59
movl -0x28(%rbp), %esi
leaq 0x5d09(%rip), %rdi      # 0x9c5b
movb $0x0, %al
callq 0x44f0
jmp 0x3f5b
leaq -0x10(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
xorl %edx, %edx
callq 0x6350
testb $0x1, %al
jne 0x3f70
jmp 0x3f9e
cmpl $0x0, -0x2c(%rbp)
je 0x3f9e
movl -0x2c(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4c(%rax)
testb $0x1, 0x8a92(%rip)      # 0xca1b
je 0x3f9c
movl -0x2c(%rbp), %esi
leaq 0x5cd9(%rip), %rdi      # 0x9c6e
movb $0x0, %al
callq 0x44f0
jmp 0x3f9e
leaq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x6350
testb $0x1, %al
jne 0x3fb3
jmp 0x4011
cmpl $0x0, -0x30(%rbp)
je 0x4011
movl -0x30(%rbp), %eax
sarl $0x0, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4d(%rax)
movl -0x30(%rbp), %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4e(%rax)
movl -0x30(%rbp), %eax
sarl $0x10, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4f(%rax)
movl -0x30(%rbp), %eax
sarl $0x18, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x50(%rax)
testb $0x1, 0x8a1f(%rip)      # 0xca1b
je 0x400f
movl -0x30(%rbp), %esi
leaq 0x5c7b(%rip), %rdi      # 0x9c83
movb $0x0, %al
callq 0x44f0
jmp 0x4011
leaq -0x10(%rbp), %rdi
leaq -0x34(%rbp), %rsi
xorl %edx, %edx
callq 0x6350
testb $0x1, %al
jne 0x4026
jmp 0x4054
cmpl $0x0, -0x34(%rbp)
je 0x4054
movl -0x34(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x51(%rax)
testb $0x1, 0x89dc(%rip)      # 0xca1b
je 0x4052
movl -0x34(%rbp), %esi
leaq 0x5c4d(%rip), %rdi      # 0x9c98
movb $0x0, %al
callq 0x44f0
jmp 0x4054
leaq -0x10(%rbp), %rdi
leaq -0x38(%rbp), %rsi
xorl %edx, %edx
callq 0x6350
testb $0x1, %al
jne 0x4069
jmp 0x40c7
cmpl $0x0, -0x38(%rbp)
je 0x40c7
movl -0x38(%rbp), %eax
sarl $0x0, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x52(%rax)
movl -0x38(%rbp), %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x53(%rax)
movl -0x38(%rbp), %eax
sarl $0x10, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x54(%rax)
movl -0x38(%rbp), %eax
sarl $0x18, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x55(%rax)
testb $0x1, 0x8969(%rip)      # 0xca1b
je 0x40c5
movl -0x38(%rbp), %esi
leaq 0x5bef(%rip), %rdi      # 0x9cad
movb $0x0, %al
callq 0x44f0
jmp 0x40c7
movb $0x1, -0x1(%rbp)
jmp 0x40f1
movq -0x10(%rbp), %rsi
leaq 0x5bff(%rip), %rdi      # 0x9cd7
movb $0x0, %al
callq 0x46f0
cmpl $0x0, 0x899a(%rip)      # 0xca80
jle 0x40ed
callq 0x2fb0
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)