// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/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;
  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+enc-3;
    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';
  }
  if( u>LARGEST_INT64 ){
    *pNum = SMALLEST_INT64;
  }else if( neg ){
    *pNum = -(i64)u;
  }else{
    *pNum = (i64)u;
  }
  testcase( i==18 );
  testcase( i==19 );
  testcase( i==20 );
  if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) || i>19*incr || nonNum ){
    /* zNum is empty or contains non-numeric text or is longer
    ** than 19 digits (thus guaranteeing that it is too large) */
    return 1;
  }else if( i<19*incr ){
    /* Less than 19 digits, so we know that it fits in 64 bits */
    assert( u<=LARGEST_INT64 );
    return 0;
  }else{
    /* zNum is a 19-digit numbers.  Compare it against 9223372036854775808. */
    c = compare2pow63(zNum, incr);
    if( c<0 ){
      /* zNum is less than 9223372036854775808 so it fits */
      assert( u<=LARGEST_INT64 );
      return 0;
    }else if( c>0 ){
      /* zNum is greater than 9223372036854775808 so it overflows */
      return 1;
    }else{
      /* zNum is exactly 9223372036854775808.  Fits if negative.  The
      ** special case 2 overflow if positive */
      assert( u-1==LARGEST_INT64 );
      assert( (*pNum)==SMALLEST_INT64 );
      return neg ? 0 : 2;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
cmpl $0x1, %ecx
jne 0x16ffa
movslq %edx, %rax
addq %rdi, %rax
movl $0x1, %r8d
xorl %edx, %edx
jmp 0x17045
movl $0x3, %r8d
movl $0x3, %eax
subl %ecx, %eax
cmpl %edx, %eax
jge 0x17023
subl %ecx, %r8d
movslq %r8d, %rax
movslq %edx, %rdx
cmpb $0x0, (%rdi,%rax)
jne 0x17027
addq $0x2, %rax
cmpq %rdx, %rax
jl 0x17014
xorl %edx, %edx
jmp 0x17029
movb $0x1, %dl
cltq
addq %rdi, %rax
movzbl %cl, %r8d
addq %r8, %rax
addq $-0x3, %rax
andl $0x1, %ecx
addq %rcx, %rdi
movl $0x2, %r8d
movb $0x1, %cl
cmpq %rax, %rdi
jae 0x17081
movl %r8d, %r9d
leaq 0x5ef5a(%rip), %r10     # 0x75fb0
movzbl (%rdi), %r11d
testb $0x1, (%r11,%r10)
je 0x1706b
addq %r9, %rdi
cmpq %rax, %rdi
jb 0x17056
jmp 0x17081
cmpl $0x2b, %r11d
je 0x1707e
cmpl $0x2d, %r11d
jne 0x17081
addq %r9, %rdi
xorl %ecx, %ecx
jmp 0x17081
addq %r9, %rdi
movq %rdi, %r9
cmpq %rax, %rdi
jae 0x1709d
movl %r8d, %r10d
movq %rdi, %r9
cmpb $0x30, (%r9)
jne 0x1709d
addq %r10, %r9
cmpq %rax, %r9
jb 0x1708f
cmpq %rax, %r9
jae 0x170ed
movl %r8d, %r15d
xorl %r10d, %r10d
xorl %ebx, %ebx
movzbl (%r9,%r10), %r14d
leal -0x30(%r14), %r11d
cmpb $0xa, %r11b
setb %r11b
jae 0x170d5
leaq (%rbx,%rbx,4), %rbx
leaq (%r14,%rbx,2), %rbx
addq $-0x30, %rbx
addq %r15, %r10
leaq (%r9,%r10), %r12
cmpq %rax, %r12
jb 0x170aa
testq %r14, %r14
sete %r14b
testq %rbx, %rbx
jns 0x170f8
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
jmp 0x17104
xorl %r10d, %r10d
movb $0x1, %r14b
movb $0x1, %r11b
xorl %ebx, %ebx
movq %rbx, %rax
negq %rax
testb %cl, %cl
cmovneq %rbx, %rax
orb %r11b, %r14b
movq %rax, (%rsi)
movl $0x1, %eax
cmpb $0x1, %r14b
jne 0x1719c
testl %r10d, %r10d
jne 0x17123
cmpq %r9, %rdi
je 0x1719c
leal (%r8,%r8,8), %esi
leal (%r8,%rsi,2), %esi
cmpl %esi, %r10d
seta %dil
orb %dil, %dl
jne 0x1719c
cmpl %esi, %r10d
jb 0x1719a
movl %r8d, %eax
xorl %edx, %edx
leaq 0x662b9(%rip), %rsi     # 0x7d401
movq %r9, %rdi
movb (%rdi), %r8b
movb (%rdx,%rsi), %r10b
cmpq $0x10, %rdx
ja 0x17163
incq %rdx
addq %rax, %rdi
cmpb %r10b, %r8b
je 0x1714b
cmpb %r10b, %r8b
jne 0x17176
leaq (%rax,%rax,8), %rax
movsbl (%r9,%rax,2), %eax
addl $-0x38, %eax
jmp 0x17185
movsbl %r8b, %eax
movsbl %r10b, %edx
subl %edx, %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
testl %eax, %eax
js 0x1719a
movzbl %cl, %ecx
addl %ecx, %ecx
testl %eax, %eax
movl $0x1, %eax
cmovel %ecx, %eax
jmp 0x1719c
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq