// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: walCleanupHash
static void walCleanupHash(Wal *pWal){
  volatile ht_slot *aHash = 0;    /* Pointer to hash table to clear */
  volatile u32 *aPgno = 0;        /* Page number array for hash table */
  u32 iZero = 0;                  /* frame == (aHash[x]+iZero) */
  int iLimit = 0;                 /* Zero values greater than this */
  int nByte;                      /* Number of bytes to zero in aPgno[] */
  int i;                          /* Used to iterate through aHash[] */

  assert( pWal->writeLock );
  testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE-1 );
  testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE );
  testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE+1 );

  if( pWal->hdr.mxFrame==0 ) return;

  /* Obtain pointers to the hash-table and page-number array containing 
  ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
  ** that the page said hash-table and array reside on is already mapped.
  */
  assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
  assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
  walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &aHash, &aPgno, &iZero);

  /* Zero all hash-table entries that correspond to frame numbers greater
  ** than pWal->hdr.mxFrame.
  */
  iLimit = pWal->hdr.mxFrame - iZero;
  assert( iLimit>0 );
  for(i=0; i<HASHTABLE_NSLOT; i++){
    if( aHash[i]>iLimit ){
      aHash[i] = 0;
    }
  }
  
  /* Zero the entries in the aPgno array that correspond to frames with
  ** frame numbers greater than pWal->hdr.mxFrame. 
  */
  nByte = (int)((char *)aHash - (char *)&aPgno[iLimit+1]);
  memset((void *)&aPgno[iLimit+1], 0, nByte);

#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
  /* Verify that the every entry in the mapping region is still reachable
  ** via the hash table even after the cleanup.
  */
  if( iLimit ){
    int i;           /* Loop counter */
    int iKey;        /* Hash key */
    for(i=1; i<=iLimit; i++){
      for(iKey=walHash(aPgno[i]); aHash[iKey]; iKey=walNextHash(iKey)){
        if( aHash[iKey]==i ) break;
      }
      assert( aHash[iKey]==i );
    }
  }
#endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
}

// Assembly:
movl 0x58(%rdi), %eax
testl %eax, %eax
je 0x1c8b2
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
addl $0x1000, %eax           # imm = 0x1000
movabsq $0xffffffff021, %r14    # imm = 0xFFFFFFFF021
addq %rax, %r14
shrq $0xc, %r14
leaq -0x18(%rbp), %rdx
movl %r14d, %esi
callq 0x1c0bd
testl %eax, %eax
je 0x1c8b3
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r14d, %r14d
jmp 0x1c8e2
retq
movq -0x18(%rbp), %rax
testl %r14d, %r14d
je 0x1c8c6
shll $0xc, %r14d
addl $-0x22, %r14d
jmp 0x1c8d4
leaq 0x88(%rax), %rcx
movq %rcx, -0x18(%rbp)
xorl %r14d, %r14d
addq $0x4000, %rax           # imm = 0x4000
movq -0x18(%rbp), %rcx
addq $-0x4, %rcx
movl 0x58(%rbx), %edx
subl %r14d, %edx
xorl %esi, %esi
movzwl (%rax,%rsi,2), %edi
cmpl %edi, %edx
jge 0x1c8f8
movw $0x0, (%rax,%rsi,2)
incq %rsi
cmpq $0x2000, %rsi           # imm = 0x2000
jne 0x1c8ea
movslq %edx, %rdx
leaq (%rcx,%rdx,4), %rdi
addq $0x4, %rdi
subl %edi, %eax
movslq %eax, %rdx
xorl %esi, %esi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x8200