// File: /workspace/github_c_makefile_star2_O2/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
movslq %edx, %r8
cmpl $0x1, %ecx
jne 0x152b6
addq %rdi, %r8
movl $0x1, %ecx
xorl %r9d, %r9d
jmp 0x15314
movl $0x3, %eax
subl %ecx, %eax
movslq %eax, %r10
movzbl %cl, %eax
movq %rax, %r9
shlq $0x20, %r9
movabsq $0x300000000, %rdx      # imm = 0x300000000
subq %r9, %rdx
movabsq $0x200000000, %r11      # imm = 0x200000000
cmpq %r8, %r10
setl %r9b
jge 0x152fa
cmpb $0x0, (%rdi,%r10)
jne 0x152fa
addq $0x2, %r10
addq %r11, %rdx
jmp 0x152e1
sarq $0x20, %rdx
addq %rdi, %rdx
leaq (%rax,%rdx), %r8
addq $-0x3, %r8
andl $0x1, %ecx
addq %rcx, %rdi
movl $0x2, %ecx
movl $0x1, %eax
movl %ecx, %ecx
leaq 0x52c4e(%rip), %r10     # 0x67f70
movb $0x1, %dl
cmpq %r8, %rdi
jae 0x1534f
movzbl (%rdi), %r11d
testb $0x1, (%r11,%r10)
je 0x15339
addq %rcx, %rdi
jmp 0x15322
cmpl $0x2b, %r11d
je 0x1534c
cmpl $0x2d, %r11d
jne 0x1534f
addq %rcx, %rdi
xorl %edx, %edx
jmp 0x1534f
addq %rcx, %rdi
xorl %r10d, %r10d
cmpq %r8, %rdi
jae 0x15364
cmpb $0x30, (%rdi)
jne 0x15364
addq %rcx, %rdi
subq %rcx, %r10
jmp 0x15352
xorl %r11d, %r11d
xorl %r14d, %r14d
xorl %ebx, %ebx
leaq (%rdi,%r11), %r15
cmpq %r8, %r15
jae 0x15396
movsbl (%r15), %ebx
leal -0x30(%rbx), %r12d
cmpb $0x9, %r12b
ja 0x15396
imulq $0xa, %r14, %r14
movl %ebx, %r15d
addq %r15, %r14
addq $-0x30, %r14
addq %rcx, %r11
jmp 0x1536c
cmpq %r8, %r15
setb %r8b
movq %r14, %r15
negq %r15
testb %dl, %dl
cmovneq %r14, %r15
testq %r14, %r14
movabsq $-0x8000000000000000, %r14 # imm = 0x8000000000000000
cmovnsq %r15, %r14
movq %r14, (%rsi)
testl %ebx, %ebx
setne %sil
testb %sil, %r8b
jne 0x15436
orq %r11, %r10
je 0x15436
imull $0x13, %ecx, %esi
cmpl %r11d, %esi
setb %r8b
orb %r8b, %r9b
jne 0x15436
cmpl %r11d, %esi
ja 0x15434
xorl %esi, %esi
leaq 0x5a037(%rip), %r8      # 0x6f421
movq %rdi, %r9
xorl %eax, %eax
testl %eax, %eax
jne 0x15410
cmpq $0x11, %rsi
ja 0x15410
movsbl (%r9), %eax
movsbl (%rsi,%r8), %r10d
subl %r10d, %eax
imull $0xa, %eax, %eax
incq %rsi
addq %rcx, %r9
jmp 0x153ef
testl %eax, %eax
jne 0x1541f
imulq $0x12, %rcx, %rax
movsbl (%rdi,%rax), %eax
addl $-0x38, %eax
testl %eax, %eax
js 0x15434
movzbl %dl, %ecx
addl %ecx, %ecx
testl %eax, %eax
movl $0x1, %eax
cmovel %ecx, %eax
jmp 0x15436
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq