// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: btreeDropTable
static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){
  int rc;
  MemPage *pPage = 0;
  BtShared *pBt = p->pBt;

  assert( sqlite3BtreeHoldsMutex(p) );
  assert( p->inTrans==TRANS_WRITE );

  /* It is illegal to drop a table if any cursors are open on the
  ** database. This is because in auto-vacuum mode the backend may
  ** need to move another root-page to fill a gap left by the deleted
  ** root page. If an open cursor was using this page a problem would 
  ** occur.
  **
  ** This error is caught long before control reaches this point.
  */
  if( NEVER(pBt->pCursor) ){
    sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
    return SQLITE_LOCKED_SHAREDCACHE;
  }

  rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
  if( rc ) return rc;
  rc = sqlite3BtreeClearTable(p, iTable, 0);
  if( rc ){
    releasePage(pPage);
    return rc;
  }

  *piMoved = 0;

  if( iTable>1 ){
#ifdef SQLITE_OMIT_AUTOVACUUM
    freePage(pPage, &rc);
    releasePage(pPage);
#else
    if( pBt->autoVacuum ){
      Pgno maxRootPgno;
      sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &maxRootPgno);

      if( iTable==maxRootPgno ){
        /* If the table being dropped is the table with the largest root-page
        ** number in the database, put the root page on the free list. 
        */
        freePage(pPage, &rc);
        releasePage(pPage);
        if( rc!=SQLITE_OK ){
          return rc;
        }
      }else{
        /* The table being dropped does not have the largest root-page
        ** number in the database. So move the page that does into the 
        ** gap left by the deleted root-page.
        */
        MemPage *pMove;
        releasePage(pPage);
        rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
        if( rc!=SQLITE_OK ){
          return rc;
        }
        rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
        releasePage(pMove);
        if( rc!=SQLITE_OK ){
          return rc;
        }
        pMove = 0;
        rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
        freePage(pMove, &rc);
        releasePage(pMove);
        if( rc!=SQLITE_OK ){
          return rc;
        }
        *piMoved = maxRootPgno;
      }

      /* Set the new 'max-root-page' value in the database header. This
      ** is the old value less one, less one more if that happens to
      ** be a root-page number, less one again if that is the
      ** PENDING_BYTE_PAGE.
      */
      maxRootPgno--;
      while( maxRootPgno==PENDING_BYTE_PAGE(pBt)
             || PTRMAP_ISPAGE(pBt, maxRootPgno) ){
        maxRootPgno--;
      }
      assert( maxRootPgno!=PENDING_BYTE_PAGE(pBt) );

      rc = sqlite3BtreeUpdateMeta(p, 4, maxRootPgno);
    }else{
      freePage(pPage, &rc);
      releasePage(pPage);
    }
#endif
  }else{
    /* If sqlite3BtreeDropTable was called on page 1.
    ** This really never should happen except in a corrupt
    ** database. 
    */
    zeroPage(pPage, PTF_INTKEY|PTF_LEAF );
    releasePage(pPage);
  }
  return rc;  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x460be
movl $0x106, -0x4(%rbp)      # imm = 0x106
jmp 0x462cb
movq -0x38(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x30(%rbp), %rdx
xorl %ecx, %ecx
callq 0x29ed0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x460e4
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x462cb
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3e500
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x46111
movq -0x30(%rbp), %rdi
callq 0x29fd0
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x462cb
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
cmpl $0x1, -0x14(%rbp)
jbe 0x462ae
movq -0x38(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x46296
movq -0x10(%rbp), %rdi
movl $0x4, %esi
leaq -0x3c(%rbp), %rdx
callq 0xe510
movl -0x14(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jne 0x46179
movq -0x30(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x44f90
movq -0x30(%rbp), %rdi
callq 0x29fd0
cmpl $0x0, -0x24(%rbp)
je 0x46174
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x462cb
jmp 0x4622e
movq -0x30(%rbp), %rdi
callq 0x29fd0
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
leaq -0x48(%rbp), %rdx
xorl %ecx, %ecx
callq 0x29ed0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x461a8
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x462cb
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %r8d
movl $0x1, %edx
xorl %r9d, %r9d
movl %r9d, %ecx
callq 0x2d7d0
movl %eax, -0x24(%rbp)
movq -0x48(%rbp), %rdi
callq 0x29fd0
cmpl $0x0, -0x24(%rbp)
je 0x461e1
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x462cb
movq $0x0, -0x48(%rbp)
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
leaq -0x48(%rbp), %rdx
xorl %ecx, %ecx
callq 0x29ed0
movl %eax, -0x24(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x44f90
movq -0x48(%rbp), %rdi
callq 0x29fd0
cmpl $0x0, -0x24(%rbp)
je 0x46225
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x462cb
movl -0x3c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
movl 0x8a690(%rip), %eax     # 0xd08d0
movq -0x38(%rbp), %rsi
xorl %edx, %edx
divl 0x30(%rsi)
movl %eax, %edx
addl $0x1, %edx
movb $0x1, %al
cmpl %edx, %ecx
movb %al, -0x49(%rbp)
je 0x4626c
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x2b950
cmpl -0x3c(%rbp), %eax
sete %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x46275
jmp 0x46280
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x46237
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl $0x4, %esi
callq 0xed20
movl %eax, -0x24(%rbp)
jmp 0x462ac
movq -0x30(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x44f90
movq -0x30(%rbp), %rdi
callq 0x29fd0
jmp 0x462c5
movq -0x30(%rbp), %rdi
movl $0x9, %esi
callq 0x2a920
movq -0x30(%rbp), %rdi
callq 0x29fd0
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)