// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %r15
testl %eax, %eax
je 0x1d67e
cmpl $0xa, %eax
je 0x1d67e
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
testb %cl, %cl
je 0x1d535
subq $0x8, %rsp
leaq 0x1c(%rsp), %r10
leaq 0x10(%rsp), %r11
leaq 0x14(%rsp), %r15
leaq 0x18(%rsp), %r12
leaq 0xc(%rsp), %r13
leaq 0x146da(%rip), %rsi     # 0x31b80
leaq 0x34(%rsp), %rdx
leaq 0x48(%rsp), %rcx
leaq 0x38(%rsp), %r8
leaq 0x20(%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 0x1d572
movl 0x18(%rsp), %ecx
movl 0x40(%rsp), %r8d
movl 0x30(%rsp), %r9d
movl 0x4(%rsp), %r11d
movl 0x10(%rsp), %r15d
movl 0xc(%rsp), %r12d
movl 0x8(%rsp), %eax
movl $0x3e8, %esi            # imm = 0x3E8
xorl %edx, %edx
divl %esi
movl %edx, %r10d
leaq 0x146af(%rip), %rdx     # 0x31bc1
pushq $0x3c
popq %rsi
movq %r14, %rdi
xorl %eax, %eax
pushq %r10
pushq %r12
pushq %r15
pushq %r11
callq 0xd120
addq $0x20, %rsp
pushq $0x2c
popq %rsi
pushq $0x6
jmp 0x1d607
leaq 0x146a8(%rip), %rsi     # 0x31be4
leaq 0x2c(%rsp), %rdx
leaq 0x4(%rsp), %rcx
leaq 0x14(%rsp), %r8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xd220
cmpl $0x2, %eax
jg 0x1d5a3
leaq 0x1463b(%rip), %rdi     # 0x31b9c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1bdd9
pushq $0x2
jmp 0x1d665
leaq 0x14623(%rip), %rdi     # 0x31b9c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1bdd9
testb %bpl, %bpl
jne 0x1d59a
movq 0x1ca39(%rip), %rax     # 0x39fc8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xd170
pushq $0x2
popq %r15
jmp 0x1d67e
movl 0x4(%rsp), %eax
movl %ebp, %r12d
movl $0x3e8, %ebp            # imm = 0x3E8
xorl %edx, %edx
divl %ebp
leaq 0x30(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x40(%rsp), %r15
movq %r15, %rsi
callq 0xd0a0
leaq 0x14239(%rip), %rdx     # 0x31808
pushq $0x3c
popq %rsi
movq %r14, %rdi
movq %r15, %rcx
callq 0xd260
movq %r14, %rdi
callq 0xd0f0
leaq (%rax,%r14), %rdi
movl 0x4(%rsp), %eax
xorl %edx, %edx
divl %ebp
movl %r12d, %ebp
leaq 0x1457e(%rip), %rsi     # 0x31b79
xorl %eax, %eax
callq 0xd2c0
pushq $0x2c
popq %rsi
pushq $0x5
popq %rdx
movq %rbx, %rdi
callq 0x1ced8
movq %rax, %r15
testq %rax, %rax
je 0x1d652
leaq 0x24(%rsp), %r10
leaq 0x28(%rsp), %r11
leaq 0x145c5(%rip), %rsi     # 0x31bee
leaq 0x10(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
leaq 0x3c(%rsp), %r9
movq %r15, %rdi
xorl %eax, %eax
pushq %r10
pushq %r11
callq 0xd220
popq %rcx
popq %rdx
cmpl $0x4, %eax
jg 0x1d690
leaq 0x14543(%rip), %rdi     # 0x31b9c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1bdd9
pushq $0x3
popq %r15
testb %bpl, %bpl
jne 0x1d67e
movq 0x1c955(%rip), %rax     # 0x39fc8
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xd170
movl %r15d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, 0x20(%rsp)
movslq 0x24(%rsp), %rax
addq %rax, %r15
leaq 0x18(%rsp), %r13
movq %r15, (%r13)
leaq 0x47(%r14), %rbp
xorl %r12d, %r12d
cmpb $0x0, (%r15)
je 0x1d6d5
movl 0x28(%rsp), %eax
cmpq %rax, %r12
jae 0x1d6d5
leaq (%r12,%rbp), %rsi
movq %r13, %rdi
callq 0x1ca7b
movq 0x18(%rsp), %r15
testl %eax, %eax
jne 0x1d705
incq %r12
jmp 0x1d6ac
movb 0x8(%rsp), %al
movl 0x14(%rsp), %ecx
movb 0xc(%rsp), %dl
movb 0x10(%rsp), %sil
movb %al, 0x3c(%r14)
movl %ecx, 0x40(%r14)
movb %dl, 0x44(%r14)
movb %sil, 0x45(%r14)
incb %r12b
movb %r12b, 0x46(%r14)
xorl %r15d, %r15d
jmp 0x1d67e
movq %r15, %rsi
subq %rbx, %rsi
leaq 0x143c6(%rip), %rdi     # 0x31ad8
movq %rbx, %rdx
movq %r15, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x1bdd9
pushq $0x2
popq %r15
cmpb $0x0, 0x20(%rsp)
je 0x1d66c
jmp 0x1d67e