// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, %r12
movq %r8, %rbx
movq %rcx, %r15
movq %rdx, -0x60(%rbp)
movq %rsi, -0x38(%rbp)
movq (%rdi), %rax
movq %rax, -0x30(%rbp)
movq %rdi, -0x40(%rbp)
callq 0x49f90
movq %rax, %r14
xorl %eax, %eax
cmpl $0x0, 0x18(%rbp)
jns 0x5fe3a
movzbl 0x2c(%rbx), %edx
movq %r14, %rdi
movl $0x89, %esi
xorl %ecx, %ecx
callq 0x4a1ab
movl %eax, -0x64(%rbp)
movq %r14, -0x48(%rbp)
leaq 0x40(%rbx), %rax
movq %rax, -0x50(%rbp)
xorl %r14d, %r14d
movq %r12, -0x58(%rbp)
xorl %eax, %eax
movq %rbx, -0x70(%rbp)
movq %r15, -0x78(%rbp)
movslq 0x28(%rbx), %rcx
cmpq %rcx, %r14
movq %rax, -0x80(%rbp)
jge 0x5fefe
testq %r15, %r15
je 0x5fe7b
movq 0x8(%r15), %rax
movzwl (%rax,%r14,2), %eax
jmp 0x5fe7f
movw $0xffff, %ax            # imm = 0xFFFF
movswl %ax, %ecx
movq -0x40(%rbp), %r15
movq %r15, %rdi
movq -0x60(%rbp), %rsi
movl 0x10(%rbp), %edx
callq 0x600e4
movq %rax, %r13
cmpq $0x0, -0x58(%rbp)
movq %r12, %rax
cmoveq -0x50(%rbp), %rax
movswq (%rax), %rax
movq (%rbx), %rcx
movq 0x8(%rcx), %rcx
imulq $0x30, %rax, %rax
movq (%rcx,%rax), %rdx
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
pushq $0x1b
popq %rsi
callq 0x43226
movq %r15, %rdi
pushq $0x4f
popq %rsi
movq %r13, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x3e36c
movq %rbx, %rdi
movq -0x70(%rbp), %rbx
movq -0x80(%rbp), %rsi
movq %rax, %rdx
callq 0x52262
incq %r14
addq $0x4, %r12
movq -0x78(%rbp), %r15
jmp 0x5fe5a
cmpl $0x0, 0x18(%rbp)
jle 0x5ff6e
movq -0x60(%rbp), %rcx
cmpq %rcx, (%rbx)
movq -0x48(%rbp), %r14
movq -0x30(%rbp), %r12
jne 0x60042
movq %rcx, %rbx
testb $0x20, 0x46(%rcx)
movq -0x38(%rbp), %r13
jne 0x5ff7b
pushq $-0x1
popq %rcx
movq -0x40(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movl 0x10(%rbp), %edx
callq 0x600e4
movq %rax, %r12
movl 0x4c(%r13), %edx
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
pushq $-0x1
popq %rcx
movq -0x30(%rbp), %rbx
callq 0x60192
pushq $0x4e
popq %rsi
movq %r15, %rdi
movq %r12, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x3e36c
jmp 0x60030
movq -0x48(%rbp), %r14
movq -0x30(%rbp), %r12
jmp 0x60042
movq %rbx, %rdi
callq 0x363b8
movq %rax, -0x88(%rbp)
xorl %ecx, %ecx
xorl %edx, %edx
movq -0x40(%rbp), %rbx
movq -0x60(%rbp), %r12
movq -0x30(%rbp), %r14
movq -0x88(%rbp), %rax
movzwl 0x5e(%rax), %eax
cmpq %rax, %rcx
jae 0x60017
movq 0x8(%r15), %rax
movswl (%rax,%rcx,2), %r13d
movq %rbx, %rdi
movq %r12, %rsi
movq %rdx, -0x50(%rbp)
movl 0x10(%rbp), %edx
movq %rcx, -0x58(%rbp)
movl %r13d, %ecx
callq 0x600e4
movq %rax, %r15
movq -0x38(%rbp), %rax
movl 0x4c(%rax), %edx
movq %r14, %rdi
movq %r12, %rsi
movl %r13d, %ecx
callq 0x60192
movq %rbx, %rdi
pushq $0x4f
popq %rsi
movq %r15, %rdx
movq -0x78(%rbp), %r15
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x3e36c
movq %r14, %rdi
movq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x52262
movq -0x58(%rbp), %rcx
movq %rax, %rdx
incq %rcx
jmp 0x5ff9a
pushq $0x13
popq %rsi
movq -0x40(%rbp), %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3e36c
movq -0x48(%rbp), %r14
movq -0x30(%rbp), %rbx
movq %rbx, %r12
movq %rbx, %rdi
movq -0x80(%rbp), %rsi
movq %rax, %rdx
callq 0x52262
movq -0x38(%rbp), %r15
xorps %xmm0, %xmm0
leaq -0xc0(%rbp), %rdi
andq $0x0, 0x30(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movq %r15, 0x8(%rdi)
movq -0x40(%rbp), %rbx
movq %rbx, (%rdi)
movq %rax, %r13
movq %rax, %rsi
callq 0x4f020
andl $0x0, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %r15
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x53a7b
movq %rax, %rbx
movq -0x70(%rbp), %rax
movzbl 0x2c(%rax), %edx
movq %r14, %rdi
movl $0x88, %esi
movl 0x18(%rbp), %ecx
callq 0x4a1ab
testq %rbx, %rbx
je 0x600b8
movq %rbx, %rdi
callq 0x56d2d
movq %r12, %rdi
movq %r15, %rsi
callq 0x367e7
movl -0x64(%rbp), %esi
testl %esi, %esi
je 0x600d2
movq %r14, %rdi
callq 0x4a022
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq