// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_misc/lv_printf.c
// Function: ftoa
static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags)
{
  char buf[PRINTF_FTOA_BUFFER_SIZE];
  size_t len  = 0U;
  double diff = 0.0;

  // powers of 10
  static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };

  // test for special values
  if (value != value)
    return _out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags);
  if (value < -DBL_MAX)
    return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags);
  if (value > DBL_MAX)
    return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", (flags & FLAGS_PLUS) ? 4U : 3U, width, flags);

  // test for very large values
  // standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad
  if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) {
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
    return _etoa(out, buffer, idx, maxlen, value, prec, width, flags);
#else
    return 0U;
#endif
  }

  // test for negative
  bool negative = false;
  if (value < 0) {
    negative = true;
    value = 0 - value;
  }

  // set default precision, if not set explicitly
  if (!(flags & FLAGS_PRECISION)) {
    prec = PRINTF_DEFAULT_FLOAT_PRECISION;
  }
  // limit precision to 9, cause a prec >= 10 can lead to overflow errors
  while ((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) {
    buf[len++] = '0';
    prec--;
  }

  int whole = (int)value;
  double tmp = (value - whole) * pow10[prec];
  unsigned long frac = (unsigned long)tmp;
  diff = tmp - frac;

  if (diff > 0.5) {
    ++frac;
    // handle rollover, e.g. case 0.99 with prec 1 is 1.0
    if (frac >= pow10[prec]) {
      frac = 0;
      ++whole;
    }
  }
  else if (diff < 0.5) {
  }
  else if ((frac == 0U) || (frac & 1U)) {
    // if halfway, round up if odd OR if last digit is 0
    ++frac;
  }

  if (prec == 0U) {
    diff = value - (double)whole;
    if ((!(diff < 0.5) || (diff > 0.5)) && (whole & 1)) {
      // exactly 0.5 and ODD, then round up
      // 1.5 -> 2, but 2.5 -> 2
      ++whole;
    }
  }
  else {
    unsigned int count = prec;
    // now do fractional part, as an unsigned number
    while (len < PRINTF_FTOA_BUFFER_SIZE) {
      --count;
      buf[len++] = (char)(48U + (frac % 10U));
      if (!(frac /= 10U)) {
        break;
      }
    }
    // add extra 0s
    while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) {
      buf[len++] = '0';
    }
    if (len < PRINTF_FTOA_BUFFER_SIZE) {
      // add decimal
      buf[len++] = '.';
    }
  }

  // do whole part, number is reversed
  while (len < PRINTF_FTOA_BUFFER_SIZE) {
    buf[len++] = (char)(48 + (whole % 10));
    if (!(whole /= 10)) {
      break;
    }
  }

  // pad leading zeros
  if (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) {
    if (width && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
      width--;
    }
    while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
      buf[len++] = '0';
    }
  }

  if (len < PRINTF_FTOA_BUFFER_SIZE) {
    if (negative) {
      buf[len++] = '-';
    }
    else if (flags & FLAGS_PLUS) {
      buf[len++] = '+';  // ignore the space if the '+' exists
    }
    else if (flags & FLAGS_SPACE) {
      buf[len++] = ' ';
    }
  }

  return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, %r12d
movl 0xb0(%rsp), %r15d
ucomisd %xmm0, %xmm0
jp 0x2c80c
movapd %xmm0, %xmm4
movsd 0x16e61(%rip), %xmm0    # 0x43250
ucomisd %xmm4, %xmm0
jbe 0x2c407
leaq 0x16f38(%rip), %r8      # 0x43334
movl $0x4, %r9d
jmp 0x2c7f1
ucomisd 0x16e49(%rip), %xmm4    # 0x43258
jbe 0x2c437
xorl %r9d, %r9d
testb $0x4, %r15b
leaq 0x16f1f(%rip), %rax     # 0x4333e
leaq 0x16f13(%rip), %r8      # 0x43339
cmoveq %rax, %r8
setne %r9b
addq $0x3, %r9
jmp 0x2c7f1
movl %r8d, %r14d
movapd 0x16eae(%rip), %xmm0    # 0x432f0
andpd %xmm4, %xmm0
ucomisd 0x16e12(%rip), %xmm0    # 0x43260
jbe 0x2c46d
movapd %xmm4, %xmm0
movl %r14d, %r8d
movl %r12d, %r9d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c81b
movq %rdi, 0x50(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm4, %xmm5
cmpltsd %xmm0, %xmm5
subsd %xmm4, %xmm0
andpd %xmm5, %xmm0
andnpd %xmm4, %xmm5
orpd %xmm0, %xmm5
btl $0xa, %r15d
movl $0x6, %esi
cmovbl %r14d, %esi
cmpl $0xa, %esi
movq %r12, 0x18(%rsp)
movapd %xmm4, 0x20(%rsp)
jb 0x2c50d
movapd %xmm5, 0x60(%rsp)
addl $-0xa, %esi
cmpl $0x1f, %esi
movl $0x1f, %ebx
cmovbl %esi, %ebx
incl %ebx
leaq 0x30(%rsp), %rdi
movl $0x30, %esi
movq %rbx, %rdx
callq 0x20a0
xorl %ecx, %ecx
incq %rcx
cmpq %rcx, %rbx
jne 0x2c4e6
leaq -0x1(%rcx), %rax
cmpq $0x1f, %rax
setb %al
subl %ecx, %r14d
movl %r14d, %esi
movapd 0x20(%rsp), %xmm4
movapd 0x60(%rsp), %xmm5
jmp 0x2c511
movb $0x1, %al
xorl %ebx, %ebx
cvttsd2si %xmm5, %r14d
cvttpd2dq %xmm5, %xmm0
cvtdq2pd %xmm0, %xmm0
movapd %xmm5, %xmm1
subsd %xmm0, %xmm1
movl %esi, %r12d
leaq 0x16cd0(%rip), %rcx     # 0x43200
movsd (%rcx,%r12,8), %xmm0
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rdx
movq %rdx, %rdi
movapd %xmm1, %xmm2
subsd 0x16d1a(%rip), %xmm2    # 0x43268
cvttsd2si %xmm2, %rcx
sarq $0x3f, %rdi
andq %rdi, %rcx
orq %rdx, %rcx
movq %rcx, %xmm2
punpckldq 0x16d96(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x16d9e(%rip), %xmm2    # 0x43310
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
subsd %xmm3, %xmm1
ucomisd 0x16ce6(%rip), %xmm1    # 0x43270
jbe 0x2c5bd
incq %rcx
movq %rcx, %xmm1
punpckldq 0x16d64(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x16d6c(%rip), %xmm1    # 0x43310
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jb 0x2c5e0
incl %r14d
xorl %ecx, %ecx
jmp 0x2c5e0
movsd 0x16cab(%rip), %xmm0    # 0x43270
ucomisd %xmm1, %xmm0
ja 0x2c5e0
testq %rcx, %rcx
sete %dl
movl %ecx, %edi
orb %dl, %dil
movzbl %dil, %edx
andl $0x1, %edx
addq %rdx, %rcx
testl %esi, %esi
je 0x2c6c6
movl $0x20, %ebp
testb %al, %al
je 0x2c740
leaq (%rsp,%rbx), %rdi
addq $0x30, %rdi
xorl %r8d, %r8d
movabsq $-0x3333333333333333, %r9 # imm = 0xCCCCCCCCCCCCCCCD
leaq (%rbx,%r8), %r10
movq %rcx, %rax
mulq %r9
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
movl %ecx, %r11d
subl %eax, %r11d
orb $0x30, %r11b
movb %r11b, (%rdi,%r8)
incq %r8
cmpq $0x1e, %r10
ja 0x2c63e
cmpq $0x9, %rcx
movq %rdx, %rcx
ja 0x2c60a
leaq (%rbx,%r8), %r13
leaq (%rbx,%r8), %rax
decq %rax
cmpq $0x1f, %rax
setae %al
jae 0x2c6ab
cmpl %r8d, %esi
je 0x2c6ab
subq %r8, %r12
addq %r8, %rbx
leaq (%rsp,%rbx), %rdi
addq $0x30, %rdi
notl %r8d
addl %esi, %r8d
movl $0x1f, %edx
subq %rbx, %rdx
cmpq %rdx, %r8
cmovbq %r8, %rdx
incq %rdx
movl $0x30, %esi
callq 0x20a0
movapd 0x20(%rsp), %xmm4
movl $0x1, %ecx
movq %r13, %rax
incq %r13
cmpq $0x1f, %rax
setae %al
jae 0x2c6ab
leal 0x1(%rcx), %edx
cmpl %ecx, %r12d
movl %edx, %ecx
jne 0x2c692
testb %al, %al
movq 0x18(%rsp), %r12
jne 0x2c745
movb $0x2e, 0x30(%rsp,%r13)
incq %r13
movq %r13, %rbx
jmp 0x2c6f1
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
subsd %xmm0, %xmm5
movsd 0x16b96(%rip), %xmm0    # 0x43270
ucomisd %xmm5, %xmm0
setbe %al
movl %r14d, %ecx
andb %al, %cl
movzbl %cl, %eax
addl %eax, %r14d
movq 0x18(%rsp), %r12
movl $0x20, %ebp
cmpq $0x1f, %rbx
ja 0x2c745
movq %rbx, %rbp
movq %rbp, %rcx
movslq %r14d, %rdx
imulq $0x66666667, %rdx, %rax # imm = 0x66666667
movq %rax, %rsi
shrq $0x3f, %rsi
sarq $0x22, %rax
addl %esi, %eax
leal (%rax,%rax), %esi
leal (%rsi,%rsi,4), %esi
subl %esi, %edx
addb $0x30, %dl
movb %dl, 0x30(%rsp,%rbp)
incq %rbp
cmpq $0x1e, %rcx
ja 0x2c745
addl $-0xa, %r14d
cmpl $-0x13, %r14d
movl %eax, %r14d
jb 0x2c6ff
jmp 0x2c745
movq 0x18(%rsp), %r12
movl %r15d, %eax
andl $0x3, %eax
cmpl $0x1, %eax
jne 0x2c7a3
testl %r12d, %r12d
je 0x2c771
xorpd %xmm0, %xmm0
ucomisd %xmm4, %xmm0
seta %al
testb $0xc, %r15b
setne %cl
orb %al, %cl
movzbl %cl, %eax
subl %eax, %r12d
jmp 0x2c774
xorl %r12d, %r12d
cmpl $0x20, %r12d
movl $0x20, %ebx
cmovbl %r12d, %ebx
movq %rbx, %rdx
subq %rbp, %rdx
jbe 0x2c7a3
leaq (%rsp,%rbp), %rdi
addq $0x30, %rdi
movl $0x30, %esi
callq 0x20a0
movapd 0x20(%rsp), %xmm4
jmp 0x2c7a6
movq %rbp, %rbx
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdx
movl $0x20, %r9d
cmpq $0x1f, %rbx
ja 0x2c7e2
movb $0x2d, %al
xorpd %xmm0, %xmm0
ucomisd %xmm4, %xmm0
ja 0x2c7d8
movb $0x2b, %al
testb $0x4, %r15b
jne 0x2c7d8
movb $0x20, %al
testb $0x8, %r15b
je 0x2c7df
movb %al, 0x30(%rsp,%rbx)
incq %rbx
movq %rbx, %r9
leaq 0x30(%rsp), %r8
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
pushq %r15
pushq %r12
callq 0x2cd0f
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16b1d(%rip), %r8      # 0x43330
movl $0x3, %r9d
jmp 0x2c7f1