// File: /workspace/github_c_makefile_star2_O1/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 0x2aa5dc
leal 0x2(%r13), %eax
cmpl 0x14(%rbx), %eax
jle 0x2aa622
testq %r15, %r15
je 0x2aa5f1
movslq %r13d, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x17660
jmp 0x2aa5f4
movq %r14, %r15
testl %r12d, %r12d
je 0x2aa5ff
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, 0x2c(%rsp)
movq 0x70(%rsp), %r15
movq 0x70(%rbx), %rdi
callq 0x280e3a
testl %eax, %eax
je 0x2aa63d
movl %eax, (%r15)
jmp 0x2aa613
movq 0x50(%rbx), %rdx
movzbl 0x9(%rbx), %esi
movl $0x0, 0x4(%rsp)
movzwl 0x12(%rbx), %eax
movzwl 0x18(%rbx), %ecx
leal (%rax,%rcx,2), %r8d
movzwl 0x5(%rdx,%rsi), %eax
rolw $0x8, %ax
movzwl %ax, %edi
cmpl %edi, %r8d
movq %rdx, 0x8(%rsp)
movq %r15, 0x30(%rsp)
jbe 0x2aa68a
testl %edi, %edi
jne 0x2aa699
movq 0x48(%rbx), %rax
movl $0x10000, %edi          # imm = 0x10000
cmpl $0x10000, 0x38(%rax)    # imm = 0x10000
jne 0x2aa699
cmpb $0x0, 0x2(%rdx,%rsi)
je 0x2aa6d1
leal 0x2(%r8), %eax
xorl %ecx, %ecx
jmp 0x2aa6e2
leaq 0x134c7f(%rip), %rsi    # 0x3df31f
leaq 0x134d89(%rip), %rdx    # 0x3df430
leaq 0x134ad7(%rip), %r8     # 0x3df185
movl $0xb, %r15d
movl $0xb, %edi
movl $0x1024c, %ecx          # imm = 0x1024C
xorl %eax, %eax
callq 0x27e637
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
jmp 0x2aa806
xorl %ecx, %ecx
cmpb $0x0, 0x1(%rdx,%rsi)
je 0x2aa796
leal 0x2(%r8), %eax
cmpl %edi, %eax
jg 0x2aa796
movq %r8, 0x18(%rsp)
movl %edi, (%rsp)
movq %rsi, 0x10(%rsp)
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
movl %r13d, %esi
callq 0x2ac943
testq %rax, %rax
je 0x2aa727
movq %rax, %rcx
movq 0x8(%rsp), %rdx
subl %edx, %ecx
xorl %eax, %eax
movq 0x18(%rsp), %r8
cmpl %ecx, %r8d
jge 0x2aa748
xorl %r15d, %r15d
jmp 0x2aa78a
movl 0x4(%rsp), %r15d
testl %r15d, %r15d
sete %al
xorl %ecx, %ecx
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rsi
movl (%rsp), %edi
movq 0x18(%rsp), %r8
jmp 0x2aa792
leaq 0x134bd0(%rip), %rsi    # 0x3df31f
leaq 0x134cda(%rip), %rdx    # 0x3df430
leaq 0x134a28(%rip), %r8     # 0x3df185
movl $0xb, %r15d
movl $0xb, %edi
movq %rcx, 0x20(%rsp)
movl $0x1025e, %ecx          # imm = 0x1025E
xorl %eax, %eax
callq 0x27e637
xorl %eax, %eax
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %rcx
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rsi
movl (%rsp), %edi
testb %al, %al
je 0x2aa806
leal (%r8,%r13), %eax
addl $0x2, %eax
cmpl %edi, %eax
jle 0x2aa7f3
movl 0x14(%rbx), %eax
subl %r13d, %eax
addl $-0x2, %eax
cmpl $0x4, %eax
movq %rsi, 0x10(%rsp)
movl $0x4, %esi
cmovll %eax, %esi
movq %rbx, %rdi
movq %rcx, %r15
callq 0x2aca77
movq 0x10(%rsp), %rsi
movq %r15, %rcx
movq 0x8(%rsp), %rdx
movl %eax, %r15d
movl %eax, 0x4(%rsp)
testl %eax, %eax
jne 0x2aa806
movzbl 0x5(%rdx,%rsi), %eax
shll $0x8, %eax
movzbl 0x6(%rdx,%rsi), %ecx
addl %ecx, %eax
decl %eax
movzwl %ax, %edi
incl %edi
subl %r13d, %edi
movl %edi, %eax
rolw $0x8, %ax
movw %ax, 0x5(%rdx,%rsi)
xorl %r15d, %r15d
movl %edi, %ecx
testl %r15d, %r15d
je 0x2aa818
movq 0x30(%rsp), %rax
movl %r15d, (%rax)
jmp 0x2aa613
movzwl 0x2c(%rsp), %eax
subl %eax, 0x14(%rbx)
movq %rcx, 0x20(%rsp)
movslq %ecx, %r15
addq %rdx, %r15
testl %r12d, %r12d
je 0x2aa84c
leaq 0x4(%r15), %rdi
leaq 0x4(%r14), %rsi
addl $-0x4, %r13d
movslq %r13d, %rdx
callq 0x17660
bswapl %r12d
movl %r12d, (%r15)
jmp 0x2aa85a
movslq %r13d, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x17660
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 0x17cd0
movq 0x20(%rsp), %rax
rolw $0x8, %ax
movw %ax, -0x2(%r15)
incw 0x18(%rbx)
movzbl 0x9(%rbx), %eax
movq 0x8(%rsp), %rcx
incb 0x4(%rcx,%rax)
jne 0x2aa8a8
movzbl 0x9(%rbx), %eax
incb 0x3(%rcx,%rax)
movq 0x48(%rbx), %rax
cmpb $0x0, 0x21(%rax)
movq 0x30(%rsp), %rcx
je 0x2aa613
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 0x2996f1