// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3CreateFunc
SQLITE_PRIVATE int sqlite3CreateFunc(
  sqlite3 *db,
  const char *zFunctionName,
  int nArg,
  int enc,
  void *pUserData,
  void (*xSFunc)(sqlite3_context*,int,sqlite3_value **),
  void (*xStep)(sqlite3_context*,int,sqlite3_value **),
  void (*xFinal)(sqlite3_context*),
  void (*xValue)(sqlite3_context*),
  void (*xInverse)(sqlite3_context*,int,sqlite3_value **),
  FuncDestructor *pDestructor
){
  FuncDef *p;
  int nName;
  int extraFlags;

  assert( sqlite3_mutex_held(db->mutex) );
  assert( xValue==0 || xSFunc==0 );
  if( zFunctionName==0                /* Must have a valid name */
   || (xSFunc!=0 && xFinal!=0)        /* Not both xSFunc and xFinal */
   || ((xFinal==0)!=(xStep==0))       /* Both or neither of xFinal and xStep */
   || ((xValue==0)!=(xInverse==0))    /* Both or neither of xValue, xInverse */
   || (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG)
   || (255<(nName = sqlite3Strlen30( zFunctionName)))
  ){
    return SQLITE_MISUSE_BKPT;
  }

  assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
  assert( SQLITE_FUNC_DIRECT==SQLITE_DIRECTONLY );
  extraFlags = enc &  (SQLITE_DETERMINISTIC|SQLITE_DIRECTONLY|
                       SQLITE_SUBTYPE|SQLITE_INNOCUOUS);
  enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);

  /* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE.  But
  ** the meaning is inverted.  So flip the bit. */
  assert( SQLITE_FUNC_UNSAFE==SQLITE_INNOCUOUS );
  extraFlags ^= SQLITE_FUNC_UNSAFE;


#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)^SQLITE_FUNC_UNSAFE,
         pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor);
    if( rc==SQLITE_OK ){
      rc = sqlite3CreateFunc(db, zFunctionName, nArg,
           (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE,
           pUserData, xSFunc, xStep, xFinal, xValue, xInverse, 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, nArg, (u8)enc, 0);
  if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==(u32)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, 0);
    }
  }

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

  /* 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->u.pDestructor = pDestructor;
  p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
  testcase( p->funcFlags & SQLITE_DETERMINISTIC );
  testcase( p->funcFlags & SQLITE_DIRECTONLY );
  p->xSFunc = xSFunc ? xSFunc : xStep;
  p->xFinalize = xFinal;
  p->xValue = xValue;
  p->xInverse = xInverse;
  p->pUserData = pUserData;
  p->nArg = (u16)nArg;
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
testq %rsi, %rsi
je 0x22aacf
movq %r9, %r15
movl %ecx, %ebp
movq 0x78(%rsp), %rbx
testq %r9, %r9
setne %al
testq %rbx, %rbx
setne %cl
testb %cl, %al
jne 0x22aacf
movq %rsi, %r13
movq 0x70(%rsp), %rsi
testq %rbx, %rbx
sete %al
testq %rsi, %rsi
setne %cl
cmpb %al, %cl
je 0x22aacf
movl %edx, %r14d
movq %rdi, %r12
movq 0x88(%rsp), %r9
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
sete %al
testq %r9, %r9
sete %cl
leal -0x80(%r14), %edx
cmpl $0xffffff7f, %edx       # imm = 0xFFFFFF7F
jb 0x22aacf
xorb %cl, %al
jne 0x22aacf
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
movq %r13, %rdi
movq %r8, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %r9, 0x20(%rsp)
callq 0x2211ac
movq 0x20(%rsp), %r11
movq 0x28(%rsp), %r10
movq 0x30(%rsp), %r8
cmpl $0x100, %eax            # imm = 0x100
jb 0x22aae7
movl $0x27bed, %edi          # imm = 0x27BED
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21ec3c
movl %ebp, %eax
andl $0x380800, %eax         # imm = 0x380800
andl $0x7, %ebp
cmpl $0x4, %ebp
movl %eax, 0xc(%rsp)
je 0x22ab6f
cmpl $0x5, %ebp
jne 0x22ab72
movl %eax, %ecx
orl $0x1, %ecx
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movq %r15, %r9
pushq 0x18(%rsp)
pushq %r11
pushq 0x30(%rsp)
pushq %rbx
pushq %r10
callq 0x22aa11
addq $0x30, %rsp
testl %eax, %eax
jne 0x22ab68
movl 0xc(%rsp), %ecx
orl $0x2, %ecx
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movq 0x38(%rsp), %r8
movq %r15, %r9
pushq 0x18(%rsp)
pushq 0x30(%rsp)
pushq 0x30(%rsp)
pushq %rbx
pushq 0x50(%rsp)
callq 0x22aa11
addq $0x30, %rsp
testl %eax, %eax
je 0x22abc2
movl %eax, %ebp
jmp 0x22ac57
pushq $0x2
popq %rbp
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x22acdc
testq %rax, %rax
je 0x22abd0
movl 0x4(%rax), %ecx
andl $0x3, %ecx
cmpl %ebp, %ecx
jne 0x22abd0
movsbl (%rax), %eax
cmpl %r14d, %eax
jne 0x22abd0
cmpl $0x0, 0xc0(%r12)
je 0x22abc6
leaq 0x14fd7c(%rip), %rdx    # 0x37a92a
pushq $0x5
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x2226f3
jmp 0x22ac57
pushq $0x3
jmp 0x22ab71
movq %r12, %rdi
xorl %esi, %esi
callq 0x227911
movzbl %bpl, %ecx
pushq $0x1
popq %r8
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x22acdc
testq %rax, %rax
je 0x22ac54
movq %rax, %r13
movq %r12, %rdi
movq %rax, %rsi
callq 0x28a82f
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0x22ac05
incl (%rcx)
movl 0x4(%r13), %eax
andl $0x3, %eax
orl 0xc(%rsp), %eax
xorl $0x200000, %eax         # imm = 0x200000
testq %r15, %r15
movq %rcx, 0x40(%r13)
movq 0x28(%rsp), %rcx
cmovneq %r15, %rcx
movl %eax, 0x4(%r13)
movq %rcx, 0x18(%r13)
movq %rbx, 0x20(%r13)
movq 0x18(%rsp), %rax
movq %rax, 0x28(%r13)
movq 0x20(%rsp), %rax
movq %rax, 0x30(%r13)
movq 0x30(%rsp), %rax
movq %rax, 0x8(%r13)
movb %r14b, (%r13)
xorl %ebp, %ebp
jmp 0x22ac57
pushq $0x7
popq %rbp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq