// File: /workspace/github_c_makefile_star2_O3/canboat[P]canboat/analyzer/analyzer.c
// Function: printField
static bool printField(const Field   *field,
                       const char    *fieldName,
                       const uint8_t *data,
                       size_t         dataLen,
                       size_t         startBit,
                       size_t        *bits,
                       bool           allowKey)
{
  size_t bytes;
  double resolution;
  bool   r;

  if (fieldName == NULL)
  {
    fieldName = field->camelName ? field->camelName : (char *) field->name;
  }

  resolution = field->resolution;
  if (resolution == 0.0)
  {
    resolution = field->ft->resolution;
  }

  logDebug("PGN %u: printField(<%s>, \"%s\", ..., dataLen=%zu, data=%p, startBit=%zu) resolution=%g\n",
           field->pgn->pgn,
           field->name,
           fieldName,
           dataLen,
           data,
           startBit,
           field->resolution);

  if (field->size != 0 || field->ft != NULL)
  {
    *bits = (field->size != 0) ? field->size : field->ft->size;
    bytes = (*bits + 7) / 8;
    bytes = min(bytes, dataLen - startBit / 8);
    *bits = min(bytes * 8, *bits);
  }
  else
  {
    bytes = 0;
    *bits = 0;
  }

  fillGlobalsBasedOnFieldName(field->name, data, dataLen, startBit, *bits);

  logDebug("PGN %u: printField <%s>, \"%s\": bits=%zu proprietary=%u refPgn=%u\n",
           field->pgn->pgn,
           field->name,
           fieldName,
           *bits,
           field->proprietary,
           g_refPgn);

  if (field->proprietary)
  {
    if ((g_refPgn >= 65280 && g_refPgn <= 65535) || (g_refPgn >= 126720 && g_refPgn <= 126975)
        || (g_refPgn >= 130816 && g_refPgn <= 131071))
    {
      // proprietary, allow field
    }
    else
    {
      // standard PGN, skip field
      *bits = 0;
      return true;
    }
  }

  if (field->ft != NULL && field->ft->pf != NULL)
  {
    size_t location            = mlocation();
    char  *oldSep              = sep;
    size_t oldClosingBracesLen = strlen(closingBraces);
    size_t location2           = 0;
    size_t location3;

    if (field->ft->pf != fieldPrintVariable)
    {
      if (showJson)
      {
        mprintf("%s\"%s\":", getSep(), fieldName);
        sep = ",";
        if (showBytes || showJsonValue)
        {
          location2 = mlocation();
        }
      }
      else
      {
        mprintf("%s %s = ", getSep(), fieldName);
        sep = ";";
      }
    }
    location3 = mlocation();
    logDebug(
        "PGN %u: printField <%s>, \"%s\": calling function for %s\n", field->pgn->pgn, field->name, fieldName, field->fieldType);
    g_skip = false;
    r      = (field->ft->pf)(field, fieldName, data, dataLen, startBit, bits);
    // if match fails, r == false. If field is not printed, g_skip == true
    logDebug("PGN %u: printField <%s>, \"%s\": result %d bits=%zu\n", field->pgn->pgn, field->name, fieldName, r, *bits);
    if (r && !g_skip)
    {
      if (location3 == mlocation() && !showBytes)
      {
        logError("PGN %u: field \"%s\" print routine did not print anything\n", field->pgn->pgn, field->name);
        r = false;
      }
      else if (field->ft->pf != fieldPrintVariable)
      {
        location3     = mlocation();
        bool endQuote = mchr(location3 - 1) == '}';
        if (endQuote)
        {
          mset(location3 - 1);
          location3--;
        }
        if (showBytes)
        {
          showBytesOrBits(data + (startBit >> 3), startBit & 7, *bits);
          if (showJson)
          {
            endQuote = true;
          }
        }
        if (showJsonValue && field->partOfPrimaryKey && allowKey)
        {
          mprintf(",\"key\":true");
          endQuote = true;
        }
        if (endQuote)
        {
          mprintf("}");
        }
      }
      if (location2 != 0)
      {
        location3 = mlocation();
        if (mchr(location3 - 1) == '}')
        {
          // Prepend {"value":
          minsert(location2, "{\"value\":");
        }
      }
    }
    if (!r || g_skip)
    {
      mset(location);
      sep                                = oldSep;
      closingBraces[oldClosingBracesLen] = '\0';
    }
    return r;
  }
  logError("PGN %u: no function found to print field '%s'\n", field->pgn->pgn, fieldName);
  return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %r15
movq %r8, %r14
movq %rcx, %rbp
movq %rdx, %r9
movq %rdi, %rbx
testq %rsi, %rsi
je 0xf331
movq %rsi, %r13
movq (%rbx), %rdx
jmp 0xf33f
movq (%rbx), %rdx
movq 0x58(%rbx), %r13
testq %r13, %r13
cmoveq %rdx, %r13
movsd 0x30(%rbx), %xmm0
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
movq %r14, (%rsp)
leaq 0xfbf1(%rip), %rdi      # 0x1ef4a
movq %r13, %rcx
movq %rbp, %r8
movq %r9, 0x10(%rsp)
movb $0x1, %al
callq 0x1990d
movl 0x10(%rbx), %eax
testl %eax, %eax
jne 0xf385
movq 0x88(%rbx), %rax
testq %rax, %rax
je 0xf5a6
movl 0x28(%rax), %eax
movl %eax, %eax
leaq 0x7(%rax), %rcx
shrq $0x3, %rcx
movq %r14, %rdx
shrq $0x3, %rdx
movq %rbp, %r12
subq %rdx, %r12
cmpq %r12, %rcx
cmovbq %rcx, %r12
shlq $0x3, %r12
cmpq %rax, %r12
cmovaeq %rax, %r12
movq %r15, 0x18(%rsp)
movq %r12, (%r15)
movq (%rbx), %r15
leaq 0x1d120(%rip), %rsi     # 0x2c4e0
movq %r15, %rdi
callq 0xd1c0
testl %eax, %eax
je 0xf429
leaq 0x19262(%rip), %rsi     # 0x28635
movq %r15, %rdi
callq 0xd1c0
testl %eax, %eax
jne 0xf469
leaq 0x48(%rsp), %rax
movq %rax, (%rsp)
leaq 0x50(%rsp), %r15
xorl %edi, %edi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq %r12, %r8
movq %r15, %r9
callq 0x16e67
movq (%r15), %rsi
leaq 0xfce1(%rip), %rdi      # 0x1f0f4
xorl %eax, %eax
callq 0x1990d
movq (%r15), %rax
leaq 0x86084(%rip), %rcx     # 0x954a8
movq %rax, (%rcx)
jmp 0xf469
leaq 0x48(%rsp), %rax
movq %rax, (%rsp)
leaq 0x50(%rsp), %r15
xorl %edi, %edi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq %r12, %r8
movq %r15, %r9
callq 0x16e67
movq (%r15), %rsi
leaq 0xfc86(%rip), %rdi      # 0x1f0df
xorl %eax, %eax
callq 0x1990d
movl (%r15), %eax
movl %eax, 0x78e8f(%rip)     # 0x882f8
movq (%rbx), %rdx
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
movq 0x18(%rsp), %r15
movq (%r15), %r8
movzbl 0x48(%rbx), %r9d
movl 0x78e6f(%rip), %eax     # 0x882f8
movl %eax, (%rsp)
leaq 0xfb0e(%rip), %rdi      # 0x1efa1
movq %r13, %rcx
xorl %eax, %eax
callq 0x1990d
cmpb $0x1, 0x48(%rbx)
jne 0xf4c7
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x78e4a(%rip), %eax     # 0x882f8
cmpl $0xff00, %eax           # imm = 0xFF00
je 0xf4c7
cmpl $0x1ef00, %eax          # imm = 0x1EF00
je 0xf4c7
cmpl $0x1ff00, %eax          # imm = 0x1FF00
jne 0xf5ae
movq 0x88(%rbx), %rax
testq %rax, %rax
je 0xf578
cmpq $0x0, 0x78(%rax)
je 0xf578
callq 0x16da9
movq %rax, 0x38(%rsp)
movq 0x72ccd(%rip), %rax     # 0x821c0
movq %rax, 0x40(%rsp)
leaq 0x78de1(%rip), %rdi     # 0x882e0
callq 0xd0f0
movq %rax, 0x30(%rsp)
movq 0x88(%rbx), %rax
leaq 0x2d9(%rip), %rcx       # 0xf7f0
cmpq %rcx, 0x78(%rax)
movq %r14, 0x20(%rsp)
je 0xf59b
movb 0x78d9f(%rip), %r12b    # 0x882c8
callq 0x16dbb
cmpb $0x1, %r12b
jne 0xf5bd
leaq 0xfaa4(%rip), %rdi      # 0x1efe3
movq %rax, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x16c1c
leaq 0x1f2ff(%rip), %rax     # 0x2e852
movq %rax, 0x72c66(%rip)     # 0x821c0
cmpb $0x0, 0x78d65(%rip)     # 0x882c6
jne 0xf56c
cmpb $0x1, 0x78d60(%rip)     # 0x882ca
jne 0xf59b
callq 0x16da9
movq %rax, 0x8(%rsp)
jmp 0xf5e8
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
leaq 0xfb27(%rip), %rdi      # 0x1f0b0
xorl %r12d, %r12d
movq %r13, %rdx
xorl %eax, %eax
callq 0x199a0
jmp 0xf7de
movq $0x0, 0x8(%rsp)
jmp 0xf5e8
xorl %r12d, %r12d
jmp 0xf3ae
movq $0x0, (%r15)
movb $0x1, %r12b
jmp 0xf7de
leaq 0xfa27(%rip), %rdi      # 0x1efeb
movq $0x0, 0x8(%rsp)
movq %rax, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x16c1c
leaq 0xfa13(%rip), %rax      # 0x1eff4
movq %rax, 0x72bd8(%rip)     # 0x821c0
callq 0x16da9
movq %rax, 0x28(%rsp)
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
movq (%rbx), %rdx
movq 0x8(%rbx), %r8
leaq 0xf9ec(%rip), %rdi      # 0x1eff6
xorl %r12d, %r12d
movq %r13, %rcx
xorl %eax, %eax
callq 0x1990d
leaq 0x85e72(%rip), %r14     # 0x95490
movb $0x0, (%r14)
movq 0x88(%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %rbp, %rcx
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r15
movq %r15, %r9
callq *0x78(%rax)
movq (%rbx), %rdx
movq 0x90(%rbx), %rcx
movl 0x8(%rcx), %esi
movzbl %al, %ebp
movq (%r15), %r9
leaq 0xf9cd(%rip), %rdi      # 0x1f02e
movq %r13, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x1990d
testb %bpl, %bpl
je 0xf7b8
movb $0x1, %r12b
cmpb $0x0, (%r14)
jne 0xf7b8
callq 0x16da9
cmpq %rax, 0x28(%rsp)
jne 0xf69d
cmpb $0x0, 0x78c2f(%rip)     # 0x882c6
je 0xf75c
movq 0x88(%rbx), %rax
movb $0x1, %r12b
leaq 0x142(%rip), %rcx       # 0xf7f0
cmpq %rcx, 0x78(%rax)
je 0xf77a
callq 0x16da9
movq %rax, %r15
decq %r15
movq %r15, %rdi
callq 0x16cf2
movl %eax, %ebp
cmpb $0x7d, %al
sete %r13b
jne 0xf6dd
movq %r15, %rdi
callq 0x16ce0
cmpb $0x1, 0x78be2(%rip)     # 0x882c6
movq 0x20(%rsp), %rsi
jne 0xf719
cmpb $0x7d, %bpl
sete %r13b
movq %rsi, %rax
shrq $0x3, %rax
movq 0x10(%rsp), %rdi
addq %rax, %rdi
andl $0x7, %esi
movq 0x18(%rsp), %rax
movq (%rax), %rdx
callq 0xf8a3
orb 0x78baf(%rip), %r13b    # 0x882c8
cmpb $0x1, 0x78baa(%rip)     # 0x882ca
leaq 0x85d69(%rip), %r14     # 0x95490
jne 0xf747
movb 0x90(%rsp), %al
andb 0x4a(%rbx), %al
cmpb $0x1, %al
jne 0xf747
leaq 0xf95c(%rip), %rdi      # 0x1f09a
xorl %eax, %eax
callq 0x16c1c
jmp 0xf74c
testb %r13b, %r13b
je 0xf77a
leaq 0x19de3(%rip), %rdi     # 0x29536
xorl %eax, %eax
callq 0x16c1c
jmp 0xf77a
movq (%rbx), %rdx
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
leaq 0xf8f1(%rip), %rdi      # 0x1f061
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x199a0
movq 0x8(%rsp), %rbx
testq %rbx, %rbx
je 0xf7a5
callq 0x16da9
leaq -0x1(%rax), %rdi
callq 0x16cf2
cmpb $0x7d, %al
jne 0xf7a5
leaq 0xf909(%rip), %rsi      # 0x1f0a6
movq %rbx, %rdi
callq 0x16cfd
testb %r12b, %r12b
je 0xf7b5
movb $0x1, %r12b
testb $0x1, (%r14)
jne 0xf7b8
jmp 0xf7de
xorl %r12d, %r12d
movq 0x38(%rsp), %rdi
callq 0x16ce0
movq 0x40(%rsp), %rax
movq %rax, 0x729f2(%rip)     # 0x821c0
leaq 0x78b0b(%rip), %rax     # 0x882e0
movq 0x30(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq