// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3Atoi64
SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc){
  int incr;
  u64 u = 0;
  int neg = 0; /* assume positive */
  int i;
  int c = 0;
  int nonNum = 0;  /* True if input contains UTF16 with high byte non-zero */
  int rc;          /* Baseline return code */
  const char *zStart;
  const char *zEnd = zNum + length;
  assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
  if( enc==SQLITE_UTF8 ){
    incr = 1;
  }else{
    incr = 2;
    assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
    for(i=3-enc; i<length && zNum[i]==0; i+=2){}
    nonNum = i<length;
    zEnd = &zNum[i^1];
    zNum += (enc&1);
  }
  while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
  if( zNum<zEnd ){
    if( *zNum=='-' ){
      neg = 1;
      zNum+=incr;
    }else if( *zNum=='+' ){
      zNum+=incr;
    }
  }
  zStart = zNum;
  while( zNum<zEnd && zNum[0]=='0' ){ zNum+=incr; } /* Skip leading zeros. */
  for(i=0; &zNum[i]<zEnd && (c=zNum[i])>='0' && c<='9'; i+=incr){
    u = u*10 + c - '0';
  }
  testcase( i==18*incr );
  testcase( i==19*incr );
  testcase( i==20*incr );
  if( u>LARGEST_INT64 ){
    /* This test and assignment is needed only to suppress UB warnings
    ** from clang and -fsanitize=undefined.  This test and assignment make
    ** the code a little larger and slower, and no harm comes from omitting
    ** them, but we must appaise the undefined-behavior pharisees. */
    *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
  }else if( neg ){
    *pNum = -(i64)u;
  }else{
    *pNum = (i64)u;
  }
  rc = 0;
  if( i==0 && zStart==zNum ){    /* No digits */
    rc = -1;
  }else if( nonNum ){            /* UTF16 with high-order bytes non-zero */
    rc = 1;
  }else if( &zNum[i]<zEnd ){     /* Extra bytes at the end */
    int jj = i;
    do{
      if( !sqlite3Isspace(zNum[jj]) ){
        rc = 1;          /* Extra non-space text after the integer */
        break;
      }
      jj += incr;
    }while( &zNum[jj]<zEnd );
  }
  if( i<19*incr ){
    /* Less than 19 digits, so we know that it fits in 64 bits */
    assert( u<=LARGEST_INT64 );
    return rc;
  }else{
    /* zNum is a 19-digit numbers.  Compare it against 9223372036854775808. */
    c = i>19*incr ? 1 : compare2pow63(zNum, incr);
    if( c<0 ){
      /* zNum is less than 9223372036854775808 so it fits */
      assert( u<=LARGEST_INT64 );
      return rc;
    }else{
      *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64;
      if( c>0 ){
        /* zNum is greater than 9223372036854775808 so it overflows */
        return 2;
      }else{
        /* zNum is exactly 9223372036854775808.  Fits if negative.  The
        ** special case 2 overflow if positive */
        assert( u-1==LARGEST_INT64 );
        return neg ? rc : 3;
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl $0x3, %eax
cmpl $0x1, %ecx
jne 0x23adbe
movl $0x1, %r9d
xorl %eax, %eax
movq %rdi, %rcx
jmp 0x23ade9
movl $0x2, %r9d
subl %ecx, %eax
movslq %edx, %r10
movslq %eax, %rdx
cmpq %r10, %rdx
setl %al
jge 0x23ade0
cmpb $0x0, (%rdi,%rdx)
jne 0x23ade0
addq $0x2, %rdx
jmp 0x23adcc
xorl $0x1, %edx
andl $0x1, %ecx
addq %rdi, %rcx
movslq %edx, %rdx
addq %rdx, %rdi
movl %r9d, %r9d
leaq 0x136a57(%rip), %r10    # 0x371850
movb $0x1, %dl
cmpq %rdi, %rcx
jae 0x23ae26
movzbl (%rcx), %r11d
testb $0x1, (%r11,%r10)
je 0x23ae10
addq %r9, %rcx
jmp 0x23adf9
cmpl $0x2b, %r11d
je 0x23ae23
cmpl $0x2d, %r11d
jne 0x23ae26
addq %r9, %rcx
xorl %edx, %edx
jmp 0x23ae26
addq %r9, %rcx
xorl %r15d, %r15d
cmpq %rdi, %rcx
jae 0x23ae3b
cmpb $0x30, (%rcx)
jne 0x23ae3b
addq %r9, %rcx
addq %r9, %r15
jmp 0x23ae29
xorl %r14d, %r14d
xorl %r13d, %r13d
leaq (%rcx,%r14), %r12
cmpq %rdi, %r12
jae 0x23ae69
movzbl (%r12), %r11d
leal -0x30(%r11), %ebx
cmpb $0x9, %bl
ja 0x23ae69
imulq $0xa, %r13, %rbx
leaq (%rbx,%r11), %r13
addq $-0x30, %r13
addq %r9, %r14
jmp 0x23ae41
movabsq $0x7fffffffffffffff, %r11 # imm = 0x7FFFFFFFFFFFFFFF
leaq 0x1(%r11), %r8
movq %r13, %rbp
negq %rbp
testb %dl, %dl
movq %r8, %rbx
cmovneq %r11, %rbx
cmovneq %r13, %rbp
testq %r13, %r13
cmovsq %rbx, %rbp
movq %rbp, (%rsi)
orq %r14, %r15
jne 0x23aea0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x23aeca
cmpq %rdi, %r12
setae %bl
orb %al, %bl
je 0x23aeaf
movzbl %al, %eax
jmp 0x23aeca
movl $0x1, %eax
movzbl (%r12), %ebx
testb $0x1, (%rbx,%r10)
je 0x23aeca
addq %r9, %r12
cmpq %rdi, %r12
jb 0x23aeb4
xorl %eax, %eax
imull $0x13, %r9d, %edi
cmpl %r14d, %edi
ja 0x23af3c
cmpl %r14d, %edi
jae 0x23aedf
movl $0x1, %edi
jmp 0x23af21
xorl %r10d, %r10d
leaq 0x13b307(%rip), %r14    # 0x3761f0
movq %rcx, %r15
xorl %edi, %edi
testl %edi, %edi
jne 0x23af0e
cmpq $0x11, %r10
ja 0x23af0e
movsbl (%r15), %edi
movsbl (%r10,%r14), %ebx
subl %ebx, %edi
imull $0xa, %edi, %edi
incq %r10
addq %r9, %r15
jmp 0x23aeee
testl %edi, %edi
jne 0x23af1d
imulq $0x12, %r9, %rdi
movsbl (%rcx,%rdi), %edi
addl $-0x38, %edi
testl %edi, %edi
js 0x23af3c
testb %dl, %dl
cmovneq %r11, %r8
movq %r8, (%rsi)
movl $0x3, %ecx
cmovnel %ecx, %eax
testl %edi, %edi
movl $0x2, %ecx
cmovnel %ecx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq