// File: /workspace/github_c_makefile_star2_O3/canboat[P]canboat/analyzer/../common/parse.c
// Function: parseRawFormatActisenseN2KAscii
int parseRawFormatActisenseN2KAscii(char *msg, RawMessage *m, bool showJson)
{
  char         *nexttoken;
  char         *p;
  char         *token;
  int           i;
  int           r;
  static time_t tiden = 0;
  struct tm     tm;
  time_t        now;
  unsigned int  millis = 0;
  unsigned int  secs;
  unsigned long n;

  // parse timestamp. Actisense doesn't give us date so let's figure it out ourself
  token = strtok_r(msg, " ", &nexttoken);
  if (!token || token[0] != 'A')
  {
    logError("No message or does not start with 'A'\n");
    return -1;
  }
  token++;

  r = sscanf(token, "%u.%u", &secs, &millis);
  if (r < 1)
  {
    return -1;
  }

  if (tiden == 0)
  {
    tiden = (time_t) (getNow() / UINT64_C(1000)) - secs;
  }
  now = tiden + secs;

  localtime_r(&now, &tm);
  strftime(m->timestamp, sizeof(m->timestamp), "%Y-%m-%dT%H:%M:%S", &tm);
  sprintf(m->timestamp + strlen(m->timestamp), ",%3.3u", millis);

  // parse <SRC><DST><P>
  token = strtok_r(NULL, " ", &nexttoken);
  if (!token)
  {
    return -1;
  }
  n       = strtoul(token, NULL, 16);
  m->prio = n & 0xf;
  m->dst  = (n >> 4) & 0xff;
  m->src  = (n >> 12) & 0xff;

  // parse <PGN>
  token = strtok_r(NULL, " ", &nexttoken);
  if (!token)
  {
    logError("Incomplete message\n");
    if (!showJson)
      fprintf(stdout, "%s", msg);
    return -1;
  }
  m->pgn = strtoul(token, NULL, 16);

  // parse DATA
  p = nexttoken;
  for (i = 0; i < FASTPACKET_MAX_SIZE; i++)
  {
    if (*p == '\0' || isspace((unsigned char) *p))
    {
      break;
    }
    if (scanHex(&p, &m->data[i]))
    {
      logError("Error reading message, scanned %zu bytes from %s/%s, index %u", p - msg, msg, p, i);
      if (!showJson)
        fprintf(stdout, "%s", msg);
      return 2;
    }
  }
  m->len = i;

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl $0x0, 0xc(%rsp)
leaq 0x47ef(%rip), %rsi      # 0x23409
leaq 0x10(%rsp), %rdx
callq 0xd190
testq %rax, %rax
je 0x1ec68
cmpb $0x41, (%rax)
jne 0x1ec68
incq %rax
leaq 0x14077(%rip), %rsi     # 0x32caf
leaq 0x8(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %rax, %rdi
xorl %eax, %eax
callq 0xd220
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testl %eax, %eax
jle 0x1ec7c
movq 0x71c73(%rip), %rdx     # 0x908d0
testq %rdx, %rdx
je 0x1ec8e
movl 0x8(%rsp), %eax
jmp 0x1ecb6
leaq 0x14019(%rip), %rdi     # 0x32c88
xorl %eax, %eax
callq 0x1cde8
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1cb34
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
shrq $0x4, %rdx
movl 0x8(%rsp), %eax
subq %rax, %rdx
movq %rdx, 0x71c1a(%rip)     # 0x908d0
addq %rdx, %rax
leaq 0x28(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x30(%rsp), %r12
movq %r12, %rsi
callq 0xd0a0
leaq 0x13b33(%rip), %rdx     # 0x32808
movl $0x3c, %esi
movq %r14, %rdi
movq %r12, %rcx
callq 0xd260
movq %r14, %rdi
callq 0xd0f0
leaq (%rax,%r14), %rdi
movl 0xc(%rsp), %edx
leaq 0x13e7d(%rip), %rsi     # 0x32b79
xorl %eax, %eax
callq 0xd2c0
leaq 0x46ff(%rip), %rsi      # 0x23409
leaq 0x10(%rsp), %rdx
xorl %edi, %edi
callq 0xd190
testq %rax, %rax
je 0x1ec7c
movq %rax, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xd2a0
movl %eax, %ecx
andb $0xf, %cl
movb %cl, 0x3c(%r14)
movl %eax, %ecx
shrl $0x4, %ecx
movb %cl, 0x44(%r14)
shrl $0xc, %eax
movb %al, 0x45(%r14)
leaq 0x46bb(%rip), %rsi      # 0x23409
leaq 0x10(%rsp), %rdx
xorl %edi, %edi
callq 0xd190
testq %rax, %rax
je 0x1edd2
movl %ebp, 0x1c(%rsp)
xorl %r15d, %r15d
movq %rax, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xd2a0
movl %eax, 0x40(%r14)
movq 0x10(%rsp), %rax
leaq 0x20(%rsp), %r12
movq %rax, (%r12)
leaq 0x47(%r14), %r13
movq 0x20(%rsp), %rax
movzbl (%rax), %ebp
testq %rbp, %rbp
je 0x1edc6
callq 0xd350
movq (%rax), %rax
testb $0x20, 0x1(%rax,%rbp,2)
jne 0x1edc6
leaq (%r15,%r13), %rsi
movq %r12, %rdi
callq 0x1db3f
testl %eax, %eax
jne 0x1edeb
incq %r15
cmpq $0xdf, %r15
jne 0x1ed8b
movb $-0x21, %r15b
movb %r15b, 0x46(%r14)
xorl %r15d, %r15d
jmp 0x1ec7c
leaq 0x13edc(%rip), %rdi     # 0x32cb5
xorl %eax, %eax
callq 0x1cde8
testb %bpl, %bpl
jne 0x1ec7c
jmp 0x1ee1b
movq 0x20(%rsp), %rcx
movq %rcx, %rsi
subq %rbx, %rsi
leaq 0x13cdb(%rip), %rdi     # 0x32ad8
movq %rbx, %rdx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x1cde8
movl $0x2, %r15d
cmpb $0x0, 0x1c(%rsp)
jne 0x1ec7c
movq 0x1a1a6(%rip), %rax     # 0x38fc8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xd170
jmp 0x1ec7c