// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %rbx
cmpl $0x1, %ecx
jne 0x2927fc
movl $0x1, %r8d
xorl %r9d, %r9d
movq %rdi, %rcx
jmp 0x29283e
movl $0x3, %r8d
movl $0x3, %eax
subl %ecx, %eax
cmpl %edx, %eax
jge 0x292825
subl %ecx, %r8d
movslq %r8d, %rax
movslq %edx, %rdx
cmpb $0x0, (%rdi,%rax)
jne 0x29282a
addq $0x2, %rax
cmpq %rdx, %rax
jl 0x292816
xorl %r9d, %r9d
jmp 0x29282d
movb $0x1, %r9b
xorl $0x1, %eax
andl $0x1, %ecx
addq %rdi, %rcx
movl $0x2, %r8d
movl %eax, %edx
movslq %edx, %rax
addq %rax, %rdi
movb $0x1, %dl
cmpq %rdi, %rcx
jae 0x292880
movl %r8d, %eax
leaq 0x13ebeb(%rip), %r10    # 0x3d1440
movzbl (%rcx), %r11d
testb $0x1, (%r11,%r10)
je 0x29286a
addq %rax, %rcx
cmpq %rdi, %rcx
jb 0x292855
jmp 0x292880
cmpl $0x2b, %r11d
je 0x29287d
cmpl $0x2d, %r11d
jne 0x292880
addq %rax, %rcx
xorl %edx, %edx
jmp 0x292880
addq %rax, %rcx
movq %rcx, %r10
cmpq %rdi, %rcx
jae 0x29289c
movl %r8d, %eax
movq %rcx, %r10
cmpb $0x30, (%r10)
jne 0x29289c
addq %rax, %r10
cmpq %rdi, %r10
jb 0x29288e
cmpq %rdi, %r10
jae 0x2928e7
movl %r8d, %r14d
xorl %r11d, %r11d
xorl %eax, %eax
movzbl (%r10,%r11), %r15d
leal -0x30(%r15), %ebx
cmpb $0xa, %bl
setb %bl
jae 0x2928d2
leaq (%rax,%rax,4), %rax
leaq (%r15,%rax,2), %rax
addq $-0x30, %rax
addq %r14, %r11
leaq (%r10,%r11), %r15
cmpq %rdi, %r15
jb 0x2928a9
testq %rax, %rax
jns 0x2928ee
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
leaq 0x1(%rax), %r14
jmp 0x2928f4
xorl %r11d, %r11d
movb $0x1, %bl
xorl %eax, %eax
movq %rax, %r14
negq %r14
testb %dl, %dl
cmovneq %rax, %r14
movq %r14, (%rsi)
testl %r11d, %r11d
jne 0x29290c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %r10, %rcx
je 0x292942
orb %r9b, %bl
je 0x292917
movzbl %r9b, %eax
jmp 0x292942
movl %r11d, %eax
movl %r8d, %ecx
addq %r10, %rax
leaq 0x13eb19(%rip), %r9     # 0x3d1440
movzbl (%rax), %ebx
testb $0x1, (%rbx,%r9)
je 0x29293d
addq %rcx, %rax
cmpq %rdi, %rax
jb 0x292927
xorl %eax, %eax
jmp 0x292942
movl $0x1, %eax
leal (%r8,%r8,8), %ecx
leal (%r8,%rcx,2), %ecx
cmpl %ecx, %r11d
jb 0x2929e8
jbe 0x292973
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
leaq 0x1(%rax), %rcx
testb %dl, %dl
cmovneq %rax, %rcx
movq %rcx, (%rsi)
movl $0x2, %eax
jmp 0x2929e8
movl %r8d, %ecx
xorl %edi, %edi
leaq 0x143451(%rip), %r8     # 0x3d5dd0
movq %r10, %r9
movb (%r9), %r11b
movb (%rdi,%r8), %bl
cmpq $0x10, %rdi
ja 0x29299a
incq %rdi
addq %rcx, %r9
cmpb %bl, %r11b
je 0x292982
cmpb %bl, %r11b
jne 0x2929ad
leaq (%rcx,%rcx,8), %rcx
movsbl (%r10,%rcx,2), %ecx
addl $-0x38, %ecx
jmp 0x2929bb
movsbl %r11b, %ecx
movsbl %bl, %edi
subl %edi, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
testl %ecx, %ecx
js 0x2929e8
movabsq $0x7fffffffffffffff, %rdi # imm = 0x7FFFFFFFFFFFFFFF
leaq 0x1(%rdi), %r8
testb %dl, %dl
cmovneq %rdi, %r8
movq %r8, (%rsi)
movl $0x3, %edx
cmovnel %edx, %eax
testl %ecx, %ecx
movl $0x2, %ecx
cmovnel %ecx, %eax
popq %rbx
popq %r14
popq %r15
retq