// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/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 eMode,          /* ONEPASS_OFF, _SINGLE, or _MULTI.  See above */
  int iIdxNoSeek     /* Cursor number of cursor that does not need seeking */
){
  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(pParse);
  opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
  if( eMode==ONEPASS_OFF ){
    sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
    VdbeCoverageIf(v, opSeek==OP_NotExists);
    VdbeCoverageIf(v, opSeek==OP_NotFound);
  }

  /* 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++){
      testcase( mask!=0xffffffff && iCol==31 );
      testcase( mask!=0xffffffff && iCol==32 );
      if( mask==0xffffffff || (iCol<=31 && (mask & MASKBIT32(iCol))!=0) ){
        int kk = sqlite3TableColumnToStorage(pTab, iCol);
        sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, iCol, iOld+kk+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 already deleted the row that the cursor was
    ** pointing to.
    **
    ** Also disable the iIdxNoSeek optimization since the BEFORE trigger
    ** may have moved that cursor.
    */
    if( addrStart<sqlite3VdbeCurrentAddr(v) ){
      sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
      VdbeCoverageIf(v, opSeek==OP_NotExists);
      VdbeCoverageIf(v, opSeek==OP_NotFound);
      testcase( iIdxNoSeek>=0 );
      iIdxNoSeek = -1;
    }

    /* 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 variable 'count' is non-zero, then this OP_Delete instruction should
  ** invoke the update-hook. The pre-update-hook, on the other hand should
  ** be invoked unless table pTab is a system table. The difference is that
  ** the update-hook is not invoked for rows removed by REPLACE, but the
  ** pre-update-hook is.
  */
  if( pTab->pSelect==0 ){
    u8 p5 = 0;
    sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
    sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
    if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
      sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
    }
    if( eMode!=ONEPASS_OFF ){
      sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
    }
    if( iIdxNoSeek>=0 && iIdxNoSeek!=iDataCur ){
      sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
    }
    if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION;
    sqlite3VdbeChangeP5(v, p5);
  }

  /* 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, 0x18(%rsp)
movl %r8d, 0x34(%rsp)
movl %ecx, 0xc(%rsp)
movq %rsi, %r15
movq %rdi, %r12
movl 0xa0(%rsp), %eax
movl %eax, 0x14(%rsp)
movb 0x98(%rsp), %cl
movb 0x90(%rsp), %bpl
movb 0x88(%rsp), %al
movb %al, 0xb(%rsp)
movzwl 0x80(%rsp), %eax
movw %ax, 0x12(%rsp)
movq 0x10(%rdi), %rbx
movl 0x44(%rdi), %r14d
decl %r14d
movl %r14d, 0x44(%rdi)
xorl %eax, %eax
testb $-0x80, 0x40(%rsi)
movq %rdx, %r13
sete %al
leal (%rax,%rax,2), %eax
addl $0x1d, %eax
movl %eax, 0x1c(%rsp)
movb %cl, 0xa(%rsp)
testb %cl, %cl
jne 0x2e0f1d
movzbl 0x1c(%rsp), %esi
movq %rbx, %rdi
movl 0xc(%rsp), %edx
movl %r14d, %ecx
movl 0x18(%rsp), %r8d
callq 0x2a83e1
movq (%rbx), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2e0f1d
movswl 0x12(%rsp), %ecx
movq 0x88(%rbx), %rdx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rdx,%rax,8)
movl %ecx, 0x10(%rdx,%rax,8)
movq (%r12), %rax
movq 0x30(%rax), %rdi
movq $0x0, 0x28(%rsp)
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2e08ce
movzbl %bpl, %ebp
testq %r13, %r13
movq %r13, 0x38(%rsp)
jne 0x2e0f50
testl %eax, %eax
je 0x2e10bc
movq %r14, 0x40(%rsp)
subq $0x8, %rsp
movq %r13, %rsi
xorl %r13d, %r13d
movq %r12, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x3, %r8d
movq %r15, %r9
movq %rbp, 0x28(%rsp)
pushq %rbp
callq 0x2e1362
addq $0x10, %rsp
movl %eax, 0x30(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2e1401
movl %eax, %r14d
movl 0x38(%r12), %ebp
leal 0x1(%rbp), %ecx
movswl 0x46(%r15), %eax
leal 0x1(%rbp,%rax), %eax
movl %eax, 0x38(%r12)
movq %rbx, %rdi
movl $0x4d, %esi
movl 0x18(%rsp), %edx
movq %rcx, 0x28(%rsp)
xorl %r8d, %r8d
callq 0x2a83e1
movzwl 0x46(%r15), %eax
testw %ax, %ax
jle 0x2e1018
orl 0x30(%rsp), %r14d
addl $0x2, %ebp
cmpl $-0x1, %r14d
je 0x2e0fe3
cmpl $0x1f, %r13d
ja 0x2e100d
btl %r13d, %r14d
jae 0x2e100d
movswl %r13w, %esi
movq %r15, %rdi
callq 0x2be097
movswl %ax, %r8d
addl %ebp, %r8d
movq %rbx, %rdi
movq %r15, %rsi
movl 0xc(%rsp), %edx
movl %r13d, %ecx
callq 0x2c010f
movzwl 0x46(%r15), %eax
incl %r13d
movswl %ax, %ecx
cmpl %ecx, %r13d
jl 0x2e0fd1
movl 0x90(%rbx), %ebp
subq $0x8, %rsp
movq %r12, %rdi
movq 0x40(%rsp), %rsi
movl $0x7e, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
movq %r15, %r9
movq 0x48(%rsp), %r14
pushq %r14
pushq 0x30(%rsp)
pushq 0x40(%rsp)
callq 0x2e14fb
addq $0x20, %rsp
cmpl 0x90(%rbx), %ebp
jge 0x2e109f
movzbl 0x1c(%rsp), %esi
movq %rbx, %rdi
movl 0xc(%rsp), %edx
movl %r14d, %ecx
movl 0x18(%rsp), %r8d
callq 0x2a83e1
movq (%rbx), %rcx
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
cmpb $0x0, 0x61(%rcx)
jne 0x2e109f
movswl 0x12(%rsp), %ecx
movq 0x88(%rbx), %rdx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rdx,%rax,8)
movl %ecx, 0x10(%rdx,%rax,8)
movq %r12, %rdi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2e1578
movq 0x20(%rsp), %rbp
cmpq $0x0, 0x18(%r15)
jne 0x2e11e6
movq %rbp, 0x20(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movl 0xc(%rsp), %ebp
movl %ebp, %edx
movl 0x34(%rsp), %ecx
xorl %r8d, %r8d
movl 0x14(%rsp), %r9d
callq 0x2e1b81
xorl %ecx, %ecx
cmpb $0x0, 0xb(%rsp)
setne %cl
movq %rbx, %rdi
movl $0x7a, %esi
movl %ebp, %edx
xorl %r8d, %r8d
callq 0x2a83e1
cmpb $0x0, 0x1e(%r12)
je 0x2e1149
movq (%r15), %rax
testq %rax, %rax
je 0x2e116e
xorl %ecx, %ecx
leaq 0xf5669(%rip), %rdx     # 0x3d6787
leaq 0xf01bb(%rip), %rsi     # 0x3d12e0
movzbl (%rax,%rcx), %edi
movzbl (%rcx,%rdx), %r8d
cmpb %r8b, %dil
jne 0x2e113a
testq %rdi, %rdi
jne 0x2e1144
jmp 0x2e1149
movb (%rdi,%rsi), %dil
cmpb (%r8,%rsi), %dil
jne 0x2e116e
incq %rcx
jmp 0x2e1125
movq (%rbx), %rax
cmpb $0x0, 0x61(%rax)
jne 0x2e116e
movq 0x88(%rbx), %rax
movslq 0x90(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $-0x6, -0x17(%rax,%rcx,8)
movq %r15, -0x8(%rax,%rcx,8)
cmpb $0x0, 0xa(%rsp)
je 0x2e1193
movslq 0x90(%rbx), %rax
testq %rax, %rax
jle 0x2e1193
movq 0x88(%rbx), %rcx
leaq (%rax,%rax,2), %rax
movw $0x4, -0x16(%rcx,%rax,8)
movl 0x14(%rsp), %edx
testl %edx, %edx
sets %al
cmpl 0xc(%rsp), %edx
sete %cl
orb %al, %cl
movq 0x20(%rsp), %rbp
jne 0x2e11be
movq %rbx, %rdi
movl $0x7a, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movslq 0x90(%rbx), %rax
testq %rax, %rax
jle 0x2e11e6
xorl %ecx, %ecx
cmpb $0x2, 0xa(%rsp)
sete %cl
addl %ecx, %ecx
movq 0x88(%rbx), %rdx
leaq (%rax,%rax,2), %rax
movw %cx, -0x16(%rdx,%rax,8)
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq 0x28(%rsp), %r13
movl %r13d, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2e1cd0
subq $0x8, %rsp
movq %r12, %rdi
movq 0x40(%rsp), %rsi
movl $0x7e, %edx
xorl %ecx, %ecx
movl $0x2, %r8d
movq %r15, %r9
pushq %r14
pushq %rbp
pushq %r13
callq 0x2e14fb
addq $0x20, %rsp
movq %rbx, %rdi
movl %r14d, %esi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2bfa39