// File: /workspace/github_c_makefile_star2_O2/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 0x18cc2
movl 0x1c(%r14), %eax
movl 0x28(%r14), %ecx
xorl %r15d, %r15d
cmpl %eax, %ecx
jae 0x18ce3
cmpq $0x0, 0x18(%rbx)
jne 0x18c99
cmpl %ecx, 0x28(%rbx)
jbe 0x18ce3
movslq 0xbc(%r14), %rcx
imulq %rax, %rcx
leaq -0x38(%rbp), %rdx
movq %rcx, (%rdx)
movq 0x48(%r14), %rdi
movq (%rdi), %rax
pushq $0x5
popq %rsi
callq *0x50(%rax)
movl 0x1c(%r14), %eax
movl %eax, 0x28(%r14)
jmp 0x18ce3
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 %eax, %eax
je 0x18c7e
leaq 0x84(%r14), %rax
movq %rax, -0x30(%rbp)
testl %r15d, %r15d
jne 0x18d8e
testq %rbx, %rbx
je 0x18d8e
movl 0x28(%rbx), %r12d
xorl %r15d, %r15d
cmpl 0x1c(%r14), %r12d
ja 0x18d85
testb $0x20, 0x2c(%rbx)
jne 0x18d85
movslq 0xbc(%r14), %r15
movl %r15d, %edx
cmpl $0x1, %r12d
jne 0x18d32
movq %rbx, %rdi
callq 0x19241
movl 0xbc(%r14), %edx
leal -0x1(%r12), %eax
imulq %rax, %r15
movq 0x8(%rbx), %r13
movq 0x48(%r14), %rdi
movq (%rdi), %rax
movq %r13, %rsi
movq %r15, %rcx
callq *0x18(%rax)
movl %eax, %r15d
cmpl $0x1, %r12d
jne 0x18d64
movups 0x18(%r13), %xmm0
movq -0x30(%rbp), %rax
movups %xmm0, (%rax)
cmpl 0x24(%r14), %r12d
jbe 0x18d6e
movl %r12d, 0x24(%r14)
incl 0xf8(%r14)
movq 0x70(%r14), %rdi
movq 0x8(%rbx), %rdx
movl %r12d, %esi
callq 0x1927c
movq 0x18(%rbx), %rbx
jmp 0x18cee
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq