// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: trimFunc
static void trimFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const unsigned char *zIn;         /* Input string */
  const unsigned char *zCharSet;    /* Set of characters to trim */
  int nIn;                          /* Number of bytes in input */
  int flags;                        /* 1: trimleft  2: trimright  3: trim */
  int i;                            /* Loop counter */
  unsigned char *aLen = 0;          /* Length of each character in zCharSet */
  unsigned char **azChar = 0;       /* Individual characters in zCharSet */
  int nChar;                        /* Number of characters in zCharSet */

  if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
    return;
  }
  zIn = sqlite3_value_text(argv[0]);
  if( zIn==0 ) return;
  nIn = sqlite3_value_bytes(argv[0]);
  assert( zIn==sqlite3_value_text(argv[0]) );
  if( argc==1 ){
    static const unsigned char lenOne[] = { 1 };
    static unsigned char * const azOne[] = { (u8*)" " };
    nChar = 1;
    aLen = (u8*)lenOne;
    azChar = (unsigned char **)azOne;
    zCharSet = 0;
  }else if( (zCharSet = sqlite3_value_text(argv[1]))==0 ){
    return;
  }else{
    const unsigned char *z;
    for(z=zCharSet, nChar=0; *z; nChar++){
      SQLITE_SKIP_UTF8(z);
    }
    if( nChar>0 ){
      azChar = contextMalloc(context, ((i64)nChar)*(sizeof(char*)+1));
      if( azChar==0 ){
        return;
      }
      aLen = (unsigned char*)&azChar[nChar];
      for(z=zCharSet, nChar=0; *z; nChar++){
        azChar[nChar] = (unsigned char *)z;
        SQLITE_SKIP_UTF8(z);
        aLen[nChar] = (u8)(z - azChar[nChar]);
      }
    }
  }
  if( nChar>0 ){
    flags = SQLITE_PTR_TO_INT(sqlite3_user_data(context));
    if( flags & 1 ){
      while( nIn>0 ){
        int len = 0;
        for(i=0; i<nChar; i++){
          len = aLen[i];
          if( len<=nIn && memcmp(zIn, azChar[i], len)==0 ) break;
        }
        if( i>=nChar ) break;
        zIn += len;
        nIn -= len;
      }
    }
    if( flags & 2 ){
      while( nIn>0 ){
        int len = 0;
        for(i=0; i<nChar; i++){
          len = aLen[i];
          if( len<=nIn && memcmp(&zIn[nIn-len],azChar[i],len)==0 ) break;
        }
        if( i>=nChar ) break;
        nIn -= len;
      }
    }
    if( zCharSet ){
      sqlite3_free(azChar);
    }
  }
  sqlite3_result_text(context, (char*)zIn, nIn, SQLITE_TRANSIENT);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, -0x34(%rbp)
movq %rdi, %r15
movq (%rdx), %rdi
cmpb $0x5, 0x26(%rdi)
je 0x5812d
movq %rdx, %rbx
callq 0xdf1e
testq %rax, %rax
je 0x5812d
movq %rax, %r12
movq (%rbx), %rdi
callq 0xdf2d
movl %eax, %r8d
cmpl $0x1, -0x34(%rbp)
jne 0x58092
leaq 0x12ce4(%rip), %rsi     # 0x6ac5c
leaq 0x2e819(%rip), %rdi     # 0x86798
pushq $0x1
popq %rax
movq %r15, -0x48(%rbp)
movq (%r15), %rcx
movq 0x8(%rcx), %rdx
testl %r8d, %r8d
setg %cl
movq %rdx, -0x58(%rbp)
andb %dl, %cl
movl %eax, %ebx
cmpb $0x1, %cl
movq %rdi, -0x30(%rbp)
movq %rsi, -0x50(%rbp)
jne 0x57ffa
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x57fe4
movzbl (%rsi,%r14), %r15d
cmpl %r15d, %r8d
jl 0x57fdf
movq -0x30(%rbp), %rax
movq (%rax,%r14,8), %rsi
movl %r15d, %edx
movq %r12, %rdi
movl %r8d, %r13d
callq 0x83e0
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rdi
movl %r13d, %r8d
testl %eax, %eax
je 0x57fe7
incq %r14
jmp 0x57fab
xorl %r15d, %r15d
subl %r15d, %r8d
movl %r15d, %eax
addq %rax, %r12
cmpq %rbx, %r14
jae 0x57ffa
testl %r8d, %r8d
jg 0x57fa8
testb $0x2, -0x58(%rbp)
movq %r12, -0x40(%rbp)
je 0x5805a
testl %r8d, %r8d
jle 0x5805a
movslq %r8d, %r13
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x5804f
movzbl (%rsi,%r14), %r15d
cmpl %r15d, %r8d
jl 0x5804a
movq %r13, %rdi
subq %r15, %rdi
addq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax,%r14,8), %rsi
movl %r15d, %edx
movl %r8d, %r12d
callq 0x83e0
movq -0x50(%rbp), %rsi
movq -0x30(%rbp), %rdi
movl %r12d, %r8d
testl %eax, %eax
je 0x58052
incq %r14
jmp 0x5800f
xorl %r15d, %r15d
subl %r15d, %r8d
cmpq %rbx, %r14
jb 0x58004
cmpl $0x1, -0x34(%rbp)
je 0x5806b
movl %r8d, %ebx
callq 0x9c7b
movl %ebx, %r8d
movq -0x48(%rbp), %r15
movq -0x40(%rbp), %r12
pushq $-0x1
popq %rcx
movq %r15, %rdi
movq %r12, %rsi
movl %r8d, %edx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe48d
movl %r8d, -0x30(%rbp)
movq 0x8(%rbx), %rdi
callq 0xdf1e
testq %rax, %rax
je 0x5812d
movq %rax, %rbx
xorl %eax, %eax
movq %rbx, %rcx
movl -0x30(%rbp), %r8d
movb (%rcx), %dl
testb %dl, %dl
je 0x580d5
cmpb $-0x40, %dl
jb 0x580ce
movb 0x1(%rcx), %dl
incq %rcx
andb $-0x40, %dl
negb %dl
jo 0x580bf
jmp 0x580d1
incq %rcx
incl %eax
jmp 0x580b4
testl %eax, %eax
je 0x58073
movl %eax, %r14d
leaq (%r14,%r14,8), %rsi
movq %r15, %rdi
callq 0x5959e
testq %rax, %rax
je 0x5812d
movq %rax, %rdi
leaq (%rax,%r14,8), %rsi
xorl %eax, %eax
movl -0x30(%rbp), %r8d
cmpb $0x0, (%rbx)
je 0x5813c
movq %rbx, (%rdi,%rax,8)
cmpb $-0x40, (%rbx)
jb 0x5811a
movq %rbx, %rcx
movb 0x1(%rcx), %dl
incq %rcx
andb $-0x40, %dl
negb %dl
jo 0x5810b
jmp 0x5811e
leaq 0x1(%rbx), %rcx
movl %ecx, %edx
subl %ebx, %edx
movb %dl, (%rsi,%rax)
incq %rax
movq %rcx, %rbx
jmp 0x580fa
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rax, %rax
jne 0x57f82
jmp 0x58073