// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, 0x14(%rsp)
movq %r8, %r15
movq 0x70(%rsp), %r8
movq (%rdi), %rax
movq 0x8(%rdi), %r12
movq 0x20(%r15), %r10
movq %rdi, 0x28(%rsp)
movq 0x18(%rdi), %rbx
movq (%rax), %rdi
movq %rdi, 0x8(%rsp)
movq 0x8(%rax), %r14
movzbl 0x10(%rbx), %eax
movslq (%r15), %rdi
andl $0x0, (%r8)
movq %rsi, (%rbx)
xorl %r8d, %r8d
testl %edi, %edi
movq %rdi, 0x20(%rsp)
cmovgl %edi, %r8d
movq 0x8(%r15), %rsi
addq $0x5, %rsi
notq %rdx
movl %r8d, 0x10(%rsp)
movl %r8d, %edi
subl $0x1, %edi
jb 0x27a482
movq 0x20(%r12), %r8
movslq 0x3(%rsi), %r9
shlq $0x6, %r9
movb $0x0, (%rsi)
testq %rdx, 0x30(%r8,%r9)
jne 0x27a47c
addq %r9, %r8
testw %cx, 0x14(%r8)
jne 0x27a47c
movb $0x1, (%rsi)
addq $0xc, %rsi
jmp 0x27a453
imulq $0x70, %rax, %r13
movq 0x20(%rsp), %rax
leaq (,%rax,8), %rdx
movq %r10, 0x18(%rsp)
movq %r10, %rdi
xorl %esi, %esi
callq 0x17380
andq $0x0, 0x30(%r15)
andl $0x0, 0x28(%r15)
andl $0x0, 0x3c(%r15)
movabsq $0x546d42aea2879f2e, %rax # imm = 0x546D42AEA2879F2E
movq %rax, 0x40(%r15)
movq $0x19, 0x48(%r15)
andl $0x0, 0x50(%r15)
movq 0x60(%r14,%r13), %rax
movq %rax, 0x58(%r15)
movq %r14, 0x30(%rsp)
movq 0x28(%r14,%r13), %rsi
movq 0x8(%rsp), %rax
movq (%rax), %rdi
callq 0x24ce25
movq 0x10(%rax), %r14
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
callq *0x18(%rax)
movl %eax, %ebp
testl %eax, %eax
je 0x27a562
cmpl $0x13, %ebp
je 0x27a562
cmpl $0x7, %ebp
jne 0x27a52e
movq 0x8(%rsp), %rax
movq (%rax), %rdi
callq 0x224bb1
movq 0x10(%r14), %rdi
callq 0x21f7f9
andq $0x0, 0x10(%r14)
movl %ebp, %eax
jmp 0x27a6c8
movq 0x10(%r14), %rdx
testq %rdx, %rdx
je 0x27a545
leaq 0xee96b(%rip), %rsi     # 0x368ea9
movq 0x8(%rsp), %rdi
jmp 0x27a55b
movl %ebp, %edi
callq 0x224b22
leaq 0xee956(%rip), %rsi     # 0x368ea9
movq 0x8(%rsp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x226dce
movq 0x10(%r14), %rdi
callq 0x21f7f9
andq $0x0, 0x10(%r14)
cmpl $0x13, %ebp
movl $0x0, %eax
je 0x27a6c8
movl %ebp, %eax
testl %ebp, %ebp
jne 0x27a6c8
movq 0x30(%rsp), %rax
addq %r13, %rax
addq $0x8, %rax
movl 0x10(%rsp), %edx
xorl %ecx, %ecx
movq 0x18(%rsp), %rbp
cmpq %rcx, %rdx
je 0x27a5b2
movq 0x38(%rbx), %rsi
andq $0x0, (%rsi,%rcx,8)
incq %rcx
jmp 0x27a59f
andw $0x0, 0x1e(%rbx)
movq 0x8(%r15), %rdi
movzwl 0x14(%rsp), %r8d
addq $0x5, %rdi
pushq $-0x1
popq %rsi
xorl %r9d, %r9d
cmpq %r9, %rdx
je 0x27a68b
movl (%rbp,%r9,8), %ecx
testl %ecx, %ecx
jle 0x27a67f
cmpl 0x20(%rsp), %ecx
jg 0x27a6ab
movl 0x3(%rdi), %r11d
testl %r11d, %r11d
js 0x27a6ab
cmpl 0x14(%r12), %r11d
jge 0x27a6ab
decl %ecx
movq 0x38(%rbx), %r14
movl %ecx, %r13d
cmpq $0x0, (%r14,%r13,8)
jne 0x27a6ab
cmpb $0x0, (%rdi)
je 0x27a6ab
movq 0x20(%r12), %rbp
shlq $0x6, %r11
leaq (%r11,%rbp), %r10
movq 0x30(%rbp,%r11), %r11
movq 0x18(%rsp), %rbp
orq %r11, (%rbx)
movq %r10, (%r14,%r13,8)
cmpl %esi, %ecx
cmovgl %ecx, %esi
cmpq $0xf, %r9
ja 0x27a663
cmpb $0x0, 0x4(%rbp,%r9,8)
je 0x27a663
btl %r9d, %r8d
jb 0x27a663
pushq $0x1
popq %r11
shll %cl, %r11d
orw %r11w, 0x1e(%rbx)
testb $0x1, 0x14(%r10)
je 0x27a67f
andl $0x0, 0x3c(%r15)
andb $-0x2, 0x50(%r15)
movq 0x70(%rsp), %rcx
movl $0x1, (%rcx)
incq %r9
addq $0xc, %rdi
jmp 0x27a5cb
leal 0x1(%rsi), %ecx
movw %cx, 0x2c(%rbx)
movslq %esi, %rcx
xorl %edx, %edx
cmpq %rcx, %rdx
jg 0x27a6d7
movq 0x38(%rbx), %rsi
cmpq $0x0, (%rsi,%rdx,8)
leaq 0x1(%rdx), %rdx
jne 0x27a697
movq 0x20(%rax), %rax
movq (%rax), %rdx
leaq 0xfe6d3(%rip), %rsi     # 0x378d8c
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x226dce
pushq $0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x28(%r15), %eax
movl %eax, 0x18(%rbx)
movb 0x38(%r15), %al
movb %al, 0x1c(%rbx)
andl $0x0, 0x38(%r15)
movq 0x30(%r15), %rax
movq %rax, 0x20(%rbx)
cmpl $0x0, 0x3c(%r15)
je 0x27a6ff
movb 0x10(%r15), %al
jmp 0x27a701
xorl %eax, %eax
movb %al, 0x1d(%rbx)
andw $0x0, 0x12(%rbx)
movsd 0x40(%r15), %xmm0
movsd 0x6bb11(%rip), %xmm1    # 0x2e6228
ucomisd %xmm0, %xmm1
jae 0x27a73e
movsd 0xfb4eb(%rip), %xmm1    # 0x375c10
ucomisd %xmm0, %xmm1
jae 0x27a742
movq %xmm0, %rax
shrq $0x34, %rax
imull $0xa, %eax, %eax
addl $0xffffd814, %eax       # imm = 0xFFFFD814
jmp 0x27a766
xorl %eax, %eax
jmp 0x27a766
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x6d5ca(%rip), %xmm0    # 0x2e7d20
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
callq 0x243f7b
movw %ax, 0x14(%rbx)
movq 0x48(%r15), %rdi
callq 0x243f7b
movw %ax, 0x16(%rbx)
movl 0x50(%r15), %eax
movl $0xffffefff, %ecx       # imm = 0xFFFFEFFF
andl 0x28(%rbx), %ecx
andl $0x1, %eax
shll $0xc, %eax
orl %ecx, %eax
movl %eax, 0x28(%rbx)
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x27a7bb
cmpb $0x0, 0x1c(%rbx)
je 0x27a6c8
movq 0x20(%rbx), %rdi
movl %eax, %ebp
callq 0x21f7f9
movl %ebp, %eax
movb $0x0, 0x1c(%rbx)
jmp 0x27a6c8