// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x8c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x4299d0
movq %rax, -0x98(%rbp)
cmpl $0x0, 0x18(%rbp)
jge 0x45d16d
movq -0x98(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %edx
movl $0x2f, %esi
xorl %ecx, %ecx
callq 0x410100
movl %eax, -0x8c(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x45d298
cmpq $0x0, -0x20(%rbp)
je 0x45d1a3
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0xf0(%rbp)
jmp 0x45d1b0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xf0(%rbp)
jmp 0x45d1b0
movl -0xf0(%rbp), %eax
movw %ax, -0xb2(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movswl -0xb2(%rbp), %ecx
callq 0x45d500
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x45d1f5
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xf4(%rbp)
jmp 0x45d202
movq -0x28(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
movw %ax, -0xb2(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movswq -0xb2(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x38(%rbp), %rdi
movq -0xc0(%rbp), %rdx
movl $0x3b, %esi
callq 0x41d620
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %rcx
movl $0x35, %esi
callq 0x418540
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xb0(%rbp), %rdx
callq 0x4229d0
movq %rax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x45d174
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x45d438
cmpl $0x0, 0x18(%rbp)
jle 0x45d438
movq -0x18(%rbp), %rax
movl 0x40(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x45d328
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x45d500
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x48(%rax), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x45d610
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rcx
movl $0x34, %esi
callq 0x418540
movq %rax, -0xc8(%rbp)
jmp 0x45d420
movq $0x0, -0xe8(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x20(%rbp), %rcx
movzwl 0x5e(%rcx), %ecx
cmpl %ecx, %eax
jge 0x45d400
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0xea(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movswl -0xea(%rbp), %ecx
callq 0x45d500
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movswq -0xea(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movl $0x3b, %esi
callq 0x41d620
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rcx
movl $0x2d, %esi
callq 0x418540
movq %rax, -0xe0(%rbp)
movq -0x8(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
callq 0x4229d0
movq %rax, -0xe8(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x45d33a
movq -0x8(%rbp), %rdi
movq -0xe8(%rbp), %rdx
movl $0x13, %esi
xorl %eax, %eax
movl %eax, %ecx
callq 0x418540
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xc8(%rbp), %rdx
callq 0x4229d0
movq %rax, -0x48(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x19360
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x435380
movq -0x8(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x45d4cd
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r8d
xorl %r9d, %r9d
movq %r8, %rcx
movl $0x0, (%rsp)
callq 0x4415b0
movq %rax, -0x88(%rbp)
movq -0x98(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %edx
movl 0x18(%rbp), %ecx
movl $0x95, %esi
callq 0x410100
cmpq $0x0, -0x88(%rbp)
je 0x45d4cb
movq -0x88(%rbp), %rdi
callq 0x444120
jmp 0x45d4cd
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x40c670
cmpl $0x0, -0x8c(%rbp)
je 0x45d4f5
movq -0x98(%rbp), %rdi
movl -0x8c(%rbp), %esi
callq 0x45a1e0
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nop