// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: whereLoopAddVirtual
static int whereLoopAddVirtual(
  WhereLoopBuilder *pBuilder,  /* WHERE clause information */
  Bitmask mExtra,              /* Tables that must be scanned before this one */
  Bitmask mUnusable            /* Tables that must be scanned after this one */
){
  WhereInfo *pWInfo;           /* WHERE analysis context */
  Parse *pParse;               /* The parsing context */
  WhereClause *pWC;            /* The WHERE clause */
  struct SrcList_item *pSrc;   /* The FROM clause term to search */
  Table *pTab;
  sqlite3 *db;
  sqlite3_index_info *pIdxInfo;
  struct sqlite3_index_constraint *pIdxCons;
  struct sqlite3_index_constraint_usage *pUsage;
  WhereTerm *pTerm;
  int i, j;
  int iTerm, mxTerm;
  int nConstraint;
  int seenIn = 0;              /* True if an IN operator is seen */
  int seenVar = 0;             /* True if a non-constant constraint is seen */
  int iPhase;                  /* 0: const w/o IN, 1: const, 2: no IN,  2: IN */
  WhereLoop *pNew;
  int rc = SQLITE_OK;

  assert( (mExtra & mUnusable)==0 );
  pWInfo = pBuilder->pWInfo;
  pParse = pWInfo->pParse;
  db = pParse->db;
  pWC = pBuilder->pWC;
  pNew = pBuilder->pNew;
  pSrc = &pWInfo->pTabList->a[pNew->iTab];
  pTab = pSrc->pTab;
  assert( IsVirtual(pTab) );
  pIdxInfo = allocateIndexInfo(pParse, pWC, mUnusable, pSrc,pBuilder->pOrderBy);
  if( pIdxInfo==0 ) return SQLITE_NOMEM;
  pNew->prereq = 0;
  pNew->rSetup = 0;
  pNew->wsFlags = WHERE_VIRTUALTABLE;
  pNew->nLTerm = 0;
  pNew->u.vtab.needFree = 0;
  pUsage = pIdxInfo->aConstraintUsage;
  nConstraint = pIdxInfo->nConstraint;
  if( whereLoopResize(db, pNew, nConstraint) ){
    sqlite3DbFree(db, pIdxInfo);
    return SQLITE_NOMEM;
  }

  for(iPhase=0; iPhase<=3; iPhase++){
    if( !seenIn && (iPhase&1)!=0 ){
      iPhase++;
      if( iPhase>3 ) break;
    }
    if( !seenVar && iPhase>1 ) break;
    pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
    for(i=0; i<pIdxInfo->nConstraint; i++, pIdxCons++){
      j = pIdxCons->iTermOffset;
      pTerm = &pWC->a[j];
      switch( iPhase ){
        case 0:    /* Constants without IN operator */
          pIdxCons->usable = 0;
          if( (pTerm->eOperator & WO_IN)!=0 ){
            seenIn = 1;
          }
          if( (pTerm->prereqRight & ~mExtra)!=0 ){
            seenVar = 1;
          }else if( (pTerm->eOperator & WO_IN)==0 ){
            pIdxCons->usable = 1;
          }
          break;
        case 1:    /* Constants with IN operators */
          assert( seenIn );
          pIdxCons->usable = (pTerm->prereqRight & ~mExtra)==0;
          break;
        case 2:    /* Variables without IN */
          assert( seenVar );
          pIdxCons->usable = (pTerm->eOperator & WO_IN)==0;
          break;
        default:   /* Variables with IN */
          assert( seenVar && seenIn );
          pIdxCons->usable = 1;
          break;
      }
    }
    memset(pUsage, 0, sizeof(pUsage[0])*pIdxInfo->nConstraint);
    if( pIdxInfo->needToFreeIdxStr ) sqlite3_free(pIdxInfo->idxStr);
    pIdxInfo->idxStr = 0;
    pIdxInfo->idxNum = 0;
    pIdxInfo->needToFreeIdxStr = 0;
    pIdxInfo->orderByConsumed = 0;
    pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
    pIdxInfo->estimatedRows = 25;
    pIdxInfo->idxFlags = 0;
    pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;
    rc = vtabBestIndex(pParse, pTab, pIdxInfo);
    if( rc ) goto whereLoopAddVtab_exit;
    pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
    pNew->prereq = mExtra;
    mxTerm = -1;
    assert( pNew->nLSlot>=nConstraint );
    for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
    pNew->u.vtab.omitMask = 0;
    for(i=0; i<nConstraint; i++, pIdxCons++){
      if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){
        j = pIdxCons->iTermOffset;
        if( iTerm>=nConstraint
         || j<0
         || j>=pWC->nTerm
         || pNew->aLTerm[iTerm]!=0
        ){
          rc = SQLITE_ERROR;
          sqlite3ErrorMsg(pParse, "%s.xBestIndex() malfunction", pTab->zName);
          goto whereLoopAddVtab_exit;
        }
        testcase( iTerm==nConstraint-1 );
        testcase( j==0 );
        testcase( j==pWC->nTerm-1 );
        pTerm = &pWC->a[j];
        pNew->prereq |= pTerm->prereqRight;
        assert( iTerm<pNew->nLSlot );
        pNew->aLTerm[iTerm] = pTerm;
        if( iTerm>mxTerm ) mxTerm = iTerm;
        testcase( iTerm==15 );
        testcase( iTerm==16 );
        if( iTerm<16 && pUsage[i].omit ) pNew->u.vtab.omitMask |= 1<<iTerm;
        if( (pTerm->eOperator & WO_IN)!=0 ){
          if( pUsage[i].omit==0 ){
            /* Do not attempt to use an IN constraint if the virtual table
            ** says that the equivalent EQ constraint cannot be safely omitted.
            ** If we do attempt to use such a constraint, some rows might be
            ** repeated in the output. */
            break;
          }
          /* A virtual table that is constrained by an IN clause may not
          ** consume the ORDER BY clause because (1) the order of IN terms
          ** is not necessarily related to the order of output terms and
          ** (2) Multiple outputs from a single IN value will not merge
          ** together.  */
          pIdxInfo->orderByConsumed = 0;
          pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
        }
      }
    }
    if( i>=nConstraint ){
      pNew->nLTerm = mxTerm+1;
      assert( pNew->nLTerm<=pNew->nLSlot );
      pNew->u.vtab.idxNum = pIdxInfo->idxNum;
      pNew->u.vtab.needFree = pIdxInfo->needToFreeIdxStr;
      pIdxInfo->needToFreeIdxStr = 0;
      pNew->u.vtab.idxStr = pIdxInfo->idxStr;
      pNew->u.vtab.isOrdered = (i8)(pIdxInfo->orderByConsumed ?
                                      pIdxInfo->nOrderBy : 0);
      pNew->rSetup = 0;
      pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
      pNew->nOut = sqlite3LogEst(pIdxInfo->estimatedRows);

      /* Set the WHERE_ONEROW flag if the xBestIndex() method indicated
      ** that the scan will visit at most one row. Clear it otherwise. */
      if( pIdxInfo->idxFlags & SQLITE_INDEX_SCAN_UNIQUE ){
        pNew->wsFlags |= WHERE_ONEROW;
      }else{
        pNew->wsFlags &= ~WHERE_ONEROW;
      }
      whereLoopInsert(pBuilder, pNew);
      if( pNew->u.vtab.needFree ){
        sqlite3_free(pNew->u.vtab.idxStr);
        pNew->u.vtab.needFree = 0;
      }
    }
  }  

whereLoopAddVtab_exit:
  if( pIdxInfo->needToFreeIdxStr ) sqlite3_free(pIdxInfo->idxStr);
  sqlite3DbFree(db, pIdxInfo);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movl $0x0, -0x9c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x8, %rax
movq -0x98(%rbp), %rcx
movzbl 0x10(%rcx), %ecx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %r8
callq 0x8b1a0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x89c93
movl $0x7, -0x4(%rbp)
jmp 0x8a2ec
movq -0x98(%rbp), %rax
movq $0x0, (%rax)
movq -0x98(%rbp), %rax
movw $0x0, 0x12(%rax)
movq -0x98(%rbp), %rax
movl $0x400, 0x28(%rax)      # imm = 0x400
movq -0x98(%rbp), %rax
movw $0x0, 0x2c(%rax)
movq -0x98(%rbp), %rax
movb $0x0, 0x1c(%rax)
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x50(%rbp), %rdi
movq -0x98(%rbp), %rsi
movl -0x84(%rbp), %edx
callq 0x8b540
cmpl $0x0, %eax
je 0x89d20
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0xd260
movl $0x7, -0x4(%rbp)
jmp 0x8a2ec
movl $0x0, -0x90(%rbp)
cmpl $0x3, -0x90(%rbp)
jg 0x8a2bd
cmpl $0x0, -0x88(%rbp)
jne 0x89d6d
movl -0x90(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x89d6d
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
cmpl $0x3, -0x90(%rbp)
jle 0x89d6b
jmp 0x8a2bd
jmp 0x89d6d
cmpl $0x0, -0x8c(%rbp)
jne 0x89d84
cmpl $0x1, -0x90(%rbp)
jle 0x89d84
jmp 0x8a2bd
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x89ecc
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x78(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0xa0(%rbp)
testl %eax, %eax
je 0x89dfa
jmp 0x89dd9
movl -0xa0(%rbp), %eax
subl $0x1, %eax
je 0x89e5d
jmp 0x89de6
movl -0xa0(%rbp), %eax
subl $0x2, %eax
je 0x89e87
jmp 0x89ea8
movq -0x60(%rbp), %rax
movb $0x0, 0x5(%rax)
movq -0x70(%rbp), %rax
movzwl 0x1a(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x89e1c
movl $0x1, -0x88(%rbp)
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x89e41
movl $0x1, -0x8c(%rbp)
jmp 0x89e5b
movq -0x70(%rbp), %rax
movzwl 0x1a(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x89e59
movq -0x60(%rbp), %rax
movb $0x1, 0x5(%rax)
jmp 0x89e5b
jmp 0x89eb0
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
movq -0x60(%rbp), %rax
movb %cl, 0x5(%rax)
jmp 0x89eb0
movq -0x70(%rbp), %rax
movzwl 0x1a(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
movq -0x60(%rbp), %rax
movb %cl, 0x5(%rax)
jmp 0x89eb0
movq -0x60(%rbp), %rax
movb $0x1, 0x5(%rax)
jmp 0x89eb2
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movq -0x60(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x60(%rbp)
jmp 0x89d97
movq -0x68(%rbp), %rdi
movq -0x58(%rbp), %rax
movslq (%rax), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0xb2b0
movq -0x58(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x89ef9
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0xb958
movq -0x58(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x58(%rbp), %rax
movsd 0x1b996(%rip), %xmm0    # 0xa58c8
movsd %xmm0, 0x40(%rax)
movq -0x58(%rbp), %rax
movq $0x19, 0x48(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x8b610
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
je 0x89f83
jmp 0x8a2bf
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rcx
movq -0x98(%rbp), %rax
movq %rcx, (%rax)
movl $0xffffffff, -0x80(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x84(%rbp), %eax
jge 0x89fd8
movq -0x98(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x74(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x89fab
movq -0x98(%rbp), %rax
movw $0x0, 0x1e(%rax)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x84(%rbp), %eax
jge 0x8a158
movq -0x68(%rbp), %rax
movslq -0x74(%rbp), %rcx
movl (%rax,%rcx,8), %eax
subl $0x1, %eax
movl %eax, -0x7c(%rbp)
cmpl $0x0, %eax
jl 0x8a13c
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x78(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x84(%rbp), %eax
jge 0x8a052
cmpl $0x0, -0x78(%rbp)
jl 0x8a052
movl -0x78(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x8a052
movq -0x98(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x7c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x8a07a
movl $0x1, -0x9c(%rbp)
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rax
movq (%rax), %rdx
leaq 0x1e2fe(%rip), %rsi     # 0xa836c
movb $0x0, %al
callq 0x17840
jmp 0x8a2bf
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x78(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x98(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movq -0x70(%rbp), %rdx
movq -0x98(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x7c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jle 0x8a0cb
movl -0x7c(%rbp), %eax
movl %eax, -0x80(%rbp)
cmpl $0x10, -0x7c(%rbp)
jge 0x8a0fe
movq -0x68(%rbp), %rax
movslq -0x74(%rbp), %rcx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x0, %eax
je 0x8a0fe
movl -0x7c(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movq -0x98(%rbp), %rax
movzwl 0x1e(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1e(%rax)
movq -0x70(%rbp), %rax
movzwl 0x1a(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x8a13a
movq -0x68(%rbp), %rax
movslq -0x74(%rbp), %rcx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x0, %eax
jne 0x8a122
jmp 0x8a158
movq -0x58(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x58(%rbp), %rax
movl 0x50(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x50(%rax)
jmp 0x8a13c
jmp 0x8a13e
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movq -0x60(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x60(%rbp)
jmp 0x89fec
movl -0x74(%rbp), %eax
cmpl -0x84(%rbp), %eax
jl 0x8a2a7
movl -0x80(%rbp), %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x98(%rbp), %rax
movw %cx, 0x2c(%rax)
movq -0x58(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x58(%rbp), %rax
movl 0x38(%rax), %eax
movb %al, %cl
movq -0x98(%rbp), %rax
movb %cl, 0x1c(%rax)
movq -0x58(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x58(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x8a1d6
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0xa4(%rbp)
jmp 0x8a1e0
xorl %eax, %eax
movl %eax, -0xa4(%rbp)
jmp 0x8a1e0
movl -0xa4(%rbp), %eax
movb %al, %cl
movq -0x98(%rbp), %rax
movb %cl, 0x1d(%rax)
movq -0x98(%rbp), %rax
movw $0x0, 0x12(%rax)
movq -0x58(%rbp), %rax
movsd 0x40(%rax), %xmm0
callq 0x8b750
movw %ax, %cx
movq -0x98(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x58(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x530d0
movw %ax, %cx
movq -0x98(%rbp), %rax
movw %cx, 0x16(%rax)
movq -0x58(%rbp), %rax
movl 0x50(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x8a25a
movq -0x98(%rbp), %rax
movl 0x28(%rax), %ecx
orl $0x1000, %ecx           # imm = 0x1000
movl %ecx, 0x28(%rax)
jmp 0x8a26d
movq -0x98(%rbp), %rax
movl 0x28(%rax), %ecx
andl $0xffffefff, %ecx       # imm = 0xFFFFEFFF
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x8b7f0
movq -0x98(%rbp), %rax
cmpb $0x0, 0x1c(%rax)
je 0x8a2a5
movq -0x98(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0xb958
movq -0x98(%rbp), %rax
movb $0x0, 0x1c(%rax)
jmp 0x8a2a7
jmp 0x8a2a9
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x89d2a
jmp 0x8a2bf
movq -0x58(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x8a2d6
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0xb958
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0xd260
movl -0x9c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)