// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/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);
      }
    }
  }
  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_text(context, (char*)z, (int)(z2-z), SQLITE_TRANSIENT);
  }else{
    if( p1+p2>len ){
      p2 = len-p1;
      if( p2<0 ) p2 = 0;
    }
    sqlite3_result_blob(context, (char*)&z[p1], (int)p2, SQLITE_TRANSIENT);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r12
movq 0x8(%rdx), %rdi
cmpb $0x5, 0x26(%rdi)
jne 0x63d99
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r13
movl %esi, %ebx
cmpl $0x3, %esi
jne 0x63dad
movq 0x10(%r13), %rax
cmpb $0x5, 0x26(%rax)
je 0x63d8a
movq (%r13), %rax
movb 0x26(%rax), %r14b
callq 0xedcc
movq %rax, -0x38(%rbp)
movq (%r13), %rdi
movb %r14b, -0x29(%rbp)
movl $0x1, %esi
cmpb $0x4, %r14b
jne 0x63def
callq 0xed28
movl %eax, %r15d
movq (%r13), %rdi
callq 0xec61
testq %rax, %rax
je 0x63d8a
movq %rax, %r14
movq %r12, %rdi
jmp 0x63e35
callq 0xee49
testq %rax, %rax
je 0x63d8a
movq %rax, %r14
movq %r12, %rdi
xorl %r15d, %r15d
cmpl $0x0, -0x38(%rbp)
jns 0x63e35
movb (%r14), %cl
testb %cl, %cl
je 0x63e35
xorl %r15d, %r15d
movq %r14, %rax
cmpb $-0x40, %cl
jb 0x63e29
movb 0x1(%rax), %cl
incq %rax
andb $-0x40, %cl
negb %cl
jo 0x63e1a
jmp 0x63e2c
incq %rax
incl %r15d
movb (%rax), %cl
testb %cl, %cl
jne 0x63e15
cmpl $0x3, %ebx
jne 0x63e5b
movq 0x10(%r13), %rdi
callq 0xedcc
movq %r12, %rdi
movslq %eax, %rcx
movq %rcx, %rax
negq %rax
testl %ecx, %ecx
setns %sil
cmovnsq %rcx, %rax
jmp 0x63e66
movq 0x8(%rdi), %rax
movslq 0x68(%rax), %rax
movb $0x1, %sil
movq -0x38(%rbp), %rcx
movslq %ecx, %r8
testl %ecx, %ecx
js 0x63e78
je 0x63e8f
decq %r8
jmp 0x63e9d
movslq %r15d, %rcx
addq %rcx, %r8
jns 0x63e9d
addq %r8, %rax
xorl %r8d, %r8d
testq %rax, %rax
cmovleq %r8, %rax
jmp 0x63e9d
xorl %ecx, %ecx
testq %rax, %rax
setg %cl
subq %rcx, %rax
xorl %r8d, %r8d
movq %r8, %rdx
subq %rax, %rdx
xorl %ecx, %ecx
testq %rdx, %rdx
cmovgq %rdx, %rcx
movq %rax, %rdx
cmovsq %r8, %rdx
testb %sil, %sil
cmovneq %r8, %rcx
cmovneq %rax, %rdx
cmpb $0x4, -0x29(%rbp)
jne 0x63eec
leaq (%rdx,%rcx), %rax
movslq %r15d, %rsi
movq %rsi, %r9
subq %rcx, %r9
xorl %r8d, %r8d
testq %r9, %r9
cmovleq %r8, %r9
addq %rcx, %r14
cmpq %rsi, %rax
cmovgl %r9d, %edx
movq %r14, %rsi
xorl %ecx, %ecx
jmp 0x63f5e
movb (%r14), %al
testb %al, %al
je 0x63f1a
testq %rcx, %rcx
je 0x63f1a
cmpb $-0x40, %al
jb 0x63f0b
movb 0x1(%r14), %al
incq %r14
andb $-0x40, %al
negb %al
jo 0x63efc
jmp 0x63f0e
incq %r14
movb (%r14), %al
testb %al, %al
je 0x63f1a
decq %rcx
jne 0x63ef8
movb (%r14), %cl
movq %r14, %rax
testb %cl, %cl
je 0x63f51
movq %r14, %rax
testq %rdx, %rdx
je 0x63f51
movq %r14, %rax
cmpb $-0x40, %cl
jb 0x63f43
movb 0x1(%rax), %cl
incq %rax
andb $-0x40, %cl
negb %cl
jo 0x63f34
jmp 0x63f46
incq %rax
movb (%rax), %cl
testb %cl, %cl
je 0x63f51
decq %rdx
jne 0x63f2f
subl %r14d, %eax
movq %r14, %rsi
movl %eax, %edx
movl $0x1, %ecx
movq $-0x1, %r8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xef1b