// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %r9, -0x58(%rbp)
movq %r8, -0x50(%rbp)
movq %rcx, %r13
movl %edx, %r12d
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x8f8e
leal -0x4(%r12), %ecx
testb $-0x5, %cl
pushq $0x2
popq %r15
movq %r12, -0x48(%rbp)
cmovnel %r12d, %r15d
leal -0x4(%r15), %ecx
cmpl $-0x4, %ecx
ja 0x14672
movl $0x1cb45, %edi          # imm = 0x1CB45
callq 0x9008
pushq $0x15
jmp 0x14775
movl %eax, %r12d
movq %r13, -0x40(%rbp)
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
movl %r15d, %esi
movq %r14, -0x38(%rbp)
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x46a5b
testq %rax, %rax
je 0x1471f
movq %rax, %r13
cmpq $0x0, 0x18(%rax)
je 0x1471f
movq -0x30(%rbp), %rdi
cmpl $0x0, 0x9c(%rdi)
je 0x146c2
leaq 0x5ad08(%rip), %rdx     # 0x6f3c0
pushq $0x5
popq %rbx
movl %ebx, %esi
jmp 0x1476a
callq 0x1108b
movzbl 0x8(%r13), %eax
andl $-0x9, %eax
cmpl %eax, %r15d
jne 0x1471f
movq -0x30(%rbp), %rax
leaq 0x290(%rax), %rdi
movq -0x38(%rbp), %rsi
movl %r12d, %edx
callq 0x2eeba
movq %rax, %rbx
xorl %r12d, %r12d
cmpq $0x78, %r12
je 0x1471f
movb 0x8(%rbx,%r12), %al
cmpb 0x8(%r13), %al
jne 0x14719
movq 0x20(%rbx,%r12), %rax
testq %rax, %rax
je 0x14713
movq 0x10(%rbx,%r12), %rdi
callq *%rax
andq $0x0, 0x18(%rbx,%r12)
addq $0x28, %r12
jmp 0x146f1
movzbl %r15b, %esi
pushq $0x1
popq %rcx
movq -0x30(%rbp), %r12
movq %r12, %rdi
movq -0x38(%rbp), %rdx
callq 0x46a5b
testq %rax, %rax
je 0x14773
movq -0x50(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0x20(%rax)
movq -0x48(%rbp), %rcx
andl $0x8, %ecx
orl %ecx, %r15d
movb %r15b, 0x8(%rax)
xorl %ebx, %ebx
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0xbdb1
jmp 0x14776
pushq $0x7
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq