// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3AtoF
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 enc){
#ifndef SQLITE_OMIT_FLOATING_POINT
  int incr;
  const char *zEnd;
  /* sign * significand * (10 ^ (esign * exponent)) */
  int sign = 1;    /* sign of significand */
  i64 s = 0;       /* significand */
  int d = 0;       /* adjust exponent for shifting decimal point */
  int esign = 1;   /* sign of exponent */
  int e = 0;       /* exponent */
  int eValid = 1;  /* True exponent is either not used or is well-formed */
  double result;
  int nDigit = 0;  /* Number of digits processed */
  int eType = 1;   /* 1: pure integer,  2+: fractional  -1 or less: bad UTF16 */

  assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
  *pResult = 0.0;   /* Default return value, in case of an error */
  if( length==0 ) return 0;

  if( enc==SQLITE_UTF8 ){
    incr = 1;
    zEnd = z + length;
  }else{
    int i;
    incr = 2;
    length &= ~1;
    assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
    testcase( enc==SQLITE_UTF16LE );
    testcase( enc==SQLITE_UTF16BE );
    for(i=3-enc; i<length && z[i]==0; i+=2){}
    if( i<length ) eType = -100;
    zEnd = &z[i^1];
    z += (enc&1);
  }

  /* skip leading spaces */
  while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
  if( z>=zEnd ) return 0;

  /* get sign of significand */
  if( *z=='-' ){
    sign = -1;
    z+=incr;
  }else if( *z=='+' ){
    z+=incr;
  }

  /* copy max significant digits to significand */
  while( z<zEnd && sqlite3Isdigit(*z) ){
    s = s*10 + (*z - '0');
    z+=incr; nDigit++;
    if( s>=((LARGEST_INT64-9)/10) ){
      /* skip non-significant significand digits
      ** (increase exponent by d to shift decimal left) */
      while( z<zEnd && sqlite3Isdigit(*z) ){ z+=incr; d++; }
    }
  }
  if( z>=zEnd ) goto do_atof_calc;

  /* if decimal point is present */
  if( *z=='.' ){
    z+=incr;
    eType++;
    /* copy digits from after decimal to significand
    ** (decrease exponent by d to shift decimal right) */
    while( z<zEnd && sqlite3Isdigit(*z) ){
      if( s<((LARGEST_INT64-9)/10) ){
        s = s*10 + (*z - '0');
        d--;
        nDigit++;
      }
      z+=incr;
    }
  }
  if( z>=zEnd ) goto do_atof_calc;

  /* if exponent is present */
  if( *z=='e' || *z=='E' ){
    z+=incr;
    eValid = 0;
    eType++;

    /* This branch is needed to avoid a (harmless) buffer overread.  The
    ** special comment alerts the mutation tester that the correct answer
    ** is obtained even if the branch is omitted */
    if( z>=zEnd ) goto do_atof_calc;              /*PREVENTS-HARMLESS-OVERREAD*/

    /* get sign of exponent */
    if( *z=='-' ){
      esign = -1;
      z+=incr;
    }else if( *z=='+' ){
      z+=incr;
    }
    /* copy digits to exponent */
    while( z<zEnd && sqlite3Isdigit(*z) ){
      e = e<10000 ? (e*10 + (*z - '0')) : 10000;
      z+=incr;
      eValid = 1;
    }
  }

  /* skip trailing spaces */
  while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;

do_atof_calc:
  /* adjust exponent by d, and update sign */
  e = (e*esign) + d;
  if( e<0 ) {
    esign = -1;
    e *= -1;
  } else {
    esign = 1;
  }

  if( s==0 ) {
    /* In the IEEE 754 standard, zero is signed. */
    result = sign<0 ? -(double)0 : (double)0;
  } else {
    /* Attempt to reduce exponent.
    **
    ** Branches that are not required for the correct answer but which only
    ** help to obtain the correct answer faster are marked with special
    ** comments, as a hint to the mutation tester.
    */
    while( e>0 ){                                       /*OPTIMIZATION-IF-TRUE*/
      if( esign>0 ){
        if( s>=(LARGEST_INT64/10) ) break;             /*OPTIMIZATION-IF-FALSE*/
        s *= 10;
      }else{
        if( s%10!=0 ) break;                           /*OPTIMIZATION-IF-FALSE*/
        s /= 10;
      }
      e--;
    }

    /* adjust the sign of significand */
    s = sign<0 ? -s : s;

    if( e==0 ){                                         /*OPTIMIZATION-IF-TRUE*/
      result = (double)s;
    }else{
      /* attempt to handle extremely small/large numbers better */
      if( e>307 ){                                      /*OPTIMIZATION-IF-TRUE*/
        if( e<342 ){                                    /*OPTIMIZATION-IF-TRUE*/
          LONGDOUBLE_TYPE scale = sqlite3Pow10(e-308);
          if( esign<0 ){
            result = s / scale;
            result /= 1.0e+308;
          }else{
            result = s * scale;
            result *= 1.0e+308;
          }
        }else{ assert( e>=342 );
          if( esign<0 ){
            result = 0.0*s;
          }else{
#ifdef INFINITY
            result = INFINITY*s;
#else
            result = 1e308*1e308*s;  /* Infinity */
#endif
          }
        }
      }else{
        LONGDOUBLE_TYPE scale = sqlite3Pow10(e);
        if( esign<0 ){
          result = s / scale;
        }else{
          result = s * scale;
        }
      }
    }
  }

  /* store the result */
  *pResult = result;

  /* return true if number and no extra non-whitespace chracters after */
  if( z==zEnd && nDigit>0 && eValid && eType>0 ){
    return eType;
  }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){
    return -1;
  }else{
    return 0;
  }
