// File: /workspace/github_c_makefile_star2_O1/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, -0x78(%rbp)
movq %rdx, -0x48(%rbp)
movq %rsi, -0x50(%rbp)
movq %rdi, %r15
movq (%rdi), %r14
callq 0x507bf
movq %rax, %rbx
xorl %eax, %eax
cmpl $0x0, 0x18(%rbp)
jns 0x6da08
movzbl 0x2c(%r13), %edx
movq %rbx, %rdi
movl $0x89, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movq %r15, -0x30(%rbp)
movq %r14, -0x38(%rbp)
movl %eax, -0x6c(%rbp)
movq %rbx, -0x88(%rbp)
cmpl $0x0, 0x28(%r13)
jle 0x6dae4
leaq 0x40(%r13), %rax
movq %rax, -0x58(%rbp)
xorl %r14d, %r14d
movq -0x40(%rbp), %r12
xorl %eax, %eax
movq -0x30(%rbp), %r15
movq -0x78(%rbp), %rcx
testq %rcx, %rcx
movq %rax, -0x68(%rbp)
je 0x6da52
movq 0x8(%rcx), %rax
movzwl (%rax,%r14,2), %eax
jmp 0x6da56
movw $0xffff, %ax            # imm = 0xFFFF
movq -0x48(%rbp), %rsi
movswl %ax, %ecx
movq %r15, %rdi
movl 0x10(%rbp), %edx
callq 0x6ddbe
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x40(%rbp)
movq %r12, %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 0x477b9
movq %r15, %rdi
movl $0x4f, %esi
movq -0x60(%rbp), %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x43f28
movq %r13, %rdi
movq %rbx, %r13
movq -0x68(%rbp), %rsi
movq %rax, %rdx
callq 0x5a64c
incq %r14
movslq 0x28(%rbx), %rcx
addq $0x4, %r12
cmpq %rcx, %r14
jl 0x6da3a
jmp 0x6dae6
xorl %eax, %eax
movl 0x18(%rbp), %ebx
testl %ebx, %ebx
movq %r13, -0x80(%rbp)
jle 0x6dbac
movq -0x48(%rbp), %rcx
cmpq %rcx, (%r13)
movq -0x38(%rbp), %r15
movq -0x30(%rbp), %r13
jne 0x6dcdb
testb $0x20, 0x46(%rcx)
movq %rcx, %rbx
movq %rax, -0x68(%rbp)
jne 0x6dbb5
movq (%r13), %rdi
leaq -0xc0(%rbp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
xorl %r12d, %r12d
movl $0x9d, %esi
xorl %ecx, %ecx
callq 0x56afe
testq %rax, %rax
movq -0x50(%rbp), %rcx
je 0x6db5a
movl 0x10(%rbp), %edx
movl %edx, 0x2c(%rax)
movb $0x44, 0x1(%rax)
movq %rax, %r12
movq %r15, %r13
movl 0x4c(%rcx), %r14d
leaq -0xc0(%rbp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movq %r15, %rdi
movl $0x98, %esi
xorl %ecx, %ecx
callq 0x56afe
testq %rax, %rax
je 0x6db98
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
jmp 0x6dcba
movq -0x38(%rbp), %r15
jmp 0x6dcd7
movq 0x10(%rbx), %rdx
testq %rdx, %rdx
je 0x6dbcf
movb 0x63(%rdx), %cl
andb $0x3, %cl
cmpb $0x2, %cl
je 0x6dbcf
movq 0x28(%rdx), %rdx
jmp 0x6dbb9
cmpw $0x0, 0x5e(%rdx)
je 0x6dca2
xorl %r14d, %r14d
xorl %r12d, %r12d
movq -0x38(%rbp), %r13
movq -0x30(%rbp), %rbx
movq %rdx, -0x58(%rbp)
movq -0x78(%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 0x6ddbe
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movl 0x4c(%rax), %eax
movl %eax, -0x40(%rbp)
movq $0x0, -0xc0(%rbp)
movl $0x0, -0xb8(%rbp)
movq %r13, %rdi
movl $0x98, %esi
leaq -0xc0(%rbp), %rdx
xorl %ecx, %ecx
callq 0x56afe
testq %rax, %rax
je 0x6dc5c
movq %rbx, 0x40(%rax)
movl -0x40(%rbp), %ecx
movl %ecx, 0x2c(%rax)
movw %r15w, 0x30(%rax)
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x4f, %esi
movq -0x60(%rbp), %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x43f28
movq -0x38(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x5a64c
movq %rax, %r12
incq %r14
movq -0x58(%rbp), %rdx
movzwl 0x5e(%rdx), %eax
cmpq %rax, %r14
jb 0x6dbec
jmp 0x6dcad
xorl %r12d, %r12d
movq -0x38(%rbp), %r13
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x13, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x43f28
movq %r13, %r15
movq %r13, %rdi
movq -0x68(%rbp), %rsi
movq %rax, %rdx
callq 0x5a64c
movl 0x18(%rbp), %ebx
movq -0x30(%rbp), %r13
xorps %xmm0, %xmm0
leaq -0xc0(%rbp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %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 0x56cd9
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 0x5e598
movq %rax, %r14
movq -0x80(%rbp), %rax
movzbl 0x2c(%rax), %edx
movq -0x88(%rbp), %r12
movq %r12, %rdi
movl $0x88, %esi
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
testq %r14, %r14
je 0x6dd5f
movq %r14, %rdi
callq 0x60262
movq %r15, %rdi
movq %r13, %rsi
callq 0x3d8f7
movl -0x6c(%rbp), %esi
testl %esi, %esi
je 0x6ddac
movl 0x3c(%r12), %eax
leal -0x1(%rax), %ecx
movq 0x30(%r12), %rdx
movl %ecx, 0x68(%rdx)
movq (%r12), %rdx
cmpb $0x0, 0x51(%rdx)
je 0x6dd94
leaq 0x27756(%rip), %rcx     # 0x954e8
jmp 0x6dda9
testl %esi, %esi
cmovnsl %esi, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%r12), %rcx
movl %eax, 0x8(%rcx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq