// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: clearCell
static int clearCell(MemPage *pPage, unsigned char *pCell){
  BtShared *pBt = pPage->pBt;
  CellInfo info;
  Pgno ovflPgno;
  int rc;
  int nOvfl;
  u32 ovflPageSize;

  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  btreeParseCellPtr(pPage, pCell, &info);
  if( info.iOverflow==0 ){
    return SQLITE_OK;  /* No overflow pages. Return without doing anything */
  }
  if( pCell+info.iOverflow+3 > pPage->aData+pPage->maskPage ){
    return SQLITE_CORRUPT_BKPT;  /* Cell extends past end of page */
  }
  ovflPgno = get4byte(&pCell[info.iOverflow]);
  assert( pBt->usableSize > 4 );
  ovflPageSize = pBt->usableSize - 4;
  nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
  assert( ovflPgno==0 || nOvfl>0 );
  while( nOvfl-- ){
    Pgno iNext = 0;
    MemPage *pOvfl = 0;
    if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
      /* 0 is not a legal page number and page 1 cannot be an 
      ** overflow page. Therefore if ovflPgno<2 or past the end of the 
      ** file the database must be corrupt. */
      return SQLITE_CORRUPT_BKPT;
    }
    if( nOvfl ){
      rc = getOverflowPage(pBt, ovflPgno, &pOvfl, &iNext);
      if( rc ) return rc;
    }

    if( ( pOvfl || ((pOvfl = btreePageLookup(pBt, ovflPgno))!=0) )
     && sqlite3PagerPageRefcount(pOvfl->pDbPage)!=1
    ){
      /* There is no reason any cursor should have an outstanding reference 
      ** to an overflow page belonging to a cell that is being deleted/updated.
      ** So if there exists more than one reference to this page, then it 
      ** must not really be an overflow page and the database must be corrupt. 
      ** It is helpful to detect this before calling freePage2(), as 
      ** freePage2() may zero the page contents if secure-delete mode is
      ** enabled. If this 'overflow' page happens to be a page that the
      ** caller is iterating through or using in some other way, this
      ** can be problematic.
      */
      rc = SQLITE_CORRUPT_BKPT;
    }else{
      rc = freePage2(pBt, pOvfl, ovflPgno);
    }

    if( pOvfl ){
      sqlite3PagerUnref(pOvfl->pDbPage);
    }
    if( rc ) return rc;
    ovflPgno = iNext;
  }
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq 0x48(%rdi), %rax
movq %rax, -0x38(%rbp)
leaq -0x60(%rbp), %r12
movq %r12, %rdx
callq 0x21585
movzwl 0x1c(%r12), %eax
testq %rax, %rax
je 0x309b0
leaq (%r14,%rax), %rcx
addq $0x3, %rcx
movzwl 0x12(%r15), %edx
addq 0x50(%r15), %rdx
cmpq %rdx, %rcx
jbe 0x3087c
leaq 0x48fbb(%rip), %rsi     # 0x79814
leaq 0x48cd9(%rip), %rcx     # 0x79539
movl $0xb, %r12d
movl $0xb, %edi
movl $0xd6e7, %edx           # imm = 0xD6E7
xorl %eax, %eax
callq 0xb8cc
jmp 0x309b3
addq %rax, %r14
movl (%r14), %r14d
bswapl %r14d
movq -0x38(%rbp), %rax
movl 0x34(%rax), %ecx
addl $-0x4, %ecx
movzwl -0x46(%rbp), %eax
movl -0x4c(%rbp), %edx
addl %ecx, %edx
notl %eax
addl %edx, %eax
xorl %edx, %edx
divl %ecx
movl %eax, %r15d
subl $0x1, %r15d
jb 0x309b0
movl $0x0, -0x3c(%rbp)
movq $0x0, -0x30(%rbp)
cmpl $0x2, %r14d
jb 0x308cc
movq -0x38(%rbp), %rax
cmpl 0x3c(%rax), %r14d
jbe 0x308f8
xorl %ebx, %ebx
movl $0xb, %r12d
movl $0xb, %edi
leaq 0x48f34(%rip), %rsi     # 0x79814
movl $0xd6f5, %edx           # imm = 0xD6F5
leaq 0x48c4d(%rip), %rcx     # 0x79539
xorl %eax, %eax
callq 0xb8cc
jmp 0x309a3
testl %r15d, %r15d
je 0x3091a
movq -0x38(%rbp), %rdi
movl %r14d, %esi
leaq -0x30(%rbp), %rdx
leaq -0x3c(%rbp), %rcx
callq 0x21be4
testl %eax, %eax
je 0x3091a
movl %eax, %r12d
jmp 0x30996
cmpq $0x0, -0x30(%rbp)
jne 0x30936
movq -0x38(%rbp), %rdi
movl %r14d, %esi
callq 0x325cd
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x30945
movq -0x30(%rbp), %rax
movq 0x68(%rax), %rax
cmpw $0x1, 0x2e(%rax)
jne 0x3095a
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdi
movl %r14d, %edx
callq 0x32647
movl %eax, %r12d
jmp 0x3097f
movl $0xb, %r12d
movl $0xb, %edi
leaq 0x48ea8(%rip), %rsi     # 0x79814
movl $0xd709, %edx           # imm = 0xD709
leaq 0x48bc1(%rip), %rcx     # 0x79539
xorl %eax, %eax
callq 0xb8cc
movq -0x30(%rbp), %rax
testq %rax, %rax
je 0x30991
movq 0x68(%rax), %rdi
callq 0xdcd4
testl %r12d, %r12d
je 0x3099a
xorl %ebx, %ebx
jmp 0x309a3
movb $0x1, %bl
movl -0x3c(%rbp), %r14d
movl %r13d, %r12d
movl %r12d, %r13d
testb %bl, %bl
jne 0x308a3
jmp 0x309b3
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq