// File: /workspace/github_c_makefile_star2_O3/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, %r15
movq %rdi, %r14
movq 0x48(%rdi), %rbx
leaq -0x58(%rbp), %r12
movq %r12, %rdx
callq 0x2121e
movzwl 0x1c(%r12), %ecx
xorl %r12d, %r12d
testq %rcx, %rcx
je 0x31142
leaq (%r15,%rcx), %rax
addq $0x3, %rax
movzwl 0x12(%r14), %edx
addq 0x50(%r14), %rdx
cmpq %rdx, %rax
jbe 0x3112b
leaq 0x48709(%rip), %rsi     # 0x79814
leaq 0x48427(%rip), %rcx     # 0x79539
movl $0xb, %r12d
movl $0xb, %edi
movl $0xd6e7, %edx           # imm = 0xD6E7
xorl %eax, %eax
callq 0xb9c7
jmp 0x31142
movl 0x34(%rbx), %esi
addl $-0x4, %esi
movzwl -0x3e(%rbp), %eax
movl -0x44(%rbp), %edx
addl %esi, %edx
notl %eax
addl %edx, %eax
cmpl %eax, %esi
jbe 0x31154
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %rcx, %r15
xorl %edx, %edx
divl %esi
movl %eax, %r14d
movl (%r15), %r13d
bswapl %r13d
leaq -0x2c(%rbp), %r15
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
cmpl $0x2, %r13d
jb 0x3123c
cmpl 0x3c(%rbx), %r13d
ja 0x3123c
decl %r14d
je 0x311b3
movq %rbx, %rdi
movl %r13d, %esi
leaq -0x38(%rbp), %rdx
movq %r15, %rcx
callq 0x218b8
testl %eax, %eax
jne 0x3125f
movq -0x38(%rbp), %rsi
testq %rsi, %rsi
jne 0x311ca
movq %rbx, %rdi
movl %r13d, %esi
callq 0x32d16
movq %rax, %rsi
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x311fc
movq 0x68(%rsi), %rax
cmpw $0x1, 0x2e(%rax)
je 0x311fe
movl $0xb, %r12d
movl $0xb, %edi
leaq 0x4862d(%rip), %rsi     # 0x79814
movl $0xd709, %edx           # imm = 0xD709
leaq 0x48346(%rip), %rcx     # 0x79539
xorl %eax, %eax
callq 0xb9c7
jmp 0x3120c
xorl %esi, %esi
movq %rbx, %rdi
movl %r13d, %edx
callq 0x32d90
movl %eax, %r12d
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x3121e
movq 0x68(%rax), %rdi
callq 0xddd3
testl %r12d, %r12d
jne 0x31142
movl -0x2c(%rbp), %r13d
testl %r14d, %r14d
jne 0x31168
xorl %r12d, %r12d
jmp 0x31142
leaq 0x485d1(%rip), %rsi     # 0x79814
leaq 0x482ef(%rip), %rcx     # 0x79539
movl $0xb, %r12d
movl $0xb, %edi
movl $0xd6f5, %edx           # imm = 0xD6F5
jmp 0x31122
movl %eax, %r12d
jmp 0x31142