#else
  return !sqlite3Atoi64(z, pResult, length, enc);
#endif /* SQLITE_OMIT_FLOATING_POINT */
}

// Assembly:
andq $0x0, (%rsi)
xorl %eax, %eax
testl %edx, %edx
je 0x23acce
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
cmpb $0x1, %cl
jne 0x23a985
pushq $0x1
popq %rdi
pushq $0x1
popq %r10
movq %r14, %r15
jmp 0x23a9c1
movzbl %cl, %r15d
andl $-0x2, %edx
pushq $0x3
popq %rdi
subl %r15d, %edi
movslq %edx, %rcx
movslq %edi, %rdx
pushq $0x1
popq %r10
pushq $-0x64
popq %rdi
cmpq %rcx, %rdx
jge 0x23a9b4
cmpb $0x0, (%r14,%rdx)
jne 0x23a9b1
addq $0x2, %rdx
jmp 0x23a99f
movl %edi, %r10d
xorl $0x1, %edx
andl $0x1, %r15d
addq %r14, %r15
pushq $0x2
popq %rdi
movslq %edx, %rcx
addq %rcx, %r14
leaq 0x136e82(%rip), %r9     # 0x371850
cmpq %r14, %r15
jae 0x23acc0
movzbl (%r15), %r8d
testb $0x1, (%r8,%r9)
je 0x23a9e7
addq %rdi, %r15
jmp 0x23a9ce
movl %r10d, %edx
movq %rsi, 0x8(%rsp)
movabsq $0xccccccccccccccb, %rsi # imm = 0xCCCCCCCCCCCCCCB
leal -0x2b(%r8), %eax
xorl %ecx, %ecx
testb $-0x3, %al
movl $0x0, %eax
cmoveq %rdi, %rax
addq %rax, %r15
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
leaq -0x1(%rsi), %r10
xorl %eax, %eax
xorl %r12d, %r12d
xorl %ebp, %ebp
movb $0x1, %r13b
cmpq %r14, %r15
jae 0x23aa6e
movzbl (%r15), %r11d
movq %r11, %rbx
addq $-0x3a, %rbx
cmpq $-0xa, %rbx
jb 0x23aa76
movsbq %r11b, %r11
imulq $0xa, %rcx, %rcx
addq %r11, %rcx
addq $-0x30, %rcx
addq %rdi, %r15
incl %r12d
cmpq %r10, %rcx
jle 0x23aa1f
jmp 0x23aa59
addq %rdi, %r15
incl %eax
cmpq %r14, %r15
jae 0x23aa1f
movzbl (%r15), %r11d
addq $-0x3a, %r11
cmpq $-0xa, %r11
jae 0x23aa54
jmp 0x23aa1f
movl %edx, %r11d
jmp 0x23ab75
cmpb $0x2e, %r11b
jne 0x23aabc
incl %edx
movq %r15, %r10
leaq (%r10,%rdi), %r15
cmpq %r14, %r15
jae 0x23aab6
movzbl (%r15), %r11d
leaq -0x3a(%r11), %rbx
cmpq $-0xa, %rbx
jb 0x23aab6
movq %r15, %r10
cmpq %rsi, %rcx
jge 0x23aa81
movsbq %r11b, %r10
imulq $0xa, %rcx, %rcx
addq %r10, %rcx
addq $-0x30, %rcx
decl %eax
incl %r12d
jmp 0x23aa7e
addq %rdi, %r10
movq %r10, %r15
movl %edx, %r11d
cmpq %r14, %r15
jae 0x23ab75
movzbl (%r15), %edx
orl $0x20, %edx
cmpl $0x65, %edx
jne 0x23ab02
addq %rdi, %r15
incl %r11d
cmpq %r14, %r15
jae 0x23ab10
movzbl (%r15), %r10d
pushq $0x1
popq %rdx
movl %edx, 0x4(%rsp)
cmpl $0x2b, %r10d
je 0x23ab1e
cmpl $0x2d, %r10d
jne 0x23ab21
addq %rdi, %r15
pushq $-0x1
popq %rdx
movl %edx, 0x4(%rsp)
jmp 0x23ab21
movb $0x1, %r13b
xorl %ebp, %ebp
pushq $0x1
popq %rdx
movl %edx, 0x4(%rsp)
jmp 0x23ab70
xorl %ebp, %ebp
pushq $0x1
popq %rdx
movl %edx, 0x4(%rsp)
xorl %r13d, %r13d
jmp 0x23ab75
addq %rdi, %r15
movl %r11d, %edx
xorl %ebp, %ebp
movl $0x2710, %r10d          # imm = 0x2710
xorl %r13d, %r13d
cmpq %r14, %r15
jae 0x23ab5d
movzbl (%r15), %r11d
leaq -0x3a(%r11), %rbx
cmpq $-0xa, %rbx
jb 0x23ab5d
movsbl %r11b, %r11d
imull $0xa, %ebp, %ebx
cmpl %r10d, %ebp
leal -0x30(%rbx,%r11), %ebp
cmovgel %r10d, %ebp
addq %rdi, %r15
movb $0x1, %r13b
jmp 0x23ab2f
movl %edx, %r11d
jmp 0x23ab70
movzbl (%r15), %r10d
testb $0x1, (%r10,%r9)
je 0x23ab75
addq %rdi, %r15
cmpq %r14, %r15
jb 0x23ab62
testq %rcx, %rcx
je 0x23abb3
imull 0x4(%rsp), %ebp
addl %eax, %ebp
movl %ebp, %edi
negl %edi
cmovsl %ebp, %edi
pushq $0xa
popq %r9
testl %edi, %edi
jle 0x23abc5
testl %ebp, %ebp
js 0x23ab9f
cmpq %rsi, %rcx
jg 0x23abde
imulq $0xa, %rcx, %rcx
jmp 0x23abaf
movq %rcx, %rax
cqto
idivq %r9
testq %rdx, %rdx
jne 0x23abde
movq %rax, %rcx
decl %edi
jmp 0x23ab8c
cmpb $0x2d, %r8b
je 0x23ac55
xorps %xmm0, %xmm0
jmp 0x23ac5d
movq %rcx, %rbx
negq %rbx
cmpb $0x2d, %r8b
cmovneq %rcx, %rbx
testl %edi, %edi
jne 0x23ac3a
cvtsi2sd %rbx, %xmm0
jmp 0x23ac5d
movq %rcx, %rbx
negq %rbx
cmpb $0x2d, %r8b
cmovneq %rcx, %rbx
cmpl $0x134, %edi            # imm = 0x134
jb 0x23ac3a
cmpl $0x155, %edi            # imm = 0x155
ja 0x23accf
movl %r11d, 0x4(%rsp)
addl $0xfffffecc, %edi       # imm = 0xFFFFFECC
callq 0x23ad20
movq %rbx, 0x20(%rsp)
fildll 0x20(%rsp)
testl %ebp, %ebp
js 0x23aceb
fmulp %st, %st(1)
fstpl 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
mulsd 0x13afbb(%rip), %xmm0   # 0x375bf0
jmp 0x23acff
movl %r11d, 0x4(%rsp)
callq 0x23ad20
movq %rbx, 0x30(%rsp)
fildll 0x30(%rsp)
testl %ebp, %ebp
js 0x23ac64
fmulp %st, %st(1)
jmp 0x23ac66
movsd 0x13af9b(%rip), %xmm0   # 0x375bf8
movq 0x8(%rsp), %rax
jmp 0x23ac7a
fdivp %st, %st(1)
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %r11d
fstpl 0x28(%rsp)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, (%rax)
cmpq %r14, %r15
sete %al
testl %r12d, %r12d
setg %cl
andb %al, %cl
andb %r13b, %cl
testl %r11d, %r11d
setg %al
testb %al, %cl
je 0x23ac9e
movl %r11d, %eax
jmp 0x23acc0
cmpl $0x2, %r11d
jl 0x23acbe
testl %r12d, %r12d
setg %al
cmpl $0x3, %r11d
sete %cl
orb %cl, %r13b
testb %al, %r13b
je 0x23acbe
pushq $-0x1
popq %rax
jmp 0x23acc0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ebp, %ebp
movq 0x8(%rsp), %rax
js 0x23ad0e
cvtsi2ss %rbx, %xmm0
mulss 0x13afbf(%rip), %xmm0   # 0x375ca4
cvtss2sd %xmm0, %xmm0
jmp 0x23ac7a
fdivp %st, %st(1)
fstpl 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
divsd 0x13aef1(%rip), %xmm0   # 0x375bf0
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %r11d
jmp 0x23ac7a
cvtsi2sd %rbx, %xmm0
andpd 0xb4d35(%rip), %xmm0    # 0x2efa50
jmp 0x23ac7a