// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x92f0
movl %eax, -0x48(%rbp)
movzbl -0x19(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x4, -0x44(%rbp)
je 0x19f10
cmpl $0x8, -0x44(%rbp)
jne 0x19f17
movl $0x2, -0x44(%rbp)
cmpl $0x1, -0x44(%rbp)
jl 0x19f23
cmpl $0x3, -0x44(%rbp)
jle 0x19f35
movl $0x1cb45, %edi          # imm = 0x1CB45
callq 0x9420
movl %eax, -0x4(%rbp)
jmp 0x1a0bb
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rdx
xorl %ecx, %ecx
movzbl %al, %esi
callq 0x65d70
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x1a03e
movq -0x40(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x1a03e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x9c(%rax)
je 0x19f98
movq -0x10(%rbp), %rdi
movl $0x5, %esi
leaq 0x97f24(%rip), %rdx     # 0xb1ea9
movb $0x0, %al
callq 0xd720
movl $0x5, -0x4(%rbp)
jmp 0x1a0bb
movq -0x10(%rbp), %rdi
callq 0x14a20
movq -0x40(%rbp), %rax
movzbl 0x8(%rax), %eax
andl $-0x9, %eax
cmpl -0x44(%rbp), %eax
jne 0x1a03c
movq -0x10(%rbp), %rdi
addq $0x290, %rdi            # imm = 0x290
movq -0x18(%rbp), %rsi
movl -0x48(%rbp), %edx
callq 0x468b0
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
cmpl $0x3, -0x54(%rbp)
jge 0x1a03a
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movzbl 0x8(%rax), %eax
movq -0x40(%rbp), %rcx
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jne 0x1a02d
movq -0x60(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x1a021
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
movq 0x10(%rcx), %rdi
callq *%rax
movq -0x60(%rbp), %rax
movq $0x0, 0x18(%rax)
jmp 0x1a02f
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x19fd7
jmp 0x1a03c
jmp 0x1a03e
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rdx
movl $0x1, %ecx
movzbl %al, %esi
callq 0x65d70
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x1a06a
movl $0x7, -0x4(%rbp)
jmp 0x1a0bb
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x44(%rbp), %eax
movzbl -0x19(%rbp), %ecx
andl $0x8, %ecx
orl %ecx, %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0xd720
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)