// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x2c070
movzwl -0x24(%rbp), %eax
cmpl $0x0, %eax
jne 0x41df2
movl $0x0, -0x4(%rbp)
jmp 0x41f70
movq -0x18(%rbp), %rax
movzwl -0x24(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
addq $0x3, %rax
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rcx
movq -0x10(%rbp), %rdx
movzwl 0x12(%rdx), %edx
movslq %edx, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x41e31
movl $0xd6e7, %edi           # imm = 0xD6E7
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x41f70
movq -0x18(%rbp), %rdi
movzwl -0x24(%rbp), %eax
addq %rax, %rdi
callq 0x20a50
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movl 0x34(%rax), %eax
subl $0x4, %eax
movl %eax, -0x50(%rbp)
movl -0x2c(%rbp), %eax
movzwl -0x26(%rbp), %ecx
subl %ecx, %eax
addl -0x50(%rbp), %eax
subl $0x1, %eax
xorl %edx, %edx
divl -0x50(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x4c(%rbp)
cmpl $0x0, %eax
je 0x41f69
movl $0x0, -0x54(%rbp)
movq $0x0, -0x60(%rbp)
cmpl $0x2, -0x44(%rbp)
jb 0x41ea9
movl -0x44(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2ab10
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
jbe 0x41ebb
movl $0xd6f5, %edi           # imm = 0xD6F5
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x41f70
cmpl $0x0, -0x4c(%rbp)
je 0x41eeb
movq -0x20(%rbp), %rdi
movl -0x44(%rbp), %esi
leaq -0x60(%rbp), %rdx
leaq -0x54(%rbp), %rcx
callq 0x2cc70
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x41ee9
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41f70
jmp 0x41eeb
cmpq $0x0, -0x60(%rbp)
jne 0x41f08
movq -0x20(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x425d0
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x41f29
movq -0x60(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x24a40
cmpl $0x1, %eax
je 0x41f29
movl $0xd709, %edi           # imm = 0xD709
callq 0x24410
movl %eax, -0x48(%rbp)
jmp 0x41f3c
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0x42630
movl %eax, -0x48(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x41f50
movq -0x60(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0xec30
cmpl $0x0, -0x48(%rbp)
je 0x41f5e
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41f70
movl -0x54(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x41e68
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)