// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rcx, %rbp
movq %rdx, %r13
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
movq (%rdi), %rbx
callq 0x2bc630
movq %rax, %r15
xorl %eax, %eax
cmpl $0x0, 0xc8(%rsp)
jns 0x2e3653
movzbl 0x2c(%r14), %edx
movq %r15, %rdi
movl $0x2f, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %r13, 0x20(%rsp)
movq %r15, 0x40(%rsp)
movq %rbx, 0x28(%rsp)
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x28(%r14)
movq %r14, 0x18(%rsp)
movq %rbp, 0x30(%rsp)
jle 0x2e3733
leaq 0x40(%r14), %rax
movq %rax, 0x48(%rsp)
xorl %r14d, %r14d
movq 0x10(%rsp), %r15
xorl %r13d, %r13d
testq %rbp, %rbp
je 0x2e369f
movq 0x8(%rbp), %rax
movzwl (%rax,%r14,2), %eax
jmp 0x2e36a3
movw $0xffff, %ax            # imm = 0xFFFF
movq 0x20(%rsp), %rsi
movl 0xc0(%rsp), %edx
movswl %ax, %ecx
movq %r12, %rdi
callq 0x2e39b0
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 0x28(%rsp), %rdi
movl $0x3b, %esi
callq 0x2b1be4
movq %r12, %rdi
movl $0x35, %esi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x2ad3b5
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x2b6b0e
movq %rax, %r13
incq %r14
movslq 0x28(%rbp), %rax
addq $0x4, %r15
cmpq %rax, %r14
movq 0x30(%rsp), %rbp
jl 0x2e368f
jmp 0x2e3736
xorl %r13d, %r13d
cmpl $0x0, 0xc8(%rsp)
jle 0x2e37f7
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %rbp
cmpq %rbp, (%r15)
movq 0x8(%rsp), %rbx
jne 0x2e38c4
testb $-0x80, 0x40(%rbp)
jne 0x2e3801
movq (%r12), %rdi
leaq 0x50(%rsp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movl $0xad, %esi
xorl %ecx, %ecx
callq 0x2b1c27
movq %rax, %r14
testq %rax, %rax
je 0x2e37a1
movl 0xc0(%rsp), %eax
movl %eax, 0x2c(%r14)
movb $0x44, 0x1(%r14)
movq 0x8(%rsp), %rax
movl 0x48(%rax), %ebx
leaq 0x50(%rsp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movq 0x28(%rsp), %rdi
movl $0xa4, %esi
xorl %ecx, %ecx
callq 0x2b1c27
testq %rax, %rax
je 0x2e37df
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 0x2ad3b5
jmp 0x2e38ae
movq 0x18(%rsp), %r15
jmp 0x2e38bf
movq 0x30(%rsp), %rax
cmpw $0x0, 0x5e(%rax)
je 0x2e3898
xorl %ebp, %ebp
xorl %edx, %edx
movq 0x20(%rsp), %r14
movq %rdx, 0x10(%rsp)
movq 0x30(%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 0x2e39b0
movq %rax, %r15
movq 0x8(%r14), %rax
shlq $0x5, %rbx
movq (%rax,%rbx), %rdx
movq 0x28(%rsp), %rdi
movl $0x3b, %esi
callq 0x2b1be4
movq %r12, %rdi
movl $0x2d, %esi
movq %r15, %rdx
movq %rax, %rcx
callq 0x2ad3b5
movq %r12, %rdi
movq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0x2b6b0e
movq %rax, %rdx
incq %rbp
movq 0x30(%rsp), %rax
movzwl 0x5e(%rax), %eax
cmpq %rax, %rbp
jb 0x2e381a
jmp 0x2e389a
xorl %edx, %edx
movq %r12, %rdi
movl $0x13, %esi
xorl %ecx, %ecx
callq 0x2ad3b5
movq 0x18(%rsp), %r15
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x2b6b0e
movq %rax, %r13
movq 0x8(%rsp), %rbx
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movq $0x0, 0x30(%rdi)
movq %rbx, 0x8(%rdi)
movq %r12, (%rdi)
movq %r13, %rsi
callq 0x2c496c
cmpl $0x0, 0x30(%r12)
jne 0x2e393e
movl $0x0, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x2ce2c4
movq %rax, %rbx
movzbl 0x2c(%r15), %edx
movq 0x40(%rsp), %rdi
movl $0x95, %esi
movl 0xc8(%rsp), %ecx
xorl %r8d, %r8d
callq 0x2a83e1
testq %rbx, %rbx
je 0x2e393e
movq %rbx, %rdi
callq 0x2d11fa
testq %r13, %r13
je 0x2e3950
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x2a6164
movl 0x3c(%rsp), %esi
testl %esi, %esi
je 0x2e399e
movq 0x40(%rsp), %rdi
movl 0x90(%rdi), %eax
leal -0x1(%rax), %ecx
cmpl %esi, %ecx
jne 0x2e3972
movl %esi, 0x90(%rdi)
jmp 0x2e399e
movq (%rdi), %rdx
cmpb $0x0, 0x61(%rdx)
je 0x2e3984
leaq 0x1db506(%rip), %rcx    # 0x4bee88
jmp 0x2e399b
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