// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3FindFunction
SQLITE_PRIVATE FuncDef *sqlite3FindFunction(
  sqlite3 *db,       /* An open database */
  const char *zName, /* Name of the function.  Not null-terminated */
  int nName,         /* Number of characters in the name */
  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 */

  assert( nArg>=(-2) );
  assert( nArg>=(-1) || createFlag==0 );
  assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
  h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);

  /* First search for a match amongst the application-defined functions.
  */
  p = functionSearch(&db->aFunc, h, zName, nName);
  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 SQLITE_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->flags & SQLITE_PreferBuiltin)!=0) ){
    FuncDefHash *pHash = &GLOBAL(FuncDefHash, sqlite3GlobalFunctions);
    bestScore = 0;
    p = functionSearch(pHash, h, zName, nName);
    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 ){
    pBest->zName = (char *)&pBest[1];
    pBest->nArg = (u16)nArg;
    pBest->iPrefEnc = enc;
    memcpy(pBest->zName, zName, nName);
    pBest->zName[nName] = 0;
    sqlite3FuncDefInsert(&db->aFunc, pBest);
  }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %r8d, -0x6c(%rbp)
movl %ecx, %eax
movl -0x6c(%rbp), %ecx
movl %eax, -0x68(%rbp)
movl %edx, %eax
movl -0x68(%rbp), %edx
movl %eax, -0x64(%rbp)
movq %rsi, %rax
movl -0x64(%rbp), %esi
movq %rax, -0x60(%rbp)
movq %rdi, %r8
movq -0x60(%rbp), %rdi
movb %r9b, %al
movq %r8, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movl %edx, -0x20(%rbp)
movb %cl, -0x21(%rbp)
movb %al, -0x22(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x91d4d(%rip), %rax     # 0xaab40
movzbl (%rax,%rcx), %eax
addl -0x1c(%rbp), %eax
movl $0x17, %ecx
cltd
idivl %ecx
movl %edx, -0x40(%rbp)
movq -0x10(%rbp), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movl -0x40(%rbp), %esi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x87490
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x18e61
movq -0x30(%rbp), %rdi
movl -0x20(%rbp), %esi
movzbl -0x21(%rbp), %edx
callq 0x8aef0
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x18e53
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x18e23
cmpb $0x0, -0x22(%rbp)
jne 0x18eec
cmpq $0x0, -0x38(%rbp)
je 0x18e83
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %eax
andl $0x200000, %eax         # imm = 0x200000
cmpl $0x0, %eax
je 0x18eec
leaq 0xb912e(%rip), %rax     # 0xd1fb8
movq %rax, -0x50(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x50(%rbp), %rdi
movl -0x40(%rbp), %esi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x87490
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x18eea
movq -0x30(%rbp), %rdi
movl -0x20(%rbp), %esi
movzbl -0x21(%rbp), %edx
callq 0x8aef0
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x18edc
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x18eac
jmp 0x18eec
movzbl -0x22(%rbp), %eax
cmpl $0x0, %eax
je 0x18f84
cmpl $0x6, -0x3c(%rbp)
jge 0x18f84
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rax
addq $0x48, %rax
addq $0x1, %rax
movl %eax, %esi
callq 0x11ca0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x18f84
movq -0x38(%rbp), %rcx
addq $0x48, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
movl -0x20(%rbp), %eax
movw %ax, %cx
movq -0x38(%rbp), %rax
movw %cx, (%rax)
movb -0x21(%rbp), %cl
movq -0x38(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x82f0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
addq $0x1d8, %rdi            # imm = 0x1D8
movq -0x38(%rbp), %rsi
callq 0x87250
cmpq $0x0, -0x38(%rbp)
je 0x18fb4
movq -0x38(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x18faa
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x18faa
movzbl -0x22(%rbp), %eax
cmpl $0x0, %eax
je 0x18fb4
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x18fbc
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)