// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movl %r9d, %r10d
movq %rdx, %rbx
movl 0x60(%rsp), %r15d
ucomisd %xmm0, %xmm0
jp 0x29f8b
movsd 0x154a0(%rip), %xmm1    # 0x3f140
ucomisd %xmm0, %xmm1
jbe 0x29cb6
leaq 0x15577(%rip), %r8      # 0x3f224
pushq $0x4
popq %r9
jmp 0x29f70
ucomisd 0x1548a(%rip), %xmm0    # 0x3f148
jbe 0x29ce6
xorl %r9d, %r9d
testb $0x4, %r15b
leaq 0x15560(%rip), %rax     # 0x3f22e
leaq 0x15554(%rip), %r8      # 0x3f229
cmoveq %rax, %r8
setne %r9b
addq $0x3, %r9
jmp 0x29f70
movapd 0x154f2(%rip), %xmm1    # 0x3f1e0
andpd %xmm0, %xmm1
ucomisd 0x15456(%rip), %xmm1    # 0x3f150
jbe 0x29d15
movq %rbx, %rdx
movl %r10d, %r9d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x29f99
xorpd %xmm2, %xmm2
subsd %xmm0, %xmm2
btl $0xa, %r15d
pushq $0x6
popq %rax
cmovael %eax, %r8d
leaq 0x153c0(%rip), %rax     # 0x3f0f0
leaq (%rax,%r8,8), %rdx
xorl %r9d, %r9d
movl %r8d, %eax
cmpq $0x1f, %r9
ja 0x29d55
cmpl $0xa, %eax
jb 0x29d55
movb $0x30, (%rsp,%r9)
incq %r9
decl %eax
addq $-0x8, %rdx
jmp 0x29d3a
xorpd %xmm3, %xmm3
movapd %xmm0, %xmm1
cmpltsd %xmm3, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
cvttsd2si %xmm1, %r11d
cvttpd2dq %xmm1, %xmm2
cvtdq2pd %xmm2, %xmm2
movapd %xmm1, %xmm3
subsd %xmm2, %xmm3
movsd (%rdx), %xmm2
mulsd %xmm2, %xmm3
cvttsd2si %xmm3, %rdx
movq %rdx, %r12
movapd %xmm3, %xmm4
subsd 0x153b9(%rip), %xmm4    # 0x3f158
cvttsd2si %xmm4, %r14
sarq $0x3f, %r12
andq %r12, %r14
orq %rdx, %r14
movq %r14, %xmm4
punpckldq 0x15435(%rip), %xmm4 # xmm4 = xmm4[0],mem[0],xmm4[1],mem[1]
subpd 0x1543d(%rip), %xmm4    # 0x3f200
movapd %xmm4, %xmm5
unpckhpd %xmm4, %xmm5            # xmm5 = xmm5[1],xmm4[1]
addsd %xmm4, %xmm5
subsd %xmm5, %xmm3
ucomisd 0x15385(%rip), %xmm3    # 0x3f160
jbe 0x29e0f
incq %r14
movq %r14, %xmm3
punpckldq 0x15403(%rip), %xmm3 # xmm3 = xmm3[0],mem[0],xmm3[1],mem[1]
subpd 0x1540b(%rip), %xmm3    # 0x3f200
movapd %xmm3, %xmm4
unpckhpd %xmm3, %xmm4            # xmm4 = xmm4[1],xmm3[1]
addsd %xmm3, %xmm4
ucomisd %xmm2, %xmm4
jb 0x29e33
incl %r11d
xorl %r14d, %r14d
jmp 0x29e33
movsd 0x15349(%rip), %xmm2    # 0x3f160
ucomisd %xmm3, %xmm2
ja 0x29e33
testq %r14, %r14
sete %dl
movl %r14d, %ebp
orb %dl, %bpl
movzbl %bpl, %edx
andl $0x1, %edx
addq %rdx, %r14
testl %eax, %eax
je 0x29e6d
cmpq $0x1f, %r9
ja 0x29e92
pushq $0xa
popq %r12
movq %r14, %rax
xorl %edx, %edx
divq %r12
movq %r9, %r13
orb $0x30, %dl
movb %dl, (%rsp,%r9)
incq %r9
cmpq $0x1e, %r13
ja 0x29e65
cmpq $0x9, %r14
movq %rax, %r14
ja 0x29e41
subl %r9d, %r8d
movl %r8d, %eax
jmp 0x29ea4
cvtsi2sd %r11d, %xmm2
subsd %xmm2, %xmm1
movsd 0x152e2(%rip), %xmm2    # 0x3f160
ucomisd %xmm1, %xmm2
setbe %al
movl %r11d, %edx
andb %al, %dl
movzbl %dl, %eax
addl %eax, %r11d
jmp 0x29ebe
pushq $0x20
popq %r9
jmp 0x29ea4
testb %dl, %dl
jne 0x29eb0
movb $0x30, (%rsp,%r9)
incq %r9
subl $0x1, %eax
setb %dl
cmpq $0x1f, %r9
jbe 0x29e98
cmpq $0x1f, %r9
ja 0x29ef1
movb $0x2e, (%rsp,%r9)
incq %r9
cmpq $0x1f, %r9
ja 0x29ef1
pushq $0xa
popq %r8
movl %r11d, %eax
cltd
idivl %r8d
movq %r9, %r14
addb $0x30, %dl
movb %dl, (%rsp,%r9)
incq %r9
cmpq $0x1e, %r14
ja 0x29ef5
addl $-0xa, %r11d
cmpl $-0x13, %r11d
movl %eax, %r11d
jb 0x29ec8
jmp 0x29ef5
pushq $0x20
popq %r9
movl %r15d, %eax
andl $0x3, %eax
cmpl $0x1, %eax
jne 0x29f3e
testl %r10d, %r10d
je 0x29f21
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
testb $0xc, %r15b
setne %dl
orb %al, %dl
movzbl %dl, %eax
subl %eax, %r10d
jmp 0x29f24
xorl %r10d, %r10d
cmpl $0x20, %r10d
pushq $0x20
popq %rax
cmovbl %r10d, %eax
cmpq %rax, %r9
jae 0x29f3e
movb $0x30, (%rsp,%r9)
incq %r9
jmp 0x29f2f
cmpq $0x1f, %r9
ja 0x29f69
movb $0x2d, %al
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x29f60
movb $0x2b, %al
testb $0x4, %r15b
jne 0x29f60
movb $0x20, %al
testb $0x8, %r15b
je 0x29f6d
movb %al, (%rsp,%r9)
incq %r9
jmp 0x29f6d
pushq $0x20
popq %r9
movq %rsp, %r8
movq %rbx, %rdx
pushq %r15
pushq %r10
callq 0x2a408
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1528e(%rip), %r8      # 0x3f220
pushq $0x3
jmp 0x29caf