// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: walIndexAppend
static int walIndexAppend(Wal *pWal, u32 iFrame, u32 iPage){
  int rc;                         /* Return code */
  WalHashLoc sLoc;                /* Wal-index hash table location */

  rc = walHashGet(pWal, walFramePage(iFrame), &sLoc);

  /* Assuming the wal-index file was successfully mapped, populate the
  ** page number array and hash table entry.
  */
  if( rc==SQLITE_OK ){
    int iKey;                     /* Hash table key */
    int idx;                      /* Value to write to hash-table slot */
    int nCollide;                 /* Number of hash collisions */

    idx = iFrame - sLoc.iZero;
    assert( idx <= HASHTABLE_NSLOT/2 + 1 );

    /* If this is the first entry to be added to this hash-table, zero the
    ** entire hash table and aPgno[] array before proceeding.
    */
    if( idx==1 ){
      int nByte = (int)((u8 *)&sLoc.aHash[HASHTABLE_NSLOT]
                               - (u8 *)&sLoc.aPgno[1]);
      memset((void*)&sLoc.aPgno[1], 0, nByte);
    }

    /* If the entry in aPgno[] is already set, then the previous writer
    ** must have exited unexpectedly in the middle of a transaction (after
    ** writing one or more dirty pages to the WAL to free up memory).
    ** Remove the remnants of that writers uncommitted transaction from
    ** the hash-table before writing any new entries.
    */
    if( sLoc.aPgno[idx] ){
      walCleanupHash(pWal);
      assert( !sLoc.aPgno[idx] );
    }

    /* Write the aPgno[] array entry and the hash-table slot. */
    nCollide = idx;
    for(iKey=walHash(iPage); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){
      if( (nCollide--)==0 ) return SQLITE_CORRUPT_BKPT;
    }
    sLoc.aPgno[idx] = iPage;
    AtomicStore(&sLoc.aHash[iKey], (ht_slot)idx);

#ifdef SQLITE_ENABLE_EXPENSIVE_ASSERT
    /* Verify that the number of entries in the hash table exactly equals
    ** the number of entries in the mapping region.
    */
    {
      int i;           /* Loop counter */
      int nEntry = 0;  /* Number of entries in the hash table */
      for(i=0; i<HASHTABLE_NSLOT; i++){ if( sLoc.aHash[i] ) nEntry++; }
      assert( nEntry==idx );
    }

    /* Verify that the every entry in the mapping region is reachable
    ** via the hash table.  This turns out to be a really, really expensive
    ** thing to check, so only do this occasionally - not on every
    ** iteration.
    */
    if( (idx&0x3ff)==0 ){
      int i;           /* Loop counter */
      for(i=1; i<=idx; i++){
        for(iKey=walHash(sLoc.aPgno[i]);
            sLoc.aHash[iKey];
            iKey=walNextHash(iKey)){
          if( sLoc.aHash[iKey]==i ) break;
        }
        assert( sLoc.aHash[iKey]==i );
      }
    }
#endif /* SQLITE_ENABLE_EXPENSIVE_ASSERT */
  }


  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x14(%rbp), %edi
callq 0x3dfc40
movq -0x58(%rbp), %rdi
movl %eax, %esi
leaq -0x38(%rbp), %rdx
callq 0x3dfeb0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x3de508
movl -0x14(%rbp), %eax
subl -0x28(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x1, -0x40(%rbp)
jne 0x3de478
movq -0x38(%rbp), %rax
addq $0x4000, %rax           # imm = 0x4000
movq -0x30(%rbp), %rcx
addq $0x4, %rcx
subq %rcx, %rax
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
addq $0x4, %rdi
movslq -0x48(%rbp), %rdx
xorl %esi, %esi
callq 0x19360
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl $0x0, %eax
je 0x3de491
movq -0x10(%rbp), %rdi
callq 0x3e0240
movl -0x40(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x18(%rbp), %edi
callq 0x3dff60
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movw (%rax,%rcx,2), %ax
cmpw $0x0, %ax
je 0x3de4e2
movl -0x44(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x44(%rbp)
cmpl $0x0, %eax
jne 0x3de4d3
movl $0xec56, %edi           # imm = 0xEC56
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x3de50e
jmp 0x3de4d5
movl -0x3c(%rbp), %edi
callq 0x3dffb0
movl %eax, -0x3c(%rbp)
jmp 0x3de4a2
movl -0x18(%rbp), %edx
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movw -0x40(%rbp), %dx
movw %dx, -0x4a(%rbp)
movw -0x4a(%rbp), %dx
movw %dx, (%rax,%rcx,2)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)