// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: pcache1Fetch
static sqlite3_pcache_page *pcache1Fetch(
  sqlite3_pcache *p, 
  unsigned int iKey, 
  int createFlag
){
  unsigned int nPinned;
  PCache1 *pCache = (PCache1 *)p;
  PGroup *pGroup;
  PgHdr1 *pPage = 0;

  assert( pCache->bPurgeable || createFlag!=1 );
  assert( pCache->bPurgeable || pCache->nMin==0 );
  assert( pCache->bPurgeable==0 || pCache->nMin==10 );
  assert( pCache->nMin==0 || pCache->bPurgeable );
  pcache1EnterMutex(pGroup = pCache->pGroup);

  /* Step 1: Search the hash table for an existing entry. */
  if( pCache->nHash>0 ){
    unsigned int h = iKey % pCache->nHash;
    for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
  }

  /* Step 2: Abort if no existing page is found and createFlag is 0 */
  if( pPage || createFlag==0 ){
    pcache1PinPage(pPage);
    goto fetch_out;
  }

  /* The pGroup local variable will normally be initialized by the
  ** pcache1EnterMutex() macro above.  But if SQLITE_MUTEX_OMIT is defined,
  ** then pcache1EnterMutex() is a no-op, so we have to initialize the
  ** local variable here.  Delaying the initialization of pGroup is an
  ** optimization:  The common case is to exit the module before reaching
  ** this point.
  */
#ifdef SQLITE_MUTEX_OMIT
  pGroup = pCache->pGroup;
#endif

  /* Step 3: Abort if createFlag is 1 but the cache is nearly full */
  assert( pCache->nPage >= pCache->nRecyclable );
  nPinned = pCache->nPage - pCache->nRecyclable;
  assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
  assert( pCache->n90pct == pCache->nMax*9/10 );
  if( createFlag==1 && (
        nPinned>=pGroup->mxPinned
     || nPinned>=pCache->n90pct
     || pcache1UnderMemoryPressure(pCache)
  )){
    goto fetch_out;
  }

  if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){
    goto fetch_out;
  }
  assert( pCache->nHash>0 && pCache->apHash );

  /* Step 4. Try to recycle a page. */
  if( pCache->bPurgeable && pGroup->pLruTail && (
         (pCache->nPage+1>=pCache->nMax)
      || pGroup->nCurrentPage>=pGroup->nMaxPage
      || pcache1UnderMemoryPressure(pCache)
  )){
    PCache1 *pOther;
    pPage = pGroup->pLruTail;
    pcache1RemoveFromHash(pPage);
    pcache1PinPage(pPage);
    pOther = pPage->pCache;

    /* We want to verify that szPage and szExtra are the same for pOther
    ** and pCache.  Assert that we can verify this by comparing sums. */
    assert( (pCache->szPage & (pCache->szPage-1))==0 && pCache->szPage>=512 );
    assert( pCache->szExtra<512 );
    assert( (pOther->szPage & (pOther->szPage-1))==0 && pOther->szPage>=512 );
    assert( pOther->szExtra<512 );

    if( pOther->szPage+pOther->szExtra != pCache->szPage+pCache->szExtra ){
      pcache1FreePage(pPage);
      pPage = 0;
    }else{
      pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
    }
  }

  /* Step 5. If a usable page buffer has still not been found, 
  ** attempt to allocate a new one. 
  */
  if( !pPage ){
    if( createFlag==1 ) sqlite3BeginBenignMalloc();
    pPage = pcache1AllocPage(pCache);
    if( createFlag==1 ) sqlite3EndBenignMalloc();
  }

  if( pPage ){
    unsigned int h = iKey % pCache->nHash;
    pCache->nPage++;
    pPage->iKey = iKey;
    pPage->pNext = pCache->apHash[h];
    pPage->pCache = pCache;
    pPage->pLruPrev = 0;
    pPage->pLruNext = 0;
    *(void **)pPage->page.pExtra = 0;
    pCache->apHash[h] = pPage;
  }

fetch_out:
  if( pPage && iKey>pCache->iMaxKey ){
    pCache->iMaxKey = iKey;
  }
  pcache1LeaveMutex(pGroup);
  return &pPage->page;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jbe 0x8a265
movl -0xc(%rbp), %eax
movq -0x20(%rbp), %rcx
xorl %edx, %edx
divl 0x2c(%rcx)
movl %edx, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x30(%rbp)
movb %al, -0x45(%rbp)
je 0x8a24a
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0xc(%rbp), %eax
setne %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x8a253
jmp 0x8a263
jmp 0x8a255
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x8a22e
jmp 0x8a265
cmpq $0x0, -0x30(%rbp)
jne 0x8a272
cmpl $0x0, -0x10(%rbp)
jne 0x8a280
movq -0x30(%rbp), %rdi
callq 0x8a7e0
jmp 0x8a473
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x20(%rbp), %rcx
subl 0x24(%rcx), %eax
movl %eax, -0x14(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x8a2cd
movl -0x14(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x8a2c8
movl -0x14(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jae 0x8a2c8
movq -0x20(%rbp), %rdi
callq 0x8a9a0
cmpl $0x0, %eax
je 0x8a2cd
jmp 0x8a473
movq -0x20(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jb 0x8a2f0
movq -0x20(%rbp), %rdi
callq 0x8a9f0
cmpl $0x0, %eax
je 0x8a2f0
jmp 0x8a473
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x8a3b7
movq -0x28(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x8a3b7
movq -0x20(%rbp), %rax
movl 0x28(%rax), %eax
addl $0x1, %eax
movq -0x20(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x8a33e
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0x8a33e
movq -0x20(%rbp), %rdi
callq 0x8a9a0
cmpl $0x0, %eax
je 0x8a3b7
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x8a8d0
movq -0x30(%rbp), %rdi
callq 0x8a7e0
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x40(%rbp), %rcx
addl 0xc(%rcx), %eax
movq -0x20(%rbp), %rcx
movl 0x8(%rcx), %ecx
movq -0x20(%rbp), %rdx
addl 0xc(%rdx), %ecx
cmpl %ecx, %eax
je 0x8a39b
movq -0x30(%rbp), %rdi
callq 0x8a950
movq $0x0, -0x30(%rbp)
jmp 0x8a3b5
movq -0x40(%rbp), %rax
movl 0x10(%rax), %edx
movq -0x20(%rbp), %rax
subl 0x10(%rax), %edx
movq -0x28(%rbp), %rax
movl 0x14(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x14(%rax)
jmp 0x8a3b7
cmpq $0x0, -0x30(%rbp)
jne 0x8a3e3
cmpl $0x1, -0x10(%rbp)
jne 0x8a3c9
callq 0x241b0
movq -0x20(%rbp), %rdi
callq 0x8ab20
movq %rax, -0x30(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x8a3e1
callq 0x24200
jmp 0x8a3e3
cmpq $0x0, -0x30(%rbp)
je 0x8a471
movl -0xc(%rbp), %eax
movq -0x20(%rbp), %rcx
xorl %edx, %edx
divl 0x2c(%rcx)
movl %edx, -0x44(%rbp)
movq -0x20(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movl -0xc(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x44(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x8a473
cmpq $0x0, -0x30(%rbp)
je 0x8a490
movl -0xc(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jbe 0x8a490
movl -0xc(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x30(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)