// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movb %cl, -0x1d(%rbp)
movb %al, -0x1e(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3c3400
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
movq -0x18(%rbp), %rsi
callq 0x40ad70
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x3d1d5d
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
movzbl -0x1d(%rbp), %edx
callq 0x46e720
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x3d1d4f
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x3d1d1f
cmpb $0x0, -0x1e(%rbp)
jne 0x3d1df6
cmpq $0x0, -0x30(%rbp)
je 0x3d1d7d
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3d1df6
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x1d4ccc(%rip), %rax    # 0x5a6a60
movzbl (%rax,%rcx), %eax
addl -0x3c(%rbp), %eax
movl $0x17, %ecx
cltd
idivl %ecx
movl %edx, -0x38(%rbp)
movl -0x38(%rbp), %edi
movq -0x18(%rbp), %rsi
callq 0x46d1f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x3d1df4
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %esi
movzbl -0x1d(%rbp), %edx
callq 0x46e720
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x3d1de6
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x3d1db6
jmp 0x3d1df6
movzbl -0x1e(%rbp), %eax
cmpl $0x0, %eax
je 0x3d1f04
cmpl $0x6, -0x34(%rbp)
jge 0x3d1f04
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
addq $0x48, %rsi
addq $0x1, %rsi
callq 0x3c9520
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x3d1f04
movq -0x30(%rbp), %rcx
addq $0x48, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
movl -0x1c(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movzbl -0x1d(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rdi
addq $0x48, %rdi
movq -0x18(%rbp), %rsi
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
callq 0x19610
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpb $0x0, (%rax)
je 0x3d1eac
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x1d4bcb(%rip), %rax    # 0x5a6a60
movb (%rax,%rcx), %cl
movq -0x58(%rbp), %rax
movb %cl, (%rax)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x3d1e7c
movq -0x10(%rbp), %rdi
addq $0x220, %rdi            # imm = 0x220
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x30(%rbp), %rdx
callq 0x40ada0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x3d1ef6
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3c00a0
movq -0x10(%rbp), %rdi
callq 0x3c8ba0
movq $0x0, -0x8(%rbp)
jmp 0x3d1f31
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x3d1f04
cmpq $0x0, -0x30(%rbp)
je 0x3d1f29
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x3d1f1f
movzbl -0x1e(%rbp), %eax
cmpl $0x0, %eax
je 0x3d1f29
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d1f31
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)