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

  assert( *pRC==SQLITE_OK );
  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) );
  assert( sz==pPage->xCellSize(pPage, pCell) || CORRUPT_DB );
  assert( pPage->nFree>=0 );
  if( pPage->nOverflow || sz+2>pPage->nFree ){
    if( pTemp ){
      memcpy(pTemp, pCell, sz);
      pCell = pTemp;
    }
    if( iChild ){
      put4byte(pCell, iChild);
    }
    j = pPage->nOverflow++;
    /* Comparison against ArraySize-1 since we hold back one extra slot
    ** as a contingency.  In other words, never need more than 3 overflow
    ** slots but 4 are allocated, just to be safe. */
    assert( j < ArraySize(pPage->apOvfl)-1 );
    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);
    if( iChild ){
      /* In a corrupt database where an entry in the cell index section of
      ** a btree page has a value of 3 or less, the pCell value might point
      ** as many as 4 bytes in front of the start of the aData buffer for
      ** the source page.  Make sure this does not cause problems by not
      ** reading the first 4 bytes */
      memcpy(&data[idx+4], pCell+4, sz-4);
      put4byte(&data[idx], iChild);
    }else{
      memcpy(&data[idx], pCell, sz);
    }
    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 || CORRUPT_DB );
#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, pPage, pCell, pRC);
    }
#endif
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %r12d
movq %r8, %r14
movl %ecx, %r13d
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rbx
cmpb $0x0, 0xc(%rdi)
jne 0x2a0c2f
leal 0x2(%r13), %eax
cmpl 0x14(%rbx), %eax
jle 0x2a0c75
testq %r14, %r14
je 0x2a0c44
movslq %r13d, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x17660
jmp 0x2a0c47
movq %r15, %r14
testl %r12d, %r12d
je 0x2a0c52
bswapl %r12d
movl %r12d, (%r14)
movzbl 0xc(%rbx), %eax
leal 0x1(%rax), %ecx
movb %cl, 0xc(%rbx)
movq %r14, 0x28(%rbx,%rax,8)
movw %bp, 0x1c(%rbx,%rax,2)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, 0x20(%rsp)
movq 0x70(%rsp), %r14
movq 0x70(%rbx), %rdi
callq 0x2774a1
testl %eax, %eax
je 0x2a0c90
movl %eax, (%r14)
jmp 0x2a0c66
movq %r14, 0x30(%rsp)
movq 0x50(%rbx), %rdx
movzbl 0x9(%rbx), %esi
movl $0x0, 0xc(%rsp)
movzwl 0x12(%rbx), %eax
movzwl 0x18(%rbx), %ecx
leal (%rax,%rcx,2), %edi
movzwl 0x5(%rdx,%rsi), %eax
rolw $0x8, %ax
movzwl %ax, %r14d
cmpl %r14d, %edi
jbe 0x2a0cdf
movl $0x1024c, %ecx          # imm = 0x1024C
testl %r14d, %r14d
jne 0x2a0d37
movq 0x48(%rbx), %rax
movl $0x10000, %r14d         # imm = 0x10000
cmpl $0x10000, 0x38(%rax)    # imm = 0x10000
jne 0x2a0d37
cmpb $0x0, 0x2(%rdx,%rsi)
movq %rdx, 0x18(%rsp)
leal 0x2(%rdi), %eax
jne 0x2a0cf9
cmpb $0x0, 0x1(%rdx,%rsi)
je 0x2a0d83
cmpl %r14d, %eax
ja 0x2a0d83
movq %rdi, 0x28(%rsp)
movq %rsi, 0x10(%rsp)
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2a2dcc
testq %rax, %rax
je 0x2a0d69
movq 0x18(%rsp), %rdx
subl %edx, %eax
movl $0x1025e, %ecx          # imm = 0x1025E
cmpl %eax, 0x28(%rsp)
jl 0x2a0de9
leaq 0x134e8d(%rip), %rsi    # 0x3d5bcb
leaq 0x134f97(%rip), %rdx    # 0x3d5cdc
leaq 0x134ce5(%rip), %r8     # 0x3d5a31
movl $0xb, %edi
xorl %eax, %eax
callq 0x274d08
movl $0xb, %ecx
movq 0x30(%rsp), %rax
movl %ecx, (%rax)
jmp 0x2a0c66
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
movq 0x28(%rsp), %rax
jne 0x2a0d5d
addl $0x2, %eax
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
addl %r13d, %eax
cmpl %r14d, %eax
jle 0x2a0dd7
movq %rsi, 0x10(%rsp)
movq %rdx, %r14
movl 0x14(%rbx), %eax
subl %r13d, %eax
addl $-0x2, %eax
cmpl $0x4, %eax
movl $0x4, %esi
cmovll %eax, %esi
movq %rbx, %rdi
callq 0x2a2eff
movl %eax, %ecx
testl %eax, %eax
jne 0x2a0d5d
movq %r14, %rdx
movq 0x10(%rsp), %rsi
movzbl 0x5(%r14,%rsi), %eax
shll $0x8, %eax
movzbl 0x6(%r14,%rsi), %ecx
addl %ecx, %eax
decl %eax
movzwl %ax, %r14d
incl %r14d
subl %r13d, %r14d
movl %r14d, %eax
rolw $0x8, %ax
movw %ax, 0x5(%rdx,%rsi)
movl %r14d, %eax
movzwl 0x20(%rsp), %ecx
subl %ecx, 0x14(%rbx)
movq %rax, 0x20(%rsp)
movslq %eax, %r14
addq %rdx, %r14
testl %r12d, %r12d
je 0x2a0e1d
leaq 0x4(%r14), %rdi
leaq 0x4(%r15), %rsi
addl $-0x4, %r13d
movslq %r13d, %rdx
callq 0x17660
bswapl %r12d
movl %r12d, (%r14)
jmp 0x2a0e2b
movslq %r13d, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x17660
movq 0x60(%rbx), %rax
movslq %ebp, %rcx
leaq (%rax,%rcx,2), %rsi
leaq (%rax,%rcx,2), %r14
addq $0x2, %r14
movzwl 0x18(%rbx), %edx
subq %rcx, %rdx
addq %rdx, %rdx
movq %r14, %rdi
callq 0x17cd0
movq 0x20(%rsp), %rax
rolw $0x8, %ax
movw %ax, -0x2(%r14)
incw 0x18(%rbx)
movzbl 0x9(%rbx), %eax
movq 0x18(%rsp), %rcx
incb 0x4(%rcx,%rax)
jne 0x2a0e79
movzbl 0x9(%rbx), %eax
incb 0x3(%rcx,%rax)
movq 0x48(%rbx), %rax
cmpb $0x0, 0x21(%rax)
movq 0x30(%rsp), %rcx
je 0x2a0c66
movq %rbx, %rdi
movq %rbx, %rsi
movq %r15, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x28f905