// File: /workspace/github_c_makefile_star2_O3/canboat[P]canboat/analyzer/../common/parse.c
// Function: parseRawFormatGarminCSV
int parseRawFormatGarminCSV(char *msg, RawMessage *m, bool showJson, bool absolute)
{
  unsigned int seq, tstamp, pgn, src, dst, prio, single, count;
  time_t       t;
  struct tm    tm;
  char        *p;
  int          consumed;
  unsigned int i;

  if (*msg == 0 || *msg == '\n')
  {
    return 1;
  }

  if (absolute)
  {
    unsigned int month, day, year, hours, minutes, seconds, ms;

    if (sscanf(msg, "%u,%u_%u_%u_%u_%u_%u_%u,%u,", &seq, &month, &day, &year, &hours, &minutes, &seconds, &ms, &pgn) < 9)
    {
      logError("Error reading Garmin CSV message: %s", msg);
      if (!showJson)
        fprintf(stdout, "%s", msg);
      return 2;
    }
    snprintf(m->timestamp,
             sizeof(m->timestamp),
             "%04u-%02u-%02uT%02u:%02u:%02u,%03u",
             year,
             month,
             day,
             hours,
             minutes,
             seconds,
             ms % 1000);

    p = findOccurrence(msg, ',', 6);
  }
  else
  {
    if (sscanf(msg, "%u,%u,%u,", &seq, &tstamp, &pgn) < 3)
    {
      logError("Error reading Garmin CSV message: %s", msg);
      if (!showJson)
        fprintf(stdout, "%s", msg);
      return 2;
    }

    t = (time_t) tstamp / 1000;
    localtime_r(&t, &tm);
    strftime(m->timestamp, sizeof(m->timestamp), "%Y-%m-%dT%H:%M:%S", &tm);
    sprintf(m->timestamp + strlen(m->timestamp), ",%3.3u", tstamp % 1000);

    p = findOccurrence(msg, ',', 5);
  }

  if (!p || sscanf(p, "%u,%u,%u,%u,%u,0x%n", &src, &dst, &prio, &single, &count, &consumed) < 5)
  {
    logError("Error reading Garmin CSV message: %s", msg);
    if (!showJson)
      fprintf(stdout, "%s", msg);
    return 3;
  }
  p += consumed;

  for (i = 0; *p && i < count; i++)
  {
    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;
    }
  }

  return setParsedValues(m, prio, pgn, dst, src, i + 1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movzbl (%rdi), %eax
movl $0x1, %r15d
testl %eax, %eax
je 0x1e89f
cmpl $0xa, %eax
je 0x1e89f
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
testb %cl, %cl
je 0x1e6b8
subq $0x8, %rsp
leaq 0x24(%rsp), %r10
leaq 0x14(%rsp), %r11
leaq 0x18(%rsp), %r15
leaq 0x1c(%rsp), %r12
leaq 0x10(%rsp), %r13
leaq 0x1456a(%rip), %rsi     # 0x32b80
leaq 0x34(%rsp), %rdx
leaq 0x48(%rsp), %rcx
leaq 0x38(%rsp), %r8
leaq 0x28(%rsp), %r9
movq %rbx, %rdi
movl $0x0, %eax
pushq %r10
pushq %r11
pushq %r15
pushq %r12
pushq %r13
callq 0xd220
addq $0x30, %rsp
cmpl $0x8, %eax
jle 0x1e6f9
movl 0x20(%rsp), %ecx
movl 0x40(%rsp), %r8d
movl 0x30(%rsp), %r9d
movl 0x8(%rsp), %r10d
movl 0x14(%rsp), %r11d
movl 0x10(%rsp), %r15d
movl 0xc(%rsp), %r12d
imulq $0x10624dd3, %r12, %rax # imm = 0x10624DD3
shrq $0x26, %rax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
subl %eax, %r12d
leaq 0x14536(%rip), %rdx     # 0x32bc1
movl $0x3c, %esi
movq %r14, %rdi
xorl %eax, %eax
pushq %r12
pushq %r15
pushq %r11
pushq %r10
callq 0xd120
addq $0x20, %rsp
movq %rbx, %rdi
movl $0x2c, %esi
movl $0x6, %edx
jmp 0x1e7a5
leaq 0x14525(%rip), %rsi     # 0x32be4
leaq 0x2c(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0x1c(%rsp), %r8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd220
cmpl $0x2, %eax
jg 0x1e72c
leaq 0x144b8(%rip), %rdi     # 0x32b9c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1cde8
movl $0x2, %r15d
jmp 0x1e805
leaq 0x1449c(%rip), %rdi     # 0x32b9c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1cde8
testb %bpl, %bpl
jne 0x1e721
movq 0x1a8b2(%rip), %rax     # 0x38fc8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xd170
movl $0x2, %r15d
jmp 0x1e89f
movl 0x8(%rsp), %eax
imulq $0x10624dd3, %rax, %rax # imm = 0x10624DD3
shrq $0x26, %rax
leaq 0x30(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x40(%rsp), %r15
movq %r15, %rsi
callq 0xd0a0
leaq 0x140b1(%rip), %rdx     # 0x32808
movl $0x3c, %esi
movq %r14, %rdi
movq %r15, %rcx
callq 0xd260
movq %r14, %rdi
callq 0xd0f0
leaq (%rax,%r14), %rdi
movl 0x8(%rsp), %edx
imulq $0x10624dd3, %rdx, %rax # imm = 0x10624DD3
shrq $0x26, %rax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
subl %eax, %edx
leaq 0x143e8(%rip), %rsi     # 0x32b79
xorl %eax, %eax
callq 0xd2c0
movq %rbx, %rdi
movl $0x2c, %esi
movl $0x5, %edx
callq 0x1dff3
movq %rax, %r15
testq %rax, %rax
je 0x1e7ee
leaq 0x28(%rsp), %r10
leaq 0x18(%rsp), %r11
leaq 0x1442b(%rip), %rsi     # 0x32bee
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0xc(%rsp), %r8
leaq 0x3c(%rsp), %r9
movq %r15, %rdi
xorl %eax, %eax
pushq %r10
pushq %r11
callq 0xd220
addq $0x10, %rsp
cmpl $0x4, %eax
jg 0x1e822
leaq 0x143a7(%rip), %rdi     # 0x32b9c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1cde8
movl $0x3, %r15d
testb %bpl, %bpl
jne 0x1e89f
movq 0x1a7b3(%rip), %rax     # 0x38fc8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xd170
jmp 0x1e89f
movslq 0x28(%rsp), %rax
leaq (%r15,%rax), %rcx
movq %rcx, 0x20(%rsp)
cmpb $0x0, (%r15,%rax)
movb $0x1, %al
je 0x1e876
cmpl $0x0, 0x18(%rsp)
je 0x1e876
leaq 0x47(%r14), %r13
xorl %r15d, %r15d
leaq 0x20(%rsp), %r12
leaq (%r15,%r13), %rsi
movq %r12, %rdi
callq 0x1db3f
movq 0x20(%rsp), %rcx
testl %eax, %eax
jne 0x1e8b1
incq %r15
cmpb $0x0, (%rcx)
je 0x1e872
movl 0x18(%rsp), %eax
cmpq %rax, %r15
jb 0x1e84c
leal 0x1(%r15), %eax
movb 0xc(%rsp), %cl
movl 0x1c(%rsp), %edx
movb 0x10(%rsp), %sil
movb 0x14(%rsp), %dil
movb %cl, 0x3c(%r14)
movl %edx, 0x40(%r14)
movb %sil, 0x44(%r14)
movb %dil, 0x45(%r14)
movb %al, 0x46(%r14)
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %rsi
subq %rbx, %rsi
leaq 0x1421a(%rip), %rdi     # 0x32ad8
movq %rbx, %rdx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x1cde8
jmp 0x1e6ee