// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq (%r9), %r9
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
callq 0x1a5ec
testb %al, %al
je 0x1b827
movq (%r14), %rsi
movq 0x20(%rsp), %r12
movsd 0x30(%r14), %xmm0
movq 0x18(%rsp), %r8
leaq 0x1240e(%rip), %rdi     # 0x2da8a
movq %rbx, %rdx
movq %r12, %rcx
movb $0x1, %al
callq 0x1cd55
movq %r12, %r15
negq %r15
cmovsq %r12, %r15
testq %r12, %r12
leaq 0x12420(%rip), %rax     # 0x2dabd
leaq 0x7cfa(%rip), %rbx      # 0x2339e
cmovsq %rax, %rbx
movsd 0x30(%r14), %xmm1
movsd 0x4ce2(%rip), %xmm0     # 0x20398
ucomisd %xmm1, %xmm0
jbe 0x1b6e1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x11fe4(%rip), %xmm0    # 0x2d6b8
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rax, %rcx
jmp 0x1b6ef
cvttsd2si %xmm1, %rax
imulq %rax, %r15
movl $0x1, %ecx
movq %r15, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rbp
movq %rax, %r14
movl %r14d, %eax
movl $0x88888889, %r12d      # imm = 0x88888889
imulq %rax, %r12
shrq $0x25, %r12
imull $0x3c, %r12d, %edx
subl %edx, %r14d
movl $0x91a2b3c5, %r13d      # imm = 0x91A2B3C5
imulq %rax, %r13
shrq $0x2b, %r13
imulq $0x8888889, %r12, %rax  # imm = 0x8888889
shrq $0x21, %rax
imull $0x3c, %eax, %eax
subl %eax, %r12d
movq %rcx, %xmm1
punpckldq 0x11f7f(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x11f87(%rip), %xmm1    # 0x2d6d0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
callq 0xd1b0
cvttsd2si %xmm0, %r9d
leaq 0x72f8c(%rip), %rax     # 0x8e6f2
cmpb $0x1, (%rax)
jne 0x1b7b4
leaq 0x72f82(%rip), %rax     # 0x8e6f4
cmpb $0x1, (%rax)
jne 0x1b791
leaq 0x12341(%rip), %rdi     # 0x2dabf
movq %rbx, %rsi
movq %r15, %rdx
xorl %eax, %eax
movl %r9d, %r15d
callq 0x1a07c
movl %r15d, %r9d
testl %ebp, %ebp
je 0x1b7d7
movl %ebp, (%rsp)
leaq 0x1232e(%rip), %rdi     # 0x2dacd
movq %rbx, %rsi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x1a07c
jmp 0x1b7f1
testl %ebp, %ebp
je 0x1b80d
movl %ebp, (%rsp)
leaq 0x12336(%rip), %rdi     # 0x2daf8
movq %rbx, %rsi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x1a07c
jmp 0x1b827
leaq 0x12307(%rip), %rdi     # 0x2dae5
movq %rbx, %rsi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x1a07c
leaq 0x72efc(%rip), %rax     # 0x8e6f4
cmpb $0x1, (%rax)
jne 0x1b827
leaq 0x121b5(%rip), %rdi     # 0x2d9b9
xorl %eax, %eax
callq 0x1a07c
jmp 0x1b827
leaq 0x122fa(%rip), %rdi     # 0x2db0e
movq %rbx, %rsi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x1a07c
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq