// File: /workspace/github_c_makefile_star2_O1/canboat[P]canboat/analyzer/analyzer.c
// Function: printFields
extern bool printFields(const Pgn *pgn, const uint8_t *data, int length, bool showData, bool showJson, size_t *variableFields)
{
  size_t  i;
  size_t  bits;
  size_t  startBit;
  int     repetition;
  char    fieldName[60];
  uint8_t variableFieldStart;
  uint8_t variableFieldCount;

  bool r = true;

  logDebug("fieldCount=%d repeatingStart1=%" PRIu8 "\n", pgn->fieldCount, pgn->repeatingStart1);

  g_variableFieldRepeat[0] = 255; // Can be overridden by '# of parameters'
  g_variableFieldRepeat[1] = 0;   // Can be overridden by '# of parameters'
  repetition               = 0;
  *variableFields          = 0;

  for (i = 0, startBit = 0; (startBit >> 3) < length; i++)
  {
    const Field *field = &pgn->fieldList[i];

    if (*variableFields == 0)
    {
      repetition = 0;
    }

    if (pgn->repeatingCount1 > 0 && field->order == pgn->repeatingStart1 && repetition == 0)
    {
      if (showJson)
      {
        mprintf("%s\"list\":[{", getSep());
        strcat(closingBraces, "]}");
        sep = "";
      }
      // Only now is g_variableFieldRepeat set
      *variableFields    = pgn->repeatingCount1 * g_variableFieldRepeat[0];
      variableFieldCount = pgn->repeatingCount1;
      variableFieldStart = pgn->repeatingStart1;
      repetition         = 1;
    }
    if (pgn->repeatingCount2 > 0 && field->order == pgn->repeatingStart2 && repetition == 0)
    {
      if (showJson)
      {
        mprintf("}],\"list2\":[{");
        sep = "";
      }
      // Only now is g_variableFieldRepeat set
      *variableFields    = pgn->repeatingCount2 * g_variableFieldRepeat[1];
      variableFieldCount = pgn->repeatingCount2;
      variableFieldStart = pgn->repeatingStart2;
      repetition         = 1;
    }

    if (*variableFields > 0)
    {
      if (i + 1 == variableFieldStart + variableFieldCount)
      {
        i     = variableFieldStart - 1;
        field = &pgn->fieldList[i];
        repetition++;
        if (showJson)
        {
          mprintf("},{");
          sep = "";
        }
      }
      logDebug("variableFields: repetition=%d field=%" PRIu8 " variableFieldStart=%" PRIu8 " variableFieldCount=%" PRIu8
               " remaining=%zu\n",
               repetition,
               i + 1,
               variableFieldStart,
               variableFieldCount,
               *variableFields);
      (*variableFields)--;
    }

    if (!field->camelName && !field->name)
    {
      logDebug("PGN %u has unknown bytes at end: %u\n", pgn->pgn, length - (startBit >> 3));
      break;
    }

    if (showCamel)
    {
      strcpy(fieldName, field->camelName ? field->camelName : field->name);
    }
    else
    {
      strcpy(fieldName, field->name);
    }

    if (repetition >= 1 && !showJson)
    {
      strcat(fieldName, field->camelName ? "_" : " ");
      sprintf(fieldName + strlen(fieldName), "%u", repetition);
    }

    if (!printField(field, fieldName, data, length, startBit, &bits, true))
    {
      r = false;
      break;
    }

    startBit += bits;
  }

  return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, %r13
movl %r8d, 0x18(%rsp)
movl %edx, %ebp
movq %rsi, 0x50(%rsp)
movq %rdi, %r14
movl 0x15c0(%rdi), %esi
movzbl 0x15ed(%rdi), %edx
leaq 0x10807(%rip), %rdi     # 0x1f878
xorl %eax, %eax
callq 0x19a95
movq $0xff, 0x7a26d(%rip) # 0x892f0
movq $0x0, (%r13)
testl %ebp, %ebp
je 0xf37b
movslq %ebp, %rax
movq %rax, 0x28(%rsp)
leaq 0x18(%r14), %rax
movq %rax, 0x40(%rsp)
movb $0x1, %al
movl %eax, 0x1c(%rsp)
xorl %r15d, %r15d
movq %rax, 0x20(%rsp)
xorl %r12d, %r12d
movq $0x0, 0x30(%rsp)
xorl %ebx, %ebx
movq %r14, 0x38(%rsp)
movq %r13, 0x48(%rsp)
imulq $0xa8, %rbx, %rbp
addq 0x40(%rsp), %rbp
cmpq $0x0, (%r13)
movl $0x0, %eax
cmovel %eax, %r12d
cmpb $0x0, 0x15eb(%r14)
je 0xf177
movb 0x4b(%rbp), %al
cmpb 0x15ed(%r14), %al
jne 0xf177
testl %r12d, %r12d
jne 0xf177
cmpb $0x0, 0x18(%rsp)
je 0xf14a
callq 0x16e6f
leaq 0x10784(%rip), %rdi     # 0x1f89a
movq %rax, %rsi
xorl %eax, %eax
callq 0x16cd0
leaq 0x7a1b9(%rip), %r12     # 0x892e0
movq %r12, %rdi
callq 0xd0f0
movw $0x7d5d, (%rax,%r12)    # imm = 0x7D5D
movb $0x0, 0x2(%rax,%r12)
leaq 0x10526(%rip), %rax     # 0x1f669
movq %rax, 0x74076(%rip)     # 0x831c0
movzbl 0x15eb(%r14), %ecx
movslq 0x7a197(%rip), %rax     # 0x892f0
movq %rcx, 0x20(%rsp)
imulq %rcx, %rax
movq %rax, (%r13)
movb 0x15ed(%r14), %al
movb %al, 0x17(%rsp)
movl $0x1, %r12d
cmpb $0x0, 0x15ec(%r14)
je 0xf1e2
movb 0x4b(%rbp), %al
cmpb 0x15ee(%r14), %al
jne 0xf1e2
testl %r12d, %r12d
jne 0xf1e2
cmpb $0x0, 0x18(%rsp)
je 0xf1b5
leaq 0x10709(%rip), %rdi     # 0x1f8a9
xorl %eax, %eax
callq 0x16cd0
leaq 0x104bb(%rip), %rax     # 0x1f669
movq %rax, 0x7400b(%rip)     # 0x831c0
movzbl 0x15ec(%r14), %ecx
movslq 0x7a130(%rip), %rax     # 0x892f4
movq %rcx, 0x20(%rsp)
imulq %rcx, %rax
movq %rax, (%r13)
movb 0x15ee(%r14), %al
movb %al, 0x17(%rsp)
movl $0x1, %r12d
cmpq $0x0, (%r13)
je 0xf26e
leaq 0x1(%rbx), %rax
movzbl 0x17(%rsp), %r14d
movzbl 0x20(%rsp), %r13d
leal (%r14,%r13), %ecx
cmpq %rcx, %rax
jne 0xf23f
leal -0x1(%r14), %eax
movslq %eax, %rbx
imulq $0xa8, %rbx, %rbp
addq 0x40(%rsp), %rbp
incl %r12d
cmpb $0x0, 0x18(%rsp)
je 0xf23f
leaq 0x1068d(%rip), %rdi     # 0x1f8b7
xorl %eax, %eax
callq 0x16cd0
leaq 0x10431(%rip), %rax     # 0x1f669
movq %rax, 0x73f81(%rip)     # 0x831c0
leaq 0x1(%rbx), %rdx
movq 0x48(%rsp), %rax
movq (%rax), %r9
leaq 0x10669(%rip), %rdi     # 0x1f8bb
movl %r12d, %esi
movl %r14d, %ecx
movl %r13d, %r8d
movq %rax, %r13
xorl %eax, %eax
callq 0x19a95
decq (%r13)
movq 0x38(%rsp), %r14
movq 0x58(%rbp), %rsi
testq %rsi, %rsi
jne 0xf282
cmpq $0x0, (%rbp)
je 0xf33d
testq %rsi, %rsi
je 0xf290
cmpb $0x0, 0x7a03e(%rip)     # 0x892cc
jne 0xf294
movq (%rbp), %rsi
leaq 0x60(%rsp), %r15
movq %r15, %rdi
callq 0xd0b0
testl %r12d, %r12d
setle %al
orb 0x18(%rsp), %al
jne 0xf2f5
cmpq $0x0, 0x58(%rbp)
movl $0x5f, %r14d
movl $0x20, %eax
cmovel %eax, %r14d
movq %r15, %rdi
callq 0xd0f0
movw %r14w, 0x60(%rsp,%rax)
movq 0x38(%rsp), %r14
movq %r15, %rdi
callq 0xd0f0
leaq (%rsp,%rax), %rdi
addq $0x60, %rdi
leaq 0x20383(%rip), %rsi     # 0x2f66e
movl %r12d, %edx
xorl %eax, %eax
callq 0xd300
movl $0x1, (%rsp)
movq %rbp, %rdi
movq %r15, %rsi
movq 0x50(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %r15
movq %r15, %r8
leaq 0x58(%rsp), %r9
callq 0xf391
xorl %ebp, %ebp
testb %al, %al
je 0xf333
addq 0x58(%rsp), %r15
movq %r15, 0x30(%rsp)
movb $0x1, %bpl
jmp 0xf359
movl $0x0, 0x1c(%rsp)
jmp 0xf359
movl 0x8(%r14), %esi
movq 0x28(%rsp), %rdx
subq %r15, %rdx
xorl %ebp, %ebp
leaq 0x105cb(%rip), %rdi     # 0x1f91d
xorl %eax, %eax
callq 0x19a95
testb %bpl, %bpl
je 0xf375
incq %rbx
movq 0x30(%rsp), %r15
shrq $0x3, %r15
cmpq 0x28(%rsp), %r15
jb 0xf0ca
movl 0x1c(%rsp), %eax
jmp 0xf37d
movb $0x1, %al
andb $0x1, %al
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq