// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r14
movq %rsi, 0x8(%rdx)
movzbl 0x6(%rdi), %eax
cmpb $0x0, 0x2(%rdi)
je 0x1e472
cmpb $0x0, 0x4(%r14)
je 0x1e48a
movsbl (%r12), %r15d
testl %r15d, %r15d
js 0x1e48f
movw $0x1, %ax
jmp 0x1e4a4
andl $0x0, 0x10(%rbx)
movzwl %ax, %r13d
movsbl (%r12,%r13), %r15d
testl %r15d, %r15d
js 0x1e4c2
movw $0x1, %ax
jmp 0x1e4da
xorl %r15d, %r15d
jmp 0x1e4a4
leaq -0x2c(%rbp), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x1e561
movzbl %al, %eax
movl (%r15), %r15d
movzwl %ax, %r13d
addq %r13, %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1e5d0
movzbl %al, %ecx
addl %r13d, %ecx
movl %r15d, 0x10(%rbx)
jmp 0x1e4e6
addq %r13, %r12
leaq -0x2c(%rbp), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x1e561
movzbl %al, %eax
movl (%r15), %r15d
movzwl %ax, %ecx
addl %r13d, %ecx
movl %r15d, %eax
movq %rax, (%rbx)
movl %r15d, 0x14(%rbx)
movw %cx, 0x18(%rbx)
movzwl 0x8(%r14), %esi
cmpl %esi, %r15d
jbe 0x1e534
movzwl 0xa(%r14), %edi
subl %edi, %r15d
movq 0x48(%r14), %rax
movl 0x34(%rax), %r8d
addl $-0x4, %r8d
movl %r15d, %eax
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 0x1e552
movzwl %cx, %eax
addl %r15d, %eax
cmpw $0x5, %ax
pushq $0x4
popq %rcx
cmovael %eax, %ecx
movw %cx, 0x1e(%rbx)
movw %r15w, 0x1a(%rbx)
andw $0x0, 0x1c(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq