// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: btreeParseCellPtr
static void btreeParseCellPtr(
  MemPage *pPage,         /* Page containing the cell */
  u8 *pCell,              /* Pointer to the cell text. */
  CellInfo *pInfo         /* Fill in this structure */
){
  u16 n;                  /* Number bytes in cell content header */
  u32 nPayload;           /* Number of bytes of cell payload */

  assert( sqlite3_mutex_held(pPage->pBt->mutex) );

  pInfo->pCell = pCell;
  assert( pPage->leaf==0 || pPage->leaf==1 );
  n = pPage->childPtrSize;
  assert( n==4-4*pPage->leaf );
  if( pPage->intKey ){
    if( pPage->hasData ){
      assert( n==0 );
      n = getVarint32(pCell, nPayload);
    }else{
      nPayload = 0;
    }
    n += getVarint(&pCell[n], (u64*)&pInfo->nKey);
    pInfo->nData = nPayload;
  }else{
    pInfo->nData = 0;
    n += getVarint32(&pCell[n], nPayload);
    pInfo->nKey = nPayload;
  }
  pInfo->nPayload = nPayload;
  pInfo->nHeader = n;
  testcase( nPayload==pPage->maxLocal );
  testcase( nPayload==pPage->maxLocal+1 );
  if( likely(nPayload<=pPage->maxLocal) ){
    /* This is the (easy) common case where the entire payload fits
    ** on the local page.  No overflow is required.
    */
    if( (pInfo->nSize = (u16)(n+nPayload))<4 ) pInfo->nSize = 4;
    pInfo->nLocal = (u16)nPayload;
    pInfo->iOverflow = 0;
  }else{
    /* If the payload will not fit completely on the local page, we have
    ** to decide how much to store locally and how much to spill onto
    ** overflow pages.  The strategy is to minimize the amount of unused
    ** space on overflow pages while keeping the amount of local storage
    ** in between minLocal and maxLocal.
    **
    ** Warning:  changing the way overflow payload is distributed in any
    ** way will result in an incompatible file format.
    */
    int minLocal;  /* Minimum amount of payload held locally */
    int maxLocal;  /* Maximum amount of payload held locally */
    int surplus;   /* Overflow payload available for local storage */

    minLocal = pPage->minLocal;
    maxLocal = pPage->maxLocal;
    surplus = minLocal + (nPayload - minLocal)%(pPage->pBt->usableSize - 4);
    testcase( surplus==maxLocal );
    testcase( surplus==maxLocal+1 );
    if( surplus <= maxLocal ){
      pInfo->nLocal = (u16)surplus;
    }else{
      pInfo->nLocal = (u16)minLocal;
    }
    pInfo->iOverflow = (u16)(pInfo->nLocal + n);
    pInfo->nSize = pInfo->iOverflow + 4;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, 0x8(%rdx)
movzbl 0x6(%rdi), %eax
cmpb $0x0, 0x2(%rdi)
je 0x215c3
cmpb $0x0, 0x4(%r14)
je 0x215e0
movsbl (%r15), %eax
testl %eax, %eax
js 0x215e9
movl %eax, -0x24(%rbp)
movw $0x1, %ax
jmp 0x215f8
movl $0x0, 0x10(%rbx)
movzwl %ax, %r12d
movsbl (%r15,%r12), %eax
testl %eax, %eax
js 0x21618
movl %eax, -0x24(%rbp)
movw $0x1, %ax
jmp 0x2162a
movl $0x0, -0x24(%rbp)
jmp 0x215f8
leaq -0x24(%rbp), %rsi
movq %r15, %rdi
callq 0x216ad
movzbl %al, %eax
movzwl %ax, %r12d
addq %r12, %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2171c
movzbl %al, %ecx
addl %r12d, %ecx
movl -0x24(%rbp), %eax
movl %eax, 0x10(%rbx)
jmp 0x21636
addq %r12, %r15
leaq -0x24(%rbp), %rsi
movq %r15, %rdi
callq 0x216ad
movzbl %al, %eax
movzwl %ax, %ecx
addl %r12d, %ecx
movl -0x24(%rbp), %eax
movq %rax, (%rbx)
movl -0x24(%rbp), %eax
movl %eax, 0x14(%rbx)
movw %cx, 0x18(%rbx)
movzwl 0x8(%r14), %esi
cmpl %esi, %eax
jbe 0x21681
movzwl 0xa(%r14), %edi
subl %edi, %eax
movq 0x48(%r14), %rdx
movl 0x34(%rdx), %r8d
addl $-0x4, %r8d
xorl %edx, %edx
divl %r8d
addl %edi, %edx
cmpl %esi, %edx
cmovgl %edi, %edx
movw %dx, 0x1a(%rbx)
movzwl %cx, %eax
leal (%rdx,%rax), %ecx
movw %cx, 0x1c(%rbx)
addl %edx, %eax
addl $0x4, %eax
movw %ax, 0x1e(%rbx)
jmp 0x216a0
movzwl %cx, %ecx
addl %eax, %ecx
cmpw $0x5, %cx
movl $0x4, %edx
cmovael %ecx, %edx
movw %dx, 0x1e(%rbx)
movw %ax, 0x1a(%rbx)
movw $0x0, 0x1c(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq