// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movzbl 0x6(%rax), %eax
movw %ax, -0x1a(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x2c125
movq -0x8(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x2c0f1
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x80, %eax
jge 0x2c0d2
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x20(%rbp)
movl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2c0e5
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2c290
movzbl %al, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movzbl %al, %eax
movw %ax, -0x1a(%rbp)
jmp 0x2c0f8
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movzwl -0x1a(%rbp), %eax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x2c3b0
movzbl %al, %ecx
movzwl -0x1a(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x1a(%rbp)
movl -0x20(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x2c192
movq -0x18(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x80, %eax
jge 0x2c15c
movq -0x10(%rbp), %rax
movzwl -0x1a(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x20(%rbp)
movl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2c176
movq -0x10(%rbp), %rdi
movzwl -0x1a(%rbp), %eax
addq %rax, %rdi
leaq -0x20(%rbp), %rsi
callq 0x2c290
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movzbl %al, %ecx
movzwl -0x1a(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x1a(%rbp)
movl -0x20(%rbp), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x20(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x14(%rax)
movw -0x1a(%rbp), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x18(%rax)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
cmpl %ecx, %eax
ja 0x2c1f5
movzwl -0x1a(%rbp), %eax
addl -0x20(%rbp), %eax
movq -0x18(%rbp), %rcx
movw %ax, 0x1e(%rcx)
movzwl %ax, %eax
cmpl $0x4, %eax
jge 0x2c1d8
movq -0x18(%rbp), %rax
movw $0x4, 0x1e(%rax)
movl -0x20(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x1a(%rax)
movq -0x18(%rbp), %rax
movw $0x0, 0x1c(%rax)
jmp 0x2c286
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x20(%rbp), %eax
subl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl 0x34(%rcx), %ecx
subl $0x4, %ecx
xorl %edx, %edx
divl %ecx
movl -0x38(%rbp), %eax
addl %edx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0x2c249
movl -0x2c(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x1a(%rax)
jmp 0x2c257
movl -0x24(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x1a(%rax)
movq -0x18(%rbp), %rax
movzwl 0x1a(%rax), %eax
movzwl -0x1a(%rbp), %ecx
addl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x1c(%rax)
movq -0x18(%rbp), %rax
movzwl 0x1c(%rax), %eax
addl $0x4, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x1e(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)