// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movl $0x0, -0x84(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x52f9(%rip), %rsi      # 0x27b68
leaq -0x28(%rbp), %rdx
callq 0xd180
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x2288f
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x41, %eax
je 0x228a9
leaq 0x13840(%rip), %rdi     # 0x360d6
movb $0x0, %al
callq 0x1f720
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x22b5b
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
leaq 0x1383d(%rip), %rsi     # 0x360fd
leaq -0x88(%rbp), %rdx
leaq -0x84(%rbp), %rcx
movb $0x0, %al
callq 0xd220
movl %eax, -0x40(%rbp)
cmpl $0x1, -0x40(%rbp)
jge 0x228ea
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x22b5b
cmpq $0x0, 0x70f5e(%rip)     # 0x93850
jne 0x22913
callq 0x1f3b0
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movl -0x88(%rbp), %ecx
subq %rcx, %rax
movq %rax, 0x70f3d(%rip)     # 0x93850
movq 0x70f36(%rip), %rax     # 0x93850
movl -0x88(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xd090
movq -0x18(%rbp), %rdi
movl $0x3c, %esi
leaq 0x132f4(%rip), %rdx     # 0x35c38
leaq -0x78(%rbp), %rcx
callq 0xd260
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rdi
callq 0xd0d0
movq -0x98(%rbp), %rdi
addq %rax, %rdi
movl -0x84(%rbp), %edx
leaq 0x1364f(%rip), %rsi     # 0x35fc7
movb $0x0, %al
callq 0xd2d0
xorl %eax, %eax
movl %eax, %edi
leaq 0x51de(%rip), %rsi      # 0x27b68
leaq -0x28(%rbp), %rdx
callq 0xd180
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x229aa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x22b5b
movq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0xd2a0
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
andq $0xf, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x3c(%rax)
movq -0x90(%rbp), %rax
shrq $0x4, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x44(%rax)
movq -0x90(%rbp), %rax
shrq $0xc, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x45(%rax)
xorl %eax, %eax
movl %eax, %edi
leaq 0x5152(%rip), %rsi      # 0x27b68
leaq -0x28(%rbp), %rdx
callq 0xd180
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x22a66
leaq 0x136d2(%rip), %rdi     # 0x36103
movb $0x0, %al
callq 0x1f720
testb $0x1, -0x19(%rbp)
jne 0x22a5a
movq 0x19593(%rip), %rax     # 0x3bfd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x135b9(%rip), %rsi     # 0x3600c
movb $0x0, %al
callq 0xd1b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x22b5b
movq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x10, %edx
callq 0xd2a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0xdf, -0x3c(%rbp)
jge 0x22b48
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x22ac9
callq 0xd350
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movzbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x22acb
jmp 0x22b48
movq -0x18(%rbp), %rsi
addq $0x47, %rsi
movslq -0x3c(%rbp), %rax
addq %rax, %rsi
leaq -0x30(%rbp), %rdi
callq 0x20e30
cmpl $0x0, %eax
je 0x22b38
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
subq %rax, %rsi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x3c(%rbp), %r8d
leaq 0x13420(%rip), %rdi     # 0x35f26
movb $0x0, %al
callq 0x1f720
testb $0x1, -0x19(%rbp)
jne 0x22b2f
movq 0x194be(%rip), %rax     # 0x3bfd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x134e4(%rip), %rsi     # 0x3600c
movb $0x0, %al
callq 0xd1b0
movl $0x2, -0x4(%rbp)
jmp 0x22b5b
jmp 0x22b3a
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x22a90
movl -0x3c(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x46(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)