// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: pager_playback
static int pager_playback(Pager *pPager, int isHot){
  sqlite3_vfs *pVfs = pPager->pVfs;
  i64 szJ;                 /* Size of the journal file in bytes */
  u32 nRec;                /* Number of Records in the journal */
  u32 u;                   /* Unsigned loop counter */
  Pgno mxPg = 0;           /* Size of the original file in pages */
  int rc;                  /* Result code of a subroutine */
  int res = 1;             /* Value returned by sqlite3OsAccess() */
  char *zSuper = 0;        /* Name of super-journal file if any */
  int needPagerReset;      /* True to reset page prior to first page rollback */
  int nPlayback = 0;       /* Total number of pages restored from journal */
  u32 savedPageSize = pPager->pageSize;

  /* Figure out how many records are in the journal.  Abort early if
  ** the journal is empty.
  */
  assert( isOpen(pPager->jfd) );
  rc = sqlite3OsFileSize(pPager->jfd, &szJ);
  if( rc!=SQLITE_OK ){
    goto end_playback;
  }

  /* Read the super-journal name from the journal, if it is present.
  ** If a super-journal file name is specified, but the file is not
  ** present on disk, then the journal is not hot and does not need to be
  ** played back.
  **
  ** TODO: Technically the following is an error because it assumes that
  ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
  ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
  ** mxPathname is 512, which is the same as the minimum allowable value
  ** for pageSize.
  */
  zSuper = pPager->pTmpSpace;
  rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
  if( rc==SQLITE_OK && zSuper[0] ){
    rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
  }
  zSuper = 0;
  if( rc!=SQLITE_OK || !res ){
    goto end_playback;
  }
  pPager->journalOff = 0;
  needPagerReset = isHot;

  /* This loop terminates either when a readJournalHdr() or
  ** pager_playback_one_page() call returns SQLITE_DONE or an IO error
  ** occurs.
  */
  while( 1 ){
    /* Read the next journal header from the journal file.  If there are
    ** not enough bytes left in the journal file for a complete header, or
    ** it is corrupted, then a process must have failed while writing it.
    ** This indicates nothing more needs to be rolled back.
    */
    rc = readJournalHdr(pPager, isHot, szJ, &nRec, &mxPg);
    if( rc!=SQLITE_OK ){
      if( rc==SQLITE_DONE ){
        rc = SQLITE_OK;
      }
      goto end_playback;
    }

    /* If nRec is 0xffffffff, then this journal was created by a process
    ** working in no-sync mode. This means that the rest of the journal
    ** file consists of pages, there are no more journal headers. Compute
    ** the value of nRec based on this assumption.
    */
    if( nRec==0xffffffff ){
      assert( pPager->journalOff==JOURNAL_HDR_SZ(pPager) );
      nRec = (int)((szJ - JOURNAL_HDR_SZ(pPager))/JOURNAL_PG_SZ(pPager));
    }

    /* If nRec is 0 and this rollback is of a transaction created by this
    ** process and if this is the final header in the journal, then it means
    ** that this part of the journal was being filled but has not yet been
    ** synced to disk.  Compute the number of pages based on the remaining
    ** size of the file.
    **
    ** The third term of the test was added to fix ticket #2565.
    ** When rolling back a hot journal, nRec==0 always means that the next
    ** chunk of the journal contains zero pages to be rolled back.  But
    ** when doing a ROLLBACK and the nRec==0 chunk is the last chunk in
    ** the journal, it means that the journal might contain additional
    ** pages that need to be rolled back and that the number of pages
    ** should be computed based on the journal file size.
    */
    if( nRec==0 && !isHot &&
        pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff ){
      nRec = (int)((szJ - pPager->journalOff) / JOURNAL_PG_SZ(pPager));
    }

    /* If this is the first header read from the journal, truncate the
    ** database file back to its original size.
    */
    if( pPager->journalOff==JOURNAL_HDR_SZ(pPager) ){
      rc = pager_truncate(pPager, mxPg);
      if( rc!=SQLITE_OK ){
        goto end_playback;
      }
      pPager->dbSize = mxPg;
    }

    /* Copy original pages out of the journal and back into the
    ** database file and/or page cache.
    */
    for(u=0; u<nRec; u++){
      if( needPagerReset ){
        pager_reset(pPager);
        needPagerReset = 0;
      }
      rc = pager_playback_one_page(pPager,&pPager->journalOff,0,1,0);
      if( rc==SQLITE_OK ){
        nPlayback++;
      }else{
        if( rc==SQLITE_DONE ){
          pPager->journalOff = szJ;
          break;
        }else if( rc==SQLITE_IOERR_SHORT_READ ){
          /* If the journal has been truncated, simply stop reading and
          ** processing the journal. This might happen if the journal was
          ** not completely written and synced prior to a crash.  In that
          ** case, the database should have never been written in the
          ** first place so it is OK to simply abandon the rollback. */
          rc = SQLITE_OK;
          goto end_playback;
        }else{
          /* If we are unable to rollback, quit and return the error
          ** code.  This will cause the pager to enter the error state
          ** so that no further harm will be done.  Perhaps the next
          ** process to come along will be able to rollback the database.
          */
          goto end_playback;
        }
      }
    }
  }
  /*NOTREACHED*/
  assert( 0 );

end_playback:
  if( rc==SQLITE_OK ){
    rc = sqlite3PagerSetPagesize(pPager, &savedPageSize, -1);
  }
  /* Following a rollback, the database file should be back in its original
  ** state prior to the start of the transaction, so invoke the
  ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
  ** assertion that the transaction counter was modified.
  */
#ifdef SQLITE_DEBUG
  sqlite3OsFileControlHint(pPager->fd,SQLITE_FCNTL_DB_UNCHANGED,0);
#endif

  /* If this playback is happening automatically as a result of an IO or
  ** malloc error that occurred after the change-counter was updated but
  ** before the transaction was committed, then the change-counter
  ** modification may just have been reverted. If this happens in exclusive
  ** mode, then subsequent transactions performed by the connection will not
  ** update the change-counter at all. This may lead to cache inconsistency
  ** problems for other processes at some point in the future. So, just
  ** in case this has happened, clear the changeCountDone flag now.
  */
  pPager->changeCountDone = pPager->tempFile;

  if( rc==SQLITE_OK ){
    zSuper = pPager->pTmpSpace;
    rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
    testcase( rc!=SQLITE_OK );
  }
  if( rc==SQLITE_OK
   && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
  ){
    rc = sqlite3PagerSync(pPager, 0);
  }
  if( rc==SQLITE_OK ){
    rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0);
    testcase( rc!=SQLITE_OK );
  }
  if( rc==SQLITE_OK && zSuper[0] && res ){
    /* If there was a super-journal and this routine will return success,
    ** see if it is possible to delete the super-journal.
    */
    rc = pager_delsuper(pPager, zSuper);
    testcase( rc!=SQLITE_OK );
  }
  if( isHot && nPlayback ){
    sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s",
                nPlayback, pPager->zJournal);
  }

  /* The Pager.sectorSize variable may have been updated while rolling
  ** back a journal created by a process with a different sector size
  ** value. Reset it to the correct value for this process.
  */
  setSectorSize(pPager);
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movq (%rdi), %r12
movl $0x0, 0x44(%rsp)
movl $0x1, 0x28(%rsp)
movl 0xbc(%rdi), %eax
movl %eax, 0x58(%rsp)
movq 0x50(%rdi), %rdi
movq (%rdi), %rax
leaq 0x48(%rsp), %rsi
callq *0x30(%rax)
xorl %r14d, %r14d
testl %eax, %eax
jne 0x289ecc
movq 0x110(%rbx), %r13
movq (%rbx), %rax
movq 0x50(%rbx), %rdi
movl 0x8(%rax), %edx
incl %edx
movq %r13, %rsi
callq 0x28ac60
testl %eax, %eax
je 0x289f15
movl %eax, %r15d
movb 0x10(%rbx), %al
movb %al, 0x16(%rbx)
testl %ebp, %ebp
je 0x289efb
testl %r14d, %r14d
je 0x289efb
movq 0xd8(%rbx), %rcx
leaq 0x14be1e(%rip), %rsi    # 0x3d5d0a
movl $0x21b, %edi            # imm = 0x21B
movl %r14d, %edx
xorl %eax, %eax
callq 0x274d08
movq %rbx, %rdi
callq 0x285ccb
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
cmpb $0x0, (%r13)
movl $0x0, %r15d
je 0x289f3a
leaq 0x28(%rsp), %rcx
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x38(%r12)
movl %eax, %r15d
testl %r15d, %r15d
jne 0x28a0bb
cmpl $0x0, 0x28(%rsp)
je 0x28a0bb
leaq 0x60(%rbx), %r12
movq $0x0, 0x60(%rbx)
xorl %r14d, %r14d
movl %ebp, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
movq 0x48(%rsp), %rdx
movq %rbx, %rdi
movl %ebp, %esi
leaq 0x2c(%rsp), %rcx
leaq 0x44(%rsp), %r8
callq 0x28a7b2
testl %eax, %eax
jne 0x28a142
movl 0x2c(%rsp), %r13d
movl 0xb8(%rbx), %ecx
cmpl $-0x1, %r13d
jne 0x289fb7
movq 0x48(%rsp), %rax
subq %rcx, %rax
movslq 0xbc(%rbx), %rsi
addq $0x8, %rsi
cqto
idivq %rsi
movq %rax, %r13
movl %r13d, 0x2c(%rsp)
movl %r13d, %eax
orl %ebp, %eax
movq (%r12), %rsi
jne 0x289fee
movq 0x68(%rbx), %rax
addq %rcx, %rax
cmpq %rsi, %rax
jne 0x289fee
movq 0x48(%rsp), %rax
subq %rsi, %rax
movslq 0xbc(%rbx), %rdi
addq $0x8, %rdi
cqto
idivq %rdi
movq %rax, %r13
movl %r13d, 0x2c(%rsp)
cmpq %rcx, %rsi
jne 0x28a01c
movq %r14, 0x18(%rsp)
movl %ebp, %r14d
movl 0x44(%rsp), %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x28ad7d
testl %eax, %eax
jne 0x28a153
movl %ebp, 0x1c(%rbx)
movl %r14d, %ebp
movq 0x18(%rsp), %r14
testl %r13d, %r13d
je 0x289f65
leal (%r14,%r13), %eax
movl %eax, 0x18(%rsp)
cmpl $0x0, 0x10(%rsp)
sete %al
negl %r13d
xorl %ebp, %ebp
testb $0x1, %al
jne 0x28a046
movq %rbx, %rdi
callq 0x28ae2e
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x28a481
testl %eax, %eax
jne 0x28a080
decl %ebp
movb $0x1, %al
cmpl %ebp, %r13d
jne 0x28a03a
movl $0x0, 0x10(%rsp)
movl 0x18(%rsp), %eax
movl %eax, %r14d
movl 0xc(%rsp), %ebp
jmp 0x289f65
movl %eax, %r15d
cmpl $0x65, %eax
jne 0x28a0a5
movq 0x48(%rsp), %rax
movq %rax, (%r12)
subl %ebp, %r14d
movl $0x0, 0x10(%rsp)
movl 0xc(%rsp), %ebp
jmp 0x289f65
subl %ebp, %r14d
cmpl $0x20a, %r15d           # imm = 0x20A
jne 0x28a0b7
movl 0xc(%rsp), %ebp
jmp 0x28a0c4
movl 0xc(%rsp), %ebp
testl %r15d, %r15d
jne 0x289ecf
leaq 0x58(%rsp), %rsi
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x285a0f
movl %eax, %r15d
movb 0x10(%rbx), %al
movb %al, 0x16(%rbx)
testl %r15d, %r15d
jne 0x289ed5
movq 0x110(%rbx), %r13
movq (%rbx), %rax
movq 0x50(%rbx), %rdi
movl 0x8(%rax), %edx
incl %edx
movq %r13, %rsi
callq 0x28ac60
testl %eax, %eax
jne 0x28a13a
movb 0x14(%rbx), %al
addb $-0x4, %al
cmpb $-0x4, %al
ja 0x28a11e
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2776ad
testl %eax, %eax
jne 0x28a13a
xorl %esi, %esi
cmpb $0x0, (%r13)
setne %sil
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x289512
testl %eax, %eax
je 0x28a163
movl %eax, %r15d
jmp 0x289ed5
movl %eax, %r15d
cmpl $0x65, %eax
jne 0x289ecf
jmp 0x28a0c4
movl %eax, %r15d
movl %r14d, %ebp
movq 0x18(%rsp), %r14
jmp 0x289ecf
cmpb $0x0, (%r13)
je 0x289ed5
cmpl $0x0, 0x28(%rsp)
je 0x289ed5
movq (%rbx), %rax
movq %rax, 0x10(%rsp)
movslq 0x4(%rax), %r15
addq %r15, %r15
movq %r15, %rdi
callq 0x272ae6
testq %rax, %rax
je 0x28a1ce
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x173a0
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %r12, 0x20(%rsp)
movq %r12, %rdx
movl $0x4001, %ecx           # imm = 0x4001
xorl %r8d, %r8d
callq *0x28(%rdi)
testl %eax, %eax
je 0x28a1d9
movl %eax, %r15d
xorl %edi, %edi
jmp 0x28a3a2
movl $0x7, %r15d
jmp 0x289ed5
movl %ebp, 0xc(%rsp)
movq 0x10(%rsp), %rax
movslq 0x4(%rax), %rbp
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
leaq 0x38(%rsp), %rsi
callq *0x30(%rax)
testl %eax, %eax
je 0x28a208
movl %eax, %r15d
xorl %edi, %edi
movl 0xc(%rsp), %ebp
jmp 0x28a3a2
movq 0x10(%rsp), %rax
movslq 0x8(%rax), %r12
movq 0x38(%rsp), %rax
leaq (%rax,%r12), %rdi
addq $0x3, %rdi
callq 0x272ae6
testq %rax, %rax
je 0x28a3f3
movq %r14, 0x18(%rsp)
movq 0x38(%rsp), %r14
movq 0x20(%rsp), %rdi
movq (%rdi), %r8
movq %rax, 0x30(%rsp)
movq %rax, %rsi
movl %r14d, %edx
xorl %ecx, %ecx
callq *0x10(%r8)
testl %eax, %eax
jne 0x28a391
movq 0x38(%rsp), %rax
xorl %ecx, %ecx
movq 0x30(%rsp), %rdx
movb %cl, (%rdx,%rax)
movq 0x38(%rsp), %rax
movb %cl, 0x1(%rdx,%rax)
cmpq $0x0, 0x38(%rsp)
jle 0x28a365
movq 0x20(%rsp), %rax
addq %rbp, %rax
movq %rax, 0x60(%rsp)
incq %r12
movq 0x30(%rsp), %rbp
leaq (%r14,%rbp), %rcx
addq $0x2, %rcx
movq %rcx, 0x50(%rsp)
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
leaq 0x5c(%rsp), %rcx
callq *0x38(%rdi)
movl %eax, %r15d
testl %eax, %eax
jne 0x28a408
cmpl $0x0, 0x5c(%rsp)
je 0x28a33f
movq 0x10(%rsp), %rdi
movq %rbp, %r14
movq %rbp, %rsi
movq 0x60(%rsp), %rbp
movq %rbp, %rdx
movl $0x4001, %ecx           # imm = 0x4001
xorl %r8d, %r8d
callq *0x28(%rdi)
testl %eax, %eax
jne 0x28a3fe
movq %rbp, %rdi
movq 0x50(%rsp), %rsi
movl %r12d, %edx
callq 0x28ac60
movl %eax, 0x40(%rsp)
movq (%rbp), %rax
testq %rax, %rax
je 0x28a312
movq %rbp, %rdi
callq *0x8(%rax)
movq $0x0, (%rbp)
cmpl $0x0, 0x40(%rsp)
jne 0x28a403
movq 0x50(%rsp), %rax
cmpb $0x0, (%rax)
movq %r14, %rbp
je 0x28a33f
movq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x17a40
testl %eax, %eax
je 0x28a408
movq %rbp, %rdi
callq 0x172f0
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
addq %rax, %rbp
incq %rbp
movq %rbp, %rax
subq 0x30(%rsp), %rax
cmpq 0x38(%rsp), %rax
jl 0x28a29d
movq 0x20(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x28a384
movq 0x20(%rsp), %r15
movq %r15, %rdi
callq *0x8(%rax)
movq $0x0, (%r15)
movq 0x10(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x30(%rdi)
movl %eax, %r15d
movl 0xc(%rsp), %ebp
movq 0x18(%rsp), %r14
movq 0x30(%rsp), %rdi
callq 0x272c00
movq 0x20(%rsp), %r12
movq (%r12), %rax
testq %rax, %rax
je 0x28a3c3
movq %r12, %rdi
callq *0x8(%rax)
movq $0x0, (%r12)
cmpl $0x0, 0x231296(%rip)    # 0x4bb660
je 0x28a3e5
movq %r12, %rdi
callq *0x2312c3(%rip)         # 0x4bb698
cltq
subq %rax, 0x23471a(%rip)    # 0x4beaf8
decq 0x23475b(%rip)          # 0x4beb40
movq %r12, %rdi
callq *0x23129a(%rip)         # 0x4bb688
jmp 0x289ed5
movl $0x7, %r15d
jmp 0x28a1fd
movl %eax, %r15d
jmp 0x28a408
movl 0x40(%rsp), %r15d
movq 0x30(%rsp), %rdi
callq 0x272c00
movl 0xc(%rsp), %ebp
movq 0x18(%rsp), %r14
jmp 0x28a3a7