// File: /workspace/github_c_makefile_star2_O3/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:
movq $0x0, (%rsi)
xorl %eax, %eax
testl %edx, %edx
je 0x292638
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
cmpb $0x1, %cl
jne 0x2922b9
movl $0x1, %r14d
movl $0x1, %r8d
movq %rdi, %r9
jmp 0x292310
movzbl %cl, %r9d
andl $-0x2, %edx
movl $0x3, %r10d
movl $0x3, %ecx
subl %r9d, %ecx
movl $0x1, %r8d
cmpl %edx, %ecx
jge 0x2922fe
subl %r9d, %r10d
movslq %r10d, %rcx
movslq %edx, %rdx
cmpb $0x0, (%rdi,%rcx)
jne 0x2922f8
addq $0x2, %rcx
cmpq %rdx, %rcx
jl 0x2922e1
movl $0x1, %r8d
jmp 0x2922fe
movl $0xffffff9c, %r8d       # imm = 0xFFFFFF9C
xorl $0x1, %ecx
andl $0x1, %r9d
addq %rdi, %r9
movl $0x2, %r14d
movl %ecx, %edx
movslq %edx, %rcx
addq %rcx, %rdi
cmpq %rdi, %r9
jae 0x29262e
leaq 0x13f11a(%rip), %rdx    # 0x3d1440
movzbl (%r9), %r11d
testb $0x1, (%r11,%rdx)
je 0x29233e
addq %r14, %r9
cmpq %rdi, %r9
jb 0x292326
jmp 0x29262e
leal -0x2b(%r11), %eax
xorl %r10d, %r10d
testb $-0x3, %al
movl $0x0, %eax
cmoveq %r14, %rax
addq %rax, %r9
movl $0x1, %ebp
cmpq %rdi, %r9
jae 0x2924f9
xorl %r10d, %r10d
movabsq $0xccccccccccccccb, %rax # imm = 0xCCCCCCCCCCCCCCB
leaq -0x1(%rax), %r15
xorl %eax, %eax
xorl %ecx, %ecx
movzbl (%r9), %ebx
movq %rbx, %r12
addq $-0x3a, %r12
cmpq $-0xa, %r12
jb 0x2923c6
movsbq %bl, %rbx
leaq (%rcx,%rcx,4), %rcx
leaq (%rbx,%rcx,2), %rcx
addq $-0x30, %rcx
addq %r14, %r9
cmpq %r15, %rcx
jle 0x2923b9
cmpq %rdi, %r9
jae 0x2923b9
movzbl (%r9), %ebx
addq $-0x3a, %rbx
cmpq $-0xa, %rbx
jb 0x2923b9
addq %r14, %r9
incl %eax
jmp 0x29239f
incl %r10d
cmpq %rdi, %r9
jb 0x292376
jmp 0x292458
cmpb $0x2e, %bl
jne 0x29240a
incl %r8d
addq %r14, %r9
cmpq %rdi, %r9
jae 0x29240a
movzbl (%r9), %ebx
leaq -0x3a(%rbx), %r15
cmpq $-0xa, %r15
jb 0x29240a
movabsq $0xccccccccccccccb, %r15 # imm = 0xCCCCCCCCCCCCCCB
cmpq %r15, %rcx
jge 0x2923ce
movsbq %bl, %rbx
leaq (%rcx,%rcx,4), %rcx
leaq (%rbx,%rcx,2), %rcx
addq $-0x30, %rcx
decl %eax
incl %r10d
jmp 0x2923ce
cmpq %rdi, %r9
jae 0x292458
movzbl (%r9), %ebx
orl $0x20, %ebx
cmpl $0x65, %ebx
jne 0x292639
addq %r14, %r9
incl %r8d
cmpq %rdi, %r9
jae 0x29264c
movzbl (%r9), %ebx
movl $0x1, %r12d
cmpl $0x2b, %ebx
je 0x29267b
cmpl $0x2d, %ebx
jne 0x29267e
addq %r14, %r9
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x29267e
xorl %r15d, %r15d
movl $0x1, %r12d
movl $0x1, %ebp
testq %rcx, %rcx
je 0x2924f9
imull %r12d, %r15d
addl %eax, %r15d
movl %r15d, %r14d
negl %r14d
cmovsl %r15d, %r14d
jae 0x292515
movabsq $0x6666666666666667, %r12 # imm = 0x6666666666666667
movabsq $-0x3333333333333333, %r13 # imm = 0xCCCCCCCCCCCCCCCD
movabsq $0x1999999999999998, %rbx # imm = 0x1999999999999998
testl %r15d, %r15d
js 0x2924c1
movabsq $0xccccccccccccccb, %rax # imm = 0xCCCCCCCCCCCCCCB
cmpq %rax, %rcx
jg 0x292533
addq %rcx, %rcx
leaq (%rcx,%rcx,4), %rcx
jmp 0x2924ea
movq %rcx, %rax
imulq %r12
movq %rcx, %rax
imulq %r13, %rax
addq %rbx, %rax
rorq %rax
cmpq %rbx, %rax
ja 0x292533
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x2, %rdx
addq %rax, %rdx
movq %rdx, %rcx
leal -0x1(%r14), %edx
cmpl $0x1, %r14d
movl %edx, %r14d
jg 0x2924a4
jmp 0x292518
cmpb $0x2d, %r11b
je 0x292508
xorpd %xmm0, %xmm0
jmp 0x2925f0
movsd 0x1432c8(%rip), %xmm0   # 0x3d57d8
jmp 0x2925f0
movl %r14d, %edx
movq %rcx, %rax
negq %rax
cmpb $0x2d, %r11b
cmovneq %rcx, %rax
testl %edx, %edx
je 0x2925dd
movl %edx, %r14d
jmp 0x292584
movq %rcx, %rax
negq %rax
cmpb $0x2d, %r11b
cmovneq %rcx, %rax
cmpl $0x134, %r14d           # imm = 0x134
jb 0x292584
cmpl $0x155, %r14d           # imm = 0x155
ja 0x29265c
leal -0x134(%r14), %ecx
testb $0x1, %r14b
fld1
flds 0x143312(%rip)          # 0x3d587c
fld %st(0)
fcmove %st(2), %st
fstp %st(2)
cmpl $0x2, %ecx
jae 0x2926a8
fstp %st(0)
fldz
fldz
jmp 0x2926c8
testb $0x1, %r14b
fld1
flds 0x1432ec(%rip)          # 0x3d587c
fld %st(0)
fcmove %st(2), %st
fstp %st(2)
cmpl $0x2, %r14d
jae 0x2925a4
fstp %st(0)
fldz
fldz
jmp 0x2925c7
movl %r14d, %ecx
fldz
fxch %st(2)
fstp %st(2)
sarl %ecx
fmul %st, %st(0)
testb $0x2, %r14b
fld %st(1)
fmul %st(1), %st
fcmove %st(2), %st
fstp %st(2)
fld %st(1)
movl %ecx, %r14d
cmpl $0x1, %ecx
ja 0x2925ab
fstp %st(1)
fstp %st(0)
movq %rax, -0x20(%rsp)
fildll -0x20(%rsp)
testl %r15d, %r15d
js 0x2925e4
fmulp %st, %st(1)
jmp 0x2925e6
cvtsi2sd %rax, %xmm0
jmp 0x2925f0
fdivp %st, %st(1)
fstpl -0x28(%rsp)
movsd -0x28(%rsp), %xmm0
movsd %xmm0, (%rsi)
testl %ebp, %ebp
je 0x29260c
cmpq %rdi, %r9
jne 0x29260c
testl %r10d, %r10d
jle 0x29260c
testl %r8d, %r8d
jle 0x29260c
movl %r8d, %eax
jmp 0x29262e
cmpl $0x2, %r8d
jl 0x29262c
testl %ebp, %ebp
sete %al
cmpl $0x3, %r8d
setne %cl
testb %cl, %al
jne 0x29262c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %r10d, %r10d
jg 0x29262e
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
movl $0x1, %r12d
movl $0x1, %ebp
jmp 0x292753
xorl %r15d, %r15d
movl $0x1, %r12d
xorl %ebp, %ebp
jmp 0x292466
testl %r15d, %r15d
js 0x29275d
cvtsi2ss %rax, %xmm0
mulss 0x143212(%rip), %xmm0   # 0x3d5884
cvtss2sd %xmm0, %xmm0
jmp 0x2925f0
addq %r14, %r9
xorl %r15d, %r15d
cmpq %rdi, %r9
jae 0x2926a1
movl %r12d, -0x2c(%rsp)
movzbl (%r9), %r12d
leaq -0x3a(%r12), %rbx
cmpq $-0xa, %rbx
jae 0x2926f7
xorl %ebp, %ebp
jmp 0x29273b
xorl %ebp, %ebp
jmp 0x292753
movl %ecx, %edx
fldz
fxch %st(2)
fstp %st(2)
sarl %edx
fmul %st, %st(0)
testb $0x2, %cl
fld %st(1)
fmul %st(1), %st
fcmove %st(2), %st
fstp %st(2)
fld %st(1)
movl %edx, %ecx
cmpl $0x1, %edx
ja 0x2926ae
fstp %st(1)
fstp %st(0)
movq %rax, -0x8(%rsp)
fildll -0x8(%rsp)
testl %r15d, %r15d
js 0x29276f
fmulp %st, %st(1)
fstpl -0x10(%rsp)
movsd -0x10(%rsp), %xmm0
mulsd 0x1430de(%rip), %xmm0   # 0x3d57d0
jmp 0x2925f0
addq %r14, %r9
xorl %r15d, %r15d
movq %r9, %rbx
movq %rbx, %r9
movl $0x2710, %ebp           # imm = 0x2710
cmpl %ebp, %r15d
leal (%r15,%r15,4), %ebx
movsbl %r12b, %r15d
leal -0x30(%r15,%rbx,2), %r15d
cmovgel %ebp, %r15d
movl $0x1, %ebp
cmpq %rdi, %r9
jae 0x29273b
movzbl (%r9), %r12d
movq %r12, %r13
addq $-0x3a, %r13
leaq (%r9,%r14), %rbx
cmpq $-0xa, %r13
jae 0x292700
movl -0x2c(%rsp), %r12d
jmp 0x292753
movzbl (%r9), %ebx
testb $0x1, (%rbx,%rdx)
je 0x292466
addq %r14, %r9
cmpq %rdi, %r9
jb 0x292742
jmp 0x292466
cvtsi2sd %rax, %xmm0
andpd 0xbd2e6(%rip), %xmm0    # 0x34fa50
jmp 0x2925f0
fdivp %st, %st(1)
fstpl -0x18(%rsp)
movsd -0x18(%rsp), %xmm0
divsd 0x14304d(%rip), %xmm0   # 0x3d57d0
jmp 0x2925f0