// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %r8, %r14
movq %rcx, %rbp
movq %rdx, 0x10(%rsp)
movq %rdi, %rbx
testq %rsi, %rsi
je 0xf1c2
movq %rsi, %r13
movq (%rbx), %rdx
jmp 0xf1d0
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 0xfd60(%rip), %rdi      # 0x1ef4a
movq %r13, %rcx
movq %rbp, %r8
movq 0x10(%rsp), %r9
movb $0x1, %al
callq 0x19050
movl 0x10(%rbx), %eax
testl %eax, %eax
movq %r14, 0x20(%rsp)
jne 0xf21b
movq 0x88(%rbx), %rax
testq %rax, %rax
je 0xf433
movl 0x28(%rax), %eax
movl %eax, %eax
leaq 0x7(%rax), %rcx
shrq $0x3, %rcx
movq %r14, %rdx
shrq $0x3, %rdx
movq %rbp, %r14
subq %rdx, %r14
cmpq %r14, %rcx
cmovbq %rcx, %r14
shlq $0x3, %r14
cmpq %rax, %r14
cmovaeq %rax, %r14
movq %r14, (%r12)
movq (%rbx), %r15
leaq 0x1d28e(%rip), %rsi     # 0x2c4e0
movq %r15, %rdi
callq 0xd1c0
leaq 0x38(%rsp), %rcx
testl %eax, %eax
je 0xf2c2
leaq 0x193cb(%rip), %rsi     # 0x28635
movq %r15, %rdi
callq 0xd1c0
testl %eax, %eax
jne 0xf2ff
leaq 0x38(%rsp), %rax
movq %rax, (%rsp)
leaq 0x30(%rsp), %r15
xorl %edi, %edi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq 0x20(%rsp), %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x166f1
movq (%r15), %rsi
leaq 0xfe48(%rip), %rdi      # 0x1f0f4
xorl %eax, %eax
callq 0x19050
movq (%r15), %rax
leaq 0x861eb(%rip), %rcx     # 0x954a8
movq %rax, (%rcx)
jmp 0xf2ff
movq %rcx, (%rsp)
leaq 0x30(%rsp), %r15
xorl %edi, %edi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq 0x20(%rsp), %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x166f1
movq (%r15), %rsi
leaq 0xfdf0(%rip), %rdi      # 0x1f0df
xorl %eax, %eax
callq 0x19050
movl (%r15), %eax
movl %eax, 0x78ff9(%rip)     # 0x882f8
movq (%rbx), %rdx
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
movq (%r12), %r8
movzbl 0x48(%rbx), %r9d
movl 0x78fdd(%rip), %eax     # 0x882f8
movl %eax, (%rsp)
leaq 0xfc7c(%rip), %rdi      # 0x1efa1
movq %r13, %rcx
xorl %eax, %eax
callq 0x19050
cmpb $0x1, 0x48(%rbx)
jne 0xf359
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
andl 0x78fb8(%rip), %eax     # 0x882f8
cmpl $0xff00, %eax           # imm = 0xFF00
je 0xf359
cmpl $0x1ef00, %eax          # imm = 0x1EF00
je 0xf359
cmpl $0x1ff00, %eax          # imm = 0x1FF00
jne 0xf43b
movq 0x88(%rbx), %rax
testq %rax, %rax
je 0xf405
cmpq $0x0, 0x78(%rax)
je 0xf405
callq 0x16637
movq %rax, 0x48(%rsp)
movq 0x72e3b(%rip), %rax     # 0x821c0
movq %rax, 0x50(%rsp)
leaq 0x78f4f(%rip), %rdi     # 0x882e0
callq 0xd0f0
movq %rax, 0x40(%rsp)
movq 0x88(%rbx), %rax
leaq 0x4b6(%rip), %rcx       # 0xf85f
cmpq %rcx, 0x78(%rax)
je 0xf428
movb 0x78f12(%rip), %r14b    # 0x882c8
callq 0x16649
cmpb $0x1, %r14b
jne 0xf448
leaq 0xfc17(%rip), %rdi      # 0x1efe3
movq %rax, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x164ac
leaq 0x1f472(%rip), %rax     # 0x2e852
movq %rax, 0x72dd9(%rip)     # 0x821c0
cmpb $0x0, 0x78ed8(%rip)     # 0x882c6
jne 0xf3f9
cmpb $0x1, 0x78ed3(%rip)     # 0x882ca
jne 0xf428
callq 0x16637
movq %rax, 0x18(%rsp)
jmp 0xf473
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
leaq 0xfc9a(%rip), %rdi      # 0x1f0b0
xorl %r14d, %r14d
movq %r13, %rdx
xorl %eax, %eax
callq 0x190e1
jmp 0xf84d
movq $0x0, 0x18(%rsp)
jmp 0xf473
xorl %r14d, %r14d
jmp 0xf244
andq $0x0, (%r12)
movb $0x1, %r14b
jmp 0xf84d
leaq 0xfb9c(%rip), %rdi      # 0x1efeb
movq $0x0, 0x18(%rsp)
movq %rax, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x164ac
leaq 0xfb88(%rip), %rax      # 0x1eff4
movq %rax, 0x72d4d(%rip)     # 0x821c0
callq 0x16637
movq %rax, 0x28(%rsp)
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
movq (%rbx), %rdx
movq 0x8(%rbx), %r8
leaq 0xfb61(%rip), %rdi      # 0x1eff6
xorl %r14d, %r14d
movq %r13, %rcx
xorl %eax, %eax
callq 0x19050
leaq 0x85fe7(%rip), %r15     # 0x95490
movb $0x0, (%r15)
movq 0x88(%rbx), %rax
movq %rbx, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %rbp, %rcx
movq 0x20(%rsp), %r8
movq %r12, %r9
callq *0x78(%rax)
movq (%rbx), %rdx
movq 0x90(%rbx), %rcx
movl 0x8(%rcx), %esi
movzbl %al, %ebp
movq (%r12), %r9
leaq 0xfb46(%rip), %rdi      # 0x1f02e
movq %r13, %rcx
movq %r15, %r13
movl %ebp, %r8d
xorl %eax, %eax
callq 0x19050
testb %bpl, %bpl
je 0xf827
movb $0x1, %r14b
cmpb $0x0, (%r13)
jne 0xf827
callq 0x16637
cmpq %rax, 0x28(%rsp)
jne 0xf528
cmpb $0x0, 0x78da4(%rip)     # 0x882c6
je 0xf5e8
movq 0x88(%rbx), %rax
movb $0x1, %r15b
leaq 0x326(%rip), %rcx       # 0xf85f
cmpq %rcx, 0x78(%rax)
je 0xf7e8
callq 0x16637
movq %rax, %r14
decq %r14
movq %r14, %rdi
callq 0x16582
movb %al, 0xf(%rsp)
cmpb $0x7d, %al
sete %bpl
jne 0xf56a
movq %r14, %rdi
callq 0x16570
cmpb $0x1, 0x78d55(%rip)     # 0x882c6
jne 0xf7ad
movq 0x20(%rsp), %r14
movq %r14, %rax
shrq $0x3, %rax
movq 0x10(%rsp), %rsi
addq %rax, %rsi
movl %r14d, %r13d
andl $0x7, %r13d
movq (%r12), %r12
leaq 0xfb75(%rip), %rdi      # 0x1f112
movq %rsi, 0x10(%rsp)
movq %r13, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x19050
cmpb $0x1, 0x78d12(%rip)     # 0x882c8
jne 0xf60b
callq 0x16637
testq %rax, %rax
je 0xf5d1
decq %rax
movq %rax, %rdi
callq 0x16582
cmpb $0x7b, %al
je 0xf5df
leaq 0x1f27a(%rip), %rdi     # 0x2e852
xorl %eax, %eax
callq 0x164ac
leaq 0xfb4b(%rip), %rdi      # 0x1f131
jmp 0xf612
movq (%rbx), %rdx
movq 0x90(%rbx), %rax
movl 0x8(%rax), %esi
leaq 0xfa65(%rip), %rdi      # 0x1f061
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x190e1
jmp 0xf7e8
leaq 0xfb29(%rip), %rdi      # 0x1f13b
xorl %eax, %eax
callq 0x164ac
leaq 0x7(%r12), %rbp
shrq $0x3, %rbp
orq $-0x8, %r14
movq %r14, 0x28(%rsp)
leaq 0xf037(%rip), %rsi      # 0x1e669
movq %r12, %r14
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0xf6cb
testq %r13, %r13
sete %cl
movq 0x10(%rsp), %rax
movzbl (%rax,%r15), %eax
testq %r15, %r15
setne %dl
orb %cl, %dl
jne 0xf688
movl %r13d, %ecx
shrl %cl, %eax
pushq $-0x1
popq %rdx
movl %r14d, %ecx
shll %cl, %edx
leaq (%r14,%r13), %rcx
cmpq $0x8, %rcx
notl %edx
movl $0xff, %ecx
cmovael %ecx, %edx
andl %eax, %edx
movl %r13d, %ecx
shll %cl, %edx
movq 0x28(%rsp), %rcx
jmp 0xf6a8
pushq $-0x1
popq %rdx
movl %r14d, %ecx
shll %cl, %edx
cmpq $0x8, %r14
notb %dl
movzbl %dl, %ecx
movl $0xff, %edx
cmovael %edx, %ecx
andl %ecx, %eax
pushq $-0x8
popq %rcx
movl %eax, %edx
addq %rcx, %r14
movzbl %dl, %edx
leaq 0xfa92(%rip), %rdi      # 0x1f147
xorl %eax, %eax
callq 0x164ac
incq %r15
leaq 0xf405(%rip), %rsi      # 0x1eacb
jmp 0xf638
leaq 0xfa73(%rip), %rdi      # 0x1f145
xorl %eax, %eax
callq 0x164ac
movq 0x20(%rsp), %rax
orl %r12d, %eax
testb $0x7, %al
movb $0x1, %r15b
je 0xf77b
leaq 0x38(%rsp), %rax
movq %rax, (%rsp)
leaq 0x30(%rsp), %r9
xorl %edi, %edi
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x166f1
leaq 0xfa3a(%rip), %rax      # 0x1f150
leaq 0xfa3d(%rip), %rdi      # 0x1f15a
cmpb $0x0, 0x78ba4(%rip)     # 0x882c8
cmovneq %rax, %rdi
xorl %eax, %eax
callq 0x164ac
decq %r12
leaq 0xf075(%rip), %r14      # 0x1e7ae
cmpq $-0x1, %r12
je 0xf76d
movq 0x30(%rsp), %rax
movl %r12d, %ecx
shrl $0x3, %ecx
sarq %cl, %rax
movl %r12d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
movl $0x0, %esi
adcl $0x30, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x164ac
decq %r12
jmp 0xf739
leaq 0xf9d1(%rip), %rdi      # 0x1f145
xorl %eax, %eax
callq 0x164ac
movb $0x1, %al
cmpb $0x0, 0x78b44(%rip)     # 0x882c8
jne 0xf79a
leaq 0x1c5df(%rip), %rdi     # 0x2bd6c
xorl %eax, %eax
callq 0x164ac
movb 0x78b2e(%rip), %al      # 0x882c8
cmpb $0x7d, 0xf(%rsp)
sete %bpl
orb %al, %bpl
leaq 0x85ce3(%rip), %r13     # 0x95490
cmpb $0x1, 0x78b16(%rip)     # 0x882ca
jne 0xf7d4
movb 0x90(%rsp), %al
andb 0x4a(%rbx), %al
cmpb $0x1, %al
jne 0xf7d4
leaq 0xf8cf(%rip), %rdi      # 0x1f09a
xorl %eax, %eax
callq 0x164ac
jmp 0xf7da
testb $0x1, %bpl
je 0xf7e8
leaq 0x19d55(%rip), %rdi     # 0x29536
xorl %eax, %eax
callq 0x164ac
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
je 0xf813
callq 0x16637
leaq -0x1(%rax), %rdi
callq 0x16582
cmpb $0x7d, %al
jne 0xf813
leaq 0xf89b(%rip), %rsi      # 0x1f0a6
movq %rbx, %rdi
callq 0x1658d
testb %r15b, %r15b
je 0xf824
movb $0x1, %r14b
testb $0x1, (%r13)
jne 0xf827
jmp 0xf84d
xorl %r14d, %r14d
movq 0x48(%rsp), %rdi
callq 0x16570
movq 0x50(%rsp), %rax
movq %rax, 0x72983(%rip)     # 0x821c0
leaq 0x78a9c(%rip), %rax     # 0x882e0
movq 0x40(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq