// File: /workspace/github_c_makefile_star2_O1/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
cmpl $0x1, %ecx
jne 0x29c511
movl $0x1, %r10d
xorl %r9d, %r9d
movq %rdi, %rcx
jmp 0x29c56e
movl $0x3, %eax
subl %ecx, %eax
cmpl %edx, %eax
setl %r9b
jge 0x29c55d
movl %ecx, %r8d
movl $0x3, %eax
subq %r8, %rax
cmpb $0x0, (%rdi,%rax)
jne 0x29c55d
movslq %edx, %rdx
movzbl %cl, %r8d
movl $0x5, %eax
subq %r8, %rax
cmpq %rdx, %rax
setl %r9b
jge 0x29c55d
leaq 0x2(%rax), %r8
cmpb $0x0, (%rdi,%rax)
movq %r8, %rax
je 0x29c540
addl $-0x2, %r8d
movl %r8d, %eax
xorl $0x1, %eax
andl $0x1, %ecx
addq %rdi, %rcx
movl $0x2, %r10d
movl %eax, %edx
movslq %edx, %rax
addq %rax, %rdi
movb $0x1, %dl
movl %r10d, %r8d
cmpq %rdi, %rcx
jae 0x29c5b0
leaq 0x13e63b(%rip), %rax    # 0x3dabc0
movzbl (%rcx), %r11d
testb $0x1, (%r11,%rax)
je 0x29c59a
addq %r8, %rcx
cmpq %rdi, %rcx
jb 0x29c585
jmp 0x29c5b0
cmpl $0x2b, %r11d
je 0x29c5ad
cmpl $0x2d, %r11d
jne 0x29c5b0
addq %r8, %rcx
xorl %edx, %edx
jmp 0x29c5b0
addq %r8, %rcx
movq %rcx, %r11
cmpq %rdi, %rcx
jae 0x29c5c9
movq %rcx, %r11
cmpb $0x30, (%r11)
jne 0x29c5c9
addq %r8, %r11
cmpq %rdi, %r11
jb 0x29c5bb
cmpq %rdi, %r11
setae %r15b
jae 0x29c613
movb (%r11), %r14b
leal -0x30(%r14), %eax
cmpb $0x9, %al
ja 0x29c613
leaq (%r11,%r8), %rbx
xorl %eax, %eax
xorl %ebp, %ebp
movzbl %r14b, %r14d
leaq (%rax,%rax,4), %rax
leaq (%r14,%rax,2), %rax
addq $-0x30, %rax
addl %r10d, %ebp
cmpq %rdi, %rbx
setae %r15b
jae 0x29c617
movb (%rbx), %r14b
leal -0x30(%r14), %r12d
addq %r8, %rbx
cmpb $0x9, %r12b
jbe 0x29c5e5
jmp 0x29c617
xorl %eax, %eax
xorl %ebp, %ebp
movabsq $0x7fffffffffffffff, %rbx # imm = 0x7FFFFFFFFFFFFFFF
leaq 0x1(%rbx), %r14
movq %rax, %r12
negq %r12
testb %dl, %dl
movq %r14, %r13
cmovneq %rbx, %r13
cmovneq %rax, %r12
testq %rax, %rax
cmovsq %r13, %r12
movq %r12, (%rsi)
testl %ebp, %ebp
jne 0x29c650
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %r11, %rcx
je 0x29c683
orb %r9b, %r15b
je 0x29c65b
movzbl %r9b, %eax
jmp 0x29c683
movl %ebp, %eax
addq %r11, %rax
leaq 0x13e559(%rip), %rcx    # 0x3dabc0
movzbl (%rax), %r9d
testb $0x1, (%r9,%rcx)
je 0x29c67e
addq %r8, %rax
cmpq %rdi, %rax
jb 0x29c667
xorl %eax, %eax
jmp 0x29c683
movl $0x1, %eax
leal (%r10,%r10,8), %ecx
leal (%r10,%rcx,2), %ecx
cmpl %ecx, %ebp
jb 0x29c6fb
movl $0x1, %ecx
ja 0x29c6dc
xorl %ecx, %ecx
leaq 0x142e85(%rip), %rdi    # 0x3df524
movq %r11, %r9
movb (%r9), %r10b
movb (%rcx,%rdi), %bpl
cmpq $0x10, %rcx
ja 0x29c6ba
incq %rcx
addq %r8, %r9
cmpb %bpl, %r10b
je 0x29c6a2
cmpb %bpl, %r10b
jne 0x29c6cd
leaq (%r8,%r8,8), %rcx
movsbl (%r11,%rcx,2), %ecx
addl $-0x38, %ecx
jmp 0x29c6dc
movsbl %r10b, %ecx
movsbl %bpl, %edi
subl %edi, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
testl %ecx, %ecx
js 0x29c6fb
testb %dl, %dl
cmovneq %rbx, %r14
movq %r14, (%rsi)
movl $0x3, %edx
cmovnel %edx, %eax
testl %ecx, %ecx
movl $0x2, %ecx
cmovnel %ecx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq