// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3c7cc0
cmpl $0x5, %eax
je 0x4678f4
cmpl $0x3, -0xc(%rbp)
jne 0x4678f9
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3c7cc0
cmpl $0x5, %eax
jne 0x4678f9
jmp 0x467c25
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3c7cc0
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3c7a40
cltq
movq %rax, -0x38(%rbp)
cmpl $0x4, -0x30(%rbp)
jne 0x467951
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3c78a0
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3c7710
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x46794c
jmp 0x467c25
jmp 0x4679db
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3c7880
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x46796d
jmp 0x467c25
movl $0x0, -0x2c(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x4679d9
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpb $0x0, (%rax)
je 0x4679d7
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movzbl (%rax), %eax
cmpl $0xc0, %eax
jl 0x4679ca
jmp 0x4679a7
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
jne 0x4679c8
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x4679a7
jmp 0x4679ca
jmp 0x4679cc
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x467983
jmp 0x4679d9
jmp 0x4679db
cmpl $0x3, -0xc(%rbp)
jne 0x467a0e
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3c7a40
cltq
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jge 0x467a0c
xorl %eax, %eax
subq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x467a1f
movq -0x8(%rbp), %rdi
callq 0x3c9230
movslq 0x7c(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x467a5e
movslq -0x2c(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x467a5c
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jge 0x467a54
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x467a8a
cmpq $0x0, -0x38(%rbp)
jle 0x467a73
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x467a88
cmpq $0x0, -0x40(%rbp)
jle 0x467a86
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x467a88
jmp 0x467a8a
cmpl $0x0, -0x44(%rbp)
je 0x467abc
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jge 0x467aba
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x467abc
cmpl $0x4, -0x30(%rbp)
je 0x467bdb
jmp 0x467ac8
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x45(%rbp)
je 0x467ae4
cmpq $0x0, -0x38(%rbp)
setne %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x467aed
jmp 0x467b39
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl (%rax), %eax
cmpl $0xc0, %eax
jl 0x467b2b
jmp 0x467b08
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
jne 0x467b29
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x467b08
jmp 0x467b2b
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x467ac8
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x46(%rbp)
je 0x467b5d
cmpq $0x0, -0x40(%rbp)
setne %al
movb %al, -0x46(%rbp)
movb -0x46(%rbp), %al
testb $0x1, %al
jne 0x467b66
jmp 0x467bb4
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movzbl (%rax), %eax
cmpl $0xc0, %eax
jl 0x467ba4
jmp 0x467b81
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
jne 0x467ba2
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x467b81
jmp 0x467ba4
jmp 0x467ba6
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x467b41
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rax
subq %rax, %rdx
movq $-0x1, %rcx
movl $0x1, %r8d
callq 0x3c8700
jmp 0x467c25
movq -0x38(%rbp), %rax
addq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpq %rcx, %rax
jle 0x467c09
movslq -0x2c(%rbp), %rax
subq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jge 0x467c07
movq $0x0, -0x40(%rbp)
jmp 0x467c09
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq $-0x1, %rcx
callq 0x3c7fe0
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)