// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: substrFunc
static void substrFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const unsigned char *z;
  const unsigned char *z2;
  int len;
  int p0type;
  i64 p1, p2;
  int negP2 = 0;

  assert( argc==3 || argc==2 );
  if( sqlite3_value_type(argv[1])==SQLITE_NULL
   || (argc==3 && sqlite3_value_type(argv[2])==SQLITE_NULL)
  ){
    return;
  }
  p0type = sqlite3_value_type(argv[0]);
  p1 = sqlite3_value_int(argv[1]);
  if( p0type==SQLITE_BLOB ){
    len = sqlite3_value_bytes(argv[0]);
    z = sqlite3_value_blob(argv[0]);
    if( z==0 ) return;
    assert( len==sqlite3_value_bytes(argv[0]) );
  }else{
    z = sqlite3_value_text(argv[0]);
    if( z==0 ) return;
    len = 0;
    if( p1<0 ){
      for(z2=z; *z2; len++){
        SQLITE_SKIP_UTF8(z2);
      }
    }
  }
#ifdef SQLITE_SUBSTR_COMPATIBILITY
  /* If SUBSTR_COMPATIBILITY is defined then substr(X,0,N) work the same as
  ** as substr(X,1,N) - it returns the first N characters of X.  This
  ** is essentially a back-out of the bug-fix in check-in [5fc125d362df4b8]
  ** from 2009-02-02 for compatibility of applications that exploited the
  ** old buggy behavior. */
  if( p1==0 ) p1 = 1; /* <rdar://problem/6778339> */
#endif
  if( argc==3 ){
    p2 = sqlite3_value_int(argv[2]);
    if( p2<0 ){
      p2 = -p2;
      negP2 = 1;
    }
  }else{
    p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH];
  }
  if( p1<0 ){
    p1 += len;
    if( p1<0 ){
      p2 += p1;
      if( p2<0 ) p2 = 0;
      p1 = 0;
    }
  }else if( p1>0 ){
    p1--;
  }else if( p2>0 ){
    p2--;
  }
  if( negP2 ){
    p1 -= p2;
    if( p1<0 ){
      p2 += p1;
      p1 = 0;
    }
  }
  assert( p1>=0 && p2>=0 );
  if( p0type!=SQLITE_BLOB ){
    while( *z && p1 ){
      SQLITE_SKIP_UTF8(z);
      p1--;
    }
    for(z2=z; *z2 && p2; p2--){
      SQLITE_SKIP_UTF8(z2);
    }
    sqlite3_result_text64(context, (char*)z, z2-z, SQLITE_TRANSIENT,
                          SQLITE_UTF8);
  }else{
    if( p1+p2>len ){
      p2 = len-p1;
      if( p2<0 ) p2 = 0;
    }
    sqlite3_result_blob64(context, (char*)&z[p1], (u64)p2, SQLITE_TRANSIENT);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rdi, %rdx
movabsq $-0x5555555555555556, %rax # imm = 0xAAAAAAAAAAAAAAAA
movq 0x8(%r15), %rdi
movl 0x8(%rdi), %ecx
btq %rcx, %rax
jb 0x286a36
movl %esi, %ebp
cmpl $0x3, %esi
jne 0x286985
movq 0x10(%r15), %rcx
movl 0x8(%rcx), %ecx
btq %rcx, %rax
jb 0x286a36
movq %rdx, (%rsp)
movq (%r15), %rax
movl 0x8(%rax), %r14d
callq 0x224451
movabsq $0x1000000010001, %rdx  # imm = 0x1000000010001
movq %rdx, %rbx
movl %r14d, %ecx
shrq %cl, %rbx
movq %rax, %r12
btq %r14, %rdx
movq (%r15), %rdi
jb 0x2869f5
callq 0x2243e3
testq %rax, %rax
movq (%rsp), %rdi
je 0x286a36
movq %rax, %r14
xorl %r13d, %r13d
testl %r12d, %r12d
jns 0x286a11
xorl %r13d, %r13d
movq %r14, %rax
movb (%rax), %cl
testb %cl, %cl
je 0x286a11
cmpb $-0x40, %cl
jb 0x2869ed
movb 0x1(%rax), %cl
incq %rax
andb $-0x40, %cl
negb %cl
jo 0x2869de
jmp 0x2869f0
incq %rax
incl %r13d
jmp 0x2869d3
callq 0x2243eb
movl %eax, %r13d
movq (%r15), %rdi
callq 0x22434b
testq %rax, %rax
movq (%rsp), %rdi
je 0x286a36
movq %rax, %r14
cmpl $0x3, %ebp
jne 0x286a45
movq 0x10(%r15), %rdi
callq 0x224451
movq (%rsp), %rdi
cltq
movq %rax, %rcx
negq %rcx
testl %eax, %eax
setns %dl
cmovnsq %rax, %rcx
jmp 0x286a52
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rdi), %rax
movq 0x28(%rax), %rax
movslq 0x7c(%rax), %rcx
movb $0x1, %dl
movslq %r12d, %r8
movslq %r13d, %rsi
testl %r12d, %r12d
js 0x286a64
je 0x286a78
decq %r8
jmp 0x286a86
addq %rsi, %r8
jns 0x286a86
addq %r8, %rcx
xorl %r8d, %r8d
testq %rcx, %rcx
cmovleq %r8, %rcx
jmp 0x286a86
xorl %eax, %eax
testq %rcx, %rcx
setg %al
subq %rax, %rcx
xorl %r8d, %r8d
movq %r8, %rax
subq %rcx, %rax
xorl %r9d, %r9d
testq %rax, %rax
cmovgq %rax, %r9
movq %rcx, %rax
cmovsq %r8, %rax
testb %dl, %dl
cmovneq %r8, %r9
cmovneq %rcx, %rax
testb $0x1, %bl
jne 0x286ad8
movb (%r14), %cl
addq $-0x1, %r9
setb %dl
testb %cl, %cl
je 0x286b0e
testb %dl, %dl
je 0x286b0e
cmpb $-0x40, %cl
jb 0x286ad3
movb 0x1(%r14), %cl
incq %r14
andb $-0x40, %cl
negb %cl
jo 0x286ac3
jmp 0x286aac
incq %r14
jmp 0x286aac
leaq (%rax,%r9), %rcx
movq %rsi, %r8
subq %r9, %r8
xorl %edx, %edx
testq %r8, %r8
cmovgq %r8, %rdx
cmpq %rsi, %rcx
cmovleq %rax, %rdx
addq %r9, %r14
pushq $-0x1
popq %rcx
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22463e
movq %r14, %rdx
addq $-0x1, %rax
setb %sil
testb %cl, %cl
je 0x286b41
testb %sil, %sil
je 0x286b41
cmpb $-0x40, %cl
jb 0x286b3a
movb 0x1(%rdx), %cl
incq %rdx
movl %ecx, %esi
andb $-0x40, %sil
negb %sil
jo 0x286b27
jmp 0x286b11
incq %rdx
movb (%rdx), %cl
jmp 0x286b11
subq %r14, %rdx
pushq $-0x1
popq %rcx
pushq $0x1
popq %r8
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2249ce