// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: fkScanChildren
static void fkScanChildren(
  Parse *pParse,                  /* Parse context */
  SrcList *pSrc,                  /* The child table to be scanned */
  Table *pTab,                    /* The parent table */
  Index *pIdx,                    /* Index on parent covering the foreign key */
  FKey *pFKey,                    /* The foreign key linking pSrc to pTab */
  int *aiCol,                     /* Map from pIdx cols to child table cols */
  int regData,                    /* Parent row data starts here */
  int nIncr                       /* Amount to increment deferred counter by */
){
  sqlite3 *db = pParse->db;       /* Database handle */
  int i;                          /* Iterator variable */
  Expr *pWhere = 0;               /* WHERE clause to scan with */
  NameContext sNameContext;       /* Context used to resolve WHERE clause */
  WhereInfo *pWInfo;              /* Context used by sqlite3WhereXXX() */
  int iFkIfZero = 0;              /* Address of OP_FkIfZero */
  Vdbe *v = sqlite3GetVdbe(pParse);

  assert( pIdx==0 || pIdx->pTable==pTab );
  assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
  assert( pIdx!=0 || pFKey->nCol==1 );
  assert( pIdx!=0 || HasRowid(pTab) );

  if( nIncr<0 ){
    iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
    VdbeCoverage(v);
  }

  /* Create an Expr object representing an SQL expression like:
  **
  **   <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
  **
  ** The collation sequence used for the comparison should be that of
  ** the parent key columns. The affinity of the parent key column should
  ** be applied to each child key value before the comparison takes place.
  */
  for(i=0; i<pFKey->nCol; i++){
    Expr *pLeft;                  /* Value from parent table row */
    Expr *pRight;                 /* Column ref to child table */
    Expr *pEq;                    /* Expression (pLeft = pRight) */
    i16 iCol;                     /* Index of column in child table */
    const char *zCol;             /* Name of column in child table */

    iCol = pIdx ? pIdx->aiColumn[i] : -1;
    pLeft = exprTableRegister(pParse, pTab, regData, iCol);
    iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
    assert( iCol>=0 );
    zCol = pFKey->pFrom->aCol[iCol].zName;
    pRight = sqlite3Expr(db, TK_ID, zCol);
    pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
    pWhere = sqlite3ExprAnd(pParse, pWhere, pEq);
  }

  /* If the child table is the same as the parent table, then add terms
  ** to the WHERE clause that prevent this entry from being scanned.
  ** The added WHERE clause terms are like this:
  **
  **     $current_rowid!=rowid
  **     NOT( $current_a==a AND $current_b==b AND ... )
  **
  ** The first form is used for rowid tables.  The second form is used
  ** for WITHOUT ROWID tables. In the second form, the *parent* key is
  ** (a,b,...). Either the parent or primary key could be used to
  ** uniquely identify the current row, but the parent key is more convenient
  ** as the required values have already been loaded into registers
  ** by the caller.
  */
  if( pTab==pFKey->pFrom && nIncr>0 ){
    Expr *pNe;                    /* Expression (pLeft != pRight) */
    Expr *pLeft;                  /* Value from parent table row */
    Expr *pRight;                 /* Column ref to child table */
    if( HasRowid(pTab) ){
      pLeft = exprTableRegister(pParse, pTab, regData, -1);
      pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
      pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight);
    }else{
      Expr *pEq, *pAll = 0;
      assert( pIdx!=0 );
      for(i=0; i<pIdx->nKeyCol; i++){
        i16 iCol = pIdx->aiColumn[i];
        assert( iCol>=0 );
        pLeft = exprTableRegister(pParse, pTab, regData, iCol);
        pRight = sqlite3Expr(db, TK_ID, pTab->aCol[iCol].zName);
        pEq = sqlite3PExpr(pParse, TK_IS, pLeft, pRight);
        pAll = sqlite3ExprAnd(pParse, pAll, pEq);
      }
      pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
    }
    pWhere = sqlite3ExprAnd(pParse, pWhere, pNe);
  }

  /* Resolve the references in the WHERE clause. */
  memset(&sNameContext, 0, sizeof(NameContext));
  sNameContext.pSrcList = pSrc;
  sNameContext.pParse = pParse;
  sqlite3ResolveExprNames(&sNameContext, pWhere);

  /* Create VDBE to loop through the entries in pSrc that match the WHERE
  ** clause. For each row found, increment either the deferred or immediate
  ** foreign key constraint counter. */
  if( pParse->nErr==0 ){
    pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
    sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
    if( pWInfo ){
      sqlite3WhereEnd(pWInfo);
    }
  }

  /* Clean up the WHERE clause constructed above. */
  sqlite3ExprDelete(db, pWhere);
  if( iFkIfZero ){
    sqlite3VdbeJumpHereOrPopInst(v, iFkIfZero);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rcx, %r13
movq %rdx, 0x20(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
movq (%rdi), %rax
movq %rax, 0x18(%rsp)
callq 0x2645be
movq %rax, %rbx
xorl %eax, %eax
cmpl $0x0, 0xc8(%rsp)
jns 0x281059
movzbl 0x2c(%r15), %edx
pushq $0x2f
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x24d51a
movl %eax, 0x2c(%rsp)
movq %rbx, 0x30(%rsp)
leaq 0x40(%r15), %rax
movq %rax, 0x48(%rsp)
xorl %ebx, %ebx
movq %r14, %rbp
movq $0x0, 0x8(%rsp)
movq %r15, 0x38(%rsp)
movq %r13, 0x40(%rsp)
movslq 0x28(%r15), %rax
cmpq %rax, %rbx
jge 0x281125
testq %r13, %r13
je 0x28109f
movq 0x8(%r13), %rax
movzwl (%rax,%rbx,2), %eax
jmp 0x2810a3
movw $0xffff, %ax            # imm = 0xFFFF
movswl %ax, %ecx
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movl 0xc0(%rsp), %edx
callq 0x2812fd
movq %rax, %r13
testq %rbp, %rbp
movq %r14, %rax
cmoveq 0x48(%rsp), %rax
movswq (%rax), %rax
movq 0x38(%rsp), %r15
movq (%r15), %rcx
movq 0x8(%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rdx
movq 0x18(%rsp), %rdi
pushq $0x3b
popq %rsi
callq 0x25bd93
movq %r12, %rdi
pushq $0x35
popq %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x254915
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0x26119e
movq %rax, 0x8(%rsp)
incq %rbx
addq $0x4, %r14
movq 0x40(%rsp), %r13
jmp 0x281083
cmpl $0x0, 0xc8(%rsp)
movq 0x20(%rsp), %rsi
jle 0x2811a6
cmpq %rsi, (%r15)
movq 0x8(%rsp), %rbx
jne 0x28119c
testb $-0x80, 0x40(%rsi)
jne 0x2811b5
pushq $-0x1
popq %rcx
movq %r12, %rdi
movl 0xc0(%rsp), %edx
movq %rsi, %r13
callq 0x2812fd
movq %rax, %r14
movq 0x10(%rsp), %rbp
movl 0x48(%rbp), %ebx
movq 0x18(%rsp), %rdi
movl $0xa4, %esi
xorl %edx, %edx
callq 0x25bd93
testq %rax, %rax
je 0x281186
movq %r13, 0x40(%rax)
movl %ebx, 0x2c(%rax)
orw $-0x1, 0x30(%rax)
pushq $0x34
popq %rsi
movq %r12, %rdi
movq %r14, %rdx
movq %rax, %rcx
callq 0x254915
jmp 0x281248
movq 0x10(%rsp), %rbp
jmp 0x28125b
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %rbx
jmp 0x28125b
xorl %ebx, %ebx
xorl %ebp, %ebp
movzwl 0x5e(%r13), %eax
cmpq %rax, %rbx
jae 0x28122e
movq 0x8(%r13), %rax
movswq (%rax,%rbx,2), %r15
movq %r12, %rdi
movq 0x20(%rsp), %r13
movq %r13, %rsi
movl 0xc0(%rsp), %edx
movl %r15d, %ecx
callq 0x2812fd
movq %rax, %r14
movq 0x8(%r13), %rax
movq 0x40(%rsp), %r13
shlq $0x5, %r15
movq (%rax,%r15), %rdx
movq 0x18(%rsp), %rdi
pushq $0x3b
popq %rsi
callq 0x25bd93
movq %r12, %rdi
pushq $0x2d
popq %rsi
movq %r14, %rdx
movq %rax, %rcx
callq 0x254915
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x26119e
movq %rax, %rbp
incq %rbx
jmp 0x2811b9
pushq $0x13
popq %rsi
movq %r12, %rdi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x254915
movq 0x38(%rsp), %r15
movq 0x10(%rsp), %rbp
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0x26119e
movq %rax, %rbx
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
andq $0x0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movq %rbp, 0x8(%rdi)
movq %r12, (%rdi)
movq %rbx, %rsi
callq 0x26afc4
cmpl $0x0, 0x30(%r12)
jne 0x2812cc
andl $0x0, (%rsp)
movq %r12, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x270b37
movq %rax, %r14
movzbl 0x2c(%r15), %edx
movq 0x30(%rsp), %rdi
movl $0x95, %esi
movl 0xc8(%rsp), %ecx
callq 0x24d51a
testq %r14, %r14
je 0x2812cc
movq %r14, %rdi
callq 0x274c3c
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x24b639
movl 0x2c(%rsp), %esi
testl %esi, %esi
je 0x2812eb
movq 0x30(%rsp), %rdi
callq 0x27e90d
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq