// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %r14
movq (%rdx), %rdi
cmpb $0x5, 0x26(%rdi)
je 0x639ba
movq %rdx, %rbx
movl %esi, %r15d
movl $0x1, %r13d
movl $0x1, %esi
callq 0xee49
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x639ba
movq (%rbx), %rdi
movl $0x1, %esi
callq 0xed28
movl %eax, %edx
cmpl $0x1, %r15d
jne 0x6376f
leaq 0x2ffe5(%rip), %rdi     # 0x93748
leaq 0x154e2(%rip), %rsi     # 0x78c4c
jmp 0x63842
movq 0x8(%rbx), %rdi
movl $0x1, %esi
movl %edx, %r12d
callq 0xee49
testq %rax, %rax
je 0x639ba
movl %r12d, %edx
movb (%rax), %cl
xorl %r13d, %r13d
testb %cl, %cl
je 0x637b8
movq %rax, %rsi
cmpb $-0x40, %cl
jb 0x637ac
movb 0x1(%rsi), %cl
incq %rsi
andb $-0x40, %cl
negb %cl
jo 0x6379d
jmp 0x637af
incq %rsi
incl %r13d
movb (%rsi), %cl
testb %cl, %cl
jne 0x63798
movb $0x1, %cl
testl %r13d, %r13d
je 0x63826
movq %rax, -0x30(%rbp)
movl %r13d, %ebx
leaq (%rbx,%rbx,8), %rsi
movq %r14, %rdi
callq 0x65256
xorl %esi, %esi
testq %rax, %rax
je 0x6382c
movq %rax, %rdi
leaq (%rax,%rbx,8), %rsi
movq -0x30(%rbp), %r8
cmpb $0x0, (%r8)
movl %r12d, %edx
je 0x63835
xorl %r13d, %r13d
movq %r8, (%rdi,%r13,8)
cmpb $-0x40, (%r8)
jb 0x6380c
movq %r8, %rax
movb 0x1(%rax), %cl
incq %rax
andb $-0x40, %cl
negb %cl
jo 0x637fd
jmp 0x63810
leaq 0x1(%r8), %rax
movl %eax, %ecx
subl %r8d, %ecx
movb %cl, (%rsi,%r13)
incq %r13
cmpb $0x0, (%rax)
movq %rax, %r8
jne 0x637f0
jmp 0x63838
xorl %esi, %esi
xorl %edi, %edi
jmp 0x6383a
xorl %edi, %edi
xorl %ecx, %ecx
movl %r12d, %edx
jmp 0x6383a
xorl %r13d, %r13d
movb $0x1, %cl
testb %cl, %cl
je 0x639ba
testl %r13d, %r13d
jle 0x63994
movl %r15d, -0x4c(%rbp)
movq %r14, -0x58(%rbp)
movq (%r14), %rax
movq 0x8(%rax), %rcx
testl %edx, %edx
setg %al
movq %rcx, -0x40(%rbp)
andb %cl, %al
cmpb $0x1, %al
movq %rdi, -0x30(%rbp)
movq %rsi, -0x60(%rbp)
movq %r13, -0x68(%rbp)
jne 0x638e8
movl %r13d, %r14d
movq %r14, -0x48(%rbp)
negq %r14
movb $0x1, %r13b
movl $0x1, %ebx
movzbl -0x1(%rsi,%rbx), %r12d
cmpl %r12d, %edx
jl 0x638b9
movq -0x30(%rbp), %rax
movq -0x8(%rax,%rbx,8), %rsi
movl %edx, %r15d
movl %r12d, %edx
movq -0x38(%rbp), %rdi
callq 0x8410
movq -0x60(%rbp), %rsi
movq -0x30(%rbp), %rdi
movl %r15d, %edx
testl %eax, %eax
je 0x638d4
cmpq -0x48(%rbp), %rbx
setb %r13b
leaq (%r14,%rbx), %rax
incq %rax
incq %rbx
cmpq $0x1, %rax
jne 0x63887
xorl %r12d, %r12d
subl %r12d, %edx
movl %r12d, %eax
addq %rax, -0x38(%rbp)
testb $0x1, %r13b
je 0x638e8
testl %edx, %edx
jg 0x6387f
testb $0x2, -0x40(%rbp)
je 0x63981
testl %edx, %edx
jle 0x63981
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
cmpl $0x2, %eax
movl $0x1, %r14d
cmovgel %eax, %r14d
negq %r14
movb $0x1, %r13b
movl $0x1, %r12d
movslq %edx, %rax
movq %rax, -0x40(%rbp)
movzbl -0x1(%rsi,%r12), %ebx
cmpl %ebx, %edx
jl 0x6395b
movq -0x40(%rbp), %rdi
subq %rbx, %rdi
addq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rax
movq -0x8(%rax,%r12,8), %rsi
movl %edx, %r15d
movl %ebx, %edx
callq 0x8410
movq -0x60(%rbp), %rsi
movq -0x30(%rbp), %rdi
movl %r15d, %edx
testl %eax, %eax
je 0x63975
cmpq -0x48(%rbp), %r12
setb %r13b
leaq (%r14,%r12), %rax
incq %rax
incq %r12
cmpq $0x1, %rax
jne 0x63924
xorl %ebx, %ebx
subl %ebx, %edx
testb $0x1, %r13b
je 0x63981
testl %edx, %edx
jg 0x63914
cmpl $0x1, -0x4c(%rbp)
je 0x63990
movl %edx, %ebx
callq 0xa2e8
movl %ebx, %edx
movq -0x58(%rbp), %r14
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movl $0x1, %ecx
movq $-0x1, %r8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xef1b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq