// File: /workspace/github_c_makefile_star2_O1/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 0x16215
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %r10, %rax
incl %r15d
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x16200
andl $0x3fffffff, %r15d      # imm = 0x3FFFFFFF
jmp 0x16218
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 0x1625d
leaq 0x671aa(%rip), %rsi     # 0x7d3e4
leaq 0x632f8(%rip), %rcx     # 0x79539
movl $0x15, %r14d
movl $0x15, %edi
movl $0x1cb45, %edx          # imm = 0x1CB45
xorl %eax, %eax
callq 0xb8cc
jmp 0x16383
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 0x4b4a6
testq %rax, %rax
je 0x1632a
movq %rax, %r12
cmpq $0x0, 0x18(%rax)
je 0x1632a
movq -0x30(%rbp), %rdi
cmpl $0x0, 0x9c(%rdi)
je 0x162b9
leaq 0x670f7(%rip), %rdx     # 0x7d3a0
movl $0x5, %r14d
movl $0x5, %esi
jmp 0x16374
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x162cf
orb $0x20, 0x9a(%rax)
movq 0x68(%rax), %rax
jmp 0x162bd
movzbl 0x8(%r12), %eax
andl $-0x9, %eax
cmpl %eax, %r14d
jne 0x1632a
movq -0x30(%rbp), %rax
leaq 0x290(%rax), %rdi
movq -0x38(%rbp), %rsi
movl %r15d, %edx
callq 0x3396f
movq %rax, %r15
xorl %r13d, %r13d
movb 0x8(%r15,%r13), %al
cmpb 0x8(%r12), %al
jne 0x16320
movq 0x20(%r15,%r13), %rax
testq %rax, %rax
je 0x16317
movq 0x10(%r15,%r13), %rdi
callq *%rax
movq $0x0, 0x18(%r15,%r13)
addq $0x28, %r13
cmpq $0x78, %r13
jne 0x162fa
movzbl %r14b, %esi
movq -0x30(%rbp), %r15
movq %r15, %rdi
movq -0x38(%rbp), %rdx
movl $0x1, %ecx
callq 0x4b4a6
testq %rax, %rax
je 0x1637d
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 0xc8f4
jmp 0x16383
movl $0x7, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq