// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: incrVacuumStep
static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){
  Pgno nFreeList;           /* Number of pages still on the free-list */
  int rc;

  assert( sqlite3_mutex_held(pBt->mutex) );
  assert( iLastPg>nFin );

  if( !PTRMAP_ISPAGE(pBt, iLastPg) && iLastPg!=PENDING_BYTE_PAGE(pBt) ){
    u8 eType;
    Pgno iPtrPage;

    nFreeList = get4byte(&pBt->pPage1->aData[36]);
    if( nFreeList==0 ){
      return SQLITE_DONE;
    }

    rc = ptrmapGet(pBt, iLastPg, &eType, &iPtrPage);
    if( rc!=SQLITE_OK ){
      return rc;
    }
    if( eType==PTRMAP_ROOTPAGE ){
      return SQLITE_CORRUPT_BKPT;
    }

    if( eType==PTRMAP_FREEPAGE ){
      if( bCommit==0 ){
        /* Remove the page from the files free-list. This is not required
        ** if bCommit is non-zero. In that case, the free-list will be
        ** truncated to zero after this function returns, so it doesn't 
        ** matter if it still contains some garbage entries.
        */
        Pgno iFreePg;
        MemPage *pFreePg;
        rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iLastPg, BTALLOC_EXACT);
        if( rc!=SQLITE_OK ){
          return rc;
        }
        assert( iFreePg==iLastPg );
        releasePage(pFreePg);
      }
    } else {
      Pgno iFreePg;             /* Index of free page to move pLastPg to */
      MemPage *pLastPg;
      u8 eMode = BTALLOC_ANY;   /* Mode parameter for allocateBtreePage() */
      Pgno iNear = 0;           /* nearby parameter for allocateBtreePage() */

      rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
      if( rc!=SQLITE_OK ){
        return rc;
      }

      /* If bCommit is zero, this loop runs exactly once and page pLastPg
      ** is swapped with the first free page pulled off the free list.
      **
      ** On the other hand, if bCommit is greater than zero, then keep
      ** looping until a free-page located within the first nFin pages
      ** of the file is found.
      */
      if( bCommit==0 ){
        eMode = BTALLOC_LE;
        iNear = nFin;
      }
      do {
        MemPage *pFreePg;
        rc = allocateBtreePage(pBt, &pFreePg, &iFreePg, iNear, eMode);
        if( rc!=SQLITE_OK ){
          releasePage(pLastPg);
          return rc;
        }
        releasePage(pFreePg);
      }while( bCommit && iFreePg>nFin );
      assert( iFreePg<iLastPg );
      
      rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, bCommit);
      releasePage(pLastPg);
      if( rc!=SQLITE_OK ){
        return rc;
      }
    }
  }

  if( bCommit==0 ){
    do {
      iLastPg--;
    }while( iLastPg==PENDING_BYTE_PAGE(pBt) || PTRMAP_ISPAGE(pBt, iLastPg) );
    pBt->bDoTruncate = 1;
    pBt->nPage = iLastPg;
  }
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x2b950
cmpl -0x18(%rbp), %eax
je 0x2bd53
movl -0x18(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl 0xa4d2a(%rip), %eax     # 0xd08d0
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divl 0x30(%rcx)
movl %eax, %ecx
movl -0x5c(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x2bd53
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x24, %rdi
callq 0x20a50
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x2bbe9
movl $0x65, -0x4(%rbp)
jmp 0x2bdb9
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
leaq -0x25(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
callq 0x2cdf0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x2bc11
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2bdb9
movzbl -0x25(%rbp), %eax
cmpl $0x1, %eax
jne 0x2bc2c
movl $0xcd7c, %edi           # imm = 0xCD7C
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x2bdb9
movzbl -0x25(%rbp), %eax
cmpl $0x2, %eax
jne 0x2bc77
cmpl $0x0, -0x1c(%rbp)
jne 0x2bc72
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %ecx
leaq -0x38(%rbp), %rsi
leaq -0x30(%rbp), %rdx
movl $0x1, %r8d
callq 0x2cef0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x2bc69
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2bdb9
movq -0x38(%rbp), %rdi
callq 0x29fd0
jmp 0x2bd51
movb $0x0, -0x49(%rbp)
movl $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
leaq -0x48(%rbp), %rdx
xorl %ecx, %ecx
callq 0x29ed0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x2bca8
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2bdb9
cmpl $0x0, -0x1c(%rbp)
jne 0x2bcb8
movb $0x2, -0x49(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x2bcba
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %ecx
leaq -0x58(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
movzbl -0x49(%rbp), %r8d
callq 0x2cef0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x2bcf0
movq -0x48(%rbp), %rdi
callq 0x29fd0
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2bdb9
movq -0x58(%rbp), %rdi
callq 0x29fd0
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x5d(%rbp)
je 0x2bd10
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
seta %al
movb %al, -0x5d(%rbp)
movb -0x5d(%rbp), %al
testb $0x1, %al
jne 0x2bcba
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movb -0x25(%rbp), %al
movl -0x2c(%rbp), %ecx
movl -0x3c(%rbp), %r8d
movl -0x1c(%rbp), %r9d
movzbl %al, %edx
callq 0x2d7d0
movl %eax, -0x24(%rbp)
movq -0x48(%rbp), %rdi
callq 0x29fd0
cmpl $0x0, -0x24(%rbp)
je 0x2bd4f
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2bdb9
jmp 0x2bd51
jmp 0x2bd53
cmpl $0x0, -0x1c(%rbp)
jne 0x2bdb2
jmp 0x2bd5b
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movl 0xa4b63(%rip), %eax     # 0xd08d0
movq -0x10(%rbp), %rsi
xorl %edx, %edx
divl 0x30(%rsi)
movl %eax, %edx
addl $0x1, %edx
movb $0x1, %al
cmpl %edx, %ecx
movb %al, -0x5e(%rbp)
je 0x2bd99
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x2b950
cmpl -0x18(%rbp), %eax
sete %al
movb %al, -0x5e(%rbp)
movb -0x5e(%rbp), %al
testb $0x1, %al
jne 0x2bd5b
movq -0x10(%rbp), %rax
movb $0x1, 0x23(%rax)
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x3c(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)