// File: /workspace/github_c_makefile_star2_O1/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 0x2f4bb4
movl %esi, %r12d
cmpl $0x3, %esi
jne 0x2f4af9
movq 0x10(%r15), %rcx
movl 0x8(%rcx), %ecx
btq %rcx, %rax
jb 0x2f4bb4
movq %rdx, (%rsp)
movq (%r15), %rax
movl 0x8(%rax), %r14d
callq 0x281c1d
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 0x2f4b72
callq 0x281c96
testq %rax, %rax
movq (%rsp), %rdi
je 0x2f4bb4
movq %rax, %r14
xorl %ebp, %ebp
testl %r13d, %r13d
jns 0x2f4b8d
movb (%r14), %cl
testb %cl, %cl
je 0x2f4b8d
xorl %ebp, %ebp
movq %r14, %rax
cmpb $-0x40, %cl
jb 0x2f4b65
movb 0x1(%rax), %cl
incq %rax
andb $-0x40, %cl
negb %cl
jo 0x2f4b56
jmp 0x2f4b68
incq %rax
incl %ebp
movb (%rax), %cl
testb %cl, %cl
jne 0x2f4b51
jmp 0x2f4b8d
callq 0x281bba
movl %eax, %ebp
movq (%r15), %rdi
callq 0x281b13
testq %rax, %rax
movq (%rsp), %rdi
je 0x2f4bb4
movq %rax, %r14
cmpl $0x3, %r12d
jne 0x2f4bc3
movq 0x10(%r15), %rdi
callq 0x281c1d
movq (%rsp), %rdi
cltq
movq %rax, %rdx
negq %rdx
testl %eax, %eax
setns %sil
cmovnsq %rax, %rdx
jmp 0x2f4bd1
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), %rdx
movb $0x1, %sil
movslq %r13d, %r8
testl %r13d, %r13d
js 0x2f4be0
je 0x2f4bf7
decq %r8
jmp 0x2f4c05
movslq %ebp, %rax
addq %rax, %r8
jns 0x2f4c05
addq %r8, %rdx
xorl %r8d, %r8d
testq %rdx, %rdx
cmovleq %r8, %rdx
jmp 0x2f4c05
xorl %eax, %eax
testq %rdx, %rdx
setg %al
subq %rax, %rdx
xorl %r8d, %r8d
movq %r8, %rax
subq %rdx, %rax
xorl %ecx, %ecx
testq %rax, %rax
cmovgq %rax, %rcx
movq %rdx, %rax
cmovsq %r8, %rax
testb %sil, %sil
cmovneq %r8, %rcx
cmovneq %rdx, %rax
testb $0x1, %bl
jne 0x2f4cbc
movb (%r14), %dl
testb %dl, %dl
je 0x2f4c5f
testq %rcx, %rcx
je 0x2f4c5f
cmpb $-0x40, %dl
jb 0x2f4c50
movb 0x1(%r14), %dl
incq %r14
andb $-0x40, %dl
negb %dl
jo 0x2f4c40
jmp 0x2f4c53
incq %r14
movb (%r14), %dl
testb %dl, %dl
je 0x2f4c5f
decq %rcx
jne 0x2f4c3b
movb (%r14), %cl
movq %r14, %rdx
testb %cl, %cl
je 0x2f4c96
movq %r14, %rdx
testq %rax, %rax
je 0x2f4c96
movq %r14, %rdx
cmpb $-0x40, %cl
jb 0x2f4c88
movb 0x1(%rdx), %cl
incq %rdx
andb $-0x40, %cl
negb %cl
jo 0x2f4c79
jmp 0x2f4c8b
incq %rdx
movb (%rdx), %cl
testb %cl, %cl
je 0x2f4c96
decq %rax
jne 0x2f4c74
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 0x2822bc
leaq (%rax,%rcx), %rsi
movslq %ebp, %r9
movq %r9, %r8
subq %rcx, %r8
xorl %edx, %edx
testq %r8, %r8
cmovgq %r8, %rdx
cmpq %r9, %rsi
cmovleq %rax, %rdx
addq %rcx, %r14
movq %r14, %rsi
movq $-0x1, %rcx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x281e51