// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3CreateFunc
SQLITE_PRIVATE int sqlite3CreateFunc(
  sqlite3 *db,
  const char *zFunctionName,
  int nArg,
  int enc,
  void *pUserData,
  void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
  void (*xStep)(sqlite3_context*,int,sqlite3_value **),
  void (*xFinal)(sqlite3_context*),
  FuncDestructor *pDestructor
){
  FuncDef *p;
  int nName;

  assert( sqlite3_mutex_held(db->mutex) );
  if( zFunctionName==0 ||
      (xFunc && (xFinal || xStep)) || 
      (!xFunc && (xFinal && !xStep)) ||
      (!xFunc && (!xFinal && xStep)) ||
      (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||
      (255<(nName = sqlite3Strlen30( zFunctionName))) ){
    return SQLITE_MISUSE_BKPT;
  }
  
#ifndef SQLITE_OMIT_UTF16
  /* 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.
  **
  ** If SQLITE_ANY is specified, add three versions of the function
  ** to the hash table.
  */
  if( enc==SQLITE_UTF16 ){
    enc = SQLITE_UTF16NATIVE;
  }else if( enc==SQLITE_ANY ){
    int rc;
    rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
         pUserData, xFunc, xStep, xFinal, pDestructor);
    if( rc==SQLITE_OK ){
      rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
          pUserData, xFunc, xStep, xFinal, pDestructor);
    }
    if( rc!=SQLITE_OK ){
      return rc;
    }
    enc = SQLITE_UTF16BE;
  }
#else
  enc = SQLITE_UTF8;
#endif
  
  /* Check if an existing function is being overridden or deleted. If so,
  ** and there are active VMs, then return SQLITE_BUSY. If a function
  ** is being overridden/deleted but there are no active VMs, allow the
  ** operation to continue but invalidate all precompiled statements.
  */
  p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
  if( p && p->iPrefEnc==enc && p->nArg==nArg ){
    if( db->nVdbeActive ){
      sqlite3Error(db, SQLITE_BUSY, 
        "unable to delete/modify user-function due to active statements");
      assert( !db->mallocFailed );
      return SQLITE_BUSY;
    }else{
      sqlite3ExpirePreparedStatements(db);
    }
  }

  p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 1);
  assert(p || db->mallocFailed);
  if( !p ){
    return SQLITE_NOMEM;
  }

  /* If an older version of the function with a configured destructor is
  ** being replaced invoke the destructor function here. */
  functionDestroy(db, p);

  if( pDestructor ){
    pDestructor->nRef++;
  }
  p->pDestructor = pDestructor;
  p->flags = 0;
  p->xFunc = xFunc;
  p->xStep = xStep;
  p->xFinalize = xFinal;
  p->pUserData = pUserData;
  p->nArg = (u16)nArg;
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rsi, %rsi
je 0x1516a
movq %r9, %r15
movl %ecx, %r12d
movl %edx, %r14d
movq %rsi, %r13
movq 0x18(%rbp), %r10
movq 0x10(%rbp), %r11
testq %r10, %r10
setne %al
testq %r9, %r9
je 0x1511f
movq %r11, %rax
orq %r10, %rax
jne 0x1516a
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x15132
testq %r10, %r10
sete %dl
testq %r11, %r11
setne %cl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x1516a
testq %r15, %r15
sete %dl
leal -0x80(%r14), %esi
cmpl $0xffffff7f, %esi       # imm = 0xFFFFFF7F
jb 0x1516a
xorb $0x1, %al
andb %dl, %cl
andb %al, %cl
jne 0x1516a
xorl %ebx, %ebx
cmpb $0x0, (%r13,%rbx)
leaq 0x1(%rbx), %rbx
jne 0x1514e
decl %ebx
andl $0x3fffffff, %ebx       # imm = 0x3FFFFFFF
cmpl $0x100, %ebx            # imm = 0x100
jb 0x151a1
leaq 0x68273(%rip), %rsi     # 0x7d3e4
leaq 0x643c1(%rip), %rcx     # 0x79539
movl $0x15, %r12d
movl $0x15, %edi
movl $0x1c8e4, %edx          # imm = 0x1C8E4
xorl %eax, %eax
callq 0xb9c7
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4, %r12d
movq %r8, -0x40(%rbp)
movq %rdi, -0x30(%rbp)
je 0x15213
cmpl $0x5, %r12d
jne 0x15219
subq $0x8, %rsp
movq %r13, %rsi
movl %r14d, %edx
movl $0x1, %ecx
movq %r15, %r9
pushq 0x20(%rbp)
pushq %r10
pushq %r11
callq 0x150dc
addq $0x20, %rsp
testl %eax, %eax
jne 0x1520b
subq $0x8, %rsp
movq -0x30(%rbp), %rdi
movq %r13, %rsi
movl %r14d, %edx
movl $0x2, %ecx
movq -0x40(%rbp), %r8
movq %r15, %r9
pushq 0x20(%rbp)
pushq 0x18(%rbp)
pushq 0x10(%rbp)
callq 0x150dc
addq $0x20, %rsp
testl %eax, %eax
je 0x15276
movl %eax, %r12d
jmp 0x1518f
movl $0x2, %r12d
movzbl %r12b, %r8d
movq -0x30(%rbp), %rdi
movq %r13, %rsi
movl %ebx, %edx
movl %r14d, %ecx
movl %r8d, -0x34(%rbp)
xorl %r9d, %r9d
callq 0x15493
movq -0x30(%rbp), %rdi
testq %rax, %rax
je 0x15294
movzbl 0x2(%rax), %ecx
cmpl %ecx, %r12d
jne 0x15294
movswl (%rax), %eax
cmpl %r14d, %eax
jne 0x15294
cmpl $0x0, 0x9c(%rdi)
je 0x1527e
leaq 0x6808f(%rip), %rdx     # 0x7d2ee
movl $0x5, %r12d
movl $0x5, %esi
xorl %eax, %eax
callq 0xca2d
jmp 0x1518f
movl $0x3, %r12d
jmp 0x15219
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x15294
orb $0x20, 0x9a(%rax)
movq 0x68(%rax), %rax
jmp 0x15282
movq %rdi, %r12
movq %r13, %rsi
movl %ebx, %edx
movl %r14d, %ecx
movl -0x34(%rbp), %r8d
movl $0x1, %r9d
callq 0x15493
testq %rax, %rax
je 0x152fd
movq %rax, %rbx
movq 0x40(%rax), %rsi
movq %r12, %rdi
callq 0x678be
movq 0x20(%rbp), %rax
testq %rax, %rax
je 0x152cd
incl (%rax)
movq %rax, 0x40(%rbx)
movb $0x0, 0x3(%rbx)
movq %r15, 0x18(%rbx)
movq 0x10(%rbp), %rax
movq %rax, 0x20(%rbx)
movq 0x18(%rbp), %rax
movq %rax, 0x28(%rbx)
movq -0x40(%rbp), %rax
movq %rax, 0x8(%rbx)
movw %r14w, (%rbx)
xorl %r12d, %r12d
jmp 0x1518f
movl $0x7, %r12d
jmp 0x1518f