// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rdx, %r9
movq %rsi, %r13
movq %rdi, %rbx
testq %rsi, %rsi
jne 0xf3c2
movq 0x58(%rbx), %r13
testq %r13, %r13
jne 0xf3c2
movq (%rbx), %r13
movsd 0x30(%rbx), %xmm0
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
movq (%rbx), %rdx
movq %r14, (%rsp)
leaq 0x10b6b(%rip), %rdi     # 0x1ff4a
movq %r13, %rcx
movq %r12, %r8
movq %r9, 0x20(%rsp)
movb $0x1, %al
callq 0x19a95
movl 0x10(%rbx), %eax
testl %eax, %eax
movq %r14, 0x18(%rsp)
je 0xf4a6
movl %eax, %eax
movq %rax, (%r15)
leaq 0x7(%rax), %rcx
shrq $0x3, %rcx
shrq $0x3, %r14
movq %r12, %rbp
subq %r14, %rbp
cmpq %rbp, %rcx
cmovbq %rcx, %rbp
shlq $0x3, %rbp
cmpq %rax, %rbp
cmovaeq %rax, %rbp
movq %rbp, (%r15)
movq (%rbx), %r14
leaq 0x1e069(%rip), %rsi     # 0x2d4a0
movq %r14, %rdi
callq 0xd1c0
testl %eax, %eax
je 0xf4cb
leaq 0x1a1e7(%rip), %rsi     # 0x29635
movq %r14, %rdi
callq 0xd1c0
testl %eax, %eax
jne 0xf50d
leaq 0x48(%rsp), %rax
movq %rax, (%rsp)
leaq 0x50(%rsp), %r14
xorl %edi, %edi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
movq 0x18(%rsp), %rcx
movq %rbp, %r8
movq %r14, %r9
callq 0x16f1b
movq (%r14), %rsi
leaq 0x10c64(%rip), %rdi     # 0x200f4
xorl %eax, %eax
callq 0x19a95
movq (%r14), %rax
leaq 0x87007(%rip), %rcx     # 0x964a8
movq %rax, (%rcx)
jmp 0xf50d
cmpq $0x0, 0x88(%rbx)
je 0xf641
testl %eax, %eax
jne 0xf401
movq 0x88(%rbx), %rax
movl 0x28(%rax), %eax
jmp 0xf401
leaq 0x48(%rsp), %rax
movq %rax, (%rsp)
leaq 0x50(%rsp), %r14
xorl %edi, %edi
movq 0x20(%rsp), %rsi
movq %r12, %rdx
movq 0x18(%rsp), %rcx
movq %rbp, %r8
movq %r14, %r9
callq 0x16f1b
movq (%r14), %rsi
leaq 0x10be2(%rip), %rdi     # 0x200df
xorl %eax, %eax
callq 0x19a95
movl (%r14), %eax
movl %eax, 0x79deb(%rip)     # 0x892f8
movq (%rbx), %rdx
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
movq (%r15), %r8
movzbl 0x48(%rbx), %r9d
movl 0x79dd0(%rip), %eax     # 0x892f8
movl %eax, (%rsp)
leaq 0x10a6f(%rip), %rdi     # 0x1ffa1
movq %r13, %rcx
xorl %eax, %eax
callq 0x19a95
cmpb $0x1, 0x48(%rbx)
jne 0xf566
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x79dab(%rip), %eax     # 0x892f8
cmpl $0xff00, %eax           # imm = 0xFF00
je 0xf566
cmpl $0x1ef00, %eax          # imm = 0x1EF00
je 0xf566
cmpl $0x1ff00, %eax          # imm = 0x1FF00
jne 0xf658
movq 0x88(%rbx), %rax
testq %rax, %rax
je 0xf61f
cmpq $0x0, 0x78(%rax)
je 0xf61f
callq 0x16e5d
movq %rax, 0x38(%rsp)
movq 0x73c2e(%rip), %rax     # 0x831c0
movq %rax, 0x40(%rsp)
leaq 0x79d42(%rip), %rdi     # 0x892e0
callq 0xd0f0
movq %rax, 0x30(%rsp)
movq 0x88(%rbx), %rax
leaq 0x2f0(%rip), %rcx       # 0xf8a6
cmpq %rcx, 0x78(%rax)
je 0xf648
movb 0x79d01(%rip), %bpl     # 0x892c8
callq 0x16e6f
cmpb $0x1, %bpl
movq 0x18(%rsp), %r14
jne 0xf666
leaq 0x10a01(%rip), %rdi     # 0x1ffe3
movq %rax, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x16cd0
leaq 0x2022f(%rip), %rax     # 0x2f825
movq %rax, 0x73bc3(%rip)     # 0x831c0
cmpb $0x0, 0x79cc2(%rip)     # 0x892c6
jne 0xf613
cmpb $0x1, 0x79cbd(%rip)     # 0x892ca
jne 0xf842
callq 0x16e5d
movq %rax, 0x10(%rsp)
jmp 0xf691
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
leaq 0x10a80(%rip), %rdi     # 0x200b0
xorl %ebx, %ebx
movq %r13, %rdx
xorl %eax, %eax
callq 0x19b28
jmp 0xf81c
xorl %ebp, %ebp
jmp 0xf42a
movq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %r14
jmp 0xf691
movq $0x0, (%r15)
movb $0x1, %bl
jmp 0xf81c
leaq 0x1097e(%rip), %rdi     # 0x1ffeb
movq $0x0, 0x10(%rsp)
movq %rax, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x16cd0
leaq 0x1096a(%rip), %rax     # 0x1fff4
movq %rax, 0x73b2f(%rip)     # 0x831c0
callq 0x16e5d
movq %rax, 0x28(%rsp)
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
movq (%rbx), %rdx
movq 0x8(%rbx), %r8
leaq 0x10943(%rip), %rdi     # 0x1fff6
movq %r13, %rcx
xorl %eax, %eax
callq 0x19a95
leaq 0x86dcc(%rip), %rbp     # 0x96490
movb $0x0, (%rbp)
movq 0x88(%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
movq 0x20(%rsp), %rdx
movq %r12, %rcx
movq %r14, %r8
movq %r15, %r9
callq *0x78(%rax)
movl %eax, %r12d
movq (%rbx), %rdx
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
movzbl %r12b, %r14d
movq (%r15), %r9
leaq 0x1092a(%rip), %rdi     # 0x2002e
movq %r13, %rcx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x19a95
testb %r14b, %r14b
je 0xf7e3
cmpb $0x0, (%rbp)
movq %rbp, %r14
jne 0xf7e6
callq 0x16e5d
cmpq %rax, 0x28(%rsp)
jne 0xf740
cmpb $0x0, 0x79b8c(%rip)     # 0x892c6
je 0xf850
movq 0x88(%rbx), %rax
leaq 0x158(%rip), %rcx       # 0xf8a6
cmpq %rcx, 0x78(%rax)
je 0xf86e
callq 0x16e5d
movq %rax, %r14
decq %r14
movq %r14, %rdi
callq 0x16da6
movl %eax, %r13d
cmpb $0x7d, %al
sete %bpl
jne 0xf77e
movq %r14, %rdi
callq 0x16d94
cmpb $0x1, 0x79b41(%rip)     # 0x892c6
jne 0xf7b5
cmpb $0x7d, %r13b
sete %bpl
movq 0x18(%rsp), %rsi
movq %rsi, %rax
shrq $0x3, %rax
movq 0x20(%rsp), %rdi
addq %rax, %rdi
andl $0x7, %esi
movq (%r15), %rdx
callq 0xf959
orb 0x79b13(%rip), %bpl     # 0x892c8
cmpb $0x1, 0x79b0e(%rip)     # 0x892ca
leaq 0x86ccd(%rip), %r14     # 0x96490
jne 0xf82d
movb 0x90(%rsp), %al
andb 0x4a(%rbx), %al
cmpb $0x1, %al
jne 0xf82d
leaq 0x108c0(%rip), %rdi     # 0x2009a
xorl %eax, %eax
callq 0x16cd0
jmp 0xf832
movq %rbp, %r14
testb %r12b, %r12b
je 0xf7f3
movb $0x1, %bl
cmpb $0x1, (%r14)
jne 0xf81c
movq 0x38(%rsp), %rdi
callq 0x16d94
movq 0x40(%rsp), %rax
movq %rax, 0x739b7(%rip)     # 0x831c0
leaq 0x79ad0(%rip), %rax     # 0x892e0
movq 0x30(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movl %r12d, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %bpl, %bpl
je 0xf86e
leaq 0x1acfd(%rip), %rdi     # 0x2a536
xorl %eax, %eax
callq 0x16cd0
jmp 0xf86e
movq $0x0, 0x10(%rsp)
jmp 0xf691
movq (%rbx), %rdx
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
leaq 0x107fd(%rip), %rdi     # 0x20061
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x19b28
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0xf7e6
callq 0x16e5d
leaq -0x1(%rax), %rdi
callq 0x16da6
cmpb $0x7d, %al
jne 0xf7e6
leaq 0x1080d(%rip), %rsi     # 0x200a6
movq %rbx, %rdi
callq 0x16db1
jmp 0xf7e6