// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movl %r9d, %r12d
movl %r8d, -0x2c(%rbp)
movl %ecx, -0x3c(%rbp)
movl %edx, -0x30(%rbp)
movq %rsi, %r13
movl 0x70(%rsi), %eax
movl %eax, -0x34(%rbp)
movq %rdi, -0x48(%rbp)
movq (%rdi), %rbx
movq 0x68(%rsi), %r15
cmpb $0x0, 0x12(%rbx)
je 0x1f40a
movq %r15, %rdi
callq 0xd10b
testl %eax, %eax
jne 0x1f5a0
movzwl 0x2c(%r15), %r14d
testb $0x2, %r14b
je 0x1f436
movq %r15, %rdi
callq 0x18474
testl %eax, %eax
je 0x1f436
movq %r15, %rdi
callq 0x184e0
testl %eax, %eax
jne 0x1f5a0
movzwl 0x2c(%r15), %r14d
movl $0x0, -0x38(%rbp)
testl %r12d, %r12d
jne 0x1f456
movl %r14d, %eax
andl $0x4, %eax
movl -0x2c(%rbp), %esi
je 0x1f459
movl 0x28(%r15), %eax
movl %eax, -0x38(%rbp)
jmp 0x1f459
movl -0x2c(%rbp), %esi
andl $0xfffb, %r14d          # imm = 0xFFFB
movw %r14w, 0x2c(%r15)
movq %rbx, %rdi
callq 0x1cdfb
movq %rax, %r14
testq %rax, %rax
je 0x1f49f
movzwl 0x2c(%r14), %eax
andl $0x4, %eax
orw %ax, 0x2c(%r15)
cmpb $0x0, 0x12(%rbx)
je 0x1f497
movl 0x1c(%rbx), %esi
incl %esi
movq %r14, %rdi
callq 0x1f8fb
jmp 0x1f49f
movq %r14, %rdi
callq 0x1c93e
movl 0x28(%r15), %r12d
movq %r15, %rdi
movl -0x2c(%rbp), %esi
callq 0x1f8fb
movq %r15, %rdi
callq 0x1ce20
cmpb $0x0, 0x12(%rbx)
je 0x1f4cf
movq %r14, %rdi
movl %r12d, %esi
callq 0x1f8fb
movq %r14, %rdi
callq 0xcf6e
movl -0x38(%rbp), %r15d
testl %r15d, %r15d
movl -0x2c(%rbp), %r12d
je 0x1f52f
leaq -0x70(%rbp), %rdx
movq %rbx, %rdi
movl %r15d, %esi
xorl %ecx, %ecx
callq 0xca7d
testl %eax, %eax
je 0x1f516
movl %eax, %r14d
cmpl 0x20(%rbx), %r15d
ja 0x1f5a3
movq 0x40(%rbx), %rdi
movq 0x108(%rbx), %rdx
movl %r15d, %esi
callq 0x1f945
jmp 0x1f5a3
movq -0x70(%rbp), %rbx
orw $0x4, 0x2c(%rbx)
movq %rbx, %rdi
callq 0x1ce20
movq %rbx, %rdi
callq 0xcf6e
andl $0x0, -0x40(%rbp)
movl %r12d, 0x70(%r13)
movl -0x30(%rbp), %eax
andb $-0x5, %al
cmpb $0x1, %al
jne 0x1f55b
movq %r13, %rdi
callq 0x1f719
testl %eax, %eax
jne 0x1f5a0
xorl %r14d, %r14d
cmpb $0x1, -0x30(%rbp)
movq -0x48(%rbp), %r15
jne 0x1f58b
jmp 0x1f5a3
movq 0x50(%r13), %rdi
callq 0x180a3
testl %eax, %eax
movq -0x48(%rbp), %r15
je 0x1f58b
pushq $0x4
popq %rdx
leaq -0x40(%rbp), %rbx
movq %r15, %rdi
movl %eax, %esi
movl %r12d, %ecx
movq %rbx, %r8
callq 0x1f801
movl (%rbx), %r14d
testl %r14d, %r14d
jne 0x1f5a3
leaq -0x50(%rbp), %rdx
movq %r15, %rdi
movl -0x3c(%rbp), %esi
xorl %ecx, %ecx
callq 0x1d84e
testl %eax, %eax
je 0x1f5b5
movl %eax, %r14d
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x50(%rbp), %r13
movq 0x68(%r13), %rdi
callq 0xd10b
testl %eax, %eax
je 0x1f5d3
movl %eax, %r14d
movq %r13, %rdi
callq 0x1d90e
jmp 0x1f5a3
cmpb $0x4, -0x30(%rbp)
jne 0x1f600
movq 0x50(%r13), %r14
movq %r14, %rdi
callq 0x180a3
movl $0xccd4, %ebx           # imm = 0xCCD4
cmpl -0x34(%rbp), %eax
jne 0x1f6c1
movl %r12d, %eax
bswapl %eax
movl %eax, (%r14)
jmp 0x1f6ec
movb (%r13), %al
movb %al, -0x38(%rbp)
movq %r13, %rdi
callq 0x1a4b5
movzwl 0x10(%r13), %r12d
xorl %r15d, %r15d
leaq -0x70(%rbp), %rbx
cmpq %r15, %r12
je 0x1f689
movzwl 0x12(%r13), %eax
movq 0x60(%r13), %rcx
movzbl (%rcx,%r15,2), %edx
shll $0x8, %edx
movzbl 0x1(%rcx,%r15,2), %r14d
orl %edx, %r14d
andl %eax, %r14d
addq 0x50(%r13), %r14
cmpb $0x3, -0x30(%rbp)
jne 0x1f677
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1e436
movzwl -0x54(%rbp), %eax
testq %rax, %rax
je 0x1f684
leaq (%r14,%rax), %rcx
addq $0x3, %rcx
movzwl 0x12(%r13), %edx
addq 0x50(%r13), %rdx
cmpq %rdx, %rcx
ja 0x1f684
addq %rax, %r14
movq %r14, %rdi
callq 0x180a3
cmpl -0x34(%rbp), %eax
je 0x1f6d9
incq %r15
jmp 0x1f61b
movl $0xccf6, %ebx           # imm = 0xCCF6
cmpb $0x5, -0x30(%rbp)
jne 0x1f6c1
movq 0x50(%r13), %r14
movzbl 0x5(%r13), %r15d
leaq (%r14,%r15), %rdi
addq $0x8, %rdi
callq 0x180a3
cmpl -0x34(%rbp), %eax
movl -0x2c(%rbp), %r12d
jne 0x1f6c1
addq %r15, %r14
movl %r12d, %eax
bswapl %eax
movl %eax, 0x8(%r14)
jmp 0x1f6e5
movl %ebx, %edi
callq 0x1a1fc
movq %r13, %rdi
callq 0x1d90e
pushq $0xb
popq %r14
jmp 0x1f5a3
movl -0x2c(%rbp), %r12d
movl %r12d, %eax
bswapl %eax
movl %eax, (%r14)
movb -0x38(%rbp), %al
movb %al, (%r13)
leaq -0x40(%rbp), %rbx
andl $0x0, (%rbx)
movq %r13, %rdi
callq 0x1d90e
movzbl -0x30(%rbp), %edx
movq -0x48(%rbp), %rdi
movl %r12d, %esi
movl -0x3c(%rbp), %ecx
movq %rbx, %r8
callq 0x1f801
movl (%rbx), %r14d
jmp 0x1f5a3