// File: /workspace/github_c_makefile_star2_O2/canboat[P]canboat/analyzer/print.c
// Function: fieldPrintLookup
extern bool fieldPrintLookup(const Field   *field,
                             const char    *fieldName,
                             const uint8_t *data,
                             size_t         dataLen,
                             size_t         startBit,
                             size_t        *bits)
{
  char        lookfor[20];
  const char *s = NULL;

  int64_t value;
  int64_t maxValue;

  // Can't use extractNumberNotEmpty when the lookup key might use the 'error/unknown' values.
  if (!extractNumber(field, data, dataLen, startBit, *bits, &value, &maxValue))
  {
    return true;
  }

  if (field->unit && field->unit[0] == '=' && isdigit((unsigned char) field->unit[1]))
  {
    sprintf(lookfor, "=%" PRId64, value);
    if (strcmp(lookfor, field->unit) != 0)
    {
      logDebug("Field %s value %" PRId64 " does not match %s\n", fieldName, value, field->unit + 1);
      g_skip = true;
      return false;
    }
    s = field->description;
    if (s == NULL && field->lookup.type == LOOKUP_TYPE_NONE)
    {
      s = lookfor + 1;
    }
  }

  if (s == NULL && field->lookup.type != LOOKUP_TYPE_NONE && value >= 0)
  {
    if (field->lookup.type == LOOKUP_TYPE_PAIR || field->lookup.type == LOOKUP_TYPE_FIELDTYPE)
    {
      s = (*field->lookup.function.pair)((size_t) value);
    }
    else if (field->lookup.type == LOOKUP_TYPE_TRIPLET)
    {
      int64_t val1;

      logDebug("Triplet extraction for field '%s'\n", field->name);

      if (field->pgn != NULL && extractNumberByOrder(field->pgn, field->lookup.val1Order, data, dataLen, &val1))
      {
        s = (*field->lookup.function.triplet)((size_t) val1, (size_t) value);
      }
    }
    // BIT is handled in fieldPrintBitLookup
  }

  if (s != NULL)
  {
    if (showJsonValue)
    {
      mprintf("%" PRId64 ",\"name\":\"%s\"}", value, s);
    }
    else if (showJson)
    {
      mprintf("\"%s\"", s);
    }
    else
    {
      mprintf("%s", s);
    }
  }
  else
  {
    if (*bits > 1 && (value >= maxValue - (*bits > 2 ? 2 : 1)))
    {
      printEmpty(fieldName, value - maxValue);
    }
    else if (showJsonValue)
    {
      mprintf("%" PRId64, value);
      if (showJsonEmpty)
      {
        mprintf(",\"name\":null");
      }
      mprintf("}");
    }
    else if (showJson)
    {
      mprintf("%" PRId64, value);
    }
    else
    {
      mprintf("%" PRId64, value);
    }
  }

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r15
movq %r8, %rax
movq %rcx, %r13
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r12
movq (%r9), %r8
leaq 0x28(%rsp), %rcx
movq %rcx, (%rsp)
leaq 0x10(%rsp), %r9
movq %rdx, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x193d9
movb $0x1, %cl
testb %al, %al
je 0x19d41
movq 0x18(%r12), %r14
testq %r14, %r14
je 0x19b85
cmpb $0x3d, (%r14)
jne 0x19b85
callq 0xd350
movq (%rax), %rax
movzbl 0x1(%r14), %ecx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x19c6a
movl 0x68(%r12), %eax
testl %eax, %eax
setne %cl
movq 0x10(%rsp), %r14
testq %r14, %r14
setns %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x19bed
cmpl $0x4, %eax
je 0x19bb4
cmpl $0x2, %eax
je 0x19cdd
cmpl $0x1, %eax
jne 0x19bed
movq %r14, %rdi
callq *0x70(%r12)
movq %rax, %rbx
testq %rbx, %rbx
je 0x19bed
leaq 0x75b29(%rip), %rax     # 0x8f6f4
cmpb $0x1, (%rax)
jne 0x19cc8
leaq 0x12dcf(%rip), %rdi     # 0x2c9aa
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x19194
jmp 0x19d3f
cmpq $0x2, (%r15)
jb 0x19c0a
movq 0x28(%rsp), %rax
sete %cl
movzbl %cl, %ecx
orq $-0x2, %rcx
addq %rax, %rcx
cmpq %rcx, %r14
jge 0x19c5a
leaq 0x75ae3(%rip), %rax     # 0x8f6f4
movb (%rax), %bl
leaq 0x12ba7(%rip), %rdi     # 0x2c7c1
movq %r14, %rsi
xorl %eax, %eax
callq 0x19194
cmpb $0x1, %bl
jne 0x19d3f
leaq 0x75abf(%rip), %rax     # 0x8f6f3
cmpb $0x1, (%rax)
jne 0x19c47
leaq 0x12c99(%rip), %rdi     # 0x2c8d9
xorl %eax, %eax
callq 0x19194
leaq 0x12d6b(%rip), %rdi     # 0x2c9b9
xorl %eax, %eax
callq 0x19194
jmp 0x19d3f
subq %rax, %r14
movq %r14, %rsi
callq 0x19614
jmp 0x19d3f
movq 0x10(%rsp), %r14
leaq 0x12c15(%rip), %rsi     # 0x2c88b
leaq 0x30(%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xd2c0
movq 0x18(%r12), %rsi
leaq 0x30(%rsp), %rdi
movq %rsi, 0x18(%rsp)
callq 0xd1a0
testl %eax, %eax
je 0x19d52
movq 0x18(%rsp), %rcx
incq %rcx
leaq 0x12be0(%rip), %rdi     # 0x2c890
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x1bd48
xorl %ecx, %ecx
movb $0x1, 0x77b7a(%rip)     # 0x91840
jmp 0x19d41
leaq 0x75a23(%rip), %rax     # 0x8f6f2
cmpb $0x1, (%rax)
jne 0x19d2e
leaq 0x12ce2(%rip), %rdi     # 0x2c9bd
jmp 0x19d35
movq (%r12), %rsi
leaq 0x12bce(%rip), %rdi     # 0x2c8b6
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1bd48
movq 0x90(%r12), %rdi
testq %rdi, %rdi
je 0x19bbf
movzbl 0x78(%r12), %esi
leaq 0x20(%rsp), %r8
movq %rbp, %rdx
movq %r13, %rcx
callq 0x1959c
testb %al, %al
je 0x19d76
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq *0x70(%r12)
jmp 0x19bbc
leaq 0x17e89(%rip), %rdi     # 0x31bbe
movq %rbx, %rsi
xorl %eax, %eax
callq 0x19194
movb $0x1, %cl
movl %ecx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r12), %rbx
testq %rbx, %rbx
jne 0x19bc4
cmpl $0x0, 0x68(%r12)
jne 0x19b85
leaq 0x31(%rsp), %rbx
jmp 0x19bc4
xorl %ebx, %ebx
jmp 0x19bbf