// File: /workspace/github_c_makefile_star2_O3/shifengbin[P]bishe/Output/../Persistence/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;
  int extraFlags;

  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;
  }

  assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
  extraFlags = enc &  SQLITE_DETERMINISTIC;
  enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
  
#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|extraFlags,
         pUserData, xFunc, xStep, xFinal, pDestructor);
    if( rc==SQLITE_OK ){
      rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
          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->funcFlags & SQLITE_FUNC_ENCMASK)==enc && p->nArg==nArg ){
    if( db->nVdbeActive ){
      sqlite3ErrorWithMsg(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->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
  testcase( p->funcFlags & SQLITE_DETERMINISTIC );
  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 0x18e0e
movq %r9, %r15
movl %ecx, %ebx
movl %edx, %r14d
movq %rsi, %r13
movq %rdi, %r12
movq 0x18(%rbp), %rcx
movq 0x10(%rbp), %rsi
testq %rcx, %rcx
setne %al
testq %r9, %r9
je 0x18dbd
movq %rsi, %rax
orq %rcx, %rax
jne 0x18e0e
xorl %ecx, %ecx
xorl %eax, %eax
jmp 0x18dd0
testq %rcx, %rcx
sete %dl
testq %rsi, %rsi
setne %cl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x18e0e
testq %r15, %r15
sete %dl
leal -0x80(%r14), %esi
cmpl $0xffffff7f, %esi       # imm = 0xFFFFFF7F
jb 0x18e0e
xorb $0x1, %al
andb %dl, %cl
andb %al, %cl
jne 0x18e0e
movq %r13, %rdi
movq %r8, -0x38(%rbp)
callq 0xa190
movq 0x10(%rbp), %r11
movq 0x18(%rbp), %r10
movq -0x38(%rbp), %r8
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpl $0x100, %eax            # imm = 0x100
jb 0x18e43
leaq 0x6668d(%rip), %rsi     # 0x7f4a2
leaq 0x62371(%rip), %rcx     # 0x7b18d
movl $0x15, %ebx
movl $0x15, %edi
movl $0x20a16, %edx          # imm = 0x20A16
xorl %eax, %eax
callq 0xa4c0
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %ecx
andl $0x800, %ecx            # imm = 0x800
andl $0x7, %ebx
cmpl $0x4, %ebx
movl %ecx, -0x2c(%rbp)
movq %rax, -0x40(%rbp)
je 0x18ebf
cmpl $0x5, %ebx
jne 0x18ec4
orl $0x1, %ecx
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movq %r15, %r9
movq 0x20(%rbp), %rax
pushq %rax
pushq %r10
pushq %r11
callq 0x18d74
addq $0x20, %rsp
testl %eax, %eax
jne 0x18eb8
movl -0x2c(%rbp), %ecx
orl $0x2, %ecx
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movq -0x38(%rbp), %r8
movq %r15, %r9
pushq 0x20(%rbp)
pushq 0x18(%rbp)
pushq 0x10(%rbp)
callq 0x18d74
addq $0x20, %rsp
testl %eax, %eax
je 0x18f1e
movl %eax, %ebx
jmp 0x18e32
movl $0x2, %ebx
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
movl %r14d, %ecx
movl %ebx, %r8d
xorl %r9d, %r9d
callq 0x191e6
testq %rax, %rax
je 0x18f40
movzwl 0x2(%rax), %ecx
andl $0x3, %ecx
cmpl %ecx, %ebx
jne 0x18f40
movswl (%rax), %eax
cmpl %r14d, %eax
jne 0x18f40
cmpl $0x0, 0xa4(%r12)
je 0x18f29
leaq 0x664a7(%rip), %rdx     # 0x7f3ac
movl $0x5, %ebx
movq %r12, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0xf060
jmp 0x18e32
movl $0x3, %ebx
movq -0x40(%rbp), %rax
jmp 0x18ec4
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x18f40
orb $0x8, 0x8c(%rax)
movq 0x58(%rax), %rax
jmp 0x18f2e
movzbl %bl, %r8d
movq %r12, %rdi
movq %r13, %rsi
movq -0x40(%rbp), %rdx
movl %r14d, %ecx
movl $0x1, %r9d
callq 0x191e6
testq %rax, %rax
je 0x18fb4
movq %rax, %rbx
movq 0x40(%rax), %rsi
movq %r12, %rdi
callq 0x76498
movq 0x20(%rbp), %rax
testq %rax, %rax
je 0x18f7b
incl (%rax)
movq %rax, 0x40(%rbx)
movzwl 0x2(%rbx), %eax
andl $0x3, %eax
orl -0x2c(%rbp), %eax
movw %ax, 0x2(%rbx)
movq %r15, 0x18(%rbx)
movq 0x10(%rbp), %rax
movq %rax, 0x20(%rbx)
movq 0x18(%rbp), %rax
movq %rax, 0x28(%rbx)
movq -0x38(%rbp), %rax
movq %rax, 0x8(%rbx)
movw %r14w, (%rbx)
xorl %ebx, %ebx
jmp 0x18e32
movl $0x7, %ebx
jmp 0x18e32