// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: walIndexPage
static int walIndexPage(Wal *pWal, int iPage, volatile u32 **ppPage){
  int rc = SQLITE_OK;

  /* Enlarge the pWal->apWiData[] array if required */
  if( pWal->nWiData<=iPage ){
    int nByte = sizeof(u32*)*(iPage+1);
    volatile u32 **apNew;
    apNew = (volatile u32 **)sqlite3_realloc((void *)pWal->apWiData, nByte);
    if( !apNew ){
      *ppPage = 0;
      return SQLITE_NOMEM;
    }
    memset((void*)&apNew[pWal->nWiData], 0,
           sizeof(u32*)*(iPage+1-pWal->nWiData));
    pWal->apWiData = apNew;
    pWal->nWiData = iPage+1;
  }

  /* Request a pointer to the required page from the VFS */
  if( pWal->apWiData[iPage]==0 ){
    if( pWal->exclusiveMode==WAL_HEAPMEMORY_MODE ){
      pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ);
      if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM;
    }else{
      rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, 
          pWal->writeLock, (void volatile **)&pWal->apWiData[iPage]
      );
      if( rc==SQLITE_READONLY ){
        pWal->readOnly |= WAL_SHM_RDONLY;
        rc = SQLITE_OK;
      }
    }
  }

  *ppPage = pWal->apWiData[iPage];
  assert( iPage==0 || *ppPage || rc!=SQLITE_OK );
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
cmpl -0x14(%rbp), %eax
jg 0x23752
movl -0x14(%rbp), %eax
addl $0x1, %eax
cltq
shlq $0x3, %rax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0x28(%rbp), %esi
callq 0xa500
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2370b
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x7, -0x4(%rbp)
jmp 0x2381e
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x28(%rax), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl -0x14(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
subl 0x28(%rcx), %eax
movslq %eax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x8200
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x14(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x23801
movq -0x10(%rbp), %rax
movzbl 0x3f(%rax), %eax
cmpl $0x2, %eax
jne 0x237af
movl $0x8000, %edi           # imm = 0x8000
callq 0xd860
movq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x14(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x14(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x237ad
movl $0x7, -0x24(%rbp)
jmp 0x237ff
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x14(%rbp), %esi
movq -0x10(%rbp), %rax
movzbl 0x40(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %r8
movslq -0x14(%rbp), %rax
shlq $0x3, %rax
addq %rax, %r8
movl $0x8000, %edx           # imm = 0x8000
callq 0x23dc0
movl %eax, -0x24(%rbp)
cmpl $0x8, -0x24(%rbp)
jne 0x237fd
movq -0x10(%rbp), %rax
movzbl 0x42(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x42(%rax)
movl $0x0, -0x24(%rbp)
jmp 0x237ff
jmp 0x23801
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)