// File: /workspace/github_c_makefile_star2_O0/skeeto[P]flappy/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);
  }

  /* 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];
        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. If the constraint is not deferred, throw an exception for
  ** each row found. Otherwise, for deferred constraints, increment the
  ** deferred constraint counter by nIncr for each row selected.  */
  pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
  if( nIncr>0 && pFKey->isDeferred==0 ){
    sqlite3ParseToplevel(pParse)->mayAbort = 1;
  }
  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
subq $0x110, %rsp            # imm = 0x110
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 0x638c0
movq %rax, -0x98(%rbp)
cmpl $0x0, 0x18(%rbp)
jge 0x862dd
movq -0x98(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %edx
movl $0x7e, %esi
xorl %ecx, %ecx
callq 0x63980
movl %eax, -0x8c(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x8640d
cmpq $0x0, -0x20(%rbp)
je 0x86313
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0xf8(%rbp)
jmp 0x86320
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xf8(%rbp)
jmp 0x86320
movl -0xf8(%rbp), %eax
movw %ax, -0xb2(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movswl -0xb2(%rbp), %ecx
callq 0x866d0
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x86365
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xfc(%rbp)
jmp 0x86372
movq -0x28(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
movw %ax, -0xb2(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movswq -0xb2(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x38(%rbp), %rdi
movq -0xc0(%rbp), %rdx
movl $0x1b, %esi
callq 0x59400
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %rcx
movl $0x4d, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x55230
movq %rax, -0xb0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xb0(%rbp), %rdx
callq 0x70230
movq %rax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x862e4
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x865c0
cmpl $0x0, 0x18(%rbp)
jle 0x865c0
movq -0x18(%rbp), %rax
movzbl 0x48(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0x864a1
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x866d0
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x867d0
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rcx
movl $0x4c, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x55230
movq %rax, -0xc8(%rbp)
jmp 0x865a8
movq $0x0, -0xe8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4b190
movq %rax, -0xf0(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0xf0(%rbp), %rcx
movzwl 0x5e(%rcx), %ecx
cmpl %ecx, %eax
jge 0x86584
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0xf2(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x10(%rbp), %edx
movswl -0xf2(%rbp), %ecx
callq 0x866d0
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x44(%rax), %edx
movswl -0xf2(%rbp), %ecx
callq 0x867d0
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
movq -0xd8(%rbp), %rcx
movl $0x4d, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x55230
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
callq 0x70230
movq %rax, -0xe8(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x864c3
movq -0x8(%rbp), %rdi
movq -0xe8(%rbp), %rdx
movl $0x13, %esi
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x55230
movq %rax, -0xc8(%rbp)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xc8(%rbp), %rdx
callq 0x70230
movq %rax, -0x48(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x71a0
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 0x6bca0
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 0x746d0
movq %rax, -0x88(%rbp)
cmpl $0x0, 0x18(%rbp)
jle 0x86662
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x0, %eax
jne 0x86662
movq -0x8(%rbp), %rax
cmpq $0x0, 0x1e0(%rax)
je 0x8664c
movq -0x8(%rbp), %rax
movq 0x1e0(%rax), %rax
movq %rax, -0x108(%rbp)
jmp 0x86657
movq -0x8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
movb $0x1, 0x24(%rax)
movq -0x98(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %edx
movl 0x18(%rbp), %ecx
movl $0x7d, %esi
callq 0x63980
cmpq $0x0, -0x88(%rbp)
je 0x86694
movq -0x88(%rbp), %rdi
callq 0x75aa0
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4b970
cmpl $0x0, -0x8c(%rbp)
je 0x866bc
movq -0x98(%rbp), %rdi
movl -0x8c(%rbp), %esi
callq 0x63950
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)