// File: /workspace/github_c_makefile_star2_O1/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, %ebx
movq %rsi, %r14
movq %rdi, %r12
movl 0xb0(%rsp), %r15d
ucomisd %xmm0, %xmm0
jp 0x2c0a6
movapd %xmm0, %xmm4
movsd 0x173f7(%rip), %xmm0    # 0x430b0
ucomisd %xmm4, %xmm0
jbe 0x2bcce
leaq 0x174ce(%rip), %r8      # 0x43194
movl $0x4, %r9d
jmp 0x2bcf9
ucomisd 0x173e2(%rip), %xmm4    # 0x430b8
jbe 0x2bd19
xorl %r9d, %r9d
testb $0x4, %r15b
leaq 0x174b8(%rip), %rax     # 0x4319e
leaq 0x174ac(%rip), %r8      # 0x43199
cmoveq %rax, %r8
setne %r9b
addq $0x3, %r9
movq %r12, %rdi
movq %r14, %rsi
pushq %r15
pushq %rbx
callq 0x2c5b1
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r8d, %r13d
movapd 0x1742c(%rip), %xmm0    # 0x43150
andpd %xmm4, %xmm0
ucomisd 0x17390(%rip), %xmm0    # 0x430c0
jbe 0x2bd55
movq %r12, %rdi
movq %r14, %rsi
movapd %xmm4, %xmm0
movl %r13d, %r8d
movl %ebx, %r9d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c0b8
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, %eax
cmovael %eax, %r13d
cmpl $0xa, %r13d
movq %r14, 0x18(%rsp)
movq %r12, 0x58(%rsp)
movapd %xmm4, 0x20(%rsp)
jb 0x2bdef
movapd %xmm5, 0x60(%rsp)
leal -0xa(%r13), %eax
cmpl $0x1f, %eax
movl $0x1f, %ebp
cmovbl %eax, %ebp
incl %ebp
leaq 0x30(%rsp), %rdi
movl $0x30, %esi
movq %rbp, %rdx
callq 0x20a0
xorl %ecx, %ecx
incq %rcx
cmpq %rcx, %rbp
jne 0x2bdcb
leaq -0x1(%rcx), %rax
cmpq $0x1f, %rax
setb %al
subl %ecx, %r13d
movapd 0x20(%rsp), %xmm4
movapd 0x60(%rsp), %xmm5
jmp 0x2bdf3
movb $0x1, %al
xorl %ebp, %ebp
cvttsd2si %xmm5, %r12d
cvttpd2dq %xmm5, %xmm0
cvtdq2pd %xmm0, %xmm0
movapd %xmm5, %xmm1
subsd %xmm0, %xmm1
movl %r13d, %ecx
leaq 0x1724e(%rip), %rdx     # 0x43060
movsd (%rdx,%rcx,8), %xmm0
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
movq %rcx, %rsi
movapd %xmm1, %xmm2
subsd 0x17299(%rip), %xmm2    # 0x430c8
cvttsd2si %xmm2, %rdx
sarq $0x3f, %rsi
andq %rsi, %rdx
orq %rcx, %rdx
movq %rdx, %xmm2
punpckldq 0x17315(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x1731d(%rip), %xmm2    # 0x43170
movapd %xmm2, %xmm3
unpckhpd %xmm2, %xmm3            # xmm3 = xmm3[1],xmm2[1]
addsd %xmm2, %xmm3
subsd %xmm3, %xmm1
ucomisd 0x17265(%rip), %xmm1    # 0x430d0
jbe 0x2be9e
incq %rdx
movq %rdx, %xmm1
punpckldq 0x172e3(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x172eb(%rip), %xmm1    # 0x43170
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
jb 0x2bec1
incl %r12d
xorl %edx, %edx
jmp 0x2bec1
movsd 0x1722a(%rip), %xmm0    # 0x430d0
ucomisd %xmm1, %xmm0
ja 0x2bec1
testq %rdx, %rdx
sete %cl
movl %edx, %esi
orb %cl, %sil
movzbl %sil, %ecx
andl $0x1, %ecx
addq %rcx, %rdx
testl %r13d, %r13d
je 0x2bf0c
testb %al, %al
je 0x2bf34
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
movq %rdx, %rcx
decl %r13d
movq %rdx, %rax
mulq %rsi
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
movl %ecx, %edi
subl %eax, %edi
orb $0x30, %dil
leaq 0x1(%rbp), %r14
movb %dil, 0x30(%rsp,%rbp)
cmpq $0xa, %rcx
jb 0x2bf37
cmpq $0x1f, %rbp
movq %r14, %rbp
jb 0x2bed4
jmp 0x2bf37
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
subsd %xmm0, %xmm5
movsd 0x171b0(%rip), %xmm0    # 0x430d0
ucomisd %xmm5, %xmm0
setbe %al
movl %r12d, %ecx
andb %al, %cl
movzbl %cl, %eax
addl %eax, %r12d
jmp 0x2bfa1
movq %rbp, %r14
cmpq $0x20, %r14
setae %al
jae 0x2bf91
testl %r13d, %r13d
je 0x2bf91
leaq (%rsp,%r14), %rdi
addq $0x30, %rdi
decl %r13d
movl $0x1f, %edx
subq %r14, %rdx
cmpq %rdx, %r13
cmovbq %r13, %rdx
incq %rdx
movl $0x30, %esi
callq 0x20a0
movapd 0x20(%rsp), %xmm4
movq %r14, %rdx
cmpq $0x1f, %r14
leaq 0x1(%r14), %r14
setae %al
subl $0x1, %r13d
setb %cl
cmpq $0x1e, %rdx
ja 0x2bf91
testb %cl, %cl
je 0x2bf72
testb %al, %al
jne 0x2bf9e
movb $0x2e, 0x30(%rsp,%r14)
incq %r14
movq %r14, %rbp
cmpq $0x1f, %rbp
ja 0x2bfe6
movq %rbp, %rcx
movslq %r12d, %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 0x2bfe6
addl $-0xa, %r12d
cmpl $-0x13, %r12d
movl %eax, %r12d
jb 0x2bfa7
movl %r15d, %eax
andl $0x3, %eax
cmpl $0x1, %eax
jne 0x2c015
testl %ebx, %ebx
movq 0x18(%rsp), %r12
je 0x2c029
xorpd %xmm0, %xmm0
ucomisd %xmm4, %xmm0
seta %al
testb $0xc, %r15b
setne %cl
orb %al, %cl
movzbl %cl, %eax
subl %eax, %ebx
jmp 0x2c02b
movq %rbp, %r14
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %r12
jmp 0x2c067
xorl %ebx, %ebx
cmpl $0x20, %ebx
movl $0x20, %r14d
cmovbl %ebx, %r14d
movq %r14, %rdx
subq %rbp, %rdx
jbe 0x2c05a
leaq (%rsp,%rbp), %rdi
addq $0x30, %rdi
movl $0x30, %esi
callq 0x20a0
movapd 0x20(%rsp), %xmm4
jmp 0x2c05d
movq %rbp, %r14
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdx
cmpq $0x1f, %r14
ja 0x2c091
movb $0x2d, %al
xorpd %xmm0, %xmm0
ucomisd %xmm4, %xmm0
ja 0x2c089
movb $0x2b, %al
testb $0x4, %r15b
jne 0x2c089
movb $0x20, %al
testb $0x8, %r15b
je 0x2c091
movb %al, 0x30(%rsp,%r14)
incq %r14
leaq 0x30(%rsp), %r8
movq 0x58(%rsp), %rdi
movq %r12, %rsi
movq %r14, %r9
jmp 0x2bcff
leaq 0x170e3(%rip), %r8      # 0x43190
movl $0x3, %r9d
jmp 0x2bcf9