// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/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 );

  if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT;  /* dbfuzz001.test */
  assert( pPage->nFree>=0 );
  assert( pParent->nFree>=0 );

  /* 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;
    CellArray b;

    assert( sqlite3PagerIswriteable(pNew->pDbPage) );
    assert( CORRUPT_DB || pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
    zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
    b.nCell = 1;
    b.pRef = pPage;
    b.apCell = &pCell;
    b.szCell = &szCell;
    b.apEnd[0] = pPage->aDataEnd;
    b.ixNx[0] = 2;
    rc = rebuildPage(&b, 0, 1, pNew);
    if( NEVER(rc) ){
      releasePage(pNew);
      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, 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. */
    if( rc==SQLITE_OK ){
      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 $0xd0, %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 0x18(%rax), %eax
cmpl $0x0, %eax
jne 0x405752
movl $0x1185d, %edi          # imm = 0x1185D
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x405a0e
movq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x38(%rbp), %rdx
xorl %r8d, %r8d
movl %r8d, %ecx
callq 0x3e9bc0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x405a08
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%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 0x3e79f0
movl $0x1, -0xc0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x48(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x4a(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0xa0(%rbp)
movl $0x2, -0x70(%rbp)
movq -0x30(%rbp), %rcx
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x407670
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x405827
movq -0x30(%rbp), %rdi
callq 0x3e9b70
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x405a0e
movq -0x28(%rbp), %rax
movl 0x38(%rax), %ecx
movq -0x30(%rbp), %rax
movzwl 0x12(%rax), %eax
subl %eax, %ecx
subl $0x2, %ecx
movzwl -0x4a(%rbp), %eax
subl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x28(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x405895
movq -0x28(%rbp), %rdi
movl -0x38(%rbp), %esi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movl $0x5, %edx
leaq -0x34(%rbp), %r8
callq 0x3eaaf0
movzwl -0x4a(%rbp), %eax
movq -0x30(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jle 0x405893
movq -0x30(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq -0x34(%rbp), %rcx
callq 0x3eb0d0
jmp 0x405895
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x18(%rbp), %rcx
movzwl 0x1a(%rcx), %ecx
movq -0x18(%rbp), %rdx
movq 0x60(%rdx), %rdx
movq -0x18(%rbp), %rsi
movzwl 0x18(%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 0x18(%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, -0xc1(%rbp)
je 0x405931
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
setb %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x40593d
jmp 0x40593f
jmp 0x4058fb
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, -0xc2(%rbp)
je 0x405994
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
setb %al
movb %al, -0xc2(%rbp)
movb -0xc2(%rbp), %al
testb $0x1, %al
jne 0x4059a0
jmp 0x4059a2
jmp 0x40594b
cmpl $0x0, -0x34(%rbp)
jne 0x4059df
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movzwl 0x18(%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 0x4(%rax), %r9d
xorl %eax, %eax
movl %eax, %r8d
leaq -0x34(%rbp), %rax
movq %rax, (%rsp)
callq 0x403ff0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
addl $0x8, %eax
cltq
addq %rax, %rdi
movl -0x38(%rbp), %esi
callq 0x3dd200
movq -0x30(%rbp), %rdi
callq 0x3e9b70
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)