// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq 0x8(%rdx), %rdi
cmpb $0x5, 0x26(%rdi)
jne 0x584a4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r12
movl %esi, %r13d
cmpl $0x3, %esi
jne 0x584ba
movq 0x10(%r12), %rax
cmpb $0x5, 0x26(%rax)
je 0x58495
movq (%r12), %rax
movb 0x26(%rax), %bl
callq 0xdfe0
movq %rax, -0x38(%rbp)
movq (%r12), %rdi
movb %bl, -0x29(%rbp)
cmpb $0x4, %bl
jne 0x584f3
callq 0xdf2d
movl %eax, %ebx
movq (%r12), %rdi
callq 0xde7e
testq %rax, %rax
je 0x58495
movq %rax, %r14
movq %r15, %rdi
jmp 0x5850f
callq 0xdf1e
testq %rax, %rax
je 0x58495
movq %rax, %r14
movq %r15, %rdi
xorl %ebx, %ebx
cmpl $0x0, -0x38(%rbp)
js 0x58658
cmpl $0x3, %r13d
jne 0x58537
movq 0x10(%r12), %rdi
callq 0xdfe0
movq %r15, %rdi
movslq %eax, %rcx
movq %rcx, %rax
negq %rax
testl %ecx, %ecx
setns %sil
cmovnsq %rcx, %rax
jmp 0x58542
movq 0x8(%rdi), %rax
movslq 0x68(%rax), %rax
movb $0x1, %sil
movb -0x29(%rbp), %r10b
movq -0x38(%rbp), %rdx
movslq %edx, %r8
movslq %ebx, %rcx
testl %edx, %edx
js 0x5855b
je 0x5856f
decq %r8
jmp 0x5857d
addq %rcx, %r8
jns 0x5857d
addq %r8, %rax
xorl %r8d, %r8d
testq %rax, %rax
cmovleq %r8, %rax
jmp 0x5857d
xorl %edx, %edx
testq %rax, %rax
setg %dl
subq %rdx, %rax
xorl %r8d, %r8d
movq %r8, %rdx
subq %rax, %rdx
xorl %r9d, %r9d
testq %rdx, %rdx
cmovgq %rdx, %r9
movq %rax, %rdx
cmovsq %r8, %rdx
testb %sil, %sil
cmovneq %r8, %r9
cmovneq %rax, %rdx
cmpb $0x4, %r10b
jne 0x585dc
leaq (%rdx,%r9), %rax
movq %rcx, %rsi
subq %r9, %rsi
xorl %r8d, %r8d
testq %rsi, %rsi
cmovgq %rsi, %r8
addq %r9, %r14
cmpq %rcx, %rax
cmovgl %r8d, %edx
pushq $-0x1
popq %rcx
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe123
movb (%r14), %cl
addq $-0x1, %r9
setb %al
testb %cl, %cl
je 0x58607
testb %al, %al
je 0x58607
cmpb $-0x40, %cl
jb 0x58602
movb 0x1(%r14), %al
incq %r14
andb $-0x40, %al
negb %al
jo 0x585f3
jmp 0x585dc
incq %r14
jmp 0x585dc
movq %r14, %rax
addq $-0x1, %rdx
setb %sil
testb %cl, %cl
je 0x5863a
testb %sil, %sil
je 0x5863a
cmpb $-0x40, %cl
jb 0x58633
movb 0x1(%rax), %cl
incq %rax
movl %ecx, %esi
andb $-0x40, %sil
negb %sil
jo 0x58620
jmp 0x5860a
incq %rax
movb (%rax), %cl
jmp 0x5860a
subl %r14d, %eax
pushq $-0x1
popq %rcx
movq %r14, %rsi
movl %eax, %edx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe48d
xorl %ebx, %ebx
movq %r14, %rax
movb (%rax), %cl
testb %cl, %cl
je 0x5850f
cmpb $-0x40, %cl
jb 0x5867b
movb 0x1(%rax), %cl
incq %rax
andb $-0x40, %cl
negb %cl
jo 0x5866c
jmp 0x5867e
incq %rax
incl %ebx
jmp 0x5865d