// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3GenerateRowDelete
SQLITE_PRIVATE void sqlite3GenerateRowDelete(
  Parse *pParse,     /* Parsing context */
  Table *pTab,       /* Table containing the row to be deleted */
  int iCur,          /* Cursor number for the table */
  int iRowid,        /* Memory cell that contains the rowid to delete */
  int count,         /* If non-zero, increment the row change counter */
  Trigger *pTrigger, /* List of triggers to (potentially) fire */
  int onconf         /* Default ON CONFLICT policy for triggers */
){
  Vdbe *v = pParse->pVdbe;        /* Vdbe */
  int iOld = 0;                   /* First register in OLD.* array */
  int iLabel;                     /* Label resolved to end of generated code */

  /* Vdbe is guaranteed to have been allocated by this stage. */
  assert( v );

  /* Seek cursor iCur to the row to delete. If this row no longer exists 
  ** (this can happen if a trigger program has already deleted it), do
  ** not attempt to delete it or fire any DELETE triggers.  */
  iLabel = sqlite3VdbeMakeLabel(v);
  sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);
 
  /* If there are any triggers to fire, allocate a range of registers to
  ** use for the old.* references in the triggers.  */
  if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
    u32 mask;                     /* Mask of OLD.* columns in use */
    int iCol;                     /* Iterator used while populating OLD.* */

    /* TODO: Could use temporary registers here. Also could attempt to
    ** avoid copying the contents of the rowid register.  */
    mask = sqlite3TriggerColmask(
        pParse, pTrigger, 0, 0, TRIGGER_BEFORE|TRIGGER_AFTER, pTab, onconf
    );
    mask |= sqlite3FkOldmask(pParse, pTab);
    iOld = pParse->nMem+1;
    pParse->nMem += (1 + pTab->nCol);

    /* Populate the OLD.* pseudo-table register array. These values will be 
    ** used by any BEFORE and AFTER triggers that exist.  */
    sqlite3VdbeAddOp2(v, OP_Copy, iRowid, iOld);
    for(iCol=0; iCol<pTab->nCol; iCol++){
      if( mask==0xffffffff || mask&(1<<iCol) ){
        sqlite3ExprCodeGetColumnOfTable(v, pTab, iCur, iCol, iOld+iCol+1);
      }
    }

    /* Invoke BEFORE DELETE trigger programs. */
    sqlite3CodeRowTrigger(pParse, pTrigger, 
        TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
    );

    /* Seek the cursor to the row to be deleted again. It may be that
    ** the BEFORE triggers coded above have already removed the row
    ** being deleted. Do not attempt to delete the row a second time, and 
    ** do not fire AFTER triggers.  */
    sqlite3VdbeAddOp3(v, OP_NotExists, iCur, iLabel, iRowid);

    /* Do FK processing. This call checks that any FK constraints that
    ** refer to this table (i.e. constraints attached to other tables) 
    ** are not violated by deleting this row.  */
    sqlite3FkCheck(pParse, pTab, iOld, 0);
  }

  /* Delete the index and table entries. Skip this step if pTab is really
  ** a view (in which case the only effect of the DELETE statement is to
  ** fire the INSTEAD OF triggers).  */ 
  if( pTab->pSelect==0 ){
    sqlite3GenerateRowIndexDelete(pParse, pTab, iCur, 0);
    sqlite3VdbeAddOp2(v, OP_Delete, iCur, (count?OPFLAG_NCHANGE:0));
    if( count ){
      sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_TRANSIENT);
    }
  }

  /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
  ** handle rows (possibly in other tables) that refer via a foreign key
  ** to the row just deleted. */ 
  sqlite3FkActions(pParse, pTab, 0, iOld);

  /* Invoke AFTER DELETE trigger programs. */
  sqlite3CodeRowTrigger(pParse, pTrigger, 
      TK_DELETE, 0, TRIGGER_AFTER, pTab, iOld, onconf, iLabel
  );

  /* Jump here if the row had already been deleted before any BEFORE
  ** trigger programs were invoked. Or if a trigger program throws a 
  ** RAISE(IGNORE) exception.  */
  sqlite3VdbeResolveLabel(v, iLabel);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, -0x50(%rbp)
movl %r8d, -0x3c(%rbp)
movl %ecx, %r13d
movl %edx, %r12d
movq %rsi, %r15
movq %rdi, %r14
movq 0x10(%rdi), %rbx
movq %rbx, %rdi
callq 0x4c5eb
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
movq -0x50(%rbp), %rbx
movl $0x3f, %esi
movl %r12d, -0x40(%rbp)
movl %r12d, %edx
movq %rax, %r12
movl %r12d, %ecx
movl %r13d, -0x44(%rbp)
movl %r13d, %r8d
callq 0x45f15
movq %r14, -0x38(%rbp)
movq (%r14), %rax
xorl %r13d, %r13d
testb $0x8, 0x2e(%rax)
movl $0x0, %eax
je 0x5c4d4
movq %r15, %rdi
callq 0x4fce3
testq %rax, %rax
jne 0x5c4e1
cmpq $0x0, 0x20(%r15)
setne %al
testq %rbx, %rbx
jne 0x5c4e1
testb %al, %al
je 0x5c5fe
movq %r12, -0x60(%rbp)
subq $0x8, %rsp
xorl %r14d, %r14d
movq -0x38(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x3, %r8d
movq %r15, %r9
movl 0x10(%rbp), %eax
pushq %rax
callq 0x5c98e
addq $0x10, %rsp
movl %eax, -0x48(%rbp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x5ca31
movl %eax, %r13d
movl 0x58(%r12), %ebx
leal 0x1(%rbx), %ecx
movswl 0x42(%r15), %eax
leal 0x1(%rbx,%rax), %eax
movl %eax, 0x58(%r12)
movq -0x30(%rbp), %rdi
movl $0x1c, %esi
movl -0x44(%rbp), %edx
movq %rcx, -0x58(%rbp)
xorl %r8d, %r8d
callq 0x45f15
movzwl 0x42(%r15), %eax
testw %ax, %ax
movl -0x40(%rbp), %r12d
jle 0x5c596
orl -0x48(%rbp), %r13d
addl $0x2, %ebx
cmpl $-0x1, %r13d
je 0x5c570
btl %r14d, %r13d
jae 0x5c58b
leal (%rbx,%r14), %r8d
movq -0x30(%rbp), %rdi
movq %r15, %rsi
movl %r12d, %edx
movl %r14d, %ecx
callq 0x4ede2
movzwl 0x42(%r15), %eax
incl %r14d
movswl %ax, %ecx
cmpl %ecx, %r14d
jl 0x5c564
subq $0x8, %rsp
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %r14
movq %r14, %rsi
movl $0x6a, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movq %r15, %r9
movq -0x60(%rbp), %rbx
pushq %rbx
movl 0x10(%rbp), %r13d
pushq %r13
movq -0x58(%rbp), %r13
pushq %r13
callq 0x5cb21
addq $0x20, %rsp
movq -0x30(%rbp), %rdi
movl $0x3f, %esi
movl %r12d, %edx
movq %rbx, %r12
movq %r14, %rbx
movl %r12d, %ecx
movl -0x44(%rbp), %r8d
callq 0x45f15
movq -0x38(%rbp), %rdi
movq %r15, %rsi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0x5cb9d
cmpq $0x0, 0x18(%r15)
jne 0x5c650
movq -0x38(%rbp), %rdi
movq %r15, %rsi
movl -0x40(%rbp), %r14d
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x5cff7
xorl %ecx, %ecx
cmpl $0x0, -0x3c(%rbp)
setne %cl
movq -0x30(%rbp), %rdi
movl $0x46, %esi
movl %r14d, %edx
xorl %r8d, %r8d
callq 0x45f15
cmpl $0x0, -0x3c(%rbp)
je 0x5c650
movq (%r15), %rdx
movq -0x30(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
callq 0x11a9f
movq -0x38(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl %r13d, %ecx
callq 0x5d0ac
subq $0x8, %rsp
movq %r14, %rdi
movq %rbx, %rsi
movl $0x6a, %edx
xorl %ecx, %ecx
movl $0x2, %r8d
movq %r15, %r9
pushq %r12
movl 0x10(%rbp), %eax
pushq %rax
pushq %r13
callq 0x5cb21
addq $0x20, %rsp
testl %r12d, %r12d
jns 0x5c6b1
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rax
testq %rax, %rax
je 0x5c6b1
notl %r12d
movq -0x30(%rbp), %rcx
movl 0x34(%rcx), %ecx
movl %r12d, %edx
movl %ecx, (%rax,%rdx,4)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq