// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/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 */
  int end;          /* First byte past the last cell pointer in data[] */
  int ins;          /* Index in data[] where new cell pointer is inserted */
  int cellOffset;   /* Address of first cell pointer in data[] */
  u8 *data;         /* The content of the whole page */
  u8 *ptr;          /* Used for moving information around in data[] */
  u8 *endPtr;       /* End of the loop */

  int nSkip = (iChild ? 4 : 0);

  if( *pRC ) return;

  assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
  assert( pPage->nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=10921 );
  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==cellSizePtr(pPage, pCell) || (sz==8 && iChild>0) );
  if( pPage->nOverflow || sz+2>pPage->nFree ){
    if( pTemp ){
      memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip);
      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;
  }else{
    int rc = sqlite3PagerWrite(pPage->pDbPage);
    if( rc!=SQLITE_OK ){
      *pRC = rc;
      return;
    }
    assert( sqlite3PagerIswriteable(pPage->pDbPage) );
    data = pPage->aData;
    cellOffset = pPage->cellOffset;
    end = cellOffset + 2*pPage->nCell;
    ins = cellOffset + 2*i;
    rc = allocateSpace(pPage, sz, &idx);
    if( rc ){ *pRC = rc; return; }
    /* The allocateSpace() routine guarantees the following two properties
    ** if it returns success */
    assert( idx >= end+2 );
    assert( idx+sz <= (int)pPage->pBt->usableSize );
    pPage->nCell++;
    pPage->nFree -= (u16)(2 + sz);
    memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
    if( iChild ){
      put4byte(&data[idx], iChild);
    }
    ptr = &data[end];
    endPtr = &data[ins];
    assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 );  /* ptr is always 2-byte aligned */
    while( ptr>endPtr ){
      *(u16*)ptr = *(u16*)&ptr[-2];
      ptr -= 2;
    }
    put2byte(&data[ins], idx);
    put2byte(&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
subq $0x60, %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)
movl -0x2c(%rbp), %edx
xorl %eax, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x5c(%rbp)
movq 0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x4215a
jmp 0x423b5
movq -0x8(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x4217d
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movq -0x8(%rbp), %rcx
movzwl 0xe(%rcx), %ecx
cmpl %ecx, %eax
jle 0x42200
cmpq $0x0, -0x28(%rbp)
je 0x421b0
movq -0x28(%rbp), %rdi
movslq -0x5c(%rbp), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x5c(%rbp), %rax
addq %rax, %rsi
movl -0x1c(%rbp), %eax
subl -0x5c(%rbp), %eax
movslq %eax, %rdx
callq 0x82f0
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x421c2
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x22060
movq -0x8(%rbp), %rcx
movb 0x1(%rcx), %al
movb %al, %dl
addb $0x1, %dl
movb %dl, 0x1(%rcx)
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq %rdx, 0x20(%rax,%rcx,8)
movl -0xc(%rbp), %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movw %dx, 0x14(%rax,%rcx,2)
jmp 0x423b5
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0xef80
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x42224
movl -0x60(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x423b5
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movzwl 0xc(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x40(%rbp), %eax
movl -0xc(%rbp), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x30(%rbp), %rdx
callq 0x42ea0
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x42281
movl -0x60(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
jmp 0x423b5
movq -0x8(%rbp), %rax
movw 0x10(%rax), %cx
addw $0x1, %cx
movw %cx, 0x10(%rax)
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movzwl %ax, %edx
movq -0x8(%rbp), %rax
movzwl 0xe(%rax), %ecx
subl %edx, %ecx
movw %cx, 0xe(%rax)
movq -0x48(%rbp), %rdi
movl -0x30(%rbp), %eax
addl -0x5c(%rbp), %eax
cltq
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x5c(%rbp), %rax
addq %rax, %rsi
movl -0x1c(%rbp), %eax
subl -0x5c(%rbp), %eax
movslq %eax, %rdx
callq 0x82f0
cmpl $0x0, -0x2c(%rbp)
je 0x422e9
movq -0x48(%rbp), %rdi
movslq -0x30(%rbp), %rax
addq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x22060
movq -0x48(%rbp), %rax
movslq -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jbe 0x4232e
movq -0x50(%rbp), %rax
movw -0x2(%rax), %cx
movq -0x50(%rbp), %rax
movw %cx, (%rax)
movq -0x50(%rbp), %rax
addq $-0x2, %rax
movq %rax, -0x50(%rbp)
jmp 0x42307
movl -0x30(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x30(%rbp), %eax
movb %al, %dl
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x8(%rbp), %rax
movzwl 0x10(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x48(%rbp), %rax
movq -0x8(%rbp), %rcx
movzbl 0x5(%rcx), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movw 0x10(%rax), %ax
movb %al, %dl
movq -0x48(%rbp), %rax
movq -0x8(%rbp), %rcx
movzbl 0x5(%rcx), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
cmpb $0x0, 0x21(%rax)
je 0x423b3
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq 0x10(%rbp), %rdx
callq 0x2e2c0
jmp 0x423b5
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)