// File: /workspace/github_c_makefile_star2_O1/canboat[P]canboat/analyzer/print.c
// Function: fieldPrintNumber
extern bool fieldPrintNumber(const Field   *field,
                             const char    *fieldName,
                             const uint8_t *data,
                             size_t         dataLen,
                             size_t         startBit,
                             size_t        *bits)
{
  int64_t value;
  int64_t maxValue;
  double  a;

  const char *unit       = field->unit;
  double      resolution = field->resolution;

  if (resolution == 0.0)
  {
    resolution = 1.0;
  }

  if (!extractNumberNotEmpty(field, fieldName, data, dataLen, startBit, *bits, &value, &maxValue))
  {
    return true;
  }

  logDebug("fieldPrintNumber <%s> value=%" PRIx64 " max=%" PRIx64 " resolution=%g offset=%g unit='%s'\n",
           fieldName,
           value,
           maxValue,
           resolution,
           field->unitOffset,
           (field->unit ? field->unit : "None"));
  if (resolution == 1.0 && field->unitOffset == 0.0)
  {
    logDebug("fieldPrintNumber <%s> print as integer %" PRId64 "\n", fieldName, value);
    mprintf("%" PRId64, value);
    if (!showJson && unit != NULL)
    {
      mprintf(" %s", unit);
    }
  }
  else
  {
    int    precision;
    double r;

    a = (double) value * field->resolution + field->unitOffset;

    precision = field->precision;
    if (precision == 0)
    {
      for (r = field->resolution; (r > 0.0) && (r < 1.0); r *= 10.0)
      {
        precision++;
      }
    }

    if (showJson)
    {
      mprintf("%.*f", precision, a);
    }
    else if (unit != NULL && strcmp(unit, "m") == 0 && a >= 1000.0)
    {
      mprintf("%.*f km", precision + 3, a / 1000);
    }
    else
    {
      mprintf("%.*f", precision, a);
      if (unit != NULL)
      {
        mprintf(" %s", unit);
      }
    }
  }

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq 0x18(%rdi), %rbx
movsd 0x30(%rdi), %xmm0
movapd %xmm0, (%rsp)
movq (%r9), %r9
leaq 0x10(%rsp), %rax
leaq 0x18(%rsp), %r10
pushq %rax
pushq %r10
callq 0x22c61
addq $0x10, %rsp
testb %al, %al
je 0x22f37
xorpd %xmm0, %xmm0
movapd (%rsp), %xmm2
movapd %xmm2, %xmm1
cmpeqsd %xmm0, %xmm1
movsd 0x55f0(%rip), %xmm3     # 0x28398
movapd %xmm1, %xmm0
andpd %xmm3, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
movapd %xmm1, %xmm0
movapd %xmm1, (%rsp)
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rcx
movsd 0x40(%r14), %xmm1
movq 0x18(%r14), %rax
testq %rax, %rax
leaq 0x147f1(%rip), %r8      # 0x375d0
cmovneq %rax, %r8
leaq 0x17c72(%rip), %rdi     # 0x3aa5c
movq %r15, %rsi
movq %r12, %rdx
movb $0x2, %al
callq 0x254dd
movsd 0x5599(%rip), %xmm4     # 0x28398
movapd (%rsp), %xmm0
ucomisd %xmm4, %xmm0
jne 0x22e5d
jp 0x22e5d
movsd 0x40(%r14), %xmm0
ucomisd 0x5586(%rip), %xmm0     # 0x283a0
jne 0x22e5d
jp 0x22e5d
leaq 0x17c82(%rip), %rdi     # 0x3aaa7
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x254dd
leaq 0x17c18(%rip), %rdi     # 0x3aa51
movq %r12, %rsi
xorl %eax, %eax
callq 0x226ec
leaq 0x788a8(%rip), %rax     # 0x9b6f2
testq %rbx, %rbx
sete %cl
orb (%rax), %cl
je 0x22f26
jmp 0x22f37
xorps %xmm0, %xmm0
cvtsi2sd %r12, %xmm0
movsd 0x30(%r14), %xmm3
mulsd %xmm3, %xmm0
movl 0x38(%r14), %ebp
testl %ebp, %ebp
je 0x22edb
addsd 0x40(%r14), %xmm0
leaq 0x7886e(%rip), %rax     # 0x9b6f2
cmpb $0x1, (%rax)
je 0x22ec9
testq %rbx, %rbx
je 0x22ec9
leaq 0x195c9(%rip), %rsi     # 0x3c45e
movq %rbx, %rdi
movsd %xmm0, (%rsp)
callq 0xd1a0
movsd (%rsp), %xmm0
testl %eax, %eax
jne 0x22f16
ucomisd 0x17a65(%rip), %xmm0    # 0x3a918
jb 0x22f16
addl $0x3, %ebp
divsd 0x17a58(%rip), %xmm0    # 0x3a918
leaq 0x17c11(%rip), %rdi     # 0x3aad8
jmp 0x22ed0
leaq 0x17c03(%rip), %rdi     # 0x3aad3
movl %ebp, %esi
movb $0x1, %al
callq 0x226ec
jmp 0x22f37
xorl %ebp, %ebp
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm3
jbe 0x22e77
ucomisd %xmm3, %xmm4
jbe 0x22e77
xorl %ebp, %ebp
movsd 0x17a19(%rip), %xmm1    # 0x3a910
xorpd %xmm2, %xmm2
incl %ebp
mulsd %xmm1, %xmm3
ucomisd %xmm2, %xmm3
jbe 0x22e77
ucomisd %xmm3, %xmm4
ja 0x22efb
jmp 0x22e77
leaq 0x17bb6(%rip), %rdi     # 0x3aad3
movl %ebp, %esi
movb $0x1, %al
callq 0x226ec
leaq 0x1cef3(%rip), %rdi     # 0x3fe20
movq %rbx, %rsi
xorl %eax, %eax
callq 0x226ec
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq