// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %r8, %rax
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r15
movq (%r9), %r8
leaq 0x28(%rsp), %rcx
movq %rcx, (%rsp)
leaq 0x10(%rsp), %r9
movq %rdx, %rsi
movq %r12, %rdx
movq %rax, %rcx
callq 0x22937
movb $0x1, %bl
testb %al, %al
je 0x23357
movq 0x18(%r15), %rbx
testq %rbx, %rbx
je 0x23165
cmpb $0x3d, (%rbx)
jne 0x23165
callq 0xd350
movq (%rax), %rax
movzbl 0x1(%rbx), %ecx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x231b4
xorl %ebp, %ebp
testq %rbp, %rbp
movb $0x1, %bl
jne 0x23284
movl 0x68(%r15), %eax
testl %eax, %eax
setne %cl
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
setns %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x23282
cmpl $0x4, %eax
je 0x231a8
cmpl $0x2, %eax
je 0x23232
cmpl $0x1, %eax
jne 0x23282
callq *0x70(%r15)
movq %rax, %rbp
jmp 0x23284
movq 0x10(%rsp), %rdx
leaq 0x1795b(%rip), %rsi     # 0x3ab1b
leaq 0x30(%rsp), %rdi
movq %rdx, 0x18(%rsp)
xorl %eax, %eax
callq 0xd2c0
movq 0x18(%r15), %rbx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0xd1a0
testl %eax, %eax
je 0x23210
incq %rbx
leaq 0x17930(%rip), %rdi     # 0x3ab20
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movq %rbx, %rcx
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x254dd
movb $0x1, 0x7a635(%rip)     # 0x9d840
jmp 0x23357
movq 0x20(%r15), %rbp
testq %rbp, %rbp
jne 0x23167
xorl %ebp, %ebp
cmpl $0x0, 0x68(%r15)
leaq 0x31(%rsp), %rax
cmoveq %rax, %rbp
jmp 0x23167
movq %rdi, 0x18(%rsp)
movq (%r15), %rsi
leaq 0x17905(%rip), %rdi     # 0x3ab46
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x254dd
movq 0x90(%r15), %rdi
testq %rdi, %rdi
je 0x23284
movzbl 0x78(%r15), %esi
leaq 0x20(%rsp), %r8
movq %r13, %rdx
movq %r12, %rcx
callq 0x22b16
testb %al, %al
je 0x23282
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq *0x70(%r15)
jmp 0x231ac
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x232b4
leaq 0x78464(%rip), %rax     # 0x9b6f4
cmpb $0x1, (%rax)
jne 0x23323
movq 0x10(%rsp), %rsi
leaq 0x17995(%rip), %rdi     # 0x3ac3a
movq %rbp, %rdx
xorl %eax, %eax
callq 0x226ec
jmp 0x23357
cmpq $0x2, (%r14)
jb 0x232d6
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rax
sete %cl
movzbl %cl, %ecx
orq $-0x2, %rcx
addq %rax, %rcx
cmpq %rcx, %rsi
jge 0x2334f
leaq 0x78417(%rip), %rax     # 0x9b6f4
movb (%rax), %bl
movq 0x10(%rsp), %rsi
leaq 0x17766(%rip), %rdi     # 0x3aa51
xorl %eax, %eax
callq 0x226ec
cmpb $0x1, %bl
jne 0x2334b
leaq 0x783f5(%rip), %rax     # 0x9b6f3
cmpb $0x1, (%rax)
movb $0x1, %bl
jne 0x23313
leaq 0x1785d(%rip), %rdi     # 0x3ab69
xorl %eax, %eax
callq 0x226ec
leaq 0x1792f(%rip), %rdi     # 0x3ac49
xorl %eax, %eax
callq 0x226ec
jmp 0x23357
leaq 0x783c8(%rip), %rax     # 0x9b6f2
cmpb $0x1, (%rax)
jne 0x23338
leaq 0x17917(%rip), %rdi     # 0x3ac4d
jmp 0x2333f
leaq 0x1cae2(%rip), %rdi     # 0x3fe21
movq %rbp, %rsi
xorl %eax, %eax
callq 0x226ec
jmp 0x23357
movb $0x1, %bl
jmp 0x23357
subq %rax, %rsi
callq 0x22ba4
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq