// File: /workspace/github_c_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
cmpl $0x1, %ecx
jne 0x16fbe
movslq %edx, %rax
addq %rdi, %rax
movl $0x1, %r9d
xorl %r8d, %r8d
jmp 0x17029
movl $0x3, %r9d
subl %ecx, %r9d
movzbl %cl, %eax
cmpl %edx, %r9d
setl %r8b
jge 0x17010
movl %ecx, %r10d
movl $0x3, %r9d
subq %r10, %r9
cmpb $0x0, (%rdi,%r9)
jne 0x17010
movslq %edx, %rdx
movl $0x5, %r9d
subq %rax, %r9
cmpq %rdx, %r9
setl %r8b
jge 0x17010
leaq 0x2(%r9), %r10
cmpb $0x0, (%rdi,%r9)
movq %r10, %r9
je 0x16ff2
addl $-0x2, %r10d
movl %r10d, %r9d
movslq %r9d, %rdx
addq %rdi, %rdx
addq %rdx, %rax
addq $-0x3, %rax
andl $0x1, %ecx
addq %rcx, %rdi
movl $0x2, %r9d
movb $0x1, %cl
movl %r9d, %edx
cmpq %rax, %rdi
jae 0x17065
leaq 0x5ef26(%rip), %r10     # 0x75f60
movzbl (%rdi), %r11d
testb $0x1, (%r11,%r10)
je 0x1704f
addq %rdx, %rdi
cmpq %rax, %rdi
jb 0x1703a
jmp 0x17065
cmpl $0x2b, %r11d
je 0x17062
cmpl $0x2d, %r11d
jne 0x17065
addq %rdx, %rdi
xorl %ecx, %ecx
jmp 0x17065
addq %rdx, %rdi
movq %rdi, %r10
cmpq %rax, %rdi
jae 0x1707e
movq %rdi, %r10
cmpb $0x30, (%r10)
jne 0x1707e
addq %rdx, %r10
cmpq %rax, %r10
jb 0x17070
cmpq %rax, %r10
setae %bl
jb 0x17091
xorl %r14d, %r14d
movb $0x1, %r15b
xorl %r11d, %r11d
jmp 0x170e3
movb (%r10), %r15b
leal -0x30(%r15), %r11d
cmpb $0x9, %r11b
ja 0x170d6
leaq (%r10,%rdx), %r12
xorl %r14d, %r14d
xorl %r11d, %r11d
movzbl %r15b, %ebx
leaq (%r14,%r14,4), %r14
leaq (%rbx,%r14,2), %r14
addq $-0x30, %r14
addl %r9d, %r11d
cmpq %rax, %r12
setae %bl
jae 0x170dc
movb (%r12), %r15b
leal -0x30(%r15), %r13d
addq %rdx, %r12
cmpb $0x9, %r13b
jbe 0x170a8
jmp 0x170dc
xorl %r14d, %r14d
xorl %r11d, %r11d
testb %r15b, %r15b
sete %r15b
movq %r14, %rax
negq %rax
testb %cl, %cl
cmovneq %r14, %rax
testq %r14, %r14
movabsq $-0x8000000000000000, %r14 # imm = 0x8000000000000000
cmovnsq %rax, %r14
movq %r14, (%rsi)
movl $0x1, %eax
testb %bl, %bl
jne 0x17115
testb %r15b, %r15b
je 0x17195
testl %r11d, %r11d
jne 0x1711f
cmpq %r10, %rdi
je 0x17195
leal (%r9,%r9,8), %esi
leal (%r9,%rsi,2), %esi
cmpl %esi, %r11d
seta %dil
orb %dil, %r8b
jne 0x17195
cmpl %esi, %r11d
jb 0x17193
xorl %eax, %eax
leaq 0x662c0(%rip), %rsi     # 0x7d401
movq %r10, %rdi
movb (%rdi), %r8b
movb (%rax,%rsi), %r9b
cmpq $0x10, %rax
ja 0x1715c
incq %rax
addq %rdx, %rdi
cmpb %r9b, %r8b
je 0x17144
cmpb %r9b, %r8b
jne 0x1716f
leaq (%rdx,%rdx,8), %rax
movsbl (%r10,%rax,2), %eax
addl $-0x38, %eax
jmp 0x1717e
movsbl %r8b, %eax
movsbl %r9b, %edx
subl %edx, %eax
addl %eax, %eax
leal (%rax,%rax,4), %eax
testl %eax, %eax
js 0x17193
movzbl %cl, %ecx
addl %ecx, %ecx
testl %eax, %eax
movl $0x1, %eax
cmovel %ecx, %eax
jmp 0x17195
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq