// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
cmpq $0x0, (%rax)
jne 0x21753
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0xb4(%rax), %edx
callq 0x21c60
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x217c2
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jae 0x217c2
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x21784
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jbe 0x217c2
movq -0x8(%rbp), %rax
movslq 0xbc(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x1c(%rcx), %ecx
imulq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x5, %esi
leaq -0x20(%rbp), %rdx
callq 0x24890
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
jmp 0x217c4
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x39(%rbp)
jne 0x217da
cmpq $0x0, -0x10(%rbp)
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x217e6
jmp 0x218eb
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
ja 0x218d8
movq -0x10(%rbp), %rax
movzwl 0x2c(%rax), %ecx
andl $0x20, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x218d8
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movq -0x8(%rbp), %rcx
movslq 0xbc(%rcx), %rcx
imulq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x28(%rax)
jne 0x21843
movq -0x10(%rbp), %rdi
callq 0x223a0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x8(%rbp), %rax
movl 0xbc(%rax), %edx
movq -0x30(%rbp), %rcx
callq 0xf430
movl %eax, -0x14(%rbp)
cmpl $0x1, -0x24(%rbp)
jne 0x21895
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x18(%rcx), %rdx
movq %rdx, 0x84(%rax)
movq 0x20(%rcx), %rcx
movq %rcx, 0x8c(%rax)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jbe 0x218ab
movl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x8(%rbp), %rax
movl 0xf8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xf8(%rax)
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rdi
movl -0x24(%rbp), %esi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x22970
jmp 0x218da
jmp 0x218da
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x217c4
movl -0x14(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)