// File: /workspace/github_c_makefile_star2_O3/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 0x2eb8de
movl %esi, %r12d
cmpl $0x3, %esi
jne 0x2eb822
movq 0x10(%r15), %rcx
movl 0x8(%rcx), %ecx
btq %rcx, %rax
jb 0x2eb8de
movq %rdx, (%rsp)
movq (%r15), %rax
movl 0x8(%rax), %r14d
callq 0x27828c
movabsq $0x1000000010001, %rdx  # imm = 0x1000000010001
movq %rdx, %rbx
movl %r14d, %ecx
shrq %cl, %rbx
movq %rax, %r13
btq %r14, %rdx
movq (%r15), %rdi
movl $0x1, %esi
jb 0x2eb89d
callq 0x278305
testq %rax, %rax
movq (%rsp), %rdi
je 0x2eb8de
movq %rax, %r14
xorl %ebp, %ebp
testl %r13d, %r13d
jns 0x2eb8b8
movb (%r14), %cl
testb %cl, %cl
je 0x2eb8b8
xorl %ebp, %ebp
movq %r14, %rax
cmpb $-0x40, %cl
jb 0x2eb890
movb 0x1(%rax), %cl
incq %rax
movl %ecx, %edx
andb $-0x40, %dl
negb %dl
jo 0x2eb87f
jmp 0x2eb895
incq %rax
movb (%rax), %cl
incl %ebp
testb %cl, %cl
jne 0x2eb87a
jmp 0x2eb8b8
callq 0x278229
movl %eax, %ebp
movq (%r15), %rdi
callq 0x278177
testq %rax, %rax
movq (%rsp), %rdi
je 0x2eb8de
movq %rax, %r14
cmpl $0x3, %r12d
jne 0x2eb8ed
movq 0x10(%r15), %rdi
callq 0x27828c
movq (%rsp), %rdi
cltq
movq %rax, %rcx
negq %rcx
testl %eax, %eax
setns %dl
cmovnsq %rax, %rcx
jmp 0x2eb8fa
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 %r13d, %r8
testl %r13d, %r13d
js 0x2eb909
je 0x2eb920
decq %r8
jmp 0x2eb92e
movslq %ebp, %rax
addq %rax, %r8
jns 0x2eb92e
addq %r8, %rcx
xorl %r8d, %r8d
testq %rcx, %rcx
cmovleq %r8, %rcx
jmp 0x2eb92e
xorl %eax, %eax
testq %rcx, %rcx
setg %al
subq %rax, %rcx
xorl %r8d, %r8d
movq %r8, %rax
subq %rcx, %rax
xorl %esi, %esi
testq %rax, %rax
cmovgq %rax, %rsi
movq %rcx, %rax
cmovsq %r8, %rax
testb %dl, %dl
cmovneq %r8, %rsi
cmovneq %rcx, %rax
testb $0x1, %bl
jne 0x2eb9e7
movb (%r14), %cl
testb %cl, %cl
je 0x2eb989
testq %rsi, %rsi
je 0x2eb989
cmpb $-0x40, %cl
jb 0x2eb97a
movb 0x1(%r14), %cl
incq %r14
movl %ecx, %edx
andb $-0x40, %dl
negb %dl
jo 0x2eb968
jmp 0x2eb980
incq %r14
movb (%r14), %cl
testb %cl, %cl
je 0x2eb989
decq %rsi
jne 0x2eb963
movq %r14, %rdx
testb %cl, %cl
je 0x2eb9c1
movq %r14, %rdx
testq %rax, %rax
je 0x2eb9c1
movq %r14, %rdx
cmpb $-0x40, %cl
jb 0x2eb9b3
movb 0x1(%rdx), %cl
incq %rdx
movl %ecx, %esi
andb $-0x40, %sil
negb %sil
jo 0x2eb9a0
jmp 0x2eb9b8
incq %rdx
movb (%rdx), %cl
testb %cl, %cl
je 0x2eb9c1
decq %rax
jne 0x2eb99b
subq %r14, %rdx
movq %r14, %rsi
movq $-0x1, %rcx
movl $0x1, %r8d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x27891d
leaq (%rax,%rsi), %rcx
movslq %ebp, %r9
movq %r9, %r8
subq %rsi, %r8
xorl %edx, %edx
testq %r8, %r8
cmovgq %r8, %rdx
cmpq %r9, %rcx
cmovleq %rax, %rdx
addq %rsi, %r14
movq %r14, %rsi
movq $-0x1, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2784be