// File: /workspace/github_c_makefile_star2_O1/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, 0x10(%rsp)
movq %r8, %rbx
movq %rcx, %rbp
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r12
movq (%rdi), %rax
movq %rax, 0x8(%rsp)
callq 0x2c5ddf
movq %rax, %r15
xorl %eax, %eax
cmpl $0x0, 0xc8(%rsp)
jns 0x2ec910
movzbl 0x2c(%rbx), %edx
movq %r15, %rdi
movl $0x2f, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %r13, 0x20(%rsp)
movq %r15, 0x40(%rsp)
movq %r14, 0x30(%rsp)
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x28(%rbx)
movq %rbx, 0x18(%rsp)
movq %rbp, 0x28(%rsp)
jle 0x2ec9ef
leaq 0x40(%rbx), %rax
movq %rax, 0x48(%rsp)
xorl %r14d, %r14d
movq 0x10(%rsp), %r15
xorl %r13d, %r13d
testq %rbp, %rbp
je 0x2ec95b
movq 0x8(%rbp), %rax
movzwl (%rax,%r14,2), %eax
jmp 0x2ec95f
movw $0xffff, %ax            # imm = 0xFFFF
movq 0x20(%rsp), %rsi
movl 0xc0(%rsp), %edx
movswl %ax, %ecx
movq %r12, %rdi
callq 0x2ecc70
movq %rax, %rbx
cmpq $0x0, 0x10(%rsp)
movq %r15, %rax
cmoveq 0x48(%rsp), %rax
movswq (%rax), %rax
movq 0x18(%rsp), %rbp
movq (%rbp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rdx
movq 0x8(%rsp), %rdi
movl $0x3b, %esi
callq 0x2bb34a
movq %r12, %rdi
movl $0x35, %esi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x2b6fa0
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x2c02f0
movq %rax, %r13
incq %r14
movslq 0x28(%rbp), %rax
addq $0x4, %r15
cmpq %rax, %r14
movq 0x28(%rsp), %rbp
jl 0x2ec94b
jmp 0x2ec9f2
xorl %r13d, %r13d
cmpl $0x0, 0xc8(%rsp)
movq 0x30(%rsp), %rbx
jle 0x2ecab4
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %rbp
cmpq %rbp, (%r15)
jne 0x2ecb81
testb $-0x80, 0x40(%rbp)
jne 0x2ecabe
movq (%r12), %rdi
leaq 0x50(%rsp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
xorl %r14d, %r14d
movl $0xad, %esi
xorl %ecx, %ecx
callq 0x2bb38d
testq %rax, %rax
je 0x2eca5e
movl 0xc0(%rsp), %ecx
movl %ecx, 0x2c(%rax)
movb $0x44, 0x1(%rax)
movq %rax, %r14
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rax
movl 0x48(%rax), %ebx
leaq 0x50(%rsp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movl $0xa4, %esi
xorl %ecx, %ecx
callq 0x2bb38d
testq %rax, %rax
je 0x2eca9c
movq %rbp, 0x40(%rax)
movl %ebx, 0x2c(%rax)
movw $0xffff, 0x30(%rax)     # imm = 0xFFFF
movq %r12, %rdi
movl $0x34, %esi
movq %r14, %rdx
movq %rax, %rcx
callq 0x2b6fa0
jmp 0x2ecb6b
movq 0x18(%rsp), %r15
jmp 0x2ecb81
movq 0x28(%rsp), %rax
cmpw $0x0, 0x5e(%rax)
je 0x2ecb55
xorl %ebp, %ebp
xorl %edx, %edx
movq 0x20(%rsp), %r14
movq %rdx, 0x10(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movswq (%rax,%rbp,2), %rbx
movq %r12, %rdi
movq %r14, %rsi
movl 0xc0(%rsp), %edx
movl %ebx, %ecx
callq 0x2ecc70
movq %rax, %r15
movq 0x8(%r14), %rax
shlq $0x5, %rbx
movq (%rax,%rbx), %rdx
movq 0x8(%rsp), %rdi
movl $0x3b, %esi
callq 0x2bb34a
movq %r12, %rdi
movl $0x2d, %esi
movq %r15, %rdx
movq %rax, %rcx
callq 0x2b6fa0
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0x2c02f0
movq %rax, %rdx
incq %rbp
movq 0x28(%rsp), %rax
movzwl 0x5e(%rax), %eax
cmpq %rax, %rbp
jb 0x2ecad7
jmp 0x2ecb57
xorl %edx, %edx
movq %r12, %rdi
movl $0x13, %esi
xorl %ecx, %ecx
callq 0x2b6fa0
movq 0x18(%rsp), %r15
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x2c02f0
movq %rax, %r13
movq 0x30(%rsp), %rbx
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movq $0x0, 0x30(%rdi)
movq %rbx, 0x8(%rdi)
movq %r12, (%rdi)
movq %r13, %rsi
callq 0x2ce0ea
cmpl $0x0, 0x30(%r12)
jne 0x2ecbfe
movl $0x0, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2d7b05
movq %rax, %rbx
movzbl 0x2c(%r15), %edx
movq 0x40(%rsp), %rdi
movl $0x95, %esi
movl 0xc8(%rsp), %ecx
xorl %r8d, %r8d
callq 0x2b200c
testq %rbx, %rbx
je 0x2ecbfe
movq %rbx, %rdi
callq 0x2daa07
testq %r13, %r13
je 0x2ecc10
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x2afd54
movl 0x3c(%rsp), %esi
testl %esi, %esi
je 0x2ecc5e
movq 0x40(%rsp), %rdi
movl 0x90(%rdi), %eax
leal -0x1(%rax), %ecx
cmpl %esi, %ecx
jne 0x2ecc32
movl %ecx, 0x90(%rdi)
jmp 0x2ecc5e
movq (%rdi), %rdx
cmpb $0x0, 0x61(%rdx)
je 0x2ecc44
leaq 0x1dd246(%rip), %rcx    # 0x4c9e88
jmp 0x2ecc5b
testl %esi, %esi
cmovnsl %esi, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%rdi), %rcx
movl %eax, 0x8(%rcx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq