// File: /workspace/github_c_makefile_star2_O2/skeeto[P]flappy/sqlite3.c
// Function: sqlite3GenerateRowDelete
SQLITE_PRIVATE void sqlite3GenerateRowDelete(
  Parse *pParse,     /* Parsing context */
  Table *pTab,       /* Table containing the row to be deleted */
  Trigger *pTrigger, /* List of triggers to (potentially) fire */
  int iDataCur,      /* Cursor from which column data is extracted */
  int iIdxCur,       /* First index cursor */
  int iPk,           /* First memory cell containing the PRIMARY KEY */
  i16 nPk,           /* Number of PRIMARY KEY memory cells */
  u8 count,          /* If non-zero, increment the row change counter */
  u8 onconf,         /* Default ON CONFLICT policy for triggers */
  u8 bNoSeek         /* iDataCur is already pointing to the row to delete */
){
  Vdbe *v = pParse->pVdbe;        /* Vdbe */
  int iOld = 0;                   /* First register in OLD.* array */
  int iLabel;                     /* Label resolved to end of generated code */
  u8 opSeek;                      /* Seek opcode */

  /* Vdbe is guaranteed to have been allocated by this stage. */
  assert( v );
  VdbeModuleComment((v, "BEGIN: GenRowDel(%d,%d,%d,%d)",
                         iDataCur, iIdxCur, iPk, (int)nPk));

  /* 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);
  opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
  if( !bNoSeek ) sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
 
  /* 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.* */
    int addrStart;                /* Start of BEFORE trigger programs */

    /* 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, iPk, iOld);
    for(iCol=0; iCol<pTab->nCol; iCol++){
      if( mask==0xffffffff || mask&(1<<iCol) ){
        sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+iCol+1);
      }
    }

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

    /* If any BEFORE triggers were coded, then seek the cursor to the 
    ** row to be deleted again. It may be that the BEFORE triggers moved
    ** the cursor or of already deleted the row that the cursor was
    ** pointing to.
    */
    if( addrStart<sqlite3VdbeCurrentAddr(v) ){
      sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
    }

    /* 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, 0, 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, iDataCur, iIdxCur, 0);
    sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (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, 0, 0);

  /* 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);
  VdbeModuleComment((v, "END: GenRowDel()"));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0xc(%rsp)
movl %r8d, 0x2c(%rsp)
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movq 0x10(%rdi), %rbx
movq %rbx, %rdi
callq 0x4595f
testb $0x20, 0x48(%r15)
movl %eax, %r13d
sete %al
addb %al, %al
addb $0x3f, %al
cmpb $0x0, 0x98(%rsp)
movzbl %al, %eax
movl %eax, 0x18(%rsp)
movswl 0x80(%rsp), %eax
movl %eax, 0x1c(%rsp)
jne 0x5594c
movq %rbx, %rdi
movl 0x18(%rsp), %esi
movl %ebp, %edx
movl %r13d, %ecx
movl 0xc(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x441d6
movq $0x0, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x55658
movzbl 0x90(%rsp), %ecx
movq %rcx, 0x20(%rsp)
testq %r12, %r12
jne 0x5597e
testl %eax, %eax
je 0x55aa0
movq %r13, 0x40(%rsp)
subq $0x8, %rsp
movq %r14, %r13
xorl %r14d, %r14d
pushq $0x3
popq %r8
movq %r13, %rdi
movq %r12, 0x40(%rsp)
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r15, %r9
pushq 0x28(%rsp)
callq 0x55ec8
popq %rcx
popq %rdx
movl %eax, 0x10(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x55f5d
movl %eax, %r12d
orl 0x10(%rsp), %r12d
movq %r13, %rdx
movl 0x58(%r13), %r13d
leal 0x1(%r13), %ecx
movswl 0x42(%r15), %eax
leal 0x1(%r13,%rax), %eax
movq %rdx, 0x30(%rsp)
movl %eax, 0x58(%rdx)
pushq $0x1e
popq %rsi
movq %rbx, %rdi
movl 0xc(%rsp), %edx
movq %rcx, 0x10(%rsp)
callq 0x43f64
addl $0x2, %r13d
movswl 0x42(%r15), %eax
cmpl %eax, %r14d
jge 0x55a29
cmpl $-0x1, %r12d
je 0x55a10
btl %r14d, %r12d
jae 0x55a24
leal (%r14,%r13), %r8d
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x4666b
incl %r14d
jmp 0x559fa
movl 0x34(%rbx), %r14d
subq $0x8, %rsp
pushq $0x6b
popq %rdx
pushq $0x1
popq %r8
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %r12
movq %r12, %rsi
xorl %ecx, %ecx
movq %r15, %r9
movq 0x48(%rsp), %r13
pushq %r13
pushq 0x30(%rsp)
pushq 0x28(%rsp)
callq 0x56034
addq $0x20, %rsp
cmpl 0x34(%rbx), %r14d
jge 0x55a83
movq %rbx, %rdi
movl 0x18(%rsp), %esi
movl %ebp, %edx
movl %r13d, %ecx
movl 0xc(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x441d6
movq 0x30(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x560ae
cmpq $0x0, 0x18(%r15)
jne 0x55aef
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movl 0x2c(%rsp), %ecx
xorl %r8d, %r8d
callq 0x56533
xorl %ecx, %ecx
cmpb $0x0, 0x88(%rsp)
setne %cl
pushq $0x48
popq %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x43f64
cmpb $0x0, 0x88(%rsp)
je 0x55aef
movq (%r15), %rdx
pushq $-0x1
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x10de3
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq 0x10(%rsp), %rbp
movl %ebp, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x56610
subq $0x8, %rsp
pushq $0x6b
popq %rdx
pushq $0x2
popq %r8
movq %r14, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
movq %r15, %r9
pushq %r13
pushq 0x30(%rsp)
pushq %rbp
callq 0x56034
addq $0x20, %rsp
testl %r13d, %r13d
jns 0x55b49
movq 0x40(%rbx), %rax
testq %rax, %rax
je 0x55b49
notl %r13d
movl 0x34(%rbx), %ecx
movl %r13d, %edx
movl %ecx, (%rax,%rdx,4)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq