// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: createCollation
static int createCollation(
  sqlite3* db,
  const char *zName, 
  u8 enc,
  void* pCtx,
  int(*xCompare)(void*,int,const void*,int,const void*),
  void(*xDel)(void*)
){
  CollSeq *pColl;
  int enc2;
  int nName = sqlite3Strlen30(zName);
  
  assert( sqlite3_mutex_held(db->mutex) );

  /* If SQLITE_UTF16 is specified as the encoding type, transform this
  ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
  ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
  */
  enc2 = enc;
  testcase( enc2==SQLITE_UTF16 );
  testcase( enc2==SQLITE_UTF16_ALIGNED );
  if( enc2==SQLITE_UTF16 || enc2==SQLITE_UTF16_ALIGNED ){
    enc2 = SQLITE_UTF16NATIVE;
  }
  if( enc2<SQLITE_UTF8 || enc2>SQLITE_UTF16BE ){
    return SQLITE_MISUSE_BKPT;
  }

  /* Check if this call is removing or replacing an existing collation 
  ** sequence. If so, and there are active VMs, return busy. If there
  ** are no active VMs, invalidate any pre-compiled statements.
  */
  pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0);
  if( pColl && pColl->xCmp ){
    if( db->nVdbeActive ){
      sqlite3Error(db, SQLITE_BUSY, 
        "unable to delete/modify collation sequence due to active statements");
      return SQLITE_BUSY;
    }
    sqlite3ExpirePreparedStatements(db);

    /* If collation sequence pColl was created directly by a call to
    ** sqlite3_create_collation, and not generated by synthCollSeq(),
    ** then any copies made by synthCollSeq() need to be invalidated.
    ** Also, collation destructor - CollSeq.xDel() - function may need
    ** to be called.
    */ 
    if( (pColl->enc & ~SQLITE_UTF16_ALIGNED)==enc2 ){
      CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
      int j;
      for(j=0; j<3; j++){
        CollSeq *p = &aColl[j];
        if( p->enc==pColl->enc ){
          if( p->xDel ){
            p->xDel(p->pUser);
          }
          p->xCmp = 0;
        }
      }
    }
  }

  pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
  if( pColl==0 ) return SQLITE_NOMEM;
  pColl->xCmp = xCompare;
  pColl->pUser = pCtx;
  pColl->xDel = xDel;
  pColl->enc = (u8)(enc2 | (enc & SQLITE_UTF16_ALIGNED));
  sqlite3Error(db, SQLITE_OK, 0);
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r10
testq %rsi, %rsi
je 0x1628e
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %r10, %rax
incl %r15d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x16279
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
jmp 0x16291
xorl %r15d, %r15d
movzbl %dl, %ebx
leal -0x4(%rbx), %eax
testb $-0x5, %al
movl $0x2, %r14d
cmovnel %ebx, %r14d
leal -0x4(%r14), %eax
cmpl $-0x4, %eax
ja 0x162d6
leaq 0x67131(%rip), %rsi     # 0x7d3e4
leaq 0x6327f(%rip), %rcx     # 0x79539
movl $0x15, %r14d
movl $0x15, %edi
movl $0x1cb45, %edx          # imm = 0x1CB45
xorl %eax, %eax
callq 0xb9c7
jmp 0x163fc
movq %r8, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r9, -0x50(%rbp)
movq %rdi, -0x30(%rbp)
movl %r14d, %esi
movq %r10, -0x38(%rbp)
movq %r10, %rdx
xorl %ecx, %ecx
callq 0x4b5e8
testq %rax, %rax
je 0x163a3
movq %rax, %r12
cmpq $0x0, 0x18(%rax)
je 0x163a3
movq -0x30(%rbp), %rdi
cmpl $0x0, 0x9c(%rdi)
je 0x16332
leaq 0x6707e(%rip), %rdx     # 0x7d3a0
movl $0x5, %r14d
movl $0x5, %esi
jmp 0x163ed
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x16348
orb $0x20, 0x9a(%rax)
movq 0x68(%rax), %rax
jmp 0x16336
movzbl 0x8(%r12), %eax
andl $-0x9, %eax
cmpl %eax, %r14d
jne 0x163a3
movq -0x30(%rbp), %rax
leaq 0x290(%rax), %rdi
movq -0x38(%rbp), %rsi
movl %r15d, %edx
callq 0x3406c
movq %rax, %r15
xorl %r13d, %r13d
movb 0x8(%r15,%r13), %al
cmpb 0x8(%r12), %al
jne 0x16399
movq 0x20(%r15,%r13), %rax
testq %rax, %rax
je 0x16390
movq 0x10(%r15,%r13), %rdi
callq *%rax
movq $0x0, 0x18(%r15,%r13)
addq $0x28, %r13
cmpq $0x78, %r13
jne 0x16373
movzbl %r14b, %esi
movq -0x30(%rbp), %r15
movq %r15, %rdi
movq -0x38(%rbp), %rdx
movl $0x1, %ecx
callq 0x4b5e8
testq %rax, %rax
je 0x163f6
movq -0x40(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x20(%rax)
andl $0x8, %ebx
orl %ebx, %r14d
movb %r14b, 0x8(%rax)
xorl %r14d, %r14d
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0xca2d
jmp 0x163fc
movl $0x7, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq