// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: balance_quick
static int balance_quick(MemPage *pParent, MemPage *pPage, u8 *pSpace){
  BtShared *const pBt = pPage->pBt;    /* B-Tree Database */
  MemPage *pNew;                       /* Newly allocated page */
  int rc;                              /* Return Code */
  Pgno pgnoNew;                        /* Page number of pNew */

  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  assert( sqlite3PagerIswriteable(pParent->pDbPage) );
  assert( pPage->nOverflow==1 );

  /* This error condition is now caught prior to reaching this function */
  if( NEVER(pPage->nCell==0) ) return SQLITE_CORRUPT_BKPT;

  /* Allocate a new page. This page will become the right-sibling of 
  ** pPage. Make the parent page writable, so that the new divider cell
  ** may be inserted. If both these operations are successful, proceed.
  */
  rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);

  if( rc==SQLITE_OK ){

    u8 *pOut = &pSpace[4];
    u8 *pCell = pPage->apOvfl[0];
    u16 szCell = pPage->xCellSize(pPage, pCell);
    u8 *pStop;

    assert( sqlite3PagerIswriteable(pNew->pDbPage) );
    assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
    zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
    rc = rebuildPage(pNew, 1, &pCell, &szCell);
    if( NEVER(rc) ) return rc;
    pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;

    /* If this is an auto-vacuum database, update the pointer map
    ** with entries for the new page, and any pointer from the 
    ** cell on the page to an overflow page. If either of these
    ** operations fails, the return code is set, but the contents
    ** of the parent page are still manipulated by thh code below.
    ** That is Ok, at this point the parent page is guaranteed to
    ** be marked as dirty. Returning an error code will cause a
    ** rollback, undoing any changes made to the parent page.
    */
    if( ISAUTOVACUUM ){
      ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno, &rc);
      if( szCell>pNew->minLocal ){
        ptrmapPutOvflPtr(pNew, pCell, &rc);
      }
    }
  
    /* Create a divider cell to insert into pParent. The divider cell
    ** consists of a 4-byte page number (the page number of pPage) and
    ** a variable length key value (which must be the same value as the
    ** largest key on pPage).
    **
    ** To find the largest key value on pPage, first find the right-most 
    ** cell on pPage. The first two fields of this cell are the 
    ** record-length (a variable length integer at most 32-bits in size)
    ** and the key value (a variable length integer, may have any value).
    ** The first of the while(...) loops below skips over the record-length
    ** field. The second while(...) loop copies the key value from the
    ** cell on pPage into the pSpace buffer.
    */
    pCell = findCell(pPage, pPage->nCell-1);
    pStop = &pCell[9];
    while( (*(pCell++)&0x80) && pCell<pStop );
    pStop = &pCell[9];
    while( ((*(pOut++) = *(pCell++))&0x80) && pCell<pStop );

    /* Insert the new divider cell into pParent. */
    insertCell(pParent, pParent->nCell, pSpace, (int)(pOut-pSpace),
               0, pPage->pgno, &rc);

    /* Set the right-child pointer of pParent to point to the new page. */
    put4byte(&pParent->aData[pParent->hdrOffset+8], pgnoNew);
  
    /* Release the reference to the new page. */
    releasePage(pNew);
  }

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x12(%rax), %eax
cmpl $0x0, %eax
jne 0x4cbcf
movl $0xf1be, %edi           # imm = 0xF1BE
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4ce2e
movq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x38(%rbp), %rdx
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x33c40
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x4ce28
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq *%rax
movw %ax, -0x4a(%rbp)
movq -0x30(%rbp), %rdi
movl $0xd, %esi
callq 0x317c0
movq -0x30(%rbp), %rdi
movl $0x1, %esi
leaq -0x48(%rbp), %rdx
leaq -0x4a(%rbp), %rcx
callq 0x4e9c0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x4cc59
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4ce2e
movq -0x28(%rbp), %rax
movl 0x34(%rax), %eax
movq -0x30(%rbp), %rcx
movzwl 0xe(%rcx), %ecx
subl %ecx, %eax
subl $0x2, %eax
movzwl -0x4a(%rbp), %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x30(%rbp), %rax
movw %cx, 0x10(%rax)
movq -0x28(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x4ccca
movq -0x28(%rbp), %rdi
movl -0x38(%rbp), %esi
movq -0x10(%rbp), %rax
movl 0x88(%rax), %ecx
movl $0x5, %edx
leaq -0x34(%rbp), %r8
callq 0x34b20
movzwl -0x4a(%rbp), %eax
movq -0x30(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jle 0x4ccc8
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x34(%rbp), %rdx
callq 0x350c0
jmp 0x4ccca
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x18(%rbp), %rcx
movzwl 0x14(%rcx), %ecx
movq -0x18(%rbp), %rdx
movq 0x60(%rdx), %rdx
movq -0x18(%rbp), %rsi
movzwl 0x12(%rsi), %esi
subl $0x1, %esi
shll %esi
movslq %esi, %rsi
movzbl (%rdx,%rsi), %edx
shll $0x8, %edx
movq -0x18(%rbp), %rsi
movq 0x60(%rsi), %rsi
movq -0x18(%rbp), %rdi
movzwl 0x12(%rdi), %edi
subl $0x1, %edi
shll %edi
movslq %edi, %rdi
movzbl 0x1(%rsi,%rdi), %esi
orl %esi, %edx
andl %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x9, %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movzbl (%rax), %ecx
andl $0x80, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x59(%rbp)
je 0x4cd60
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
setb %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x4cd69
jmp 0x4cd6b
jmp 0x4cd30
movq -0x48(%rbp), %rax
addq $0x9, %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movb (%rax), %al
movq -0x40(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %al, (%rcx)
movzbl %al, %ecx
andl $0x80, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x5a(%rbp)
je 0x4cdba
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
setb %al
movb %al, -0x5a(%rbp)
movb -0x5a(%rbp), %al
testb $0x1, %al
jne 0x4cdc3
jmp 0x4cdc5
jmp 0x4cd77
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movzwl 0x12(%rax), %esi
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl 0x88(%rax), %r9d
xorl %eax, %eax
movl %eax, %r8d
leaq -0x34(%rbp), %rax
movq %rax, (%rsp)
callq 0x4b610
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
addl $0x8, %eax
cltq
addq %rax, %rdi
movl -0x38(%rbp), %esi
callq 0x28290
movq -0x30(%rbp), %rdi
callq 0x30e20
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)