// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3PagerOpenSavepoint
SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int nSavepoint){
  int rc = SQLITE_OK;                       /* Return code */
  int nCurrent = pPager->nSavepoint;        /* Current number of savepoints */

  assert( pPager->eState>=PAGER_WRITER_LOCKED );
  assert( assert_pager_state(pPager) );

  if( nSavepoint>nCurrent && pPager->useJournal ){
    int ii;                                 /* Iterator variable */
    PagerSavepoint *aNew;                   /* New Pager.aSavepoint array */

    /* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
    ** if the allocation fails. Otherwise, zero the new portion in case a 
    ** malloc failure occurs while populating it in the for(...) loop below.
    */
    aNew = (PagerSavepoint *)sqlite3Realloc(
        pPager->aSavepoint, sizeof(PagerSavepoint)*nSavepoint
    );
    if( !aNew ){
      return SQLITE_NOMEM;
    }
    memset(&aNew[nCurrent], 0, (nSavepoint-nCurrent) * sizeof(PagerSavepoint));
    pPager->aSavepoint = aNew;

    /* Populate the PagerSavepoint structures just allocated. */
    for(ii=nCurrent; ii<nSavepoint; ii++){
      aNew[ii].nOrig = pPager->dbSize;
      if( isOpen(pPager->jfd) && pPager->journalOff>0 ){
        aNew[ii].iOffset = pPager->journalOff;
      }else{
        aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
      }
      aNew[ii].iSubRec = pPager->nSubRec;
      aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
      if( !aNew[ii].pInSavepoint ){
        return SQLITE_NOMEM;
      }
      if( pagerUseWal(pPager) ){
        sqlite3WalSavepoint(pPager->pWal, aNew[ii].aWalData);
      }
      pPager->nSavepoint = ii+1;
    }
    assert( pPager->nSavepoint==nSavepoint );
    assertTruncateConstraint(pPager);
  }

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movslq 0x80(%rdi), %r13
xorl %r15d, %r15d
cmpl %r13d, %esi
jle 0x1ff09
movq %rdi, %r14
cmpb $0x0, 0xa(%rdi)
je 0x1ff09
movq 0x78(%r14), %rdi
movl %esi, %eax
shll $0x4, %eax
movq %rsi, %rbx
leal (%rax,%rax,2), %esi
callq 0xa37d
movl $0x7, %r15d
testq %rax, %rax
je 0x1ff09
movq %rax, %r12
movq %rbx, %rax
movq %rbx, -0x30(%rbp)
leaq (,%r13,2), %rbx
addq %r13, %rbx
shlq $0x4, %rbx
leaq (%r12,%rbx), %rdi
subl %r13d, %eax
cltq
shlq $0x4, %rax
leaq (%rax,%rax,2), %rdx
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x8200
movq %r12, 0x78(%r14)
movq -0x30(%rbp), %rdx
cmpl %r13d, %edx
jle 0x1ff09
addq %rbx, %r12
addq $0x2c, %r12
negl %edx
incl %r13d
movq %rdx, -0x30(%rbp)
movl 0x1c(%r14), %ebx
movl %ebx, -0x14(%r12)
movq 0x50(%r14), %rax
cmpq $0x0, (%rax)
je 0x1fe67
movq 0x60(%r14), %rax
testq %rax, %rax
jg 0x1fe6e
movl 0xb8(%r14), %eax
movq %rax, -0x2c(%r12)
movl 0x38(%r14), %eax
movl %eax, -0x10(%r12)
movl $0x200, %edi            # imm = 0x200
callq 0xa2a2
movq %rax, %r15
testq %rax, %rax
je 0x1fefe
movl $0x200, %edx            # imm = 0x200
movq %r15, %rdi
xorl %esi, %esi
callq 0x8200
movl %ebx, (%r15)
movq %r15, -0x1c(%r12)
movq 0x118(%r14), %rax
testq %rax, %rax
je 0x1fed3
movl 0x58(%rax), %ecx
movl %ecx, -0xc(%r12)
movl 0x60(%rax), %ecx
movl %ecx, -0x8(%r12)
movl 0x64(%rax), %ecx
movl %ecx, -0x4(%r12)
movl 0x80(%rax), %eax
movl %eax, (%r12)
movl %r13d, 0x80(%r14)
addq $0x30, %r12
movq -0x30(%rbp), %rdx
leal (%rdx,%r13), %eax
incl %eax
movl %r13d, %ecx
incl %ecx
movl %ecx, %r13d
cmpl $0x1, %eax
jne 0x1fe4b
xorl %r15d, %r15d
jmp 0x1ff09
movq %r15, -0x1c(%r12)
movl $0x7, %r15d
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq