// File: /workspace/github_c_makefile_star2_O2/canboat[P]canboat/analyzer/analyzer.c
// Function: printPgn
bool printPgn(const RawMessage *msg, const uint8_t *data, int length, bool showData, bool showJson)
{
  const Pgn *pgn;

  size_t i;
  bool   r;
  size_t variableFields = 0; // How many variable fields remain (product of repetition count * # of fields)

  if (msg == NULL)
  {
    return false;
  }
  pgn = getMatchingPgn(msg->pgn, data, length);
  if (!pgn)
  {
    logAbort("No PGN definition found for PGN %u\n", msg->pgn);
  }

  if (showData)
  {
    FILE *f = stdout;

    if (showJson)
    {
      f = stderr;
    }

    fprintf(f, "%s %u %3u %3u %6u %s: ", msg->timestamp, msg->prio, msg->src, msg->dst, msg->pgn, pgn->description);
    for (i = 0; i < length; i++)
    {
      fprintf(f, " %2.02X", data[i]);
    }
    putc('\n', f);

    fprintf(f, "%s %u %3u %3u %6u %s: ", msg->timestamp, msg->prio, msg->src, msg->dst, msg->pgn, pgn->description);
    for (i = 0; i < length; i++)
    {
      fprintf(f, "  %c", isalnum(data[i]) ? data[i] : '.');
    }
    putc('\n', f);
  }
  if (showJson)
  {
    if (pgn->camelDescription)
    {
      mprintf("{\"%s\":", pgn->camelDescription);
    }
    mprintf("{\"timestamp\":\"%s\",\"prio\":%u,\"src\":%u,\"dst\":%u,\"pgn\":%u,\"description\":\"%s\"",
            msg->timestamp,
            msg->prio,
            msg->src,
            msg->dst,
            msg->pgn,
            pgn->description);
    if (showAllBytes)
    {
      mprintf(",\"data\":\"");
      for (i = 0; i < length; i++)
      {
        mprintf("%2.02X", data[i]);
      }
      mprintf("\"");
    }
    if (pgn->camelDescription)
    {
      strcpy(closingBraces, "}}");
    }
    else
    {
      strcpy(closingBraces, "}");
    }
    sep = ",\"fields\":{";
  }
  else
  {
    mprintf("%s %u %3u %3u %6u %s:", msg->timestamp, msg->prio, msg->src, msg->dst, msg->pgn, pgn->description);
    sep = " ";
  }
  r = printFields(pgn, data, length, showData, showJson, &variableFields);

  if (showJson)
  {
    for (i = strlen(closingBraces); i;)
    {
      mprintf("%c", closingBraces[--i]);
    }
  }
  mprintf("\n");

  if (r)
  {
    mwrite(stdout);
    if (variableFields > 0 && g_variableFieldRepeat[0] < UINT8_MAX)
    {
      logError("PGN %u has %zu missing fields in repeating set\n", msg->pgn, variableFields);
    }
  }
  else
  {
    if (!showJson)
    {
      mwrite(stdout);
    }
    mreset();
    logError("PGN %u analysis error\n", msg->pgn);
  }

  if (msg->pgn == 126992 && currentDate < UINT16_MAX && currentTime < UINT32_MAX && clockSrc == msg->src)
  {
    setSystemClock();
  }
  return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
andq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0xeb39
movl %r8d, %ebx
movl %ecx, %r13d
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %r12
movl 0x40(%rdi), %edi
callq 0xd5d7
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0xeb12
movl 0x40(%r12), %esi
leaq 0xfc5e(%rip), %rdi      # 0x1e769
xorl %eax, %eax
callq 0x19172
movslq %r14d, %rbp
testb %r13b, %r13b
movq %r12, 0x10(%rsp)
je 0xec44
testb %bl, %bl
movl %ebx, 0x1c(%rsp)
movl %r14d, 0x18(%rsp)
je 0xeb40
movq 0x264b9(%rip), %rax     # 0x34ff0
jmp 0xeb47
xorl %ebp, %ebp
jmp 0xee41
movq 0x26479(%rip), %rax     # 0x34fc0
movq (%rax), %r13
movzbl 0x3c(%r12), %ecx
movzbl 0x45(%r12), %r8d
movzbl 0x44(%r12), %r9d
movl 0x40(%r12), %r10d
leaq 0xfc25(%rip), %rsi      # 0x1e78d
movq %r13, %rdi
movq %r12, %rdx
xorl %eax, %eax
movq 0x8(%rsp), %r11
pushq (%r11)
pushq %r10
callq 0xd1e0
addq $0x10, %rsp
leaq 0xfc1a(%rip), %r14      # 0x1e7a4
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0xeba8
movzbl (%r15,%rbx), %edx
movq %r13, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0xd1e0
incq %rbx
jmp 0xeb8c
pushq $0xa
popq %rdi
movq %r13, %rsi
callq 0xd1b0
movzbl 0x3c(%r12), %ecx
movzbl 0x45(%r12), %r8d
movzbl 0x44(%r12), %r9d
movl 0x40(%r12), %r10d
leaq 0xfbbc(%rip), %rsi      # 0x1e78d
movq %r13, %rdi
movq %r12, %rdx
xorl %eax, %eax
movq 0x8(%rsp), %r11
pushq (%r11)
pushq %r10
callq 0xd1e0
addq $0x10, %rsp
pushq $0x2e
popq %r12
leaq 0xfbb5(%rip), %r14      # 0x1e7ac
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0xec2b
callq 0xd390
movq (%rax), %rcx
movzbl (%r15,%rbx), %eax
movzwl (%rcx,%rax,2), %ecx
movl %r12d, %edx
testb $0x8, %cl
je 0xec19
movl %eax, %edx
movq %r13, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0xd1e0
incq %rbx
jmp 0xebf9
pushq $0xa
popq %rdi
movq %r13, %rsi
callq 0xd1b0
movq 0x10(%rsp), %r12
movl 0x1c(%rsp), %ebx
movl 0x18(%rsp), %r14d
testb %bl, %bl
movq 0x8(%rsp), %r13
je 0xece0
movq 0x15c8(%r13), %rsi
testq %rsi, %rsi
je 0xec6b
leaq 0xfb4d(%rip), %rdi      # 0x1e7b1
xorl %eax, %eax
callq 0x164ac
movzbl 0x3c(%r12), %edx
movzbl 0x45(%r12), %ecx
movzbl 0x44(%r12), %r8d
movl 0x40(%r12), %r9d
subq $0x8, %rsp
leaq 0xfb2b(%rip), %rdi      # 0x1e7b8
movq %r12, %rsi
xorl %eax, %eax
pushq (%r13)
callq 0x164ac
popq %rax
popq %rcx
cmpb $0x1, 0x79623(%rip)     # 0x882c7
jne 0xed34
movl %r14d, %r13d
movl %ebx, %r12d
leaq 0xfb4b(%rip), %rdi      # 0x1e802
xorl %eax, %eax
callq 0x164ac
leaq 0xfae0(%rip), %r14      # 0x1e7a5
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0xed1b
movzbl (%r15,%rbx), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x164ac
incq %rbx
jmp 0xecc7
movzbl 0x3c(%r12), %edx
movzbl 0x45(%r12), %ecx
movzbl 0x44(%r12), %r8d
movl 0x40(%r12), %r9d
subq $0x8, %rsp
leaq 0xfb19(%rip), %rdi      # 0x1e81b
movq %r12, %rsi
xorl %eax, %eax
pushq (%r13)
callq 0x164ac
popq %rax
popq %rcx
leaq 0xfdb2(%rip), %rax      # 0x1eacb
jmp 0xed60
leaq 0x10423(%rip), %rdi     # 0x1f145
xorl %eax, %eax
callq 0x164ac
movl %r12d, %ebx
movl %r13d, %r14d
movq 0x8(%rsp), %r13
cmpq $0x0, 0x15c8(%r13)
je 0xed50
movb $0x0, 0x7959d(%rip)     # 0x882e2
movw $0x7d7d, 0x79592(%rip)  # imm = 0x7D7D
jmp 0xed59
movw $0x7d, 0x79587(%rip)    # 0x882e0
leaq 0xfaaf(%rip), %rax      # 0x1e80f
movq %rax, 0x73459(%rip)     # 0x821c0
movzbl %bl, %r8d
leaq 0x20(%rsp), %r9
movq %r13, %rdi
movq %r15, %rsi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0xee52
movl %eax, %r14d
movl %ebx, %ebp
testb %bl, %bl
je 0xedbd
leaq 0x79550(%rip), %r15     # 0x882e0
movq %r15, %rdi
callq 0xd0f0
leaq 0xfa0f(%rip), %r12      # 0x1e7ae
movq %rax, %rbx
subq $0x1, %rbx
jb 0xedbd
movsbl -0x1(%rax,%r15), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x164ac
movq %rbx, %rax
jmp 0xeda2
leaq 0xf8a4(%rip), %rdi      # 0x1e668
xorl %eax, %eax
callq 0x164ac
testb %r14b, %r14b
je 0xee10
movq 0x261e9(%rip), %rax     # 0x34fc0
movq (%rax), %rdi
callq 0x165fa
movq 0x20(%rsp), %rdx
movb $0x1, %bpl
testq %rdx, %rdx
movq 0x10(%rsp), %rax
je 0xee41
cmpl $0xfe, 0x794f5(%rip)    # 0x882f0
jg 0xee41
movl 0x40(%rax), %esi
leaq 0xfa2a(%rip), %rdi      # 0x1e831
xorl %eax, %eax
callq 0x190e1
jmp 0xee41
testb %bpl, %bpl
movq 0x10(%rsp), %rbx
jne 0xee29
movq 0x2619f(%rip), %rax     # 0x34fc0
movq (%rax), %rdi
callq 0x165fa
callq 0x16561
movl 0x40(%rbx), %esi
leaq 0xfa29(%rip), %rdi      # 0x1e861
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x190e1
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq