// File: /workspace/github_c_makefile_star2_O1/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), %r15
cmpl $0x0, (%r15)
jne 0x386e0
movl %r9d, %r13d
movq %r8, %r12
movl %ecx, %r14d
movq %rdx, %rcx
movq %rdi, %rbx
cmpb $0x0, 0x1(%rdi)
jne 0x386a2
leal 0x2(%r14), %edx
movzwl 0x10(%rbx), %eax
cmpl %eax, %edx
jle 0x386ef
testq %r12, %r12
je 0x386bd
movslq %r14d, %rdx
movq %r12, %rdi
movl %esi, %r14d
movq %rcx, %rsi
callq 0xa310
movl %r14d, %esi
jmp 0x386c0
movq %rcx, %r12
testl %r13d, %r13d
je 0x386cc
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, -0x50(%rbp)
movl %esi, -0x54(%rbp)
movq %rcx, -0x38(%rbp)
movq 0x70(%rbx), %rdi
callq 0x10764
testl %eax, %eax
je 0x3870b
movl %eax, (%r15)
jmp 0x386e0
movq 0x50(%rbx), %rdi
movzbl 0x6(%rbx), %r10d
movl $0x0, -0x2c(%rbp)
movzwl 0xe(%rbx), %eax
movzwl 0x12(%rbx), %ecx
leal (%rax,%rcx,2), %r9d
movzwl 0x5(%rdi,%r10), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
cmpl %ecx, %r9d
movq %rdi, -0x48(%rbp)
jbe 0x38753
testl %ecx, %ecx
jne 0x3876f
movq 0x48(%rbx), %rax
movl $0x10000, %ecx          # imm = 0x10000
cmpl $0x10000, 0x34(%rax)    # imm = 0x10000
jne 0x3876f
cmpb $0x0, 0x2(%rdi,%r10)
je 0x387a4
leal 0x2(%r9), %eax
xorl %r8d, %r8d
cmpl %ecx, %eax
movq -0x38(%rbp), %rsi
jle 0x387bb
jmp 0x3880e
leaq 0x44d62(%rip), %rsi     # 0x7d4d8
leaq 0x44a00(%rip), %rcx     # 0x7d17d
movl $0xb, %r12d
movl $0xb, %edi
movl $0xdd37, %edx           # imm = 0xDD37
xorl %eax, %eax
callq 0xa4b0
xorl %r8d, %r8d
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
jmp 0x3886e
xorl %r8d, %r8d
cmpb $0x0, 0x1(%rdi,%r10)
movq -0x38(%rbp), %rsi
je 0x3880e
leal 0x2(%r9), %eax
cmpl %ecx, %eax
jg 0x3880e
leaq -0x2c(%rbp), %rdx
movq %rbx, %rdi
movl %r14d, %esi
movq %r10, -0x40(%rbp)
movl %ecx, -0x4c(%rbp)
movq %r9, %r12
callq 0x3aa53
movq %r12, %r9
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x2c(%rbp), %rcx
movl (%rcx), %ecx
testl %ecx, %ecx
sete %dl
movl %eax, %r8d
subl %edi, %r8d
xorl %r12d, %r12d
testq %rax, %rax
sete %al
cmovel %r12d, %r8d
cmovel %ecx, %r12d
movl -0x4c(%rbp), %ecx
andb %dl, %al
movq -0x40(%rbp), %r10
cmpb $0x1, %al
jne 0x3886e
leal (%r14,%r9), %eax
addl $0x2, %eax
cmpl %ecx, %eax
jle 0x38859
movq %rbx, %rdi
movq %r10, %r12
movl %r8d, -0x40(%rbp)
callq 0x3aba4
movl -0x40(%rbp), %r8d
movq %r12, %r10
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl %eax, %r12d
movl %eax, -0x2c(%rbp)
testl %eax, %eax
jne 0x3886e
movzbl 0x5(%rdi,%r10), %eax
shll $0x8, %eax
movzbl 0x6(%rdi,%r10), %ecx
addl %ecx, %eax
decl %eax
movzwl %ax, %ecx
incl %ecx
subl %r14d, %ecx
movl %ecx, %eax
rolw $0x8, %ax
movw %ax, 0x5(%rdi,%r10)
xorl %r12d, %r12d
movl %ecx, %r8d
testl %r12d, %r12d
je 0x3887b
movl %r12d, (%r15)
jmp 0x386e0
movl -0x50(%rbp), %eax
subw %ax, 0x10(%rbx)
movl %r8d, -0x40(%rbp)
movslq %r8d, %r12
addq %rdi, %r12
movslq %r14d, %rdx
movq %r12, %rdi
callq 0xa310
testl %r13d, %r13d
je 0x388a3
bswapl %r13d
movl %r13d, (%r12)
movq 0x60(%rbx), %rax
movslq -0x54(%rbp), %rcx
leaq (%rax,%rcx,2), %rsi
leaq (%rax,%rcx,2), %r14
addq $0x2, %r14
movzwl 0x12(%rbx), %edx
subq %rcx, %rdx
addq %rdx, %rdx
movq %r14, %rdi
callq 0xa440
movl -0x40(%rbp), %eax
rolw $0x8, %ax
movw %ax, -0x2(%r14)
incw 0x12(%rbx)
movzbl 0x6(%rbx), %eax
movq -0x48(%rbp), %rcx
incb 0x4(%rcx,%rax)
jne 0x388ef
movzbl 0x6(%rbx), %eax
incb 0x3(%rcx,%rax)
movq 0x48(%rbx), %rax
cmpb $0x0, 0x21(%rax)
movq -0x38(%rbp), %rsi
je 0x386e0
movq %rbx, %rdi
movq %r15, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x28671