// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
testq %rsi, %rsi
je 0x27fa62
movq %r9, %r15
movl %ecx, %ebp
movl %edx, %r14d
movq 0x48(%rsp), %rdx
testq %r9, %r9
setne %al
testq %rdx, %rdx
setne %cl
testb %cl, %al
jne 0x27fa62
testq %rdx, %rdx
sete %al
cmpq $0x0, 0x40(%rsp)
setne %cl
cmpb %al, %cl
je 0x27fa62
cmpq $0x0, 0x50(%rsp)
sete %al
cmpq $0x0, 0x58(%rsp)
sete %cl
leal -0x80(%r14), %edx
cmpl $0xffffff7f, %edx       # imm = 0xFFFFFF7F
jb 0x27fa62
xorb %cl, %al
jne 0x27fa62
movq %r8, %rbx
movq %rsi, %r13
movq %rdi, %r12
movq %rsi, %rdi
callq 0x172f0
movq 0x40(%rsp), %r11
movq 0x48(%rsp), %r10
testl $0x3fffff00, %eax       # imm = 0x3FFFFF00
je 0x27fa9e
leaq 0x156162(%rip), %rsi    # 0x3d5bcb
leaq 0x15a9d7(%rip), %rdx    # 0x3da447
leaq 0x155fba(%rip), %r8     # 0x3d5a31
movl $0x15, %ebp
movl $0x15, %edi
movl $0x27bed, %ecx          # imm = 0x27BED
xorl %eax, %eax
callq 0x274d08
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %eax
andl $0x380800, %eax         # imm = 0x380800
andl $0x7, %ebp
cmpl $0x4, %ebp
movl %eax, 0x4(%rsp)
je 0x27fb3b
cmpl $0x5, %ebp
jne 0x27fb40
movl %eax, %ecx
orl $0x1, %ecx
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movq %rbx, %r8
movq %r15, %r9
movq 0x68(%rsp), %rax
pushq %rax
movq 0x68(%rsp), %rax
pushq %rax
movq 0x68(%rsp), %rax
pushq %rax
pushq %r10
pushq %r11
callq 0x27f9de
addq $0x30, %rsp
testl %eax, %eax
jne 0x27fb34
movl 0x4(%rsp), %ecx
orl $0x2, %ecx
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movq %rbx, %r8
movq %r15, %r9
pushq 0x68(%rsp)
pushq 0x68(%rsp)
pushq 0x68(%rsp)
pushq 0x68(%rsp)
pushq 0x68(%rsp)
callq 0x27f9de
addq $0x30, %rsp
testl %eax, %eax
je 0x27fb95
movl %eax, %ebp
jmp 0x27fa8d
movl $0x2, %ebp
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x27fcd2
testq %rax, %rax
je 0x27fbbf
movl 0x4(%rax), %ecx
andl $0x3, %ecx
cmpl %ebp, %ecx
jne 0x27fbbf
movsbl (%rax), %eax
cmpl %r14d, %eax
jne 0x27fbbf
cmpl $0x0, 0xc0(%r12)
je 0x27fb9c
leaq 0x15a98e(%rip), %rdx    # 0x3da50a
movl $0x5, %ebp
movq %r12, %rdi
movl $0x5, %esi
xorl %eax, %eax
callq 0x2762da
jmp 0x27fa8d
movl $0x3, %ebp
jmp 0x27fb40
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x27fbbf
movzwl 0xc6(%rax), %ecx
andl $-0x4, %ecx
incl %ecx
movw %cx, 0xc6(%rax)
movq 0x10(%rax), %rax
jmp 0x27fba1
movzbl %bpl, %ecx
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
movl $0x1, %r8d
callq 0x27fcd2
testq %rax, %rax
je 0x27fc49
movq %rax, %r13
movq 0x40(%rax), %rsi
movq %r12, %rdi
callq 0x2f07cb
movq 0x60(%rsp), %rcx
testq %rcx, %rcx
je 0x27fbf7
incl (%rcx)
movl 0x4(%r13), %eax
andl $0x3, %eax
orl 0x4(%rsp), %eax
xorl $0x200000, %eax         # imm = 0x200000
testq %r15, %r15
movq %rcx, 0x40(%r13)
movq 0x40(%rsp), %rcx
cmovneq %r15, %rcx
movl %eax, 0x4(%r13)
movq %rcx, 0x18(%r13)
movq 0x48(%rsp), %rax
movq %rax, 0x20(%r13)
movq 0x50(%rsp), %rax
movq %rax, 0x28(%r13)
movq 0x58(%rsp), %rax
movq %rax, 0x30(%r13)
movq %rbx, 0x8(%r13)
movb %r14b, (%r13)
xorl %ebp, %ebp
jmp 0x27fa8d
movl $0x7, %ebp
jmp 0x27fa8d