// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: autoVacuumCommit
static int autoVacuumCommit(BtShared *pBt){
  int rc = SQLITE_OK;
  Pager *pPager = pBt->pPager;
  VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager) );

  assert( sqlite3_mutex_held(pBt->mutex) );
  invalidateAllOverflowCache(pBt);
  assert(pBt->autoVacuum);
  if( !pBt->incrVacuum ){
    Pgno nFin;         /* Number of pages in database after autovacuuming */
    Pgno nFree;        /* Number of pages on the freelist initially */
    Pgno iFree;        /* The next page to be freed */
    Pgno nOrig;        /* Database size before freeing */

    nOrig = btreePagecount(pBt);
    if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
      /* It is not possible to create a database for which the final page
      ** is either a pointer-map page or the pending-byte page. If one
      ** is encountered, this indicates corruption.
      */
      return SQLITE_CORRUPT_BKPT;
    }

    nFree = get4byte(&pBt->pPage1->aData[36]);
    nFin = finalDbSize(pBt, nOrig, nFree);
    if( nFin>nOrig ) return SQLITE_CORRUPT_BKPT;
    if( nFin<nOrig ){
      rc = saveAllCursors(pBt, 0, 0);
    }
    for(iFree=nOrig; iFree>nFin && rc==SQLITE_OK; iFree--){
      rc = incrVacuumStep(pBt, nFin, iFree, 1);
    }
    if( (rc==SQLITE_DONE || rc==SQLITE_OK) && nFree>0 ){
      rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
      put4byte(&pBt->pPage1->aData[32], 0);
      put4byte(&pBt->pPage1->aData[36], 0);
      put4byte(&pBt->pPage1->aData[28], nFin);
      pBt->bDoTruncate = 1;
      pBt->nPage = nFin;
    }
    if( rc!=SQLITE_OK ){
      sqlite3PagerRollback(pPager);
    }
  }

  assert( nRef>=sqlite3PagerRefcount(pPager) );
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2b910
movq -0x10(%rbp), %rax
cmpb $0x0, 0x22(%rax)
jne 0x2b8fa
movq -0x10(%rbp), %rdi
callq 0x2ab10
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x2b950
cmpl -0x30(%rbp), %eax
je 0x2b7b3
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl 0xa5132(%rip), %eax     # 0xd08d0
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divl 0x30(%rcx)
movl %eax, %ecx
movl -0x34(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2b7c5
movl $0xce1f, %edi           # imm = 0xCE1F
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x2b900
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x24, %rdi
callq 0x20a50
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x2b9d0
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x30(%rbp), %eax
jbe 0x2b809
movl $0xce24, %edi           # imm = 0xCE24
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x2b900
movl -0x24(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x2b823
movq -0x10(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2bad0
movl %eax, -0x14(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x24(%rbp), %ecx
movb %al, -0x35(%rbp)
jbe 0x2b840
cmpl $0x0, -0x14(%rbp)
sete %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0x2b849
jmp 0x2b86b
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x2c(%rbp), %edx
movl $0x1, %ecx
callq 0x2bb70
movl %eax, -0x14(%rbp)
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2b829
cmpl $0x65, -0x14(%rbp)
je 0x2b877
cmpl $0x0, -0x14(%rbp)
jne 0x2b8e9
cmpl $0x0, -0x28(%rbp)
jbe 0x2b8e9
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x68(%rax), %rdi
callq 0xef80
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x20, %rdi
xorl %esi, %esi
callq 0x22060
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x24, %rdi
xorl %esi, %esi
callq 0x22060
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x1c, %rdi
movl -0x24(%rbp), %esi
callq 0x22060
movq -0x10(%rbp), %rax
movb $0x1, 0x23(%rax)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x3c(%rax)
cmpl $0x0, -0x14(%rbp)
je 0x2b8f8
movq -0x20(%rbp), %rdi
callq 0x26840
jmp 0x2b8fa
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)