// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_misc/lv_printf.c
// Function: etoa
static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags)
{
  // check for NaN and special values
  if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) {
    return _ftoa(out, buffer, idx, maxlen, value, prec, width, flags);
  }

  // determine the sign
  const bool negative = value < 0;
  if (negative) {
    value = -value;
  }

  // default precision
  if (!(flags & FLAGS_PRECISION)) {
    prec = PRINTF_DEFAULT_FLOAT_PRECISION;
  }

  // determine the decimal exponent
  // based on the algorithm by David Gay (https://www.ampl.com/netlib/fp/dtoa.c)
  union {
    uint64_t U;
    double   F;
  } conv;

  conv.F = value;
  int exp2 = (int)((conv.U >> 52U) & 0x07FFU) - 1023;           // effectively log2
  conv.U = (conv.U & ((1ULL << 52U) - 1U)) | (1023ULL << 52U);  // drop the exponent so conv.F is now in [1,2)
  // now approximate log10 from the log2 integer part and an expansion of ln around 1.5
  int expval = (int)(0.1760912590558 + exp2 * 0.301029995663981 + (conv.F - 1.5) * 0.289529654602168);
  // now we want to compute 10^expval but we want to be sure it won't overflow
  exp2 = (int)(expval * 3.321928094887362 + 0.5);
  const double z  = expval * 2.302585092994046 - exp2 * 0.6931471805599453;
  const double z2 = z * z;
  conv.U = (uint64_t)(exp2 + 1023) << 52U;
  // compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex
  conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14)))));
  // correct for rounding errors
  if (value < conv.F) {
    expval--;
    conv.F /= 10;
  }

  // the exponent format is "%+03d" and largest value is "307", so set aside 4-5 characters
  unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U;

  // in "%g" mode, "prec" is the number of *significant figures* not decimals
  if (flags & FLAGS_ADAPT_EXP) {
    // do we want to fall-back to "%f" mode?
    if ((value >= 1e-4) && (value < 1e6)) {
      if ((int)prec > expval) {
        prec = (unsigned)((int)prec - expval - 1);
      }
      else {
        prec = 0;
      }
      flags |= FLAGS_PRECISION;   // make sure _ftoa respects precision
      // no characters in exponent
      minwidth = 0U;
      expval   = 0;
    }
    else {
      // we use one sigfig for the whole part
      if ((prec > 0) && (flags & FLAGS_PRECISION)) {
        --prec;
      }
    }
  }

  // will everything fit?
  unsigned int fwidth = width;
  if (width > minwidth) {
    // we didn't fall-back so subtract the characters required for the exponent
    fwidth -= minwidth;
  } else {
    // not enough characters, so go back to default sizing
    fwidth = 0U;
  }
  if ((flags & FLAGS_LEFT) && minwidth) {
    // if we're padding on the right, DON'T pad the floating part
    fwidth = 0U;
  }

  // rescale the float value
  if (expval) {
    value /= conv.F;
  }

  // output the floating part
  const size_t start_idx = idx;
  idx = _ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~FLAGS_ADAPT_EXP);

  // output the exponent part
  if (minwidth) {
    // output the exponential symbol
    out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen);
    // output the exponent value
    idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS);
    // might need to right-pad spaces
    if (flags & FLAGS_LEFT) {
      while (idx - start_idx < width) out(' ', buffer, idx++, maxlen);
    }
  }
  return idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %r10d
