// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movzbl 0xc(%rax), %eax
cmpl $0x0, %eax
jne 0x404035
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movq -0x8(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jle 0x4040a5
cmpq $0x0, -0x28(%rbp)
je 0x404055
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x19610
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x404067
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x3dd200
movq -0x8(%rbp), %rcx
movb 0xc(%rcx), %al
movb %al, %dl
addb $0x1, %dl
movb %dl, 0xc(%rcx)
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, 0x28(%rax,%rcx,8)
movl -0xc(%rbp), %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movw %dx, 0x1c(%rax,%rcx,2)
jmp 0x40422d
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x3c6610
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x4040c9
movl -0x4c(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x40422d
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x30(%rbp), %rdx
callq 0x404ac0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x4040fc
movl -0x4c(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x40422d
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movzwl %ax, %edx
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x14(%rax)
cmpl $0x0, -0x2c(%rbp)
je 0x404151
movq -0x40(%rbp), %rdi
movl -0x30(%rbp), %eax
addl $0x4, %eax
cltq
addq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
movl -0x1c(%rbp), %eax
subl $0x4, %eax
movslq %eax, %rdx
callq 0x19610
movq -0x40(%rbp), %rdi
movslq -0x30(%rbp), %rax
addq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x3dd200
jmp 0x404169
movq -0x40(%rbp), %rdi
movslq -0x30(%rbp), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x19610
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movl -0xc(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
addq $0x2, %rdi
movq -0x48(%rbp), %rsi
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %eax
subl -0xc(%rbp), %eax
shll %eax
movslq %eax, %rdx
callq 0x19bf0
movl -0x30(%rbp), %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, (%rax)
movl -0x30(%rbp), %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x8(%rbp), %rax
movw 0x18(%rax), %cx
addw $0x1, %cx
movw %cx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rax
movzbl 0x9(%rax), %eax
addl $0x4, %eax
movslq %eax, %rdx
movb (%rcx,%rdx), %al
addb $0x1, %al
movb %al, (%rcx,%rdx)
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x404208
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
movzbl 0x9(%rcx), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
addb $0x1, %dl
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
cmpb $0x0, 0x21(%rax)
je 0x40422b
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x3eb0d0
jmp 0x40422d
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)