// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: whereLoopAddVirtualOne
static int whereLoopAddVirtualOne(
  WhereLoopBuilder *pBuilder,
  Bitmask mPrereq,                /* Mask of tables that must be used. */
  Bitmask mUsable,                /* Mask of usable tables */
  u16 mExclude,                   /* Exclude terms using these operators */
  sqlite3_index_info *pIdxInfo,   /* Populated object for xBestIndex */
  u16 mNoOmit,                    /* Do not omit these constraints */
  int *pbIn                       /* OUT: True if plan uses an IN(...) op */
){
  WhereClause *pWC = pBuilder->pWC;
  struct sqlite3_index_constraint *pIdxCons;
  struct sqlite3_index_constraint_usage *pUsage = pIdxInfo->aConstraintUsage;
  int i;
  int mxTerm;
  int rc = SQLITE_OK;
  WhereLoop *pNew = pBuilder->pNew;
  Parse *pParse = pBuilder->pWInfo->pParse;
  struct SrcList_item *pSrc = &pBuilder->pWInfo->pTabList->a[pNew->iTab];
  int nConstraint = pIdxInfo->nConstraint;

  assert( (mUsable & mPrereq)==mPrereq );
  *pbIn = 0;
  pNew->prereq = mPrereq;

  /* Set the usable flag on the subset of constraints identified by
  ** arguments mUsable and mExclude. */
  pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
  for(i=0; i<nConstraint; i++, pIdxCons++){
    WhereTerm *pTerm = &pWC->a[pIdxCons->iTermOffset];
    pIdxCons->usable = 0;
    if( (pTerm->prereqRight & mUsable)==pTerm->prereqRight
     && (pTerm->eOperator & mExclude)==0
    ){
      pIdxCons->usable = 1;
    }
  }

  /* Initialize the output fields of the sqlite3_index_info structure */
  memset(pUsage, 0, sizeof(pUsage[0])*nConstraint);
  assert( pIdxInfo->needToFreeIdxStr==0 );
  pIdxInfo->idxStr = 0;
  pIdxInfo->idxNum = 0;
  pIdxInfo->orderByConsumed = 0;
  pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
  pIdxInfo->estimatedRows = 25;
  pIdxInfo->idxFlags = 0;
  pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;

  /* Invoke the virtual table xBestIndex() method */
  rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo);
  if( rc ){
    if( rc==SQLITE_CONSTRAINT ){
      /* If the xBestIndex method returns SQLITE_CONSTRAINT, that means
      ** that the particular combination of parameters provided is unusable.
      ** Make no entries in the loop table.
      */
      WHERETRACE(0xffff, ("  ^^^^--- non-viable plan rejected!\n"));
      return SQLITE_OK;
    }
    return rc;
  }

  mxTerm = -1;
  assert( pNew->nLSlot>=nConstraint );
  for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
  pNew->u.vtab.omitMask = 0;
  pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
  for(i=0; i<nConstraint; i++, pIdxCons++){
    int iTerm;
    if( (iTerm = pUsage[i].argvIndex - 1)>=0 ){
      WhereTerm *pTerm;
      int j = pIdxCons->iTermOffset;
      if( iTerm>=nConstraint
       || j<0
       || j>=pWC->nTerm
       || pNew->aLTerm[iTerm]!=0
       || pIdxCons->usable==0
      ){
        sqlite3ErrorMsg(pParse,"%s.xBestIndex malfunction",pSrc->pTab->zName);
        testcase( pIdxInfo->needToFreeIdxStr );
        return SQLITE_ERROR;
      }
      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( pUsage[i].omit ){
        if( i<16 && ((1<<i)&mNoOmit)==0 ){
          testcase( i!=iTerm );
          pNew->u.vtab.omitMask |= 1<<iTerm;
        }else{
          testcase( i!=iTerm );
        }
      }
      if( (pTerm->eOperator & WO_IN)!=0 ){
        /* 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;
        *pbIn = 1; assert( (mExclude & WO_IN)==0 );
      }
    }
  }

  pNew->nLTerm = mxTerm+1;
  for(i=0; i<=mxTerm; i++){
    if( pNew->aLTerm[i]==0 ){
      /* The non-zero argvIdx values must be contiguous.  Raise an
      ** error if they are not */
      sqlite3ErrorMsg(pParse,"%s.xBestIndex malfunction",pSrc->pTab->zName);
      testcase( pIdxInfo->needToFreeIdxStr );
      return SQLITE_ERROR;
    }
  }
  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;
  }
  rc = whereLoopInsert(pBuilder, pNew);
  if( pNew->u.vtab.needFree ){
    sqlite3_free(pNew->u.vtab.idxStr);
    pNew->u.vtab.needFree = 0;
  }
  WHERETRACE(0xffff, ("  bIn=%d prereqIn=%04llx prereqOut=%04llx\n",
                      *pbIn, (sqlite3_uint64)mPrereq,
                      (sqlite3_uint64)(pNew->prereq & ~mPrereq)));

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movw %r9w, %ax
movq 0x10(%rbp), %r9
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movw %cx, -0x22(%rbp)
movq %r8, -0x30(%rbp)
movw %ax, -0x32(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
addq $0x8, %rax
movq -0x68(%rbp), %rcx
movzbl 0x10(%rcx), %ecx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
movq 0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x4529ab
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x48(%rbp), %rcx
movslq 0x8(%rcx), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rax
movb $0x0, 0x5(%rax)
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
andq -0x20(%rbp), %rax
movq -0x88(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jne 0x45298f
movq -0x88(%rbp), %rax
movzwl 0x14(%rax), %eax
movzwl -0x22(%rbp), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x45298f
movq -0x48(%rbp), %rax
movb $0x1, 0x5(%rax)
jmp 0x452991
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x48(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x48(%rbp)
jmp 0x452927
movq -0x50(%rbp), %rdi
movslq -0x7c(%rbp), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x19360
movq -0x30(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x30(%rbp), %rax
movsd 0x15828c(%rip), %xmm0   # 0x5aac78
movsd %xmm0, 0x40(%rax)
movq -0x30(%rbp), %rax
movq $0x19, 0x48(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x78(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x30(%rbp), %rdx
callq 0x452dd0
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x452a53
cmpl $0x13, -0x5c(%rbp)
jne 0x452a48
movl $0x0, -0x4(%rbp)
jmp 0x452dbd
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x452dbd
movl $0xffffffff, -0x58(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x452a88
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x54(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x452a61
movq -0x68(%rbp), %rax
movw $0x0, 0x1e(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x452c48
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl (%rax,%rcx,8), %eax
subl $0x1, %eax
movl %eax, -0x8c(%rbp)
cmpl $0x0, %eax
jl 0x452c2c
movq -0x48(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x9c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x452b21
cmpl $0x0, -0x9c(%rbp)
jl 0x452b21
movl -0x9c(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x452b21
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x8c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x452b21
movq -0x48(%rbp), %rax
movzbl 0x5(%rax), %eax
cmpl $0x0, %eax
jne 0x452b4a
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rdx
leaq 0x15b2cf(%rip), %rsi    # 0x5ade06
movb $0x0, %al
callq 0x3cb660
movl $0x1, -0x4(%rbp)
jmp 0x452dbd
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x9c(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x68(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movq -0x98(%rbp), %rdx
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x8c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x8c(%rbp), %eax
cmpl -0x58(%rbp), %eax
jle 0x452baa
movl -0x8c(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
cmpb $0x0, 0x4(%rax,%rcx,8)
je 0x452bf5
cmpl $0x10, -0x54(%rbp)
jge 0x452bf1
movl -0x54(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movzwl -0x32(%rbp), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x452bf1
movl -0x8c(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movq -0x68(%rbp), %rax
movzwl 0x1e(%rax), %ecx
orl %edx, %ecx
movw %cx, 0x1e(%rax)
jmp 0x452bf3
jmp 0x452bf3
jmp 0x452bf5
movq -0x98(%rbp), %rax
movzwl 0x14(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x452c2a
movq -0x30(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x30(%rbp), %rax
movl 0x50(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x50(%rax)
movq 0x10(%rbp), %rax
movl $0x1, (%rax)
jmp 0x452c2c
jmp 0x452c2e
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x48(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x48(%rbp)
jmp 0x452aa5
movl -0x58(%rbp), %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x68(%rbp), %rax
movw %cx, 0x2c(%rax)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x58(%rbp), %eax
jg 0x452cb1
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x54(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x452ca4
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rdx
leaq 0x15b175(%rip), %rsi    # 0x5ade06
movb $0x0, %al
callq 0x3cb660
movl $0x1, -0x4(%rbp)
jmp 0x452dbd
jmp 0x452ca6
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x452c60
movq -0x30(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x30(%rbp), %rax
movl 0x38(%rax), %eax
movb %al, %cl
movq -0x68(%rbp), %rax
movb %cl, 0x1c(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x452d03
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0xa0(%rbp)
jmp 0x452d0d
xorl %eax, %eax
movl %eax, -0xa0(%rbp)
jmp 0x452d0d
movl -0xa0(%rbp), %eax
movb %al, %cl
movq -0x68(%rbp), %rax
movb %cl, 0x1d(%rax)
movq -0x68(%rbp), %rax
movw $0x0, 0x12(%rax)
movq -0x30(%rbp), %rax
movsd 0x40(%rax), %xmm0
callq 0x452eb0
movw %ax, %cx
movq -0x68(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x3fcec0
movw %ax, %cx
movq -0x68(%rbp), %rax
movw %cx, 0x16(%rax)
movq -0x30(%rbp), %rax
movl 0x50(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x452d78
movq -0x68(%rbp), %rax
movl 0x28(%rax), %ecx
orl $0x1000, %ecx           # imm = 0x1000
movl %ecx, 0x28(%rax)
jmp 0x452d88
movq -0x68(%rbp), %rax
movl 0x28(%rax), %ecx
andl $0xffffefff, %ecx       # imm = 0xFFFFEFFF
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x452f50
movl %eax, -0x5c(%rbp)
movq -0x68(%rbp), %rax
cmpb $0x0, 0x1c(%rax)
je 0x452db7
movq -0x68(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x3c0800
movq -0x68(%rbp), %rax
movb $0x0, 0x1c(%rax)
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)