// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: pagerPlaybackSavepoint
static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
  i64 szJ;                 /* Effective size of the main journal */
  i64 iHdrOff;             /* End of first segment of main-journal records */
  int rc = SQLITE_OK;      /* Return code */
  Bitvec *pDone = 0;       /* Bitvec to ensure pages played back only once */

  assert( pPager->eState!=PAGER_ERROR );
  assert( pPager->eState>=PAGER_WRITER_LOCKED );

  /* Allocate a bitvec to use to store the set of pages rolled back */
  if( pSavepoint ){
    pDone = sqlite3BitvecCreate(pSavepoint->nOrig);
    if( !pDone ){
      return SQLITE_NOMEM;
    }
  }

  /* Set the database size back to the value it was before the savepoint 
  ** being reverted was opened.
  */
  pPager->dbSize = pSavepoint ? pSavepoint->nOrig : pPager->dbOrigSize;
  pPager->changeCountDone = pPager->tempFile;

  if( !pSavepoint && pagerUseWal(pPager) ){
    return pagerRollbackWal(pPager);
  }

  /* Use pPager->journalOff as the effective size of the main rollback
  ** journal.  The actual file might be larger than this in
  ** PAGER_JOURNALMODE_TRUNCATE or PAGER_JOURNALMODE_PERSIST.  But anything
  ** past pPager->journalOff is off-limits to us.
  */
  szJ = pPager->journalOff;
  assert( pagerUseWal(pPager)==0 || szJ==0 );

  /* Begin by rolling back records from the main journal starting at
  ** PagerSavepoint.iOffset and continuing to the next journal header.
  ** There might be records in the main journal that have a page number
  ** greater than the current database size (pPager->dbSize) but those
  ** will be skipped automatically.  Pages are added to pDone as they
  ** are played back.
  */
  if( pSavepoint && !pagerUseWal(pPager) ){
    iHdrOff = pSavepoint->iHdrOffset ? pSavepoint->iHdrOffset : szJ;
    pPager->journalOff = pSavepoint->iOffset;
    while( rc==SQLITE_OK && pPager->journalOff<iHdrOff ){
      rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
    }
    assert( rc!=SQLITE_DONE );
  }else{
    pPager->journalOff = 0;
  }

  /* Continue rolling back records out of the main journal starting at
  ** the first journal header seen and continuing until the effective end
  ** of the main journal file.  Continue to skip out-of-range pages and
  ** continue adding pages rolled back to pDone.
  */
  while( rc==SQLITE_OK && pPager->journalOff<szJ ){
    u32 ii;            /* Loop counter */
    u32 nJRec = 0;     /* Number of Journal Records */
    u32 dummy;
    rc = readJournalHdr(pPager, 0, szJ, &nJRec, &dummy);
    assert( rc!=SQLITE_DONE );

    /*
    ** The "pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff"
    ** test is related to ticket #2565.  See the discussion in the
    ** pager_playback() function for additional information.
    */
    if( nJRec==0 
     && pPager->journalHdr+JOURNAL_HDR_SZ(pPager)==pPager->journalOff
    ){
      nJRec = (u32)((szJ - pPager->journalOff)/JOURNAL_PG_SZ(pPager));
    }
    for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
      rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
    }
    assert( rc!=SQLITE_DONE );
  }
  assert( rc!=SQLITE_OK || pPager->journalOff>=szJ );

  /* Finally,  rollback pages from the sub-journal.  Page that were
  ** previously rolled back out of the main journal (and are hence in pDone)
  ** will be skipped.  Out-of-range pages are also skipped.
  */
  if( pSavepoint ){
    u32 ii;            /* Loop counter */
    i64 offset = (i64)pSavepoint->iSubRec*(4+pPager->pageSize);

    if( pagerUseWal(pPager) ){
      rc = sqlite3WalSavepointUndo(pPager->pWal, pSavepoint->aWalData);
    }
    for(ii=pSavepoint->iSubRec; rc==SQLITE_OK && ii<pPager->nSubRec; ii++){
      assert( offset==(i64)ii*(4+pPager->pageSize) );
      rc = pager_playback_one_page(pPager, &offset, pDone, 0, 1);
    }
    assert( rc!=SQLITE_DONE );
  }

  sqlite3BitvecDestroy(pDone);
  if( rc==SQLITE_OK ){
    pPager->journalOff = szJ;
  }

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x270fb
movq -0x18(%rbp), %rax
movl 0x18(%rax), %edi
callq 0x22360
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x270f9
movl $0x7, -0x4(%rbp)
jmp 0x273d9
jmp 0x270fb
cmpq $0x0, -0x18(%rbp)
je 0x2710e
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x54(%rbp)
jmp 0x27118
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movb 0x10(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x15(%rax)
cmpq $0x0, -0x18(%rbp)
jne 0x27156
movq -0x10(%rbp), %rdi
callq 0x211a0
cmpl $0x0, %eax
je 0x27156
movq -0x10(%rbp), %rdi
callq 0x273f0
movl %eax, -0x4(%rbp)
jmp 0x273d9
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x27202
movq -0x10(%rbp), %rdi
callq 0x211a0
cmpl $0x0, %eax
jne 0x27202
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x27198
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x271a0
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x61(%rbp)
jne 0x271d4
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpq -0x28(%rbp), %rax
setl %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x271dd
jmp 0x27200
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x60, %rsi
movq -0x38(%rbp), %rdx
movl $0x1, %r8d
movl %r8d, %ecx
callq 0x27490
movl %eax, -0x2c(%rbp)
jmp 0x271b7
jmp 0x2720e
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x27210
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x62(%rbp)
jne 0x2722d
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpq -0x20(%rbp), %rax
setl %al
movb %al, -0x62(%rbp)
movb -0x62(%rbp), %al
testb $0x1, %al
jne 0x27239
jmp 0x2730e
movl $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rdx
xorl %esi, %esi
leaq -0x40(%rbp), %rcx
leaq -0x44(%rbp), %r8
callq 0x278d0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x272a3
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0xb8(%rcx), %ecx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
cmpq 0x60(%rcx), %rax
jne 0x272a3
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
subq 0x60(%rcx), %rax
movq -0x10(%rbp), %rcx
movl 0xbc(%rcx), %ecx
addl $0x8, %ecx
movslq %ecx, %rcx
cqto
idivq %rcx
movl %eax, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x63(%rbp)
jne 0x272d4
movl -0x3c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x40(%rbp), %ecx
movb %al, -0x63(%rbp)
jae 0x272d4
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
cmpq -0x20(%rbp), %rax
setl %al
movb %al, -0x63(%rbp)
movb -0x63(%rbp), %al
testb $0x1, %al
jne 0x272dd
jmp 0x27309
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x60, %rsi
movq -0x38(%rbp), %rdx
movl $0x1, %r8d
movl %r8d, %ecx
callq 0x27490
movl %eax, -0x2c(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x272aa
jmp 0x27210
cmpq $0x0, -0x18(%rbp)
je 0x273b8
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x10(%rbp), %rcx
movl 0xbc(%rcx), %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
imulq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x211a0
cmpl $0x0, %eax
je 0x27361
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x20, %rsi
callq 0x27b20
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x48(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x64(%rbp)
jne 0x27386
movl -0x48(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x38(%rcx), %eax
setb %al
movb %al, -0x64(%rbp)
movb -0x64(%rbp), %al
testb $0x1, %al
jne 0x2738f
jmp 0x273b6
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq -0x50(%rbp), %rsi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x27490
movl %eax, -0x2c(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x2736b
jmp 0x273b8
movq -0x38(%rbp), %rdi
callq 0x26630
cmpl $0x0, -0x2c(%rbp)
jne 0x273d3
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)