// File: /workspace/github_c_makefile_star2_O3/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 0x379cc
movl %r9d, %r13d
movq %r8, %r12
movl %ecx, %r15d
movq %rdx, %rcx
movq %rdi, %rbx
cmpb $0x0, 0x1(%rdi)
jne 0x3798e
leal 0x2(%r15), %edx
movzwl 0x10(%rbx), %eax
cmpl %eax, %edx
jle 0x379db
testq %r12, %r12
je 0x379a9
movslq %r15d, %rdx
movq %r12, %rdi
movl %esi, %r14d
movq %rcx, %rsi
callq 0xa320
movl %r14d, %esi
jmp 0x379ac
movq %rcx, %r12
testl %r13d, %r13d
je 0x379b8
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, -0x2c(%rbp)
movl %esi, -0x54(%rbp)
movq %rcx, -0x38(%rbp)
movq 0x70(%rbx), %rdi
callq 0x107f0
testl %eax, %eax
je 0x379f7
movl %eax, (%r14)
jmp 0x379cc
movq 0x50(%rbx), %rdx
movzbl 0x6(%rbx), %edi
movl $0x0, -0x3c(%rbp)
movzwl 0xe(%rbx), %eax
movzwl 0x12(%rbx), %ecx
leal (%rax,%rcx,2), %ecx
movzwl 0x5(%rdx,%rdi), %eax
rolw $0x8, %ax
movzwl %ax, %r12d
cmpl %r12d, %ecx
jbe 0x37a69
testl %r12d, %r12d
movq -0x38(%rbp), %rsi
jne 0x37a3f
movq 0x48(%rbx), %rax
movl $0x10000, %r12d         # imm = 0x10000
cmpl $0x10000, 0x34(%rax)    # imm = 0x10000
je 0x37a6d
leaq 0x43aa2(%rip), %rsi     # 0x7b4e8
leaq 0x43740(%rip), %rcx     # 0x7b18d
movl $0xb, %r12d
movl $0xb, %edi
movl $0xdd37, %edx           # imm = 0xDD37
xorl %eax, %eax
callq 0xa4c0
jmp 0x37aef
movq -0x38(%rbp), %rsi
cmpb $0x0, 0x2(%rdx,%rdi)
movq %rdx, -0x48(%rbp)
leal 0x2(%rcx), %eax
jne 0x37a82
cmpb $0x0, 0x1(%rdx,%rdi)
je 0x37ad4
cmpl %r12d, %eax
ja 0x37ad4
movq %rcx, -0x60(%rbp)
movq %rdi, -0x50(%rbp)
leaq -0x3c(%rbp), %rdx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x39b48
testq %rax, %rax
je 0x37ab2
movq -0x48(%rbp), %rdx
subl %edx, %eax
movl %eax, %r12d
movq -0x38(%rbp), %rsi
jmp 0x37b2a
movl %r12d, %ecx
movl -0x3c(%rbp), %r12d
testl %r12d, %r12d
jne 0x37aef
movq -0x60(%rbp), %rax
addl $0x2, %eax
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
movl %ecx, %r12d
movq -0x50(%rbp), %rdi
addl %r15d, %eax
cmpl %r12d, %eax
jle 0x37b1b
movq %rdi, -0x50(%rbp)
movq %rbx, %rdi
callq 0x39c5d
movl %eax, %r12d
testl %eax, %eax
je 0x37af7
movl %r12d, (%r14)
jmp 0x379cc
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rdi
movzbl 0x5(%rdx,%rdi), %eax
shll $0x8, %eax
movzbl 0x6(%rdx,%rdi), %ecx
addl %ecx, %eax
decl %eax
movzwl %ax, %r12d
incl %r12d
movq -0x38(%rbp), %rsi
subl %r15d, %r12d
movl %r12d, %eax
rolw $0x8, %ax
movw %ax, 0x5(%rdx,%rdi)
movl -0x2c(%rbp), %eax
subw %ax, 0x10(%rbx)
movl %r12d, -0x2c(%rbp)
movslq %r12d, %r12
addq %rdx, %r12
movslq %r15d, %rdx
movq %r12, %rdi
callq 0xa320
testl %r13d, %r13d
je 0x37b52
bswapl %r13d
movl %r13d, (%r12)
movq 0x60(%rbx), %rax
movslq -0x54(%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 0xa450
movl -0x2c(%rbp), %eax
rolw $0x8, %ax
movw %ax, -0x2(%r15)
incw 0x12(%rbx)
movzbl 0x6(%rbx), %eax
movq -0x48(%rbp), %rcx
incb 0x4(%rcx,%rax)
jne 0x37b9e
movzbl 0x6(%rbx), %eax
incb 0x3(%rcx,%rax)
movq 0x48(%rbx), %rax
cmpb $0x0, 0x21(%rax)
movq -0x38(%rbp), %rsi
je 0x379cc
movq %rbx, %rdi
movq %r14, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x28244