// File: /workspace/github_c_makefile_star2_O3/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
movq %rdi, %r12
movq (%rdx), %rdi
cmpb $0x5, 0x26(%rdi)
je 0x6374d
movq %rdx, %rbx
movl %esi, %r13d
movl $0x1, %r15d
movl $0x1, %esi
callq 0xef29
movq %rax, -0x48(%rbp)
testq %rax, %rax
je 0x6374d
movq (%rbx), %rdi
movl $0x1, %esi
callq 0xee02
movl %eax, %edx
cmpl $0x1, %r13d
jne 0x63694
leaq 0x1564c(%rip), %rsi     # 0x78c4c
leaq 0x30141(%rip), %rax     # 0x93748
movq %rax, -0x38(%rbp)
movl %r13d, -0x4c(%rbp)
movq (%r12), %rax
movq 0x8(%rax), %rcx
testl %edx, %edx
setg %al
andb %cl, %al
cmpb $0x1, %al
movq %rsi, -0x30(%rbp)
movq %r12, -0x40(%rbp)
jne 0x63764
movq %rcx, -0x58(%rbp)
movl %r15d, %eax
movq %r15, -0x60(%rbp)
xorl %r12d, %r12d
movzbl (%rsi,%r12), %r14d
cmpl %r14d, %edx
jl 0x63675
movq %rax, %r15
movq -0x38(%rbp), %rax
movq (%rax,%r12,8), %rsi
movl %r14d, %ebx
movq -0x48(%rbp), %rdi
movl %edx, %r13d
movq %rbx, %rdx
callq 0x8410
movq -0x30(%rbp), %rsi
movl %r13d, %edx
testl %eax, %eax
movq %r15, %rax
movq -0x60(%rbp), %r15
je 0x63682
incq %r12
cmpq %r12, %rax
jne 0x6363c
jmp 0x6375c
addq %rbx, -0x48(%rbp)
subl %r14d, %edx
movq -0x40(%rbp), %r12
jg 0x63639
jmp 0x637c8
movl %edx, -0x30(%rbp)
movq 0x8(%rbx), %rdi
movl $0x1, %esi
callq 0xef29
testq %rax, %rax
je 0x6374d
movq %rax, %rbx
movb (%rax), %dl
testb %dl, %dl
je 0x637dd
xorl %eax, %eax
movq %rbx, %rcx
cmpb $-0x40, %dl
jb 0x636d8
movb 0x1(%rcx), %dl
incq %rcx
movl %edx, %esi
andb $-0x40, %sil
negb %sil
jo 0x636c5
jmp 0x636dd
incq %rcx
movb (%rcx), %dl
incl %eax
testb %dl, %dl
jne 0x636c0
movl %eax, %r14d
leaq (%r14,%r14,8), %rsi
movq %r12, %rdi
callq 0x65096
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x6374d
cmpb $0x0, (%rbx)
je 0x637dd
movq -0x38(%rbp), %rax
leaq (%rax,%r14,8), %rsi
xorl %r15d, %r15d
movl -0x30(%rbp), %edx
movq -0x38(%rbp), %rax
movq %rbx, (%rax,%r15,8)
cmpb $-0x40, (%rbx)
jb 0x63731
movq %rbx, %rax
movb 0x1(%rax), %cl
incq %rax
andb $-0x40, %cl
negb %cl
jo 0x63722
jmp 0x63735
leaq 0x1(%rbx), %rax
movl %eax, %ecx
subl %ebx, %ecx
movb %cl, (%rsi,%r15)
incq %r15
cmpb $0x0, (%rax)
movq %rax, %rbx
jne 0x63712
jmp 0x6360b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x40(%rbp), %r12
movq -0x58(%rbp), %rcx
testb $0x2, %cl
je 0x637c8
testl %edx, %edx
jle 0x637c8
cmpl $0x1, %r15d
adcl $0x0, %r15d
movslq %edx, %rbx
xorl %r13d, %r13d
movzbl (%rsi,%r13), %eax
cmpl %eax, %edx
jl 0x637af
movq %rbx, %r12
subq %rax, %r12
movq -0x48(%rbp), %rcx
leaq (%rcx,%r12), %rdi
movq -0x38(%rbp), %rcx
movq (%rcx,%r13,8), %rsi
movl %edx, %r14d
movl %eax, %edx
callq 0x8410
movq -0x30(%rbp), %rsi
movl %r14d, %edx
testl %eax, %eax
je 0x637b9
incq %r13
cmpq %r13, %r15
jne 0x6377b
jmp 0x637c4
movl %r12d, %edx
testl %r12d, %r12d
jg 0x63775
movl %r12d, %edx
movq -0x40(%rbp), %r12
cmpl $0x1, -0x4c(%rbp)
je 0x637e0
movq -0x38(%rbp), %rdi
movl %edx, %ebx
callq 0xa3c7
movl %ebx, %edx
jmp 0x637e0
movl -0x30(%rbp), %edx
movq %r12, %rdi
movq -0x48(%rbp), %rsi
movl $0x1, %ecx
movq $-0x1, %r8
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xeffe