// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rdi, %rbx
movq (%r9), %r9
leaq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, (%rsp)
callq 0x22c61
testb %al, %al
je 0x23eda
movq (%rbx), %rsi
movq 0x18(%rsp), %r15
movsd 0x30(%rbx), %xmm0
movq 0x20(%rsp), %r8
leaq 0x17006(%rip), %rdi     # 0x3ad1a
movq %r14, %rdx
movq %r15, %rcx
movb $0x1, %al
callq 0x254dd
testq %r15, %r15
js 0x23d2f
leaq 0x7671(%rip), %rax      # 0x2b39e
jmp 0x23d3e
negq %r15
movq %r15, 0x18(%rsp)
leaq 0x1700f(%rip), %rax     # 0x3ad4d
movq %rax, 0x10(%rsp)
movsd 0x30(%rbx), %xmm1
movsd 0x4648(%rip), %xmm0     # 0x28398
ucomisd %xmm1, %xmm0
jbe 0x23d7b
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x16bd2(%rip), %xmm0    # 0x3a940
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rax, %rcx
jmp 0x23d90
cvttsd2si %xmm1, %rax
imulq 0x18(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x1, %ecx
movq 0x18(%rsp), %rbp
movq %rbp, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %r13
movq %rax, %r14
movl %r14d, %eax
movl $0x88888889, %r15d      # imm = 0x88888889
imulq %rax, %r15
shrq $0x25, %r15
imull $0x3c, %r15d, %edx
subl %edx, %r14d
movl $0x91a2b3c5, %r12d      # imm = 0x91A2B3C5
imulq %rax, %r12
shrq $0x2b, %r12
imulq $0x8888889, %r15, %rax  # imm = 0x8888889
shrq $0x21, %rax
imull $0x3c, %eax, %eax
subl %eax, %r15d
movq %rcx, %xmm1
punpckldq 0x16b69(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x16b71(%rip), %xmm1    # 0x3a960
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
callq 0xd1b0
cvttsd2si %xmm0, %ebx
leaq 0x778e7(%rip), %rax     # 0x9b6f2
cmpb $0x1, (%rax)
jne 0x23e5c
leaq 0x778dd(%rip), %rax     # 0x9b6f4
cmpb $0x1, (%rax)
jne 0x23e32
leaq 0x16f2c(%rip), %rdi     # 0x3ad4f
movq 0x10(%rsp), %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x226ec
testl %r13d, %r13d
je 0x23e86
movl %r13d, (%rsp)
leaq 0x16f1b(%rip), %rdi     # 0x3ad5d
movq 0x10(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
movl %ebx, %r9d
xorl %eax, %eax
callq 0x226ec
jmp 0x23ea2
testl %r13d, %r13d
je 0x23ebe
movl %r13d, (%rsp)
leaq 0x16f1c(%rip), %rdi     # 0x3ad88
movq 0x10(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
movl %ebx, %r9d
xorl %eax, %eax
callq 0x226ec
jmp 0x23eda
leaq 0x16ee8(%rip), %rdi     # 0x3ad75
movq 0x10(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x226ec
leaq 0x7784b(%rip), %rax     # 0x9b6f4
cmpb $0x1, (%rax)
jne 0x23eda
leaq 0x16d94(%rip), %rdi     # 0x3ac49
xorl %eax, %eax
callq 0x226ec
jmp 0x23eda
leaq 0x16ed9(%rip), %rdi     # 0x3ad9e
movq 0x10(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x226ec
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq