// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3DeleteFrom
SQLITE_PRIVATE void sqlite3DeleteFrom(
  Parse *pParse,         /* The parser context */
  SrcList *pTabList,     /* The table from which we should delete things */
  Expr *pWhere           /* The WHERE clause.  May be null */
){
  Vdbe *v;               /* The virtual database engine */
  Table *pTab;           /* The table from which records will be deleted */
  const char *zDb;       /* Name of database holding pTab */
  int end, addr = 0;     /* A couple addresses of generated code */
  int i;                 /* Loop counter */
  WhereInfo *pWInfo;     /* Information about the WHERE clause */
  Index *pIdx;           /* For looping over indices of the table */
  int iCur;              /* VDBE Cursor number for pTab */
  sqlite3 *db;           /* Main database structure */
  AuthContext sContext;  /* Authorization context */
  NameContext sNC;       /* Name context to resolve expressions in */
  int iDb;               /* Database number */
  int memCnt = -1;       /* Memory cell used for change counting */
  int rcauth;            /* Value returned by authorization callback */

#ifndef SQLITE_OMIT_TRIGGER
  int isView;                  /* True if attempting to delete from a view */
  Trigger *pTrigger;           /* List of table triggers, if required */
#endif

  memset(&sContext, 0, sizeof(sContext));
  db = pParse->db;
  if( pParse->nErr || db->mallocFailed ){
    goto delete_from_cleanup;
  }
  assert( pTabList->nSrc==1 );

  /* Locate the table which we want to delete.  This table has to be
  ** put in an SrcList structure because some of the subroutines we
  ** will be calling are designed to work with multiple tables and expect
  ** an SrcList* parameter instead of just a Table* parameter.
  */
  pTab = sqlite3SrcListLookup(pParse, pTabList);
  if( pTab==0 )  goto delete_from_cleanup;

  /* Figure out if we have any triggers and if the table being
  ** deleted from is a view
  */
#ifndef SQLITE_OMIT_TRIGGER
  pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
  isView = pTab->pSelect!=0;
#else
# define pTrigger 0
# define isView 0
#endif
#ifdef SQLITE_OMIT_VIEW
# undef isView
# define isView 0
#endif

  /* If pTab is really a view, make sure it has been initialized.
  */
  if( sqlite3ViewGetColumnNames(pParse, pTab) ){
    goto delete_from_cleanup;
  }

  if( sqlite3IsReadOnly(pParse, pTab, (pTrigger?1:0)) ){
    goto delete_from_cleanup;
  }
  iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  assert( iDb<db->nDb );
  zDb = db->aDb[iDb].zName;
  rcauth = sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb);
  assert( rcauth==SQLITE_OK || rcauth==SQLITE_DENY || rcauth==SQLITE_IGNORE );
  if( rcauth==SQLITE_DENY ){
    goto delete_from_cleanup;
  }
  assert(!isView || pTrigger);

  /* Assign  cursor number to the table and all its indices.
  */
  assert( pTabList->nSrc==1 );
  iCur = pTabList->a[0].iCursor = pParse->nTab++;
  for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
    pParse->nTab++;
  }

  /* Start the view context
  */
  if( isView ){
    sqlite3AuthContextPush(pParse, &sContext, pTab->zName);
  }

  /* Begin generating code.
  */
  v = sqlite3GetVdbe(pParse);
  if( v==0 ){
    goto delete_from_cleanup;
  }
  if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
  sqlite3BeginWriteOperation(pParse, 1, iDb);

  /* If we are trying to delete from a view, realize that view into
  ** a ephemeral table.
  */
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
  if( isView ){
    sqlite3MaterializeView(pParse, pTab, pWhere, iCur);
  }
#endif

  /* Resolve the column names in the WHERE clause.
  */
  memset(&sNC, 0, sizeof(sNC));
  sNC.pParse = pParse;
  sNC.pSrcList = pTabList;
  if( sqlite3ResolveExprNames(&sNC, pWhere) ){
    goto delete_from_cleanup;
  }

  /* Initialize the counter of the number of rows deleted, if
  ** we are counting rows.
  */
  if( db->flags & SQLITE_CountRows ){
    memCnt = ++pParse->nMem;
    sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
  }

#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
  /* Special case: A DELETE without a WHERE clause deletes everything.
  ** It is easier just to erase the whole table. Prior to version 3.6.5,
  ** this optimization caused the row change count (the value returned by 
  ** API function sqlite3_count_changes) to be set incorrectly.  */
  if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab) 
   && 0==sqlite3FkRequired(pParse, pTab, 0, 0)
  ){
    assert( !isView );
    sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
                      pTab->zName, P4_STATIC);
    for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
      assert( pIdx->pSchema==pTab->pSchema );
      sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
    }
  }else
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
  /* The usual case: There is a WHERE clause so we have to scan through
  ** the table and pick which records to delete.
  */
  {
    int iRowSet = ++pParse->nMem;   /* Register for rowset of rows to delete */
    int iRowid = ++pParse->nMem;    /* Used for storing rowid values. */
    int regRowid;                   /* Actual register containing rowids */

    /* Collect rowids of every row to be deleted.
    */
    sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet);
    pWInfo = sqlite3WhereBegin(
        pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0
    );
    if( pWInfo==0 ) goto delete_from_cleanup;
    regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0);
    sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid);
    if( db->flags & SQLITE_CountRows ){
      sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
    }
    sqlite3WhereEnd(pWInfo);

    /* Delete every item whose key was written to the list during the
    ** database scan.  We have to delete items after the scan is complete
    ** because deleting an item can change the scan order.  */
    end = sqlite3VdbeMakeLabel(v);

    /* Unless this is a view, open cursors for the table we are 
    ** deleting from and all its indices. If this is a view, then the
    ** only effect this statement has is to fire the INSTEAD OF 
    ** triggers.  */
    if( !isView ){
      sqlite3OpenTableAndIndices(pParse, pTab, iCur, OP_OpenWrite);
    }

    addr = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, end, iRowid);

    /* Delete the row */
#ifndef SQLITE_OMIT_VIRTUALTABLE
    if( IsVirtual(pTab) ){
      const char *pVTab = (const char *)sqlite3GetVTable(db, pTab);
      sqlite3VtabMakeWritable(pParse, pTab);
      sqlite3VdbeAddOp4(v, OP_VUpdate, 0, 1, iRowid, pVTab, P4_VTAB);
      sqlite3VdbeChangeP5(v, OE_Abort);
      sqlite3MayAbort(pParse);
    }else
#endif
    {
      int count = (pParse->nested==0);    /* True to count changes */
      sqlite3GenerateRowDelete(pParse, pTab, iCur, iRowid, count, pTrigger, OE_Default);
    }

    /* End of the delete loop */
    sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
    sqlite3VdbeResolveLabel(v, end);

    /* Close the cursors open on the table and its indexes. */
    if( !isView && !IsVirtual(pTab) ){
      for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
        sqlite3VdbeAddOp2(v, OP_Close, iCur + i, pIdx->tnum);
      }
      sqlite3VdbeAddOp1(v, OP_Close, iCur);
    }
  }

  /* Update the sqlite_sequence table by storing the content of the
  ** maximum rowid counter values recorded while inserting into
  ** autoincrement tables.
  */
  if( pParse->nested==0 && pParse->pTriggerTab==0 ){
    sqlite3AutoincrementEnd(pParse);
  }

  /* Return the number of rows that were deleted. If this routine is 
  ** generating code because of a call to sqlite3NestedParse(), do not
  ** invoke the callback function.
  */
  if( (db->flags&SQLITE_CountRows) && !pParse->nested && !pParse->pTriggerTab ){
    sqlite3VdbeAddOp2(v, OP_ResultRow, memCnt, 1);
    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted", SQLITE_STATIC);
  }

delete_from_cleanup:
  sqlite3AuthContextPop(&sContext);
  sqlite3SrcListDelete(db, pTabList);
  sqlite3ExprDelete(db, pWhere);
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x38(%rbp)
movl $0xffffffff, -0xb0(%rbp) # imm = 0xFFFFFFFF
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x8200
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x54eba
movq -0x60(%rbp), %rax
movzbl 0x50(%rax), %eax
cmpl $0x0, %eax
je 0x54ebf
jmp 0x554d2
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x66c90
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x54edc
jmp 0x554d2
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x6a, %edx
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x7c4e0
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xb8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x64180
cmpl $0x0, %eax
je 0x54f2b
jmp 0x554d2
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0xc0(%rbp), %rcx
xorl %edx, %edx
movl $0x1, %eax
cmpq $0x0, %rcx
cmovnel %eax, %edx
callq 0x7c5c0
cmpl $0x0, %eax
je 0x54f57
jmp 0x554d2
movq -0x60(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x13940
movl %eax, -0xac(%rbp)
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0xac(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x30(%rbp), %r8
movl $0x9, %esi
xorl %eax, %eax
movl %eax, %ecx
callq 0x5e720
movl %eax, -0xb4(%rbp)
cmpl $0x1, -0xb4(%rbp)
jne 0x54fbc
jmp 0x554d2
movq -0x8(%rbp), %rcx
movl 0x54(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x54(%rcx)
movq -0x10(%rbp), %rcx
movl %eax, 0x44(%rcx)
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x55003
movq -0x8(%rbp), %rax
movl 0x54(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x54(%rax)
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x54fe1
cmpl $0x0, -0xb8(%rbp)
je 0x55020
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
leaq -0x70(%rbp), %rsi
callq 0x7c6a0
movq -0x8(%rbp), %rdi
callq 0x5e000
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x55039
jmp 0x554d2
movq -0x8(%rbp), %rax
movzbl 0x1e(%rax), %eax
cmpl $0x0, %eax
jne 0x5504f
movq -0x20(%rbp), %rdi
callq 0x7c6e0
movq -0x8(%rbp), %rdi
movl -0xac(%rbp), %edx
movl $0x1, %esi
callq 0x5ec70
cmpl $0x0, -0xb8(%rbp)
je 0x55080
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x54(%rbp), %ecx
callq 0x7c710
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x8200
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x5f5b0
cmpl $0x0, %eax
je 0x550c3
jmp 0x554d2
movq -0x60(%rbp), %rax
movl 0x2c(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x550fd
movq -0x8(%rbp), %rcx
movl 0x58(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x58(%rcx)
movl %eax, -0xb0(%rbp)
movq -0x20(%rbp), %rdi
movl -0xb0(%rbp), %ecx
movl $0x15, %esi
xorl %edx, %edx
callq 0x5e0c0
cmpl $0x0, -0xb4(%rbp)
jne 0x551c3
cmpq $0x0, -0x18(%rbp)
jne 0x551c3
cmpq $0x0, -0xc0(%rbp)
jne 0x551c3
movq -0x28(%rbp), %rax
movzbl 0x46(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x551c3
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x7c850
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x551c3
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x3c(%rax), %edx
movl -0xac(%rbp), %ecx
movl -0xb0(%rbp), %r8d
movq -0x28(%rbp), %rax
movq (%rax), %r9
movl $0x6d, %esi
movl $0xfffffffe, (%rsp)     # imm = 0xFFFFFFFE
callq 0x5e1b0
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x551be
movq -0x20(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x50(%rax), %edx
movl -0xac(%rbp), %ecx
movl $0x6d, %esi
callq 0x5e0c0
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x5518e
jmp 0x55443
movq -0x8(%rbp), %rcx
movl 0x58(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x58(%rcx)
movl %eax, -0xc4(%rbp)
movq -0x8(%rbp), %rcx
movl 0x58(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x58(%rcx)
movl %eax, -0xc8(%rbp)
movq -0x20(%rbp), %rdi
movl -0xc4(%rbp), %ecx
movl $0x18, %esi
xorl %edx, %edx
callq 0x5e0c0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r8d
movl $0x8, %r9d
xorl %eax, %eax
movq %r8, %rcx
movl $0x0, (%rsp)
callq 0x6db30
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x55237
jmp 0x554d2
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x54(%rbp), %ecx
movl -0xc8(%rbp), %r8d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
callq 0x69870
movl %eax, -0xcc(%rbp)
movq -0x20(%rbp), %rdi
movl -0xc4(%rbp), %edx
movl -0xcc(%rbp), %ecx
movl $0x76, %esi
callq 0x5e0c0
movq -0x60(%rbp), %rax
movl 0x2c(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x552a0
movq -0x20(%rbp), %rdi
movl -0xb0(%rbp), %edx
movl $0x20, %esi
movl $0x1, %ecx
callq 0x5e0c0
movq -0x48(%rbp), %rdi
callq 0x6ee10
movq -0x20(%rbp), %rdi
callq 0x67890
movl %eax, -0x34(%rbp)
cmpl $0x0, -0xb8(%rbp)
jne 0x552d3
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x54(%rbp), %edx
movl $0x31, %ecx
callq 0x7ca80
movq -0x20(%rbp), %rdi
movl -0xc4(%rbp), %edx
movl -0x34(%rbp), %ecx
movl -0xc8(%rbp), %r8d
movl $0x77, %esi
callq 0x5e0f0
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x46(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x55368
movq -0x60(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x49880
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x7cb90
movq -0x20(%rbp), %rdi
movl -0xc8(%rbp), %r8d
movq -0xd8(%rbp), %r9
movl $0xd, %esi
xorl %edx, %edx
movl $0x1, %ecx
movl $0xfffffff6, (%rsp)     # imm = 0xFFFFFFF6
callq 0x5e1b0
movq -0x20(%rbp), %rdi
movl $0x2, %esi
callq 0x5e540
movq -0x8(%rbp), %rdi
callq 0x6a6f0
jmp 0x553ac
movq -0x8(%rbp), %rax
movzbl 0x1e(%rax), %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xdc(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x54(%rbp), %edx
movl -0xc8(%rbp), %ecx
movl -0xdc(%rbp), %r8d
movq -0xc0(%rbp), %r9
movl $0x63, (%rsp)
callq 0x7cca0
movq -0x20(%rbp), %rdi
movl -0x38(%rbp), %ecx
movl $0xe, %esi
xorl %edx, %edx
callq 0x5e0c0
movq -0x20(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x677f0
cmpl $0x0, -0xb8(%rbp)
jne 0x55441
movq -0x28(%rbp), %rax
movzbl 0x46(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x55441
movl $0x1, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x55430
movq -0x20(%rbp), %rdi
movl -0x54(%rbp), %edx
addl -0x3c(%rbp), %edx
movq -0x50(%rbp), %rax
movl 0x50(%rax), %ecx
movl $0x36, %esi
callq 0x5e0c0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x50(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x553f7
movq -0x20(%rbp), %rdi
movl -0x54(%rbp), %edx
movl $0x36, %esi
callq 0x5ecf0
jmp 0x55443
movq -0x8(%rbp), %rax
movzbl 0x1e(%rax), %eax
cmpl $0x0, %eax
jne 0x55467
movq -0x8(%rbp), %rax
cmpq $0x0, 0x1e0(%rax)
jne 0x55467
movq -0x8(%rbp), %rdi
callq 0x7cf10
movq -0x60(%rbp), %rax
movl 0x2c(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x554d0
movq -0x8(%rbp), %rax
cmpb $0x0, 0x1e(%rax)
jne 0x554d0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x1e0(%rax)
jne 0x554d0
movq -0x20(%rbp), %rdi
movl -0xb0(%rbp), %edx
movl $0x1e, %esi
movl $0x1, %ecx
callq 0x5e0c0
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x4bf60
movq -0x20(%rbp), %rdi
xorl %edx, %edx
leaq 0x5b364(%rip), %rcx     # 0xb0828
xorl %eax, %eax
movl %eax, %r8d
movl %edx, %esi
callq 0x4c030
jmp 0x554d2
leaq -0x70(%rbp), %rdi
callq 0x7d100
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x475c0
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x47330
addq $0xf0, %rsp
popq %rbp
retq
nop