// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movl %r9d, %r15d
movl %r8d, -0x30(%rbp)
movl %ecx, -0x38(%rbp)
movl %edx, -0x34(%rbp)
movq %rsi, %rbx
movl 0x70(%rsi), %eax
movl %eax, -0x54(%rbp)
movq %rdi, -0x50(%rbp)
movq (%rdi), %r13
movq 0x68(%rsi), %r14
cmpb $0x0, 0x12(%r13)
je 0x227b8
movq %r14, %rdi
callq 0xdebf
testl %eax, %eax
jne 0x227d7
testb $0x2, 0x2c(%r14)
je 0x227df
movq %r14, %rdi
callq 0x1a814
testl %eax, %eax
je 0x227df
movq %r14, %rdi
callq 0x1a878
testl %eax, %eax
je 0x227df
movl %eax, %r12d
jmp 0x22919
movzwl 0x2c(%r14), %eax
movl $0x0, -0x3c(%rbp)
testl %r15d, %r15d
jne 0x227fe
movl %eax, %ecx
andl $0x4, %ecx
je 0x227fe
movl 0x28(%r14), %ecx
movl %ecx, -0x3c(%rbp)
andl $0xfffb, %eax           # imm = 0xFFFB
movw %ax, 0x2c(%r14)
movq 0x110(%r13), %rdi
leaq -0x48(%rbp), %r15
movl -0x30(%rbp), %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0x1f6fc
movq (%r15), %r12
testq %r12, %r12
je 0x22855
movzwl 0x2c(%r12), %eax
andl $0x4, %eax
orw %ax, 0x2c(%r14)
cmpb $0x0, 0x12(%r13)
je 0x2284d
movl 0x1c(%r13), %esi
incl %esi
movq %r12, %rdi
callq 0x22e5c
jmp 0x22855
movq %r12, %rdi
callq 0x1f452
movl 0x28(%r14), %r15d
movq %r14, %rdi
movl -0x30(%rbp), %esi
callq 0x22e5c
movzwl 0x2c(%r14), %ecx
movl %ecx, %eax
andl $-0x21, %eax
movw %ax, 0x2c(%r14)
testb $0x2, %cl
jne 0x22888
orl $0x2, %eax
movw %ax, 0x2c(%r14)
movq %r14, %rdi
callq 0x1fa07
cmpb $0x0, 0x12(%r13)
je 0x228a2
movq %r12, %rdi
movl %r15d, %esi
callq 0x22e5c
movq %r12, %rdi
callq 0xdcd4
movl -0x3c(%rbp), %r14d
testl %r14d, %r14d
je 0x22916
leaq -0x48(%rbp), %rdx
movq %r13, %rdi
movl %r14d, %esi
xorl %ecx, %ecx
callq 0xd803
movl %eax, %r12d
testl %eax, %eax
je 0x228de
cmpl 0x20(%r13), %r14d
ja 0x22911
movq 0x40(%r13), %rdi
movq 0x108(%r13), %rdx
movl %r14d, %esi
callq 0x22ea6
jmp 0x22911
movq -0x48(%rbp), %r14
movzwl 0x2c(%r14), %ecx
movl %ecx, %eax
andl $-0x25, %eax
leal 0x4(%rax), %edx
movw %dx, 0x2c(%r14)
testb $0x2, %cl
jne 0x22909
orl $0x6, %eax
movw %ax, 0x2c(%r14)
movq %r14, %rdi
callq 0x1fa07
movq %r14, %rdi
callq 0xdcd4
testl %r12d, %r12d
jne 0x22919
xorl %r12d, %r12d
movl %r12d, -0x2c(%rbp)
testl %r12d, %r12d
jne 0x229a0
movl -0x30(%rbp), %eax
movl %eax, 0x70(%rbx)
movl -0x34(%rbp), %eax
andb $-0x5, %al
cmpb $0x1, %al
jne 0x22942
movq %rbx, %rdi
callq 0x22a27
movl %eax, -0x2c(%rbp)
testl %eax, %eax
jne 0x2299d
jmp 0x22978
movq 0x50(%rbx), %rax
movl (%rax), %esi
bswapl %esi
testl %esi, %esi
je 0x22972
leaq -0x2c(%rbp), %rbx
movq -0x50(%rbp), %rdi
movl $0x4, %edx
movl -0x30(%rbp), %ecx
movq %rbx, %r8
callq 0x22b09
movl (%rbx), %r12d
testl %r12d, %r12d
je 0x22972
xorl %eax, %eax
jmp 0x22974
movb $0x1, %al
testb %al, %al
je 0x229a0
cmpb $0x1, -0x34(%rbp)
jne 0x22984
movl -0x2c(%rbp), %r12d
jmp 0x229a0
leaq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rdi
movl -0x38(%rbp), %esi
xorl %ecx, %ecx
callq 0x2035c
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0x229b2
movl %eax, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x48(%rbp), %rbx
movq 0x68(%rbx), %rdi
callq 0xdebf
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0x229d9
movl %eax, %r12d
testq %rbx, %rbx
je 0x229a0
movq 0x68(%rbx), %rdi
callq 0xdcd4
jmp 0x229a0
movzbl -0x34(%rbp), %r14d
movq %rbx, %rdi
movl -0x54(%rbp), %esi
movl -0x30(%rbp), %edx
movl %r14d, %ecx
callq 0x22c6d
movl %eax, %r15d
movl %eax, -0x2c(%rbp)
testq %rbx, %rbx
je 0x22a03
movq 0x68(%rbx), %rdi
callq 0xdcd4
testl %r15d, %r15d
jne 0x2297e
leaq -0x2c(%rbp), %r8
movq -0x50(%rbp), %rdi
movl -0x30(%rbp), %esi
movl %r14d, %edx
movl -0x38(%rbp), %ecx
callq 0x22b09
jmp 0x2297e