// File: /workspace/github_c_makefile_star2_O3/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, -0x40(%rbp)
movq %r8, %r13
movq %rcx, -0x80(%rbp)
movq %rdx, -0x48(%rbp)
movq %rsi, -0x50(%rbp)
movq %rdi, %r15
movq (%rdi), %r14
callq 0x4f63b
movq %rax, %rbx
xorl %eax, %eax
cmpl $0x0, 0x18(%rbp)
jns 0x6c3be
movzbl 0x2c(%r13), %edx
movq %rbx, %rdi
movl $0x89, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movq %r15, -0x30(%rbp)
movq %r14, -0x38(%rbp)
movl %eax, -0x6c(%rbp)
movq %rbx, -0x78(%rbp)
cmpl $0x0, 0x28(%r13)
jle 0x6c497
leaq 0x40(%r13), %rax
movq %rax, -0x58(%rbp)
xorl %r12d, %r12d
movq -0x40(%rbp), %r14
xorl %eax, %eax
movq -0x30(%rbp), %r15
movq -0x80(%rbp), %rcx
testq %rcx, %rcx
movq %rax, -0x68(%rbp)
je 0x6c405
movq 0x8(%rcx), %rax
movzwl (%rax,%r12,2), %eax
jmp 0x6c409
movw $0xffff, %ax            # imm = 0xFFFF
movq -0x48(%rbp), %rsi
movswl %ax, %ecx
movq %r15, %rdi
movl 0x10(%rbp), %edx
callq 0x6c766
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x40(%rbp)
movq %r14, %rax
cmoveq -0x58(%rbp), %rax
movswq (%rax), %rax
movq (%r13), %rcx
movq 0x8(%rcx), %rcx
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movq (%rcx,%rax), %rdx
movq %r13, %rbx
movq -0x38(%rbp), %r13
movq %r13, %rdi
movl $0x1b, %esi
callq 0x46837
movq %r15, %rdi
movl $0x4f, %esi
movq -0x60(%rbp), %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x42edf
movq %r13, %rdi
movq %rbx, %r13
movq -0x68(%rbp), %rsi
movq %rax, %rdx
callq 0x591f9
incq %r12
movslq 0x28(%rbx), %rcx
addq $0x4, %r14
cmpq %rcx, %r12
jl 0x6c3ed
jmp 0x6c499
xorl %eax, %eax
movl 0x18(%rbp), %ebx
testl %ebx, %ebx
movq -0x78(%rbp), %r15
movq %r13, -0x88(%rbp)
jle 0x6c689
movq -0x48(%rbp), %rcx
cmpq %rcx, (%r13)
movq -0x30(%rbp), %r13
jne 0x6c68d
testb $0x20, 0x46(%rcx)
movq %rcx, %rbx
movq %rax, -0x68(%rbp)
jne 0x6c56c
movq (%r13), %rdi
leaq -0xc0(%rbp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movl $0x9d, %esi
xorl %ecx, %ecx
callq 0x5589f
movq %rax, %r12
testq %rax, %rax
movq -0x50(%rbp), %rax
je 0x6c511
movl 0x10(%rbp), %ecx
movl %ecx, 0x2c(%r12)
movb $0x44, 0x1(%r12)
movl 0x4c(%rax), %r14d
leaq -0xc0(%rbp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movq -0x38(%rbp), %r13
movq %r13, %rdi
movl $0x98, %esi
xorl %ecx, %ecx
callq 0x5589f
testq %rax, %rax
je 0x6c550
movq %rbx, 0x40(%rax)
movl %r14d, 0x2c(%rax)
movw $0xffff, 0x30(%rax)     # imm = 0xFFFF
movq -0x30(%rbp), %rdi
movl $0x4e, %esi
movq %r12, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x42edf
jmp 0x6c677
leaq 0x10(%rbx), %rdx
movq (%rdx), %r13
movb 0x63(%r13), %cl
andb $0x3, %cl
leaq 0x28(%r13), %rdx
cmpb $0x2, %cl
jne 0x6c570
cmpw $0x0, 0x5e(%r13)
je 0x6c654
xorl %r14d, %r14d
xorl %edx, %edx
movq -0x38(%rbp), %r12
movq -0x30(%rbp), %rbx
movq %rdx, -0x60(%rbp)
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rax
movzwl (%rax,%r14,2), %r15d
movswl %r15w, %ecx
movq %rbx, %rdi
movq -0x48(%rbp), %rbx
movq %rbx, %rsi
movl 0x10(%rbp), %edx
callq 0x6c766
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rax
movl 0x4c(%rax), %eax
movl %eax, -0x58(%rbp)
movq $0x0, -0xc0(%rbp)
movl $0x0, -0xb8(%rbp)
movq %r12, %rdi
movl $0x98, %esi
leaq -0xc0(%rbp), %rdx
xorl %ecx, %ecx
callq 0x5589f
testq %rax, %rax
je 0x6c610
movq %rbx, 0x40(%rax)
movl -0x58(%rbp), %ecx
movl %ecx, 0x2c(%rax)
movw %r15w, 0x30(%rax)
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x4f, %esi
movq -0x40(%rbp), %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x42edf
movq -0x38(%rbp), %r12
movq %r12, %rdi
movq -0x60(%rbp), %rsi
movq %rax, %rdx
callq 0x591f9
movq %rax, %rdx
incq %r14
movzwl 0x5e(%r13), %eax
cmpq %rax, %r14
jb 0x6c59c
jmp 0x6c65e
xorl %edx, %edx
movq -0x38(%rbp), %r12
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x13, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x42edf
movq -0x78(%rbp), %r15
movq %r12, %r13
movq %r13, %rdi
movq -0x68(%rbp), %rsi
movq %rax, %rdx
callq 0x591f9
movl 0x18(%rbp), %ebx
movq -0x30(%rbp), %r13
xorps %xmm0, %xmm0
leaq -0xc0(%rbp), %rdi
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movq $0x0, 0x30(%rdi)
movq -0x50(%rbp), %r14
movq %r14, 0x8(%rdi)
movq %r13, (%rdi)
movq %rax, %r12
movq %rax, %rsi
callq 0x55a7d
movl $0x0, (%rsp)
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %r13
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x5d034
movq %rax, %r14
movq -0x88(%rbp), %rax
movzbl 0x2c(%rax), %edx
movq %r15, %rdi
movl $0x88, %esi
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
testq %r14, %r14
je 0x6c70a
movq %r14, %rdi
callq 0x5ec9b
movq -0x38(%rbp), %rdi
movq %r13, %rsi
callq 0x3c8fe
movl -0x6c(%rbp), %esi
testl %esi, %esi
je 0x6c754
movl 0x3c(%r15), %eax
leal -0x1(%rax), %ecx
movq 0x30(%r15), %rdx
movl %ecx, 0x68(%rdx)
movq (%r15), %rdx
cmpb $0x0, 0x51(%rdx)
je 0x6c73d
leaq 0x26dbd(%rip), %rcx     # 0x934f8
jmp 0x6c751
testl %esi, %esi
cmovnsl %esi, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%r15), %rcx
movl %eax, 0x8(%rcx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq