// File: /workspace/github_c_makefile_star2_O3/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
cmpq $0x0, (%rdx)
je 0x1b020
movl 0x1c(%r14), %eax
movl 0x28(%r14), %ecx
cmpl %eax, %ecx
jae 0x1af74
cmpq $0x0, 0x18(%rbx)
jne 0x1af4b
cmpl %ecx, 0x28(%rbx)
jbe 0x1af74
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)
testq %rbx, %rbx
je 0x1b046
leaq 0x84(%r14), %rax
movq %rax, -0x30(%rbp)
movl 0x28(%rbx), %r15d
xorl %r12d, %r12d
cmpl 0x1c(%r14), %r15d
ja 0x1b00c
testb $0x20, 0x2c(%rbx)
jne 0x1b00c
movslq 0xbc(%r14), %r12
movl %r12d, %edx
cmpl $0x1, %r15d
jne 0x1afba
movq %rbx, %rdi
callq 0x1b67c
movl 0xbc(%r14), %edx
leal -0x1(%r15), %eax
imulq %rax, %r12
movq 0x8(%rbx), %r13
movq 0x48(%r14), %rdi
movq (%rdi), %rax
movq %r13, %rsi
movq %r12, %rcx
callq *0x18(%rax)
movl %eax, %r12d
cmpl $0x1, %r15d
jne 0x1afeb
movups 0x18(%r13), %xmm0
movq -0x30(%rbp), %rax
movups %xmm0, (%rax)
cmpl 0x24(%r14), %r15d
jbe 0x1aff5
movl %r15d, 0x24(%r14)
incl 0xf8(%r14)
movq 0x70(%r14), %rdi
movq 0x8(%rbx), %rdx
movl %r15d, %esi
callq 0x1b6ab
testl %r12d, %r12d
jne 0x1b049
movq 0x18(%rbx), %rbx
testq %rbx, %rbx
jne 0x1af88
jmp 0x1b049
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, %r12d
testl %eax, %eax
jne 0x1b049
jmp 0x1af33
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq