// File: /workspace/github_c_makefile_star2_O1/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, (%rsp)
movq %r8, %r15
movq %rdi, %r13
movq 0x70(%rsp), %r8
movq (%rdi), %rax
movq 0x8(%rdi), %rdi
movq %rdi, 0x10(%rsp)
movq 0x20(%r15), %r9
movq 0x18(%r13), %rbx
movq (%rax), %rdi
movq %rdi, 0x8(%rsp)
movq 0x8(%rax), %rax
movzbl 0x10(%rbx), %edi
imulq $0x70, %rdi, %rdi
addq %rdi, %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
movslq (%r15), %r12
movl $0x0, (%r8)
movq %rsi, (%rbx)
testq %r12, %r12
jle 0x2e462b
movq 0x8(%r15), %rax
movq 0x10(%rsp), %rsi
movq 0x20(%rsi), %rsi
addq $0x5, %rax
notq %rdx
movl %r12d, %edi
movslq 0x3(%rax), %r8
shlq $0x6, %r8
movb $0x0, (%rax)
testq %rdx, 0x30(%rsi,%r8)
jne 0x2e4623
addq %rsi, %r8
testw %cx, 0x14(%r8)
jne 0x2e4623
movb $0x1, (%rax)
addq $0xc, %rax
decl %edi
jne 0x2e4604
movq %r12, %rdx
shlq $0x3, %rdx
xorl %ebp, %ebp
movq %r9, 0x28(%rsp)
movq %r9, %rdi
xorl %esi, %esi
callq 0x173a0
movq $0x0, 0x30(%r15)
movl %ebp, 0x28(%r15)
movl %ebp, 0x3c(%r15)
movabsq $0x546d42aea2879f2e, %rax # imm = 0x546D42AEA2879F2E
movq %rax, 0x40(%r15)
movq $0x19, 0x48(%r15)
movl %ebp, 0x50(%r15)
movq 0x18(%rsp), %rcx
movq 0x58(%rcx), %rax
movq %rax, 0x58(%r15)
movq 0x20(%rcx), %rax
movq 0x60(%rax), %rax
testq %rax, %rax
je 0x2e469d
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
cmpq %rcx, (%rax)
je 0x2e469d
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x2e468f
movq 0x10(%rax), %r14
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
callq *0x18(%rax)
movl %eax, %ebp
testl %eax, %eax
je 0x2e46ec
cmpl $0x13, %ebp
je 0x2e46ec
cmpl $0x7, %ebp
jne 0x2e46cc
movq 0x8(%rsp), %rax
movq (%rax), %rdi
callq 0x2824bb
jmp 0x2e46ec
movq 0x10(%r14), %rdx
testq %rdx, %rdx
je 0x2e48ad
leaq 0xedaf1(%rip), %rsi     # 0x3d21d1
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x284eb8
movq 0x10(%r14), %rdi
callq 0x27c490
movq $0x0, 0x10(%r14)
cmpl $0x13, %ebp
je 0x2e4849
testl %ebp, %ebp
jne 0x2e49b2
movl %r12d, %r14d
testl %r12d, %r12d
jle 0x2e472c
xorl %eax, %eax
movq 0x38(%rbx), %rcx
movq $0x0, (%rcx,%rax,8)
incq %rax
cmpq %rax, %r14
jne 0x2e4718
movq %r13, 0x30(%rsp)
movw $0x0, 0x1e(%rbx)
testl %r12d, %r12d
movq 0x28(%rsp), %r9
jle 0x2e4850
movq 0x8(%r15), %r12
movzwl (%rsp), %eax
movl %eax, 0x24(%rsp)
addq $0x5, %r12
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, (%rsp)
xorl %ebp, %ebp
movl (%r9,%rbp,8), %ecx
movb $0x1, %r13b
testl %ecx, %ecx
jle 0x2e47b9
cmpl %r14d, %ecx
jg 0x2e4792
movl 0x3(%r12), %edx
testl %edx, %edx
js 0x2e4792
movq 0x10(%rsp), %rax
cmpl 0x14(%rax), %edx
jge 0x2e4792
decl %ecx
movq 0x38(%rbx), %rsi
movl %ecx, %edi
cmpq $0x0, (%rsi,%rdi,8)
je 0x2e47d3
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rdx
xorl %r13d, %r13d
movq 0x8(%rsp), %rdi
leaq 0xfd914(%rip), %rsi     # 0x3e20c1
xorl %eax, %eax
callq 0x284eb8
movq 0x28(%rsp), %r9
testb %r13b, %r13b
je 0x2e48f6
incq %rbp
addq $0xc, %r12
cmpq %rbp, %r14
jne 0x2e4760
jmp 0x2e4859
cmpb $0x0, (%r12)
je 0x2e4792
movq 0x10(%rsp), %rax
movq 0x20(%rax), %r8
shlq $0x6, %rdx
leaq (%r8,%rdx), %rax
movq 0x30(%r8,%rdx), %rdx
orq %rdx, (%rbx)
movq %rax, (%rsi,%rdi,8)
movq (%rsp), %rdx
cmpl %edx, %ecx
cmovgl %ecx, %edx
movq %rdx, (%rsp)
cmpq $0xf, %rbp
ja 0x2e4826
cmpb $0x0, 0x4(%r9,%rbp,8)
je 0x2e4826
movl 0x24(%rsp), %edx
btl %ebp, %edx
jb 0x2e4826
movl $0x1, %edx
shll %cl, %edx
orw %dx, 0x1e(%rbx)
testb $0x1, 0x14(%rax)
je 0x2e47b9
movl $0x0, 0x3c(%r15)
andb $-0x2, 0x50(%r15)
movq 0x70(%rsp), %rax
movl $0x1, (%rax)
jmp 0x2e47b9
xorl %ebp, %ebp
jmp 0x2e49b2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, (%rsp)
movq (%rsp), %rcx
leal 0x1(%rcx), %eax
movw %ax, 0x2c(%rbx)
testl %ecx, %ecx
movq 0x30(%rsp), %r14
js 0x2e4882
movq 0x38(%rbx), %rcx
xorl %edx, %edx
cmpq $0x0, (%rcx,%rdx,8)
je 0x2e48d7
incq %rdx
cmpq %rdx, %rax
jne 0x2e4873
movl 0x28(%r15), %eax
movl %eax, 0x18(%rbx)
movb 0x38(%r15), %al
movb %al, 0x1c(%rbx)
movl $0x0, 0x38(%r15)
movq 0x30(%r15), %rax
movq %rax, 0x20(%rbx)
cmpl $0x0, 0x3c(%r15)
je 0x2e4900
movb 0x10(%r15), %al
jmp 0x2e4902
cmpl $0x204, %ebp            # imm = 0x204
je 0x2e49cf
cmpl $0x65, %ebp
je 0x2e49c3
cmpl $0x64, %ebp
jne 0x2e49db
leaq 0xff360(%rip), %rdx     # 0x3e3c32
jmp 0x2e46d9
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rdx
leaq 0xfd7d7(%rip), %rsi     # 0x3e20c1
movq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x284eb8
movl $0x1, %ebp
jmp 0x2e49b2
xorl %eax, %eax
movb %al, 0x1d(%rbx)
movw $0x0, 0x12(%rbx)
movsd 0x40(%r15), %xmm0
movsd 0x6a90f(%rip), %xmm1    # 0x34f228
ucomisd %xmm0, %xmm1
jae 0x2e4942
movsd 0xfa5b9(%rip), %xmm1    # 0x3deee0
ucomisd %xmm0, %xmm1
jae 0x2e4946
movq %xmm0, %rax
shrq $0x34, %rax
addl %eax, %eax
leal (%rax,%rax,4), %eax
addl $0xffffd814, %eax       # imm = 0xFFFFD814
jmp 0x2e496a
xorl %eax, %eax
jmp 0x2e496a
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x6c3c6(%rip), %xmm0    # 0x350d20
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
callq 0x2a680d
movw %ax, 0x14(%rbx)
movq 0x48(%r15), %rdi
callq 0x2a680d
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 %r14, %rdi
movq %rbx, %rsi
callq 0x2e4a10
movl %eax, %ebp
cmpb $0x0, 0x1c(%rbx)
je 0x2e49b2
movq 0x20(%rbx), %rdi
callq 0x27c490
movb $0x0, 0x1c(%rbx)
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xff27e(%rip), %rdx     # 0x3e3c48
jmp 0x2e46d9
leaq 0xff246(%rip), %rdx     # 0x3e3c1c
jmp 0x2e46d9
movzbl %bpl, %eax
leaq 0xff228(%rip), %rdx     # 0x3e3c0e
cmpl $0x1c, %eax
ja 0x2e46d9
movl $0x1410004, %ecx        # imm = 0x1410004
btq %rax, %rcx
jb 0x2e46d9
movl %eax, %eax
leaq 0x1de7e9(%rip), %rcx    # 0x4c31f0
movq (%rcx,%rax,8), %rdx
jmp 0x2e46d9