// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: relocatePage
static int relocatePage(
  BtShared *pBt,           /* Btree */
  MemPage *pDbPage,        /* Open page to move */
  u8 eType,                /* Pointer map 'type' entry for pDbPage */
  Pgno iPtrPage,           /* Pointer map 'page-no' entry for pDbPage */
  Pgno iFreePage,          /* The location to move pDbPage to */
  int isCommit             /* isCommit flag passed to sqlite3PagerMovepage */
){
  MemPage *pPtrPage;   /* The page that contains a pointer to pDbPage */
  Pgno iDbPage = pDbPage->pgno;
  Pager *pPager = pBt->pPager;
  int rc;

  assert( eType==PTRMAP_OVERFLOW2 || eType==PTRMAP_OVERFLOW1 || 
      eType==PTRMAP_BTREE || eType==PTRMAP_ROOTPAGE );
  assert( sqlite3_mutex_held(pBt->mutex) );
  assert( pDbPage->pBt==pBt );

  /* Move page iDbPage from its current location to page number iFreePage */
  TRACE(("AUTOVACUUM: Moving %d to free page %d (ptr page %d type %d)\n", 
      iDbPage, iFreePage, iPtrPage, eType));
  rc = sqlite3PagerMovepage(pPager, pDbPage->pDbPage, iFreePage, isCommit);
  if( rc!=SQLITE_OK ){
    return rc;
  }
  pDbPage->pgno = iFreePage;

  /* If pDbPage was a btree-page, then it may have child pages and/or cells
  ** that point to overflow pages. The pointer map entries for all these
  ** pages need to be changed.
  **
  ** If pDbPage is an overflow page, then the first 4 bytes may store a
  ** pointer to a subsequent overflow page. If this is the case, then
  ** the pointer map needs to be updated for the subsequent overflow page.
  */
  if( eType==PTRMAP_BTREE || eType==PTRMAP_ROOTPAGE ){
    rc = setChildPtrmaps(pDbPage);
    if( rc!=SQLITE_OK ){
      return rc;
    }
  }else{
    Pgno nextOvfl = get4byte(pDbPage->aData);
    if( nextOvfl!=0 ){
      ptrmapPut(pBt, nextOvfl, PTRMAP_OVERFLOW2, iFreePage, &rc);
      if( rc!=SQLITE_OK ){
        return rc;
      }
    }
  }

  /* Fix the database pointer on page iPtrPage that pointed at iDbPage so
  ** that it points at iFreePage. Also fix the pointer map entry for
  ** iPtrPage.
  */
  if( eType!=PTRMAP_ROOTPAGE ){
    rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
    if( rc!=SQLITE_OK ){
      return rc;
    }
    rc = sqlite3PagerWrite(pPtrPage->pDbPage);
    if( rc!=SQLITE_OK ){
      releasePage(pPtrPage);
      return rc;
    }
    rc = modifyPagePointer(pPtrPage, iDbPage, iFreePage, eType);
    releasePage(pPtrPage);
    if( rc==SQLITE_OK ){
      ptrmapPut(pBt, iFreePage, eType, iPtrPage, &rc);
    }
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r15d
movl %r8d, -0x2c(%rbp)
movl %ecx, -0x50(%rbp)
movl %edx, -0x30(%rbp)
movq %rsi, %r13
movl 0x70(%rsi), %eax
movl %eax, -0x4c(%rbp)
movq %rdi, -0x48(%rbp)
movq (%rdi), %rbx
movq 0x68(%rsi), %r12
cmpb $0x0, 0x12(%rbx)
je 0x223bf
movq %r12, %rdi
callq 0xdfbf
testl %eax, %eax
jne 0x225a4
movzwl 0x2c(%r12), %r14d
testb $0x2, %r14b
je 0x223ed
movq %r12, %rdi
callq 0x1a636
testl %eax, %eax
je 0x223ed
movq %r12, %rdi
callq 0x1a69a
testl %eax, %eax
jne 0x225a4
movzwl 0x2c(%r12), %r14d
movl $0x0, -0x38(%rbp)
testl %r15d, %r15d
jne 0x2240e
movl %r14d, %eax
andl $0x4, %eax
movl -0x2c(%rbp), %esi
je 0x22411
movl 0x28(%r12), %eax
movl %eax, -0x38(%rbp)
jmp 0x22411
movl -0x2c(%rbp), %esi
andl $0xfffb, %r14d          # imm = 0xFFFB
movw %r14w, 0x2c(%r12)
movq 0x110(%rbx), %rdi
leaq -0x40(%rbp), %r14
xorl %edx, %edx
movq %r14, %rcx
callq 0x1f4e2
movq (%r14), %r14
testq %r14, %r14
je 0x22466
movzwl 0x2c(%r14), %eax
andl $0x4, %eax
orw %ax, 0x2c(%r12)
cmpb $0x0, 0x12(%rbx)
je 0x2245e
movl 0x1c(%rbx), %esi
incl %esi
movq %r14, %rdi
callq 0x229ee
jmp 0x22466
movq %r14, %rdi
callq 0x1f27c
movl 0x28(%r12), %r15d
movq %r12, %rdi
movl -0x2c(%rbp), %esi
callq 0x229ee
movzwl 0x2c(%r12), %ecx
movl %ecx, %eax
andl $-0x21, %eax
movw %ax, 0x2c(%r12)
testb $0x2, %cl
jne 0x2249d
orl $0x2, %eax
movw %ax, 0x2c(%r12)
movq %r12, %rdi
callq 0x1f7db
cmpb $0x0, 0x12(%rbx)
je 0x224b6
movq %r14, %rdi
movl %r15d, %esi
callq 0x229ee
movq %r14, %rdi
callq 0xddd3
movl -0x38(%rbp), %r12d
testl %r12d, %r12d
movl -0x2c(%rbp), %r15d
je 0x2252d
leaq -0x40(%rbp), %rdx
movq %rbx, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
callq 0xd8e2
testl %eax, %eax
je 0x224fd
movl %eax, %r14d
cmpl 0x20(%rbx), %r12d
ja 0x225a7
movq 0x40(%rbx), %rdi
movq 0x108(%rbx), %rdx
movl %r12d, %esi
callq 0x22a38
jmp 0x225a7
movq -0x40(%rbp), %rbx
movzwl 0x2c(%rbx), %ecx
movl %ecx, %eax
andl $-0x25, %eax
leal 0x4(%rax), %edx
movw %dx, 0x2c(%rbx)
testb $0x2, %cl
jne 0x22525
orl $0x6, %eax
movw %ax, 0x2c(%rbx)
movq %rbx, %rdi
callq 0x1f7db
movq %rbx, %rdi
callq 0xddd3
movl $0x0, -0x34(%rbp)
movl %r15d, 0x70(%r13)
movl -0x30(%rbp), %eax
andb $-0x5, %al
cmpb $0x1, %al
jne 0x2255c
movq %r13, %rdi
callq 0x22623
testl %eax, %eax
jne 0x225a4
xorl %r14d, %r14d
cmpb $0x1, -0x30(%rbp)
movq -0x48(%rbp), %r12
jne 0x2258b
jmp 0x225a7
movq 0x50(%r13), %rax
movl (%rax), %esi
bswapl %esi
testl %esi, %esi
movq -0x48(%rbp), %r12
je 0x2258b
leaq -0x34(%rbp), %rbx
movq %r12, %rdi
movl $0x4, %edx
movl %r15d, %ecx
movq %rbx, %r8
callq 0x22705
movl (%rbx), %r14d
testl %r14d, %r14d
jne 0x225a7
leaq -0x40(%rbp), %rdx
movq %r12, %rdi
movl -0x50(%rbp), %r12d
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x20068
testl %eax, %eax
je 0x225b9
movl %eax, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x40(%rbp), %rbx
movq 0x68(%rbx), %rdi
callq 0xdfbf
testl %eax, %eax
je 0x225d8
movl %eax, %r14d
movq 0x68(%rbx), %rdi
callq 0xddd3
jmp 0x225a7
movl %r15d, %r13d
movzbl -0x30(%rbp), %r15d
movq %rbx, %rdi
movl -0x4c(%rbp), %esi
movl %r13d, %edx
movl %r15d, %ecx
callq 0x22874
movl %eax, %r14d
movl %eax, -0x34(%rbp)
movq 0x68(%rbx), %rdi
callq 0xddd3
testl %r14d, %r14d
jne 0x225a7
leaq -0x34(%rbp), %rbx
movq -0x48(%rbp), %rdi
movl %r13d, %esi
movl %r15d, %edx
movl %r12d, %ecx
movq %rbx, %r8
callq 0x22705
movl (%rbx), %r14d
jmp 0x225a7