// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl %ecx, %r15d
movl %edx, %ebx
movl %esi, %r12d
movq %rdi, %r14
xorl %eax, %eax
cmpl $0x2, %edx
jb 0x20f36
movl 0x34(%r14), %eax
movl $0xcccccccd, %esi       # imm = 0xCCCCCCCD
imulq %rax, %rsi
shrq $0x22, %rsi
incl %esi
leal -0x2(%rbx), %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %esi
subl %edx, %ecx
movl 0x73921(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%r14)
leal 0x1(%rcx), %edx
xorl %esi, %esi
cmpl %eax, %edx
sete %sil
leal (%rcx,%rsi), %eax
addl $0x2, %eax
cmpl %ebx, %eax
je 0x20f4c
movl 0x73900(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%r14)
incl %eax
cmpl %ebx, %eax
jne 0x20fc5
xorl %r13d, %r13d
testl %r15d, %r15d
jne 0x2102a
movl 0x738e2(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%r14)
movl %eax, %ecx
decl %ebx
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
subl %eax, %edi
movl $0xcccccccd, %r8d       # imm = 0xCCCCCCCD
leal (%rdi,%rbx), %eax
cmpl $-0x1, %eax
je 0x20fb3
xorl %eax, %eax
cmpl $0x2, %ebx
jb 0x20faf
movl 0x34(%r14), %r9d
imulq %r8, %r9
shrq $0x22, %r9
incl %r9d
leal -0x2(%rbx), %esi
movl %esi, %eax
xorl %edx, %edx
divl %r9d
subl %edx, %esi
leal 0x1(%rsi), %eax
xorl %edx, %edx
cmpl %ecx, %eax
sete %dl
leal (%rsi,%rdx), %eax
addl $0x2, %eax
cmpl %eax, %ebx
jne 0x20fb7
decl %ebx
jmp 0x20f75
movb $0x1, 0x23(%r14)
movl %ebx, 0x3c(%r14)
xorl %r13d, %r13d
jmp 0x2102a
movq 0x18(%r14), %rax
movq 0x50(%rax), %rax
movl 0x24(%rax), %eax
bswapl %eax
testl %eax, %eax
je 0x21024
leaq -0x29(%rbp), %rdx
leaq -0x48(%rbp), %rcx
movq %r14, %rdi
movl %ebx, %esi
callq 0x21a08
movl %eax, %r13d
testl %eax, %eax
jne 0x2102a
movzbl -0x29(%rbp), %eax
cmpl $0x2, %eax
je 0x2103c
cmpl $0x1, %eax
jne 0x2106a
leaq 0x58810(%rip), %rsi     # 0x79814
leaq 0x5852e(%rip), %rcx     # 0x79539
movl $0xb, %r13d
movl $0xb, %edi
movl $0xcd7c, %edx           # imm = 0xCD7C
xorl %eax, %eax
callq 0xb9c7
jmp 0x2102a
movl $0x65, %r13d
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r15d, %r15d
jne 0x20f4c
leaq -0x38(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movq %r14, %rdi
movl %ebx, %ecx
movl $0x1, %r8d
callq 0x21af9
testl %eax, %eax
je 0x21137
movl %eax, %r13d
jmp 0x2102a
movl %r12d, -0x30(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x38(%rbp), %rdx
xorl %r12d, %r12d
movq %r14, %rdi
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x20068
movl %eax, %r13d
testl %eax, %eax
jne 0x2102a
testl %r15d, %r15d
sete %al
cmovel -0x30(%rbp), %r12d
addb %al, %al
movzbl %al, %eax
movl %eax, -0x40(%rbp)
movl %r12d, %ecx
movq %r14, %rdi
leaq -0x50(%rbp), %rsi
leaq -0x44(%rbp), %rdx
movl %ecx, %r12d
movl -0x40(%rbp), %r8d
callq 0x21af9
testl %eax, %eax
jne 0x21119
movq -0x50(%rbp), %rax
testq %rax, %rax
je 0x210ce
movq 0x68(%rax), %rdi
callq 0xddd3
movl -0x44(%rbp), %r8d
testl %r15d, %r15d
je 0x210e0
movl %r12d, %ecx
cmpl -0x30(%rbp), %r8d
ja 0x210a1
movq -0x38(%rbp), %r12
movl -0x48(%rbp), %ecx
movzbl -0x3c(%rbp), %edx
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %r9d
callq 0x22377
movl %eax, %r13d
testq %r12, %r12
je 0x2110b
movq 0x68(%r12), %rdi
callq 0xddd3
testl %r13d, %r13d
jne 0x2102a
jmp 0x20f4c
movl %eax, %r13d
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x2102a
movq 0x68(%rax), %rdi
callq 0xddd3
jmp 0x2102a
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x20f4c
movq 0x68(%rax), %rdi
callq 0xddd3
jmp 0x20f4c