// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
xorl %r13d, %r13d
testl %r9d, %r9d
setne %al
movq 0x10(%rbp), %r15
cmpl $0x0, (%r15)
jne 0x30d6e
movl %r9d, %r12d
movq %r8, %r14
movq %rdx, %r8
movq %rdi, %rbx
movb %al, %r13b
shll $0x2, %r13d
cmpb $0x0, 0x1(%rdi)
jne 0x30d27
leal 0x2(%rcx), %edx
movzwl 0xe(%rbx), %eax
cmpl %eax, %edx
jle 0x30d7d
testq %r14, %r14
je 0x30d4c
movl %r13d, %eax
leaq (%r14,%rax), %rdi
addq %rax, %r8
subl %r13d, %ecx
movslq %ecx, %rdx
movl %esi, %r15d
movq %r8, %rsi
callq 0x82f0
movl %r15d, %esi
jmp 0x30d4f
movq %r8, %r14
testl %r12d, %r12d
je 0x30d5a
bswapl %r12d
movl %r12d, (%r14)
movzbl 0x1(%rbx), %eax
leal 0x1(%rax), %ecx
movb %cl, 0x1(%rbx)
movq %r14, 0x20(%rbx,%rax,8)
movw %si, 0x14(%rbx,%rax,2)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, -0x80(%rbp)
movq %rcx, -0x68(%rbp)
movl %esi, -0x30(%rbp)
movq %r8, -0x40(%rbp)
movq 0x68(%rbx), %rdi
callq 0xdebf
testl %eax, %eax
jne 0x3102e
movq 0x50(%rbx), %r8
movzwl 0xc(%rbx), %ecx
movzwl 0x10(%rbx), %eax
movq %rax, -0x78(%rbp)
movq %rcx, -0x98(%rbp)
leal (%rcx,%rax,2), %r14d
movzbl 0x5(%rbx), %edx
movzbl 0x5(%r8,%rdx), %eax
shll $0x8, %eax
movzbl 0x6(%r8,%rdx), %ecx
addl %ecx, %eax
decl %eax
movzwl %ax, %ecx
incl %ecx
cmpl %ecx, %r14d
movq %r8, -0x48(%rbp)
jbe 0x30e18
leaq 0x48a31(%rip), %rsi     # 0x79814
leaq 0x4874f(%rip), %rcx     # 0x79539
movq $0x0, -0x38(%rbp)
movl $0xb, %edi
movl $0xc665, %edx           # imm = 0xC665
xorl %eax, %eax
callq 0xb8cc
movl $0xb, %eax
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %rcx
movl -0x30(%rbp), %esi
jmp 0x3102a
movq %rdx, -0x58(%rbp)
movb 0x7(%r8,%rdx), %al
cmpb $0x3c, %al
jb 0x30e4d
movq %rbx, %rdi
callq 0x32969
testl %eax, %eax
je 0x30f91
movq $0x0, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movl -0x30(%rbp), %esi
movq -0x48(%rbp), %r8
jmp 0x3102a
movq %rax, -0x90(%rbp)
leal 0x2(%r14), %eax
movq $0x0, -0x38(%rbp)
movl %ecx, -0x5c(%rbp)
cmpl %ecx, %eax
movl -0x30(%rbp), %esi
jbe 0x30e73
movq -0x40(%rbp), %rcx
jmp 0x30fc3
movq %r14, -0x70(%rbp)
movq 0x48(%rbx), %rax
movl 0x34(%rax), %ecx
movq -0x58(%rbp), %rax
leal 0x1(%rax), %r14d
movq %rcx, -0x88(%rbp)
leal -0x4(%rcx), %eax
movl %eax, -0x7c(%rbp)
movq $0x0, -0x38(%rbp)
movl %r14d, %eax
movzwl (%r8,%rax), %ecx
rolw $0x8, %cx
movzwl %cx, %r14d
testw %cx, %cx
je 0x30f7b
cmpl -0x7c(%rbp), %r14d
jg 0x30f00
leal 0x4(%rax), %ecx
cmpl %ecx, %r14d
jl 0x30f00
movzwl 0x2(%r8,%r14), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
movb $0x1, %dil
movl %edx, %ecx
subl -0x68(%rbp), %ecx
jl 0x30f72
cmpl $0x3, %ecx
jg 0x30f31
movzwl (%r8,%r14), %edx
movw %dx, (%r8,%rax)
movq -0x90(%rbp), %rax
addl %ecx, %eax
movq -0x58(%rbp), %rdx
movb %al, 0x7(%r8,%rdx)
jmp 0x30f62
movl $0xb, -0x4c(%rbp)
movl $0xb, %edi
leaq 0x48901(%rip), %rsi     # 0x79814
movl $0xc678, %edx           # imm = 0xC678
leaq 0x4861a(%rip), %rcx     # 0x79539
xorl %eax, %eax
callq 0xb8cc
xorl %edi, %edi
movq -0x48(%rbp), %r8
movl -0x30(%rbp), %esi
jmp 0x30f72
addl %r14d, %edx
cmpl -0x88(%rbp), %edx
jle 0x30f56
movl $0xb, -0x4c(%rbp)
movl $0xb, %edi
leaq 0x488c5(%rip), %rsi     # 0x79814
movl $0xc685, %edx           # imm = 0xC685
jmp 0x30f18
movl %ecx, %eax
rolw $0x8, %ax
movw %ax, 0x2(%r8,%r14)
addl %r14d, %ecx
xorl %edi, %edi
movq %rcx, -0x38(%rbp)
movl $0x0, -0x4c(%rbp)
testb %dil, %dil
jne 0x30e9b
testl %r14d, %r14d
movq -0x40(%rbp), %rcx
movq -0x70(%rbp), %r14
movl -0x4c(%rbp), %eax
jne 0x3102a
jmp 0x30fc3
movq -0x48(%rbp), %r8
movq -0x58(%rbp), %rcx
movzbl 0x5(%r8,%rcx), %eax
shll $0x8, %eax
movzbl 0x6(%r8,%rcx), %ecx
addl %ecx, %eax
decl %eax
movzwl %ax, %eax
incl %eax
movl %eax, -0x5c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movl -0x30(%rbp), %esi
movq -0x68(%rbp), %rdx
leal (%rdx,%r14), %eax
addl $0x2, %eax
movl -0x5c(%rbp), %edi
cmpl %edi, %eax
jle 0x31010
movq %rbx, %rdi
callq 0x32969
movq -0x48(%rbp), %r8
movl -0x30(%rbp), %esi
movq -0x40(%rbp), %rcx
testl %eax, %eax
jne 0x3102a
movq -0x58(%rbp), %rcx
movzbl 0x5(%r8,%rcx), %eax
shll $0x8, %eax
movzbl 0x6(%r8,%rcx), %ecx
addl %ecx, %eax
decl %eax
movq -0x40(%rbp), %rcx
movzwl %ax, %edi
incl %edi
movq -0x68(%rbp), %rdx
subl %edx, %edi
movl %edi, %eax
rolw $0x8, %ax
movq -0x58(%rbp), %rdx
movw %ax, 0x5(%r8,%rdx)
movl %edi, %eax
movq %rax, -0x38(%rbp)
xorl %eax, %eax
testl %eax, %eax
je 0x31036
movl %eax, (%r15)
jmp 0x30d6e
movq %r14, -0x70(%rbp)
movslq %esi, %rax
leaq (%rax,%rax), %rdx
movq %rdx, -0x30(%rbp)
incw 0x10(%rbx)
movq -0x78(%rbp), %rdx
addl %edx, %edx
movq %rdx, -0x78(%rbp)
movl -0x80(%rbp), %edx
subw %dx, 0xe(%rbx)
movq -0x98(%rbp), %rdx
leaq (%rdx,%rax,2), %r14
movq -0x38(%rbp), %rax
addl %r13d, %eax
movslq %eax, %rdi
addq %r8, %rdi
movl %r13d, %esi
addq %rcx, %rsi
movq -0x68(%rbp), %rax
subl %r13d, %eax
movslq %eax, %rdx
callq 0x82f0
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
testl %r12d, %r12d
je 0x3109e
movslq %esi, %rax
bswapl %r12d
movl %r12d, (%rdx,%rax)
addq %rdx, %r14
movq -0x30(%rbp), %rax
cmpl %eax, -0x78(%rbp)
jle 0x310c3
movl -0x70(%rbp), %eax
addq %rdx, %rax
movzwl -0x2(%rax), %ecx
movw %cx, (%rax)
leaq -0x2(%rax), %rcx
movq %rcx, %rax
cmpq %r14, %rcx
ja 0x310b0
rolw $0x8, %si
movw %si, (%r14)
movb 0x11(%rbx), %al
movzbl 0x5(%rbx), %ecx
movb %al, 0x3(%rdx,%rcx)
movb 0x10(%rbx), %al
movzbl 0x5(%rbx), %ecx
movb %al, 0x4(%rdx,%rcx)
movq 0x48(%rbx), %rax
cmpb $0x0, 0x21(%rax)
movq -0x40(%rbp), %rsi
je 0x30d6e
movq %rbx, %rdi
movq %r15, %rdx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22f9e