// File: /workspace/github_c_makefile_star2_O1/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 0x4028(%rip), %rsi      # 0x2b409
leaq 0x10(%rsp), %rdx
callq 0xd190
testq %rax, %rax
je 0x27583
cmpb $0x41, (%rax)
jne 0x27583
incq %rax
leaq 0x18b0b(%rip), %rsi     # 0x3ff12
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 0x27597
cmpq $0x0, 0x7649f(%rip)     # 0x9d8d0
jne 0x2745b
callq 0x252bc
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
mulq %rcx
shrq $0x4, %rdx
movl 0x8(%rsp), %eax
subq %rax, %rdx
movq %rdx, 0x76475(%rip)     # 0x9d8d0
movl 0x8(%rsp), %eax
addq 0x7646a(%rip), %rax     # 0x9d8d0
leaq 0x28(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x30(%rsp), %r12
movq %r12, %rsi
callq 0xd0a0
leaq 0x185d6(%rip), %rdx     # 0x3fa58
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 0x18933(%rip), %rsi     # 0x3fddc
xorl %eax, %eax
callq 0xd2c0
leaq 0x3f52(%rip), %rsi      # 0x2b409
leaq 0x10(%rsp), %rdx
xorl %edi, %edi
callq 0xd190
testq %rax, %rax
je 0x27597
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 0x3f0e(%rip), %rsi      # 0x2b409
leaq 0x10(%rsp), %rdx
xorl %edi, %edi
callq 0xd190
testq %rax, %rax
je 0x275a9
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 0x2757a
callq 0xd350
movq (%rax), %rax
testb $0x20, 0x1(%rax,%rbp,2)
jne 0x2757a
leaq (%r15,%r13), %rsi
movq %r12, %rdi
callq 0x262e5
testl %eax, %eax
jne 0x275be
incq %r15
cmpq $0xdf, %r15
jne 0x2753c
movl $0xdf, %r15d
movb %r15b, 0x46(%r14)
xorl %r15d, %r15d
jmp 0x27597
leaq 0x18961(%rip), %rdi     # 0x3feeb
xorl %eax, %eax
callq 0x25570
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18968(%rip), %rdi     # 0x3ff18
xorl %eax, %eax
callq 0x25570
testb %bpl, %bpl
jne 0x27597
jmp 0x275ea
movq 0x20(%rsp), %rcx
movq %rcx, %rsi
subq %rbx, %rsi
leaq 0x1876b(%rip), %rdi     # 0x3fd3b
movq %rbx, %rdx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x25570
movl $0x2, %r15d
cmpb $0x0, 0x1c(%rsp)
jne 0x27597
movq 0x1e9d7(%rip), %rax     # 0x45fc8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xd170
jmp 0x27597