movl %r8d, %eax
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %rbp
movsd 0x16a10(%rip), %xmm1    # 0x43250
ucomisd %xmm0, %xmm1
ja 0x2c9e9
ucomisd %xmm0, %xmm0
jp 0x2c9e9
ucomisd 0x169fc(%rip), %xmm0    # 0x43258
ja 0x2c9e9
movl 0x50(%rsp), %r12d
movapd 0x16ab1(%rip), %xmm1    # 0x43320
xorpd %xmm0, %xmm1
maxsd %xmm0, %xmm1
btl $0xa, %r12d
movl $0x6, %r8d
cmovbl %eax, %r8d
movq %xmm1, %rcx
movabsq $0xfffffffffffff, %rdx  # imm = 0xFFFFFFFFFFFFF
andq %rcx, %rdx
shrq $0x34, %rcx
andl $0x7ff, %ecx            # imm = 0x7FF
addl $0xfffffc01, %ecx       # imm = 0xFFFFFC01
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
cvtsi2sd %ecx, %xmm2
mulsd 0x169ba(%rip), %xmm2    # 0x43278
orq %rdx, %rsi
addsd 0x169b7(%rip), %xmm2    # 0x43280
movq %rsi, %xmm3
addsd 0x169b2(%rip), %xmm3    # 0x43288
mulsd 0x169b2(%rip), %xmm3    # 0x43290
addsd %xmm2, %xmm3
cvttsd2si %xmm3, %esi
cvttpd2dq %xmm3, %xmm2
cvtdq2pd %xmm2, %xmm3
movsd 0x169a2(%rip), %xmm2    # 0x43298
mulsd %xmm3, %xmm2
addsd 0x1696e(%rip), %xmm2    # 0x43270
cvttsd2si %xmm2, %ecx
cvttpd2dq %xmm2, %xmm2
cvtdq2pd %xmm2, %xmm2
mulsd 0x1698a(%rip), %xmm2    # 0x432a0
mulsd 0x1698a(%rip), %xmm3    # 0x432a8
addsd %xmm2, %xmm3
movapd %xmm3, %xmm2
mulsd %xmm3, %xmm2
addl $0x3ff, %ecx            # imm = 0x3FF
movsd 0x16978(%rip), %xmm5    # 0x432b0
subsd %xmm3, %xmm5
movapd %xmm2, %xmm6
divsd 0x16970(%rip), %xmm6    # 0x432b8
addsd %xmm3, %xmm3
movsd 0x1696c(%rip), %xmm4    # 0x432c0
addsd %xmm4, %xmm6
movapd %xmm2, %xmm7
divsd %xmm6, %xmm7
addsd 0x16960(%rip), %xmm7    # 0x432c8
divsd %xmm7, %xmm2
addsd %xmm5, %xmm2
divsd %xmm2, %xmm3
addsd 0x16954(%rip), %xmm3    # 0x432d0
shlq $0x34, %rcx
movq %rcx, %xmm2
mulsd %xmm3, %xmm2
xorl %ecx, %ecx
ucomisd %xmm1, %xmm2
seta %dl
jbe 0x2c998
divsd %xmm4, %xmm2
movb %dl, %cl
subl %ecx, %esi
leal 0x63(%rsi), %ecx
cmpl $0xc7, %ecx
movl $0x5, %ebx
sbbl $0x0, %ebx
btl $0xb, %r12d
jae 0x2ca26
ucomisd 0x1691c(%rip), %xmm1    # 0x432d8
jb 0x2ca0b
movsd 0x1691a(%rip), %xmm3    # 0x432e0
ucomisd %xmm1, %xmm3
jbe 0x2ca0b
movl %esi, %eax
notl %eax
addl %r8d, %eax
xorl %ebx, %ebx
cmpl %esi, %r8d
cmovlel %ebx, %eax
orl $0x400, %r12d           # imm = 0x400
movl %eax, %r8d
xorl %esi, %esi
jmp 0x2ca26
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
movl %eax, %r8d
movl %r10d, %r9d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c3c0
testl %r8d, %r8d
je 0x2ca23
decl %eax
btl $0xa, %r12d
movl $0x6, %r8d
cmovbl %eax, %r8d
jmp 0x2ca26
xorl %r8d, %r8d
xorl %r9d, %r9d
movl %r10d, %eax
subl %ebx, %eax
cmovbl %r9d, %eax
testl %ebx, %ebx
cmovel %eax, %r9d
testb $0x2, %r12b
cmovel %eax, %r9d
testl %esi, %esi
movl %r10d, 0x14(%rsp)
movq %rsi, (%rsp)
je 0x2ca51
divsd %xmm2, %xmm1
movapd 0x168c7(%rip), %xmm2    # 0x43320
xorpd %xmm1, %xmm2
xorpd %xmm3, %xmm3
cmpltsd %xmm3, %xmm0
movapd %xmm0, %xmm3
andnpd %xmm1, %xmm3
andpd %xmm2, %xmm0
orpd %xmm3, %xmm0
movl %r12d, %eax
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
subq $0x8, %rsp
movq %rdi, %r13
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
pushq %rax
callq 0x2c3c0
addq $0x10, %rsp
movl %r12d, %ecx
movq %rbp, %r12
movq %rax, %rbp
testl %ebx, %ebx
je 0x2cb5a
movq %r15, 0x8(%rsp)
movl %ecx, %eax
andb $0x20, %al
xorb $0x65, %al
movq %r14, %r15
movq %rbp, %r14
incq %r14
movzbl %al, %edi
movq %r12, %rsi
movq %rbp, %rdx
movl %ecx, %ebp
movq %r15, %rcx
callq *%r13
movq (%rsp), %r9
movl %r9d, %r8d
negl %r8d
cmovsl %r9d, %r8d
decl %ebx
shrl $0x1f, %r9d
movq %r13, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r15, %rcx
pushq $0x5
pushq %rbx
pushq $0x0
pushq $0xa
callq 0x2c2f3
addq $0x20, %rsp
movq %rax, %r13
testb $0x2, %bpl
je 0x2cb57
movl 0x14(%rsp), %ecx
movq %r13, %rax
subq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0x2cb57
negq 0x8(%rsp)
movq %r15, %r14
movq (%rsp), %rbx
leaq 0x1(%r13), %rbp
movl $0x20, %edi
movq %r12, %rsi
movq %r13, %rdx
movq %rcx, %r15
movq %r14, %rcx
callq *%rbx
movq %r15, %rcx
movq 0x8(%rsp), %rax
addq %r13, %rax
incq %rax
movq %rbp, %r13
cmpq %r15, %rax
jb 0x2cb28
jmp 0x2cb5a
movq %r13, %rbp
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq