// File: /workspace/github_c_makefile_star2_O3/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 0x1a2c7
movb $0x1, %cl
testb %al, %al
je 0x1ac88
movq 0x18(%r12), %r14
testq %r14, %r14
je 0x1aacc
cmpb $0x3d, (%r14)
jne 0x1aacc
callq 0xd350
movq (%rax), %rax
movzbl 0x1(%r14), %ecx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x1abb1
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 0x1ab34
cmpl $0x4, %eax
je 0x1aafb
cmpl $0x2, %eax
je 0x1ac24
cmpl $0x1, %eax
jne 0x1ab34
movq %r14, %rdi
callq *0x70(%r12)
movq %rax, %rbx
testq %rbx, %rbx
je 0x1ab34
leaq 0x73be2(%rip), %rax     # 0x8e6f4
cmpb $0x1, (%rax)
jne 0x1ac0f
leaq 0x12e88(%rip), %rdi     # 0x2d9aa
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1a07c
jmp 0x1ac86
cmpq $0x2, (%r15)
jb 0x1ab51
movq 0x28(%rsp), %rax
sete %cl
movzbl %cl, %ecx
orq $-0x2, %rcx
addq %rax, %rcx
cmpq %rcx, %r14
jge 0x1aba1
leaq 0x73b9c(%rip), %rax     # 0x8e6f4
movb (%rax), %bl
leaq 0x12c60(%rip), %rdi     # 0x2d7c1
movq %r14, %rsi
xorl %eax, %eax
callq 0x1a07c
cmpb $0x1, %bl
jne 0x1ac86
leaq 0x73b78(%rip), %rax     # 0x8e6f3
cmpb $0x1, (%rax)
jne 0x1ab8e
leaq 0x12d52(%rip), %rdi     # 0x2d8d9
xorl %eax, %eax
callq 0x1a07c
leaq 0x12e24(%rip), %rdi     # 0x2d9b9
xorl %eax, %eax
callq 0x1a07c
jmp 0x1ac86
subq %rax, %r14
movq %r14, %rsi
callq 0x1a52f
jmp 0x1ac86
movq 0x10(%rsp), %r14
leaq 0x12cce(%rip), %rsi     # 0x2d88b
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 0x1ac99
movq 0x18(%rsp), %rcx
incq %rcx
leaq 0x12c99(%rip), %rdi     # 0x2d890
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x1cd55
xorl %ecx, %ecx
movb $0x1, 0x75c33(%rip)     # 0x90840
jmp 0x1ac88
leaq 0x73adc(%rip), %rax     # 0x8e6f2
cmpb $0x1, (%rax)
jne 0x1ac75
leaq 0x12d9b(%rip), %rdi     # 0x2d9bd
jmp 0x1ac7c
movq (%r12), %rsi
leaq 0x12c87(%rip), %rdi     # 0x2d8b6
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1cd55
movq 0x90(%r12), %rdi
testq %rdi, %rdi
je 0x1ab06
movzbl 0x78(%r12), %esi
leaq 0x20(%rsp), %r8
movq %rbp, %rdx
movq %r13, %rcx
callq 0x1a4ad
testb %al, %al
je 0x1acbd
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq *0x70(%r12)
jmp 0x1ab03
leaq 0x17f42(%rip), %rdi     # 0x32bbe
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1a07c
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 0x1ab0b
cmpl $0x0, 0x68(%r12)
jne 0x1aacc
leaq 0x31(%rsp), %rbx
jmp 0x1ab0b
xorl %ebx, %ebx
jmp 0x1ab06