// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/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, 0);
    pWhere = sqlite3ExprAnd(db, 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 primary key is
  ** (a,b,...)
  */
  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, 0);
    }else{
      Expr *pEq, *pAll = 0;
      Index *pPk = sqlite3PrimaryKeyIndex(pTab);
      assert( pIdx!=0 );
      for(i=0; i<pPk->nKeyCol; i++){
        i16 iCol = pIdx->aiColumn[i];
        assert( iCol>=0 );
        pLeft = exprTableRegister(pParse, pTab, regData, iCol);
        pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
        pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
        pAll = sqlite3ExprAnd(db, pAll, pEq);
      }
      pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0, 0);
    }
    pWhere = sqlite3ExprAnd(db, 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. */
  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 ){
    sqlite3VdbeJumpHere(v, iFkIfZero);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x8c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6bd00
movq %rax, -0x98(%rbp)
cmpl $0x0, 0x18(%rbp)
jge 0x9265d
movq -0x98(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %edx
movl $0x89, %esi
xorl %ecx, %ecx
callq 0x6c310
movl %eax, -0x8c(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x9278d
cmpq $0x0, -0x20(%rbp)
je 0x92693
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0xf8(%rbp)
jmp 0x926a0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xf8(%rbp)
jmp 0x926a0
movl -0xf8(%rbp), %eax
movw %ax, -0xb2(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movswl -0xb2(%rbp), %ecx
callq 0x92a00
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x926e5
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xfc(%rbp)
jmp 0x926f2
movq -0x28(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
movw %ax, -0xb2(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movswq -0xb2(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x38(%rbp), %rdi
movq -0xc0(%rbp), %rdx
movl $0x1b, %esi
callq 0x61600
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %rcx
movl $0x4f, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x5d170
movq %rax, -0xb0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xb0(%rbp), %rdx
callq 0x79a50
movq %rax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x92664
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x92940
cmpl $0x0, 0x18(%rbp)
jle 0x92940
movq -0x18(%rbp), %rax
movzbl 0x46(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0x92821
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x92a00
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x92b00
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rcx
movl $0x4e, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x5d170
movq %rax, -0xc8(%rbp)
jmp 0x92928
movq $0x0, -0xe8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x52e70
movq %rax, -0xf0(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0xf0(%rbp), %rcx
movzwl 0x5e(%rcx), %ecx
cmpl %ecx, %eax
jge 0x92904
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0xf2(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movswl -0xf2(%rbp), %ecx
callq 0x92a00
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %edx
movswl -0xf2(%rbp), %ecx
callq 0x92b00
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rcx
movl $0x4f, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x5d170
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
callq 0x79a50
movq %rax, -0xe8(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x92843
movq -0x8(%rbp), %rdi
movq -0xe8(%rbp), %rdx
movl $0x13, %esi
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x5d170
movq %rax, -0xc8(%rbp)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xc8(%rbp), %rdx
callq 0x79a50
movq %rax, -0x48(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0xb2b0
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x74b50
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
movq %r8, %rcx
movl $0x0, (%rsp)
callq 0x7dfc0
movq %rax, -0x88(%rbp)
movq -0x98(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %edx
movl 0x18(%rbp), %ecx
movl $0x88, %esi
callq 0x6c310
cmpq $0x0, -0x88(%rbp)
je 0x929c9
movq -0x88(%rbp), %rdi
callq 0x7f7a0
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x536c0
cmpl $0x0, -0x8c(%rbp)
je 0x929f1
movq -0x98(%rbp), %rdi
movl -0x8c(%rbp), %esi
callq 0x6be30
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw (%rax,%rax)