// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: pager_write_pagelist
static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
  int rc = SQLITE_OK;                  /* Return code */

  /* This function is only called for rollback pagers in WRITER_DBMOD state. */
  assert( !pagerUseWal(pPager) );
  assert( pPager->eState==PAGER_WRITER_DBMOD );
  assert( pPager->eLock==EXCLUSIVE_LOCK );

  /* If the file is a temp-file has not yet been opened, open it now. It
  ** is not possible for rc to be other than SQLITE_OK if this branch
  ** is taken, as pager_wait_on_lock() is a no-op for temp-files.
  */
  if( !isOpen(pPager->fd) ){
    assert( pPager->tempFile && rc==SQLITE_OK );
    rc = pagerOpentemp(pPager, pPager->fd, pPager->vfsFlags);
  }

  /* Before the first write, give the VFS a hint of what the final
  ** file size will be.
  */
  assert( rc!=SQLITE_OK || isOpen(pPager->fd) );
  if( rc==SQLITE_OK 
   && pPager->dbHintSize<pPager->dbSize
   && (pList->pDirty || pList->pgno>pPager->dbHintSize)
  ){
    sqlite3_int64 szFile = pPager->pageSize * (sqlite3_int64)pPager->dbSize;
    sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_SIZE_HINT, &szFile);
    pPager->dbHintSize = pPager->dbSize;
  }

  while( rc==SQLITE_OK && pList ){
    Pgno pgno = pList->pgno;

    /* If there are dirty pages in the page cache with page numbers greater
    ** than Pager.dbSize, this means sqlite3PagerTruncateImage() was called to
    ** make the file smaller (presumably by auto-vacuum code). Do not write
    ** any such pages to the file.
    **
    ** Also, do not write out any page that has the PGHDR_DONT_WRITE flag
    ** set (set by sqlite3PagerDontWrite()).
    */
    if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
      i64 offset = (pgno-1)*(i64)pPager->pageSize;   /* Offset to write */
      char *pData;                                   /* Data to write */    

      assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
      if( pList->pgno==1 ) pager_write_changecounter(pList);

      /* Encode the database */
      CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM, pData);

      /* Write out the page data. */
      rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);

      /* If page 1 was just written, update Pager.dbFileVers to match
      ** the value now stored in the database file. If writing this 
      ** page caused the database file to grow, update dbFileSize. 
      */
      if( pgno==1 ){
        memcpy(&pPager->dbFileVers, &pData[24], sizeof(pPager->dbFileVers));
      }
      if( pgno>pPager->dbFileSize ){
        pPager->dbFileSize = pgno;
      }
      pPager->aStat[PAGER_STAT_WRITE]++;

      /* Update any backup objects copying the contents of this pager. */
      sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)pList->pData);

      PAGERTRACE(("STORE %d page %d hash(%08x)\n",
                   PAGERID(pPager), pgno, pager_pagehash(pList)));
      IOTRACE(("PGOUT %p %d\n", pPager, pgno));
      PAGER_INCR(sqlite3_pager_writedb_count);
    }else{
      PAGERTRACE(("NOSTORE %d page %d\n", PAGERID(pPager), pgno));
    }
    pager_set_pagehash(pList);
    pList = pList->pDirty;
  }

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x48(%rdi), %rdx
xorl %r15d, %r15d
cmpq $0x0, (%rdx)
jne 0x1b161
movq (%r14), %rdi
movl $0x87f61, %ecx          # imm = 0x87F61
andl 0xb4(%r14), %ecx
orl $0x1e, %ecx
xorl %esi, %esi
xorl %r8d, %r8d
callq *0x28(%rdi)
movl %eax, %r15d
testl %r15d, %r15d
jne 0x1b1a7
movl 0x1c(%r14), %eax
movl 0x28(%r14), %ecx
cmpl %eax, %ecx
jae 0x1b1a7
cmpq $0x0, 0x18(%rbx)
jne 0x1b17e
cmpl %ecx, 0x28(%rbx)
jbe 0x1b1a7
movslq 0xbc(%r14), %rcx
imulq %rax, %rcx
leaq -0x38(%rbp), %rdx
movq %rcx, (%rdx)
movq 0x48(%r14), %rdi
movq (%rdi), %rax
movl $0x5, %esi
callq *0x50(%rax)
movl 0x1c(%r14), %eax
movl %eax, 0x28(%r14)
testl %r15d, %r15d
setne %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0x1b25a
leaq 0x84(%r14), %rax
movq %rax, -0x30(%rbp)
movl 0x28(%rbx), %r12d
xorl %r15d, %r15d
cmpl 0x1c(%r14), %r12d
ja 0x1b248
testb $0x20, 0x2c(%rbx)
jne 0x1b248
movslq 0xbc(%r14), %r15
cmpl $0x1, %r12d
jne 0x1b1ee
movq %rbx, %rdi
callq 0x1b7f7
leal -0x1(%r12), %eax
imulq %rax, %r15
movq 0x8(%rbx), %r13
movq 0x48(%r14), %rdi
movl 0xbc(%r14), %edx
movq (%rdi), %rax
movq %r13, %rsi
movq %r15, %rcx
callq *0x18(%rax)
movl %eax, %r15d
cmpl $0x1, %r12d
jne 0x1b227
movups 0x18(%r13), %xmm0
movq -0x30(%rbp), %rax
movups %xmm0, (%rax)
cmpl 0x24(%r14), %r12d
jbe 0x1b231
movl %r12d, 0x24(%r14)
incl 0xf8(%r14)
movq 0x70(%r14), %rdi
movq 0x8(%rbx), %rdx
movl %r12d, %esi
callq 0x1b826
testl %r15d, %r15d
jne 0x1b25a
movq 0x18(%rbx), %rbx
testq %rbx, %rbx
jne 0x1b1c6
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq