// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r15d
movl %edx, %ebx
movl %esi, %r12d
movq %rdi, %r14
movl %edx, %esi
callq 0x1dfda
cmpl %ebx, %eax
je 0x1e1c3
movl 0x69689(%rip), %eax     # 0x87840
xorl %edx, %edx
divl 0x30(%r14)
incl %eax
cmpl %ebx, %eax
jne 0x1e209
xorl %r13d, %r13d
testl %r15d, %r15d
jne 0x1e257
movl 0x6966b(%rip), %eax     # 0x87840
xorl %edx, %edx
divl 0x30(%r14)
pushq $-0x2
popq %r15
subl %eax, %r15d
decl %ebx
leal (%r15,%rbx), %eax
cmpl $-0x1, %eax
je 0x1e1e2
movq %r14, %rdi
movl %ebx, %esi
callq 0x1dfda
cmpl %eax, %ebx
je 0x1e1e2
movb $0x1, 0x23(%r14)
movl %ebx, 0x3c(%r14)
xorl %r13d, %r13d
jmp 0x1e257
movq 0x18(%r14), %rax
movq 0x50(%rax), %rdi
addq $0x24, %rdi
callq 0x180a3
testl %eax, %eax
je 0x1e253
leaq -0x29(%rbp), %rdx
leaq -0x4c(%rbp), %rcx
movq %r14, %rdi
movl %ebx, %esi
callq 0x1ebb8
movl %eax, %r13d
testl %eax, %eax
jne 0x1e257
movzbl -0x29(%rbp), %eax
cmpl $0x2, %eax
je 0x1e269
cmpl $0x1, %eax
jne 0x1e295
movl $0xcd7c, %edi           # imm = 0xCD7C
callq 0x1a1fc
pushq $0xb
jmp 0x1e255
pushq $0x65
popq %r13
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r15d, %r15d
jne 0x1e1c3
leaq -0x38(%rbp), %rsi
leaq -0x58(%rbp), %rdx
pushq $0x1
popq %r8
movq %r14, %rdi
movl %ebx, %ecx
callq 0x1ec5e
testl %eax, %eax
je 0x1e343
movl %eax, %r13d
jmp 0x1e257
movl %eax, -0x3c(%rbp)
leaq -0x38(%rbp), %rdx
movq %r14, %rdi
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x1d84e
movl %eax, %r13d
testl %eax, %eax
jne 0x1e257
testl %r15d, %r15d
sete %al
movl %r12d, -0x40(%rbp)
movl $0x0, %ecx
cmovel %r12d, %ecx
addb %al, %al
movzbl %al, %eax
movl %eax, -0x44(%rbp)
movq %r14, %rdi
leaq -0x58(%rbp), %rsi
leaq -0x48(%rbp), %rdx
movl %ecx, %r12d
movl -0x44(%rbp), %r8d
callq 0x1ec5e
testl %eax, %eax
jne 0x1e332
movq -0x58(%rbp), %rdi
callq 0x1d90e
movl -0x48(%rbp), %r8d
testl %r15d, %r15d
je 0x1e300
movl %r12d, %ecx
cmpl -0x40(%rbp), %r8d
ja 0x1e2ca
movq -0x38(%rbp), %r12
movl -0x4c(%rbp), %ecx
movzbl -0x3c(%rbp), %edx
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %r9d
callq 0x1f3c2
movl %eax, %r13d
movq %r12, %rdi
callq 0x1d90e
testl %r13d, %r13d
jne 0x1e257
jmp 0x1e1c3
movl %eax, %r13d
movq -0x38(%rbp), %rdi
callq 0x1d90e
jmp 0x1e257
movq -0x38(%rbp), %rdi
callq 0x1d90e
jmp 0x1e1c3