// File: /workspace/github_c_makefile_star2_O2/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, %r15
movl %ecx, %r13d
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
cmpb $0x0, 0xc(%rdi)
jne 0x246ae8
leal 0x2(%r13), %eax
cmpl 0x14(%rbx), %eax
jle 0x246b2e
testq %r15, %r15
je 0x246afd
movslq %r13d, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x17630
jmp 0x246b00
movq %r14, %r15
testl %r12d, %r12d
je 0x246b0b
bswapl %r12d
movl %r12d, (%r15)
movzbl 0xc(%rbx), %eax
leal 0x1(%rax), %ecx
movb %cl, 0xc(%rbx)
movq %r15, 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), %r15
movq 0x70(%rbx), %rdi
callq 0x2236f2
testl %eax, %eax
je 0x246b49
movl %eax, (%r15)
jmp 0x246b1f
movq %r15, 0x30(%rsp)
movq 0x50(%rbx), %rdx
movzbl 0x9(%rbx), %esi
andl $0x0, 0xc(%rsp)
movzwl 0x12(%rbx), %eax
movzwl 0x18(%rbx), %ecx
leal (%rax,%rcx,2), %ecx
movzwl 0x5(%rdx,%rsi), %eax
rolw $0x8, %ax
movzwl %ax, %r15d
cmpl %r15d, %ecx
jbe 0x246b95
movl $0x1024c, %edi          # imm = 0x1024C
testl %r15d, %r15d
jne 0x246be5
movq 0x48(%rbx), %rax
movl $0x10000, %r15d         # imm = 0x10000
cmpl $0x10000, 0x38(%rax)    # imm = 0x10000
jne 0x246be5
cmpb $0x0, 0x2(%rdx,%rsi)
movq %rdx, 0x18(%rsp)
leal 0x2(%rcx), %eax
jne 0x246bab
cmpb $0x0, 0x1(%rdx,%rsi)
je 0x246c12
cmpl %r15d, %eax
ja 0x246c12
movq %rcx, 0x28(%rsp)
movq %rsi, 0x10(%rsp)
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
movl %r13d, %esi
callq 0x248b98
testq %rax, %rax
je 0x246bf6
movq 0x18(%rsp), %rdx
subl %edx, %eax
movl $0x1025e, %edi          # imm = 0x1025E
cmpl %eax, 0x28(%rsp)
jl 0x246c74
callq 0x232547
movq 0x30(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x246b1f
movl 0xc(%rsp), %eax
testl %eax, %eax
movq 0x28(%rsp), %rcx
jne 0x246bea
addl $0x2, %ecx
movl %ecx, %eax
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
addl %r13d, %eax
cmpl %r15d, %eax
jle 0x246c62
movq %rsi, 0x10(%rsp)
movq %rdx, %r15
movl 0x14(%rbx), %eax
subl %r13d, %eax
addl $-0x2, %eax
cmpl $0x4, %eax
pushq $0x4
popq %rsi
cmovll %eax, %esi
movq %rbx, %rdi
callq 0x248c6b
testl %eax, %eax
jne 0x246bea
movq %r15, %rdx
movq 0x10(%rsp), %rsi
movzbl 0x5(%r15,%rsi), %eax
shll $0x8, %eax
movzbl 0x6(%r15,%rsi), %ecx
addl %ecx, %eax
decl %eax
movzwl %ax, %r15d
incl %r15d
subl %r13d, %r15d
movl %r15d, %eax
rolw $0x8, %ax
movw %ax, 0x5(%rdx,%rsi)
movl %r15d, %eax
movzwl 0x20(%rsp), %ecx
subl %ecx, 0x14(%rbx)
movq %rax, 0x20(%rsp)
movslq %eax, %r15
addq %rdx, %r15
testl %r12d, %r12d
je 0x246ca8
leaq 0x4(%r15), %rdi
leaq 0x4(%r14), %rsi
addl $-0x4, %r13d
movslq %r13d, %rdx
callq 0x17630
bswapl %r12d
movl %r12d, (%r15)
jmp 0x246cb6
movslq %r13d, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x17630
movq 0x60(%rbx), %rax
movslq %ebp, %rcx
leaq (%rax,%rcx,2), %rsi
leaq (%rax,%rcx,2), %r15
addq $0x2, %r15
movzwl 0x18(%rbx), %edx
subq %rcx, %rdx
addq %rdx, %rdx
movq %r15, %rdi
callq 0x17c50
movq 0x20(%rsp), %rax
rolw $0x8, %ax
movw %ax, -0x2(%r15)
incw 0x18(%rbx)
movzbl 0x9(%rbx), %eax
movq 0x18(%rsp), %rcx
incb 0x4(%rcx,%rax)
jne 0x246d04
movzbl 0x9(%rbx), %eax
incb 0x3(%rcx,%rax)
movq 0x48(%rbx), %rax
cmpb $0x0, 0x21(%rax)
movq 0x30(%rsp), %rcx
je 0x246b1f
movq %rbx, %rdi
movq %rbx, %rsi
movq %r14, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x238515