// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x10(%rbp), %r14
cmpl $0x0, (%r14)
jne 0x31ef6
movl %r9d, %r13d
movq %r8, %r12
movl %ecx, %r15d
movq %rdx, %rcx
movq %rdi, %rbx
cmpb $0x0, 0x1(%rdi)
jne 0x31eb8
leal 0x2(%r15), %edx
movzwl 0x10(%rbx), %eax
cmpl %eax, %edx
jle 0x31f05
testq %r12, %r12
je 0x31ed3
movslq %r15d, %rdx
movq %r12, %rdi
movl %esi, %r14d
movq %rcx, %rsi
callq 0xa3b0
movl %r14d, %esi
jmp 0x31ed6
movq %rcx, %r12
testl %r13d, %r13d
je 0x31ee2
bswapl %r13d
movl %r13d, (%r12)
movzbl 0x1(%rbx), %eax
leal 0x1(%rax), %ecx
movb %cl, 0x1(%rbx)
movq %r12, 0x20(%rbx,%rax,8)
movw %si, 0x16(%rbx,%rax,2)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, -0x54(%rbp)
movl %esi, -0x58(%rbp)
movq %rcx, -0x38(%rbp)
movq 0x70(%rbx), %rdi
callq 0xfd43
testl %eax, %eax
je 0x31f21
movl %eax, (%r14)
jmp 0x31ef6
movq 0x50(%rbx), %rdx
movzbl 0x6(%rbx), %edi
andl $0x0, -0x3c(%rbp)
movzwl 0xe(%rbx), %eax
movzwl 0x12(%rbx), %ecx
leal (%rax,%rcx,2), %r12d
movzwl 0x5(%rdx,%rdi), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
cmpl %ecx, %r12d
jbe 0x31f73
testl %ecx, %ecx
movq -0x38(%rbp), %rsi
jne 0x31f64
movq 0x48(%rbx), %rax
movl $0x10000, %ecx          # imm = 0x10000
cmpl $0x10000, 0x34(%rax)    # imm = 0x10000
je 0x31f77
movl $0xdd37, %edi           # imm = 0xDD37
callq 0x1ec07
pushq $0xb
popq %rax
jmp 0x31f1c
movq -0x38(%rbp), %rsi
cmpb $0x0, 0x2(%rdx,%rdi)
movq %rdx, -0x50(%rbp)
leal 0x2(%r12), %eax
jne 0x31f8e
cmpb $0x0, 0x1(%rdx,%rdi)
je 0x31fdc
cmpl %ecx, %eax
ja 0x31fdc
movq %rdi, -0x48(%rbp)
movl %ecx, -0x2c(%rbp)
leaq -0x3c(%rbp), %rdx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x34017
testq %rax, %rax
je 0x31fbb
movq -0x50(%rbp), %rdx
subl %edx, %eax
movl %eax, %ecx
movq -0x38(%rbp), %rsi
jmp 0x3202b
movl -0x3c(%rbp), %eax
testl %eax, %eax
jne 0x31f1c
addl $0x2, %r12d
movl %r12d, %eax
movq -0x38(%rbp), %rsi
movq -0x50(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movq -0x48(%rbp), %rdi
addl %r15d, %eax
cmpl %ecx, %eax
jle 0x3201d
movq %rdi, -0x48(%rbp)
movq %rdx, %r12
movq %rbx, %rdi
callq 0x340ff
testl %eax, %eax
jne 0x31f1c
movq %r12, %rdx
movq -0x48(%rbp), %rdi
movzbl 0x5(%r12,%rdi), %eax
shll $0x8, %eax
movzbl 0x6(%r12,%rdi), %ecx
addl %ecx, %eax
decl %eax
movzwl %ax, %ecx
incl %ecx
movq -0x38(%rbp), %rsi
subl %r15d, %ecx
movl %ecx, %eax
rolw $0x8, %ax
movw %ax, 0x5(%rdx,%rdi)
movl -0x54(%rbp), %eax
subw %ax, 0x10(%rbx)
movl %ecx, -0x2c(%rbp)
movslq %ecx, %r12
addq %rdx, %r12
movslq %r15d, %rdx
movq %r12, %rdi
callq 0xa3b0
testl %r13d, %r13d
je 0x32052
bswapl %r13d
movl %r13d, (%r12)
movq 0x60(%rbx), %rax
movslq -0x58(%rbp), %rcx
leaq (%rax,%rcx,2), %rsi
leaq (%rax,%rcx,2), %r15
addq $0x2, %r15
movzwl 0x12(%rbx), %edx
subq %rcx, %rdx
addq %rdx, %rdx
movq %r15, %rdi
callq 0xa560
movl -0x2c(%rbp), %eax
rolw $0x8, %ax
movw %ax, -0x2(%r15)
incw 0x12(%rbx)
movzbl 0x6(%rbx), %eax
movq -0x50(%rbp), %rcx
incb 0x4(%rcx,%rax)
jne 0x3209e
movzbl 0x6(%rbx), %eax
incb 0x3(%rcx,%rax)
movq 0x48(%rbx), %rax
cmpb $0x0, 0x21(%rax)
movq -0x38(%rbp), %rsi
je 0x31ef6
movq %rbx, %rdi
movq %r14, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x24a02