// File: /workspace/github_c_makefile_star2_O1/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
xorl %eax, %eax
cmpl $0x2, %edx
jb 0x21280
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 0x735d7(%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 0x212d4
movl 0x735b6(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%r14)
incl %eax
cmpl %ebx, %eax
je 0x212d4
movq 0x18(%r14), %rax
movq 0x50(%rax), %rax
movl 0x24(%rax), %eax
bswapl %eax
testl %eax, %eax
je 0x212c6
leaq -0x29(%rbp), %rdx
leaq -0x50(%rbp), %rcx
movq %r14, %rdi
movl %ebx, %esi
callq 0x21d4e
testl %eax, %eax
je 0x21359
movl %eax, %r13d
jmp 0x212cc
movl $0x65, %r13d
xorl %r12d, %r12d
testb %r12b, %r12b
je 0x21347
xorl %r13d, %r13d
testl %r15d, %r15d
jne 0x21347
movl 0x7355e(%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
jmp 0x212fd
decl %ebx
leal (%rdi,%rbx), %eax
cmpl $-0x1, %eax
je 0x212fb
xorl %eax, %eax
cmpl $0x2, %ebx
jb 0x21337
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
je 0x212fb
movb $0x1, 0x23(%r14)
movl %ebx, 0x3c(%r14)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl -0x29(%rbp), %eax
cmpl $0x2, %eax
je 0x21394
cmpl $0x1, %eax
jne 0x213a5
leaq 0x584a6(%rip), %rsi     # 0x79814
leaq 0x581c4(%rip), %rcx     # 0x79539
xorl %r12d, %r12d
movl $0xb, %r13d
movl $0xb, %edi
movl $0xcd7c, %edx           # imm = 0xCD7C
xorl %eax, %eax
callq 0xb8cc
jmp 0x212cf
movb $0x1, %r12b
testl %r15d, %r15d
je 0x21443
jmp 0x212cf
movl %eax, -0x3c(%rbp)
leaq -0x38(%rbp), %rdx
movq %r14, %rdi
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x2035c
testl %eax, %eax
jne 0x212c1
testl %r15d, %r15d
sete %al
movl %r12d, -0x40(%rbp)
movl $0x0, %edx
cmovel %r12d, %edx
addb %al, %al
movq -0x38(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movzbl %al, %eax
movl %eax, -0x48(%rbp)
movl %edx, %ecx
movl %edx, -0x44(%rbp)
movq %r14, %rdi
leaq -0x58(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
movl -0x48(%rbp), %r8d
callq 0x21e3f
movl %eax, %r12d
testl %eax, %eax
je 0x21438
movq -0x60(%rbp), %rcx
movq %rcx, %rax
movl %r12d, %r13d
testq %rcx, %rcx
je 0x2141b
movq 0x68(%rax), %rdi
callq 0xdcd4
testl %r12d, %r12d
jne 0x212cc
movl -0x4c(%rbp), %r8d
testl %r15d, %r15d
movl -0x44(%rbp), %ecx
je 0x21481
cmpl -0x40(%rbp), %r8d
ja 0x213e8
jmp 0x21481
movq -0x58(%rbp), %rax
testq %rax, %rax
jne 0x21412
jmp 0x2141b
leaq -0x38(%rbp), %rsi
leaq -0x58(%rbp), %rdx
movq %r14, %rdi
movl %ebx, %ecx
movl $0x1, %r8d
callq 0x21e3f
movl %eax, %r13d
testl %eax, %eax
jne 0x212cc
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x212cf
movq 0x68(%rax), %rdi
callq 0xdcd4
jmp 0x212cf
movq -0x38(%rbp), %r12
movl -0x50(%rbp), %ecx
movzbl -0x3c(%rbp), %edx
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %r9d
callq 0x22773
testq %r12, %r12
je 0x214af
movq 0x68(%r12), %rdi
movl %eax, %r12d
callq 0xdcd4
movl %r12d, %eax
testl %eax, %eax
sete %r12b
cmovnel %eax, %r13d
jmp 0x212cf