// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x189c3
cmpq $0x0, -0x30(%rbp)
je 0x18976
cmpq $0x0, 0x18(%rbp)
jne 0x189c3
cmpq $0x0, 0x10(%rbp)
jne 0x189c3
cmpq $0x0, -0x30(%rbp)
jne 0x1898b
cmpq $0x0, 0x18(%rbp)
je 0x1898b
cmpq $0x0, 0x10(%rbp)
je 0x189c3
cmpq $0x0, -0x30(%rbp)
jne 0x189a0
cmpq $0x0, 0x18(%rbp)
jne 0x189a0
cmpq $0x0, 0x10(%rbp)
jne 0x189c3
cmpl $-0x1, -0x1c(%rbp)
jl 0x189c3
cmpl $0x7f, -0x1c(%rbp)
jg 0x189c3
movq -0x18(%rbp), %rdi
callq 0x92f0
movl %eax, %ecx
movl %ecx, -0x3c(%rbp)
movl $0xff, %eax
cmpl %ecx, %eax
jge 0x189d5
movl $0x1c8e4, %edi          # imm = 0x1C8E4
callq 0x9420
movl %eax, -0x4(%rbp)
jmp 0x18bac
cmpl $0x4, -0x20(%rbp)
jne 0x189e7
movl $0x2, -0x20(%rbp)
jmp 0x18a85
cmpl $0x5, -0x20(%rbp)
jne 0x18a83
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movq 0x20(%rbp), %rax
movl $0x1, %ecx
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x18930
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x18a6b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movq 0x20(%rbp), %rax
movl $0x2, %ecx
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x18930
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x18a7c
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x18bac
movl $0x3, -0x20(%rbp)
jmp 0x18a85
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x3c(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %eax
xorl %r9d, %r9d
movzbl %al, %r8d
callq 0x18d90
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x18b01
movq -0x38(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x18b01
movq -0x38(%rbp), %rax
movswl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x18b01
movq -0x10(%rbp), %rax
cmpl $0x0, 0x9c(%rax)
je 0x18af6
movq -0x10(%rbp), %rdi
movl $0x5, %esi
leaq 0x99314(%rip), %rdx     # 0xb1df7
movb $0x0, %al
callq 0xd720
movl $0x5, -0x4(%rbp)
jmp 0x18bac
movq -0x10(%rbp), %rdi
callq 0x14a20
jmp 0x18b01
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x3c(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %eax
movl $0x1, %r9d
movzbl %al, %r8d
callq 0x18d90
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x18b35
movl $0x7, -0x4(%rbp)
jmp 0x18bac
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x8ae90
cmpq $0x0, 0x20(%rbp)
je 0x18b54
movq 0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq 0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x38(%rbp), %rax
movb $0x0, 0x3(%rax)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x1c(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)