// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: insertCell
static void insertCell(
  MemPage *pPage,   /* Page into which we are copying */
  int i,            /* New cell becomes the i-th cell of the page */
  u8 *pCell,        /* Content of the new cell */
  int sz,           /* Bytes of content in pCell */
  u8 *pTemp,        /* Temp storage space for pCell, if needed */
  Pgno iChild,      /* If non-zero, replace first 4 bytes with this value */
  int *pRC          /* Read and write return code from here */
){
  int idx = 0;      /* Where to write new cell content in data[] */
  int j;            /* Loop counter */
  u8 *data;         /* The content of the whole page */
  u8 *pIns;         /* The point in pPage->aCellIdx[] where no cell inserted */

  if( *pRC ) return;

  assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
  assert( MX_CELL(pPage->pBt)<=10921 );
  assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB );
  assert( pPage->nOverflow<=ArraySize(pPage->apOvfl) );
  assert( ArraySize(pPage->apOvfl)==ArraySize(pPage->aiOvfl) );
  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  /* The cell should normally be sized correctly.  However, when moving a
  ** malformed cell from a leaf page to an interior page, if the cell size
  ** wanted to be less than 4 but got rounded up to 4 on the leaf, then size
  ** might be less than 8 (leaf-size + pointer) on the interior node.  Hence
  ** the term after the || in the following assert(). */
  assert( sz==pPage->xCellSize(pPage, pCell) || (sz==8 && iChild>0) );
  if( pPage->nOverflow || sz+2>pPage->nFree ){
    if( pTemp ){
      memcpy(pTemp, pCell, sz);
      pCell = pTemp;
    }
    if( iChild ){
      put4byte(pCell, iChild);
    }
    j = pPage->nOverflow++;
    assert( j<(int)(sizeof(pPage->apOvfl)/sizeof(pPage->apOvfl[0])) );
    pPage->apOvfl[j] = pCell;
    pPage->aiOvfl[j] = (u16)i;

    /* When multiple overflows occur, they are always sequential and in
    ** sorted order.  This invariants arise because multiple overflows can
    ** only occur when inserting divider cells into the parent page during
    ** balancing, and the dividers are adjacent and sorted.
    */
    assert( j==0 || pPage->aiOvfl[j-1]<(u16)i ); /* Overflows in sorted order */
    assert( j==0 || i==pPage->aiOvfl[j-1]+1 );   /* Overflows are sequential */
  }else{
    int rc = sqlite3PagerWrite(pPage->pDbPage);
    if( rc!=SQLITE_OK ){
      *pRC = rc;
      return;
    }
    assert( sqlite3PagerIswriteable(pPage->pDbPage) );
    data = pPage->aData;
    assert( &data[pPage->cellOffset]==pPage->aCellIdx );
    rc = allocateSpace(pPage, sz, &idx);
    if( rc ){ *pRC = rc; return; }
    /* The allocateSpace() routine guarantees the following properties
    ** if it returns successfully */
    assert( idx >= 0 );
    assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB );
    assert( idx+sz <= (int)pPage->pBt->usableSize );
    pPage->nFree -= (u16)(2 + sz);
    memcpy(&data[idx], pCell, sz);
    if( iChild ){
      put4byte(&data[idx], iChild);
    }
    pIns = pPage->aCellIdx + i*2;
    memmove(pIns+2, pIns, 2*(pPage->nCell - i));
    put2byte(pIns, idx);
    pPage->nCell++;
    /* increment the cell count */
    if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
    assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell );
#ifndef SQLITE_OMIT_AUTOVACUUM
    if( pPage->pBt->autoVacuum ){
      /* The cell may contain a pointer to an overflow page. If so, write
      ** the entry for the overflow page into the pointer map.
      */
      ptrmapPutOvflPtr(pPage, pCell, pRC);
    }
#endif
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x4b647
jmp 0x4b835
movq -0x8(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x4b666
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movq -0x8(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
cmpl %ecx, %eax
jle 0x4b6d6
cmpq $0x0, -0x28(%rbp)
je 0x4b686
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0xb420
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x4b698
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x28290
movq -0x8(%rbp), %rcx
movb 0x1(%rcx), %al
movb %al, %dl
addb $0x1, %dl
movb %dl, 0x1(%rcx)
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movl -0xc(%rbp), %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movw %dx, 0x16(%rax,%rcx,2)
jmp 0x4b835
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x12d70
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x4b6fa
movl -0x4c(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x4b835
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x30(%rbp), %rdx
callq 0x4c360
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x4b72d
movl -0x4c(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x4b835
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movzwl %ax, %edx
movq -0x8(%rbp), %rax
movzwl 0x10(%rax), %ecx
subl %edx, %ecx
movw %cx, 0x10(%rax)
movq -0x40(%rbp), %rdi
movslq -0x30(%rbp), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0xb420
cmpl $0x0, -0x2c(%rbp)
je 0x4b775
movq -0x40(%rbp), %rdi
movslq -0x30(%rbp), %rax
addq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x28290
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movl -0xc(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
addq $0x2, %rdi
movq -0x48(%rbp), %rsi
movq -0x8(%rbp), %rax
movzwl 0x12(%rax), %eax
subl -0xc(%rbp), %eax
shll %eax
movslq %eax, %rdx
callq 0xb640
movl -0x30(%rbp), %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, (%rax)
movl -0x30(%rbp), %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x8(%rbp), %rax
movw 0x12(%rax), %cx
addw $0x1, %cx
movw %cx, 0x12(%rax)
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rax
movzbl 0x6(%rax), %eax
addl $0x4, %eax
movslq %eax, %rdx
movb (%rcx,%rdx), %al
addb $0x1, %al
movb %al, (%rcx,%rdx)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x4b814
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
addb $0x1, %dl
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
cmpb $0x0, 0x21(%rax)
je 0x4b833
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x350c0
jmp 0x4b835
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)