// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movl %ecx, %r14d
movl %edx, %r13d
movq %rsi, %r12
movq %rdi, %rbx
testq %rsi, %rsi
je 0x27fd0a
movq %r12, %rdi
callq 0x172f0
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq %rax, 0x10(%rsp)
jmp 0x27fd13
movq $0x0, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
leaq 0x220(%rbx), %rdi
xorl %ebp, %ebp
movq %rdi, 0x20(%rsp)
movq %r12, %rsi
xorl %edx, %edx
callq 0x2a547e
movq 0x10(%rax), %rbx
testq %rbx, %rbx
movl %r14d, 0xc(%rsp)
je 0x27fd87
movzbl %r14b, %r15d
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x2f07ff
cmpl %ebp, %eax
cmovgl %eax, %ebp
cmovgq %rbx, %r14
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x27fd45
cmpb $0x0, 0x8(%rsp)
jne 0x27fe02
testq %r14, %r14
je 0x27fd98
movq 0x18(%rsp), %rax
testb $0x2, 0x2c(%rax)
jne 0x27fd9b
xorl %eax, %eax
jmp 0x27fea9
xorl %r14d, %r14d
movl $0x0, %ebp
cmpb $0x0, 0x8(%rsp)
jne 0x27fe02
jmp 0x27fd9b
xorl %r14d, %r14d
movzbl (%r12), %eax
leaq 0x151539(%rip), %rcx    # 0x3d12e0
movzbl (%rax,%rcx), %eax
addl 0x10(%rsp), %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
movq %r12, %rsi
callq 0x2efd9f
xorl %ebp, %ebp
testq %rax, %rax
je 0x27fea2
movq %rax, %rbx
movzbl 0xc(%rsp), %r15d
movq %rbx, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x2f07ff
cmpl %ebp, %eax
cmovgl %eax, %ebp
cmovgq %rbx, %r14
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x27fde2
cmpb $0x0, 0x8(%rsp)
setne %al
je 0x27fea4
cmpl $0x5, %ebp
jg 0x27fea4
movq 0x10(%rsp), %rbp
leal 0x49(%rbp), %esi
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x279b27
testq %rax, %rax
je 0x27fec9
movq %rax, %r14
leaq 0x48(%rax), %rbx
movq %rbx, 0x38(%rax)
movb %r13b, (%rax)
movzbl 0xc(%rsp), %eax
movl %eax, 0x4(%r14)
incl %ebp
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x17660
movb 0x48(%r14), %al
testb %al, %al
je 0x27fe87
leaq 0x49(%r14), %rcx
leaq 0x15146f(%rip), %rdx    # 0x3d12e0
movzbl %al, %eax
movb (%rax,%rdx), %al
movb %al, -0x1(%rcx)
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x27fe71
movq 0x38(%r14), %rbx
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2a5210
cmpq %r14, %rax
je 0x27feb6
movq %rax, 0x10(%r14)
jmp 0x27fecc
xorl %eax, %eax
testq %r14, %r14
je 0x27fec9
testb %al, %al
jne 0x27fecc
cmpq $0x0, 0x18(%r14)
je 0x27fec9
jmp 0x27fecc
movq %r15, %rdi
movq %r14, %rsi
callq 0x282904
movq %r15, %rdi
callq 0x278b1c
xorl %r14d, %r14d
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq