// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: fkScanChildren
static void fkScanChildren(
  Parse *pParse,                  /* Parse context */
  SrcList *pSrc,                  /* SrcList containing the table to scan */
  Table *pTab,
  Index *pIdx,                    /* Foreign key index */
  FKey *pFKey,                    /* Foreign key relationship */
  int *aiCol,                     /* Map from pIdx cols to child table cols */
  int regData,                    /* Referenced table 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 || pIdx->pTable==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) */
    int iCol;                     /* Index of column in child table */ 
    const char *zCol;             /* Name of column in child table */

    pLeft = sqlite3Expr(db, TK_REGISTER, 0);
    if( pLeft ){
      /* Set the collation sequence and affinity of the LHS of each TK_EQ
      ** expression to the parent key column defaults.  */
      if( pIdx ){
        Column *pCol;
        const char *zColl;
        iCol = pIdx->aiColumn[i];
        pCol = &pTab->aCol[iCol];
        if( pTab->iPKey==iCol ) iCol = -1;
        pLeft->iTable = regData+iCol+1;
        pLeft->affinity = pCol->affinity;
        zColl = pCol->zColl;
        if( zColl==0 ) zColl = db->pDfltColl->zName;
        pLeft = sqlite3ExprAddCollateString(pParse, pLeft, zColl);
      }else{
        pLeft->iTable = regData;
        pLeft->affinity = SQLITE_AFF_INTEGER;
      }
    }
    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, and this scan
  ** is taking place as part of a DELETE operation (operation D.2), omit the
  ** row being deleted from the scan by adding ($rowid != rowid) to the WHERE 
  ** clause, where $rowid is the rowid of the row being deleted.  */
  if( pTab==pFKey->pFrom && nIncr>0 ){
    Expr *pEq;                    /* Expression (pLeft = pRight) */
    Expr *pLeft;                  /* Value from parent table row */
    Expr *pRight;                 /* Column ref to child table */
    pLeft = sqlite3Expr(db, TK_REGISTER, 0);
    pRight = sqlite3Expr(db, TK_COLUMN, 0);
    if( pLeft && pRight ){
      pLeft->iTable = regData;
      pLeft->affinity = SQLITE_AFF_INTEGER;
      pRight->iTable = pSrc->a[0].iCursor;
      pRight->iColumn = -1;
    }
    pEq = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
    pWhere = sqlite3ExprAnd(db, pWhere, pEq);
  }

  /* 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 $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 0x5e000
movq %rax, -0x98(%rbp)
cmpl $0x0, 0x18(%rbp)
jge 0x7edad
movq -0x98(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %edx
movl $0x7c, %esi
xorl %ecx, %ecx
callq 0x5e0c0
movl %eax, -0x8c(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x7ef94
movq -0x38(%rbp), %rdi
movl $0x84, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x548b0
movq %rax, -0xa0(%rbp)
cmpq $0x0, -0xa0(%rbp)
je 0x7eed4
cmpq $0x0, -0x20(%rbp)
je 0x7eeba
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xb4(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xb4(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rax
movswl 0x40(%rax), %eax
cmpl -0xb4(%rbp), %eax
jne 0x7ee42
movl $0xffffffff, -0xb4(%rbp) # imm = 0xFFFFFFFF
movl 0x10(%rbp), %ecx
addl -0xb4(%rbp), %ecx
addl $0x1, %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0xc8(%rbp), %rax
movb 0x29(%rax), %cl
movq -0xa0(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0xc8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, -0xd0(%rbp)
jne 0x7ee9a
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0xd0(%rbp), %rdx
callq 0x61710
movq %rax, -0xa0(%rbp)
jmp 0x7eed2
movl 0x10(%rbp), %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0xa0(%rbp), %rax
movb $0x64, 0x1(%rax)
jmp 0x7eed4
cmpq $0x0, -0x30(%rbp)
je 0x7eeee
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xec(%rbp)
jmp 0x7eefb
movq -0x28(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0xec(%rbp)
movl -0xec(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movslq -0xb4(%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 $0x1a, %esi
callq 0x548b0
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %rcx
movl $0x4c, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x508b0
movq %rax, -0xb0(%rbp)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xb0(%rbp), %rdx
callq 0x64b70
movq %rax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x7edb4
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x7f06b
cmpl $0x0, 0x18(%rbp)
jle 0x7f06b
movq -0x38(%rbp), %rdi
movl $0x84, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x548b0
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rdi
movl $0x98, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x548b0
movq %rax, -0xe8(%rbp)
cmpq $0x0, -0xe0(%rbp)
je 0x7f02b
cmpq $0x0, -0xe8(%rbp)
je 0x7f02b
movl 0x10(%rbp), %ecx
movq -0xe0(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0xe0(%rbp), %rax
movb $0x64, 0x1(%rax)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %ecx
movq -0xe8(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0xe8(%rbp), %rax
movw $0xffff, 0x30(%rax)     # imm = 0xFFFF
movq -0x8(%rbp), %rdi
movq -0xe0(%rbp), %rdx
movq -0xe8(%rbp), %rcx
movl $0x4b, %esi
xorl %eax, %eax
movl %eax, %r8d
callq 0x508b0
movq %rax, -0xd8(%rbp)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xd8(%rbp), %rdx
callq 0x64b70
movq %rax, -0x48(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x8200
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 0x5f5b0
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 0x6db30
movq %rax, -0x88(%rbp)
cmpl $0x0, 0x18(%rbp)
jle 0x7f10d
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x0, %eax
jne 0x7f10d
movq -0x8(%rbp), %rax
cmpq $0x0, 0x1d8(%rax)
je 0x7f0f7
movq -0x8(%rbp), %rax
movq 0x1d8(%rax), %rax
movq %rax, -0xf8(%rbp)
jmp 0x7f102
movq -0x8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
movb $0x1, 0x24(%rax)
movq -0x98(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x2c(%rax), %edx
movl 0x18(%rbp), %ecx
movl $0x7b, %esi
callq 0x5e0c0
cmpq $0x0, -0x88(%rbp)
je 0x7f13f
movq -0x88(%rbp), %rdi
callq 0x6ee10
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x47330
cmpl $0x0, -0x8c(%rbp)
je 0x7f167
movq -0x98(%rbp), %rdi
movl -0x8c(%rbp), %esi
callq 0x5e090
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq