// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3FindFunction
SQLITE_PRIVATE FuncDef *sqlite3FindFunction(
  sqlite3 *db,       /* An open database */
  const char *zName, /* Name of the function.  zero-terminated */
  int nArg,          /* Number of arguments.  -1 means any number */
  u8 enc,            /* Preferred text encoding */
  u8 createFlag      /* Create new entry if true and does not otherwise exist */
){
  FuncDef *p;         /* Iterator variable */
  FuncDef *pBest = 0; /* Best match found so far */
  int bestScore = 0;  /* Score of best match */
  int h;              /* Hash value */
  int nName;          /* Length of the name */

  assert( nArg>=(-2) );
  assert( nArg>=(-1) || createFlag==0 );
  nName = sqlite3Strlen30(zName);

  /* First search for a match amongst the application-defined functions.
  */
  p = (FuncDef*)sqlite3HashFind(&db->aFunc, zName);
  while( p ){
    int score = matchQuality(p, nArg, enc);
    if( score>bestScore ){
      pBest = p;
      bestScore = score;
    }
    p = p->pNext;
  }

  /* If no match is found, search the built-in functions.
  **
  ** If the DBFLAG_PreferBuiltin flag is set, then search the built-in
  ** functions even if a prior app-defined function was found.  And give
  ** priority to built-in functions.
  **
  ** Except, if createFlag is true, that means that we are trying to
  ** install a new function.  Whatever FuncDef structure is returned it will
  ** have fields overwritten with new information appropriate for the
  ** new function.  But the FuncDefs for built-in functions are read-only.
  ** So we must not search for built-ins when creating a new function.
  */
  if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){
    bestScore = 0;
    h = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zName[0]], nName);
    p = sqlite3FunctionSearch(h, zName);
    while( p ){
      int score = matchQuality(p, nArg, enc);
      if( score>bestScore ){
        pBest = p;
        bestScore = score;
      }
      p = p->pNext;
    }
  }

  /* If the createFlag parameter is true and the search did not reveal an
  ** exact match for the name, number of arguments and encoding, then add a
  ** new entry to the hash table and return it.
  */
  if( createFlag && bestScore<FUNC_PERFECT_MATCH &&
      (pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
    FuncDef *pOther;
    u8 *z;
    pBest->zName = (const char*)&pBest[1];
    pBest->nArg = (u16)nArg;
    pBest->funcFlags = enc;
    memcpy((char*)&pBest[1], zName, nName+1);
    for(z=(u8*)pBest->zName; *z; z++) *z = sqlite3UpperToLower[*z];
    pOther = (FuncDef*)sqlite3HashInsert(&db->aFunc, pBest->zName, pBest);
    if( pOther==pBest ){
      sqlite3DbFree(db, pBest);
      sqlite3OomFault(db);
      return 0;
    }else{
      pBest->pNext = pOther;
    }
  }

  if( pBest && (pBest->xSFunc || createFlag) ){
    return pBest;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, 0xc(%rsp)
movl %ecx, 0x8(%rsp)
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
xorl %r13d, %r13d
movl $0x0, %r12d
testq %rsi, %rsi
je 0x289893
movq %r14, %rdi
callq 0x172f0
movq %rax, %r12
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
movq %rbx, 0x18(%rsp)
leaq 0x220(%rbx), %rdi
movq %rdi, 0x20(%rsp)
movq %r14, 0x10(%rsp)
movq %r14, %rsi
xorl %edx, %edx
callq 0x2aefdf
movq 0x10(%rax), %r14
movl $0x0, %r15d
testq %r14, %r14
je 0x2898ed
xorl %r15d, %r15d
movzbl 0x8(%rsp), %ebx
xorl %r13d, %r13d
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x2f9b8e
cmpl %r13d, %eax
cmovgl %eax, %r13d
cmovgq %r14, %r15
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x2898cd
cmpb $0x0, 0xc(%rsp)
jne 0x28996b
testq %r15, %r15
je 0x289904
movq 0x18(%rsp), %rax
testb $0x2, 0x2c(%rax)
je 0x28996b
movq 0x10(%rsp), %rsi
movzbl (%rsi), %eax
leaq 0x15114d(%rip), %rcx    # 0x3daa60
movzbl (%rax,%rcx), %eax
addl %r12d, %eax
movl $0xb21642c9, %edi       # imm = 0xB21642C9
imulq %rax, %rdi
shrq $0x24, %rdi
leal (%rdi,%rdi,2), %ecx
shll $0x3, %ecx
subl %ecx, %edi
addl %eax, %edi
callq 0x2f916a
testq %rax, %rax
je 0x289968
movq %rax, %r14
xorl %r13d, %r13d
movzbl 0x8(%rsp), %ebx
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x2f9b8e
cmpl %r13d, %eax
cmovgl %eax, %r13d
cmovgq %r14, %r15
movq 0x10(%r14), %r14
testq %r14, %r14
jne 0x289946
jmp 0x28996b
xorl %r13d, %r13d
cmpb $0x0, 0xc(%rsp)
je 0x289a1f
cmpl $0x5, %r13d
jg 0x289a1f
leal 0x49(%r12), %esi
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x283569
testq %rax, %rax
je 0x289a02
movq %rax, %r15
leaq 0x48(%rax), %rdi
movq %rdi, 0x38(%rax)
movb %bpl, (%rax)
movzbl 0x8(%rsp), %eax
movl %eax, 0x4(%r15)
incl %r12d
movq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x17660
movb 0x48(%r15), %al
testb %al, %al
je 0x2899e3
leaq 0x49(%r15), %rcx
leaq 0x15108f(%rip), %rdx    # 0x3daa60
movzbl %al, %eax
movb (%rax,%rdx), %al
movb %al, -0x1(%rcx)
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x2899d1
movq 0x38(%r15), %rsi
movq 0x20(%rsp), %rdi
movq %r15, %rdx
callq 0x2aed98
movq %rax, %rbx
cmpq %r15, %rax
je 0x289a07
movq %rbx, 0x10(%r15)
jmp 0x289a1a
xorl %r15d, %r15d
jmp 0x289a1f
movq %r14, %rdi
movq %r15, %rsi
callq 0x28c3e7
movq %r14, %rdi
callq 0x2824bb
cmpq %r15, %rbx
je 0x289a32
testq %r15, %r15
je 0x289a32
cmpb $0x0, 0xc(%rsp)
jne 0x289a35
cmpq $0x0, 0x18(%r15)
jne 0x289a35
xorl %r15d, %r15d
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq