// File: /workspace/github_c_makefile_star2_O2/canboat[P]canboat/analyzer/print.c
// Function: fieldPrintTime
extern bool fieldPrintTime(const Field   *field,
                           const char    *fieldName,
                           const uint8_t *data,
                           size_t         dataLen,
                           size_t         startBit,
                           size_t        *bits)
{
  uint64_t unitspersecond;
  uint32_t hours;
  uint32_t minutes;
  uint32_t seconds;
  uint32_t fraction;
  int64_t  value;
  int64_t  maxValue;
  uint64_t t;
  int      digits;

  const char *sign = "";

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

  logDebug("fieldPrintTime(<%s>, \"%s\") v=%" PRId64 " res=%g max=0x%" PRIx64 "\n",
           field->name,
           fieldName,
           value,
           field->resolution,
           maxValue);

  if (value < 0)
  {
    value = -value;
    sign  = "-";
  }

  if (field->resolution < 1.0)
  {
    unitspersecond = (uint64_t) (1.0 / field->resolution);
  }
  else
  {
    unitspersecond = 1;
    value *= (int64_t) field->resolution;
  }

  t        = (uint64_t) value;
  seconds  = t / unitspersecond;
  fraction = t % unitspersecond;
  minutes  = seconds / 60;
  seconds  = seconds % 60;
  hours    = minutes / 60;
  minutes  = minutes % 60;

  digits = log10(unitspersecond);

  if (showJson)
  {
    if (showJsonValue)
    {
      mprintf("%s%" PRId64 ",\"name\":", sign, value);
    }
    if (fraction != 0)
    {
      mprintf("\"%s%02u:%02u:%02u.%0*u\"", sign, hours, minutes, seconds, digits, fraction);
    }
    else
    {
      mprintf("\"%s%02u:%02u:%02u\"", sign, hours, minutes, seconds);
    }
    if (showJsonValue)
    {
      mprintf("}");
    }
  }
  else
  {
    if (fraction)
    {
      mprintf("%s%02u:%02u:%02u.%0*u", sign, hours, minutes, seconds, digits, fraction);
    }
    else
    {
      mprintf("%s%02u:%02u:%02u", sign, hours, minutes, seconds);
    }
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r15
movq (%r9), %r9
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
callq 0x196cf
testb %al, %al
je 0x1a8b6
movq (%r15), %rsi
movq 0x20(%rsp), %r12
movsd 0x30(%r15), %xmm0
movq 0x18(%rsp), %r8
leaq 0x1237a(%rip), %rdi     # 0x2ca8a
movq %rbx, %rdx
movq %r12, %rcx
movb $0x1, %al
callq 0x1bd48
movq %r12, %r14
negq %r14
cmovsq %r12, %r14
testq %r12, %r12
leaq 0x1238c(%rip), %rax     # 0x2cabd
leaq 0x7c66(%rip), %rbx      # 0x2239e
cmovsq %rax, %rbx
movsd 0x30(%r15), %xmm1
movsd 0x4c4e(%rip), %xmm0     # 0x1f398
ucomisd %xmm1, %xmm0
jbe 0x1a775
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x11f50(%rip), %xmm0    # 0x2c6b8
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
jmp 0x1a781
cvttsd2si %xmm1, %rax
imulq %rax, %r14
pushq $0x1
popq %rdi
movq %r14, %rax
xorl %edx, %edx
divq %rdi
movq %rax, %rcx
movq %rdx, %r13
pushq $0x3c
popq %r8
xorl %edx, %edx
divl %r8d
movl %eax, %esi
movl %edx, 0x14(%rsp)
movl $0xe10, %r9d            # imm = 0xE10
movl %ecx, %eax
xorl %edx, %edx
divl %r9d
movl %eax, %r15d
movl %esi, %eax
xorl %edx, %edx
divl %r8d
movl %edx, %r12d
movq %rdi, %xmm1
punpckldq 0x11efb(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x11f03(%rip), %xmm1    # 0x2c6d0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
callq 0xd1b0
cvttsd2si %xmm0, %ebp
leaq 0x74f09(%rip), %rax     # 0x8f6f2
cmpb $0x1, (%rax)
jne 0x1a838
leaq 0x74eff(%rip), %rax     # 0x8f6f4
cmpb $0x1, (%rax)
jne 0x1a80e
leaq 0x122be(%rip), %rdi     # 0x2cabf
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x19194
testl %r13d, %r13d
je 0x1a862
movl %r13d, (%rsp)
leaq 0x122af(%rip), %rdi     # 0x2cacd
movq %rbx, %rsi
movl %r15d, %edx
movl %r12d, %ecx
movl 0x14(%rsp), %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x19194
jmp 0x1a87e
testl %r13d, %r13d
je 0x1a89a
movl %r13d, (%rsp)
leaq 0x122b0(%rip), %rdi     # 0x2caf8
movq %rbx, %rsi
movl %r15d, %edx
movl %r12d, %ecx
movl 0x14(%rsp), %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x19194
jmp 0x1a8b6
leaq 0x1227c(%rip), %rdi     # 0x2cae5
movq %rbx, %rsi
movl %r15d, %edx
movl %r12d, %ecx
movl 0x14(%rsp), %r8d
xorl %eax, %eax
callq 0x19194
leaq 0x74e6f(%rip), %rax     # 0x8f6f4
cmpb $0x1, (%rax)
jne 0x1a8b6
leaq 0x12128(%rip), %rdi     # 0x2c9b9
xorl %eax, %eax
callq 0x19194
jmp 0x1a8b6
leaq 0x1226d(%rip), %rdi     # 0x2cb0e
movq %rbx, %rsi
movl %r15d, %edx
movl %r12d, %ecx
movl 0x14(%rsp), %r8d
xorl %eax, %eax
callq 0x19194
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq