// File: /workspace/github_c_makefile_star2_O3/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 0x63bd6
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 0x63bea
movq 0x10(%r13), %rax
cmpb $0x5, 0x26(%rax)
je 0x63bc7
movq (%r13), %rax
movb 0x26(%rax), %r14b
callq 0xeeac
movq %rax, -0x38(%rbp)
movq (%r13), %rdi
movb %r14b, -0x29(%rbp)
movl $0x1, %esi
cmpb $0x4, %r14b
jne 0x63c2c
callq 0xee02
movl %eax, %r15d
movq (%r13), %rdi
callq 0xed3b
testq %rax, %rax
je 0x63bc7
movq %rax, %r14
movq %r12, %rdi
jmp 0x63c74
callq 0xef29
testq %rax, %rax
je 0x63bc7
movq %rax, %r14
movq %r12, %rdi
xorl %r15d, %r15d
cmpl $0x0, -0x38(%rbp)
jns 0x63c74
movb (%r14), %cl
testb %cl, %cl
je 0x63c74
xorl %r15d, %r15d
movq %r14, %rax
cmpb $-0x40, %cl
jb 0x63c68
movb 0x1(%rax), %cl
incq %rax
movl %ecx, %edx
andb $-0x40, %dl
negb %dl
jo 0x63c57
jmp 0x63c6d
incq %rax
movb (%rax), %cl
incl %r15d
testb %cl, %cl
jne 0x63c52
cmpl $0x3, %ebx
jne 0x63c99
movq 0x10(%r13), %rdi
callq 0xeeac
movq %r12, %rdi
cltq
movq %rax, %rcx
negq %rcx
testl %eax, %eax
setns %sil
cmovnsq %rax, %rcx
jmp 0x63ca4
movq 0x8(%rdi), %rax
movslq 0x68(%rax), %rcx
movb $0x1, %sil
movq -0x38(%rbp), %rax
movslq %eax, %r8
testl %eax, %eax
js 0x63cb6
je 0x63ccd
decq %r8
jmp 0x63cdb
movslq %r15d, %rax
addq %rax, %r8
jns 0x63cdb
addq %r8, %rcx
xorl %r8d, %r8d
testq %rcx, %rcx
cmovleq %r8, %rcx
jmp 0x63cdb
xorl %eax, %eax
testq %rcx, %rcx
setg %al
subq %rax, %rcx
xorl %r8d, %r8d
movq %r8, %rdx
subq %rcx, %rdx
xorl %eax, %eax
testq %rdx, %rdx
cmovgq %rdx, %rax
movq %rcx, %rdx
cmovsq %r8, %rdx
testb %sil, %sil
cmovneq %r8, %rax
cmovneq %rcx, %rdx
cmpb $0x4, -0x29(%rbp)
jne 0x63d2a
leaq (%rdx,%rax), %rcx
movslq %r15d, %rsi
movq %rsi, %r9
subq %rax, %r9
xorl %r8d, %r8d
testq %r9, %r9
cmovleq %r8, %r9
addq %rax, %r14
cmpq %rsi, %rcx
cmovgl %r9d, %edx
movq %r14, %rsi
xorl %ecx, %ecx
jmp 0x63da3
movb (%r14), %cl
testb %cl, %cl
je 0x63d5e
testq %rax, %rax
je 0x63d5e
cmpb $-0x40, %cl
jb 0x63d4f
movb 0x1(%r14), %cl
incq %r14
movl %ecx, %esi
andb $-0x40, %sil
negb %sil
jo 0x63d3b
jmp 0x63d55
incq %r14
movb (%r14), %cl
testb %cl, %cl
je 0x63d5e
decq %rax
jne 0x63d36
movq %r14, %rax
testb %cl, %cl
je 0x63d96
movq %r14, %rax
testq %rdx, %rdx
je 0x63d96
movq %r14, %rax
cmpb $-0x40, %cl
jb 0x63d88
movb 0x1(%rax), %cl
incq %rax
movl %ecx, %esi
andb $-0x40, %sil
negb %sil
jo 0x63d75
jmp 0x63d8d
incq %rax
movb (%rax), %cl
testb %cl, %cl
je 0x63d96
decq %rdx
jne 0x63d70
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 0xeffe