// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movl %r9d, 0x1c(%rsp)
movq %r8, %r15
movq 0x60(%rsp), %r8
movq (%rdi), %rax
movq 0x8(%rdi), %r9
movq 0x20(%r15), %r13
movq %rdi, 0x20(%rsp)
movq 0x18(%rdi), %rbx
movq (%rax), %rdi
movq %rdi, (%rsp)
movq 0x8(%rax), %rax
movzbl 0x10(%rbx), %edi
imulq $0x70, %rdi, %rdi
addq %rdi, %rax
addq $0x8, %rax
movq %rax, 0x10(%rsp)
movslq (%r15), %r14
movl $0x0, (%r8)
movq %rsi, (%rbx)
testq %r14, %r14
jle 0x2db18d
movq 0x8(%r15), %rax
movq 0x20(%r9), %rsi
addq $0x5, %rax
notq %rdx
movl %r14d, %edi
movslq 0x3(%rax), %r8
shlq $0x6, %r8
movb $0x0, (%rax)
testq %rdx, 0x30(%rsi,%r8)
jne 0x2db185
addq %rsi, %r8
testw %cx, 0x14(%r8)
jne 0x2db185
movb $0x1, (%rax)
addq $0xc, %rax
decl %edi
jne 0x2db166
movq %r9, 0x8(%rsp)
movq %r14, %rdx
shlq $0x3, %rdx
xorl %ebp, %ebp
movq %r13, %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 0x10(%rsp), %rcx
movq 0x58(%rcx), %rax
movq %rax, 0x58(%r15)
movq 0x20(%rcx), %rax
movq 0x60(%rax), %rax
movq (%rsp), %rcx
movq (%rcx), %rcx
cmpq %rcx, (%rax)
je 0x2db1f6
movq 0x28(%rax), %rax
jmp 0x2db1eb
movq 0x10(%rax), %r12
movq (%r12), %rax
movq %r12, %rdi
movq %r15, %rsi
callq *0x18(%rax)
movl %eax, %ebp
testl %eax, %eax
je 0x2db25b
cmpl $0x13, %ebp
je 0x2db25b
cmpl $0x7, %ebp
jne 0x2db23b
movq (%rsp), %rax
movq (%rax), %rdi
callq 0x278b1c
movq 0x10(%r12), %rdi
callq 0x272c00
movq $0x0, 0x10(%r12)
jmp 0x2db4ed
movq 0x10(%r12), %rdx
testq %rdx, %rdx
je 0x2db3e7
leaq 0xed859(%rip), %rsi     # 0x3c8aa9
movq (%rsp), %rdi
xorl %eax, %eax
callq 0x27b48d
movq 0x10(%r12), %rdi
callq 0x272c00
movq $0x0, 0x10(%r12)
cmpl $0x13, %ebp
je 0x2db3a9
testl %ebp, %ebp
jne 0x2db4ed
testl %r14d, %r14d
jle 0x2db3b0
movl %r14d, %eax
xorl %ecx, %ecx
movq 0x38(%rbx), %rdx
movq $0x0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x2db28d
movw $0x0, 0x1e(%rbx)
testl %r14d, %r14d
movq 0x60(%rsp), %rbp
movq 0x8(%rsp), %r9
jle 0x2db3b6
movq 0x8(%r15), %rsi
movzwl 0x1c(%rsp), %edi
addq $0x5, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movl (%r13,%r8,8), %ecx
testl %ecx, %ecx
jle 0x2db377
cmpl %eax, %ecx
jg 0x2db411
movl 0x3(%rsi), %r10d
testl %r10d, %r10d
js 0x2db411
cmpl 0x14(%r9), %r10d
jge 0x2db411
decl %ecx
movq 0x38(%rbx), %r11
movl %ecx, %r14d
cmpq $0x0, (%r11,%r14,8)
jne 0x2db411
cmpb $0x0, (%rsi)
je 0x2db411
movq 0x20(%r9), %r12
shlq $0x6, %r10
leaq (%r12,%r10), %r9
movq 0x30(%r12,%r10), %r10
orq %r10, (%rbx)
movq %r9, (%r11,%r14,8)
cmpl %edx, %ecx
cmovgl %ecx, %edx
cmpq $0xf, %r8
ja 0x2db357
cmpb $0x0, 0x4(%r13,%r8,8)
je 0x2db357
btl %r8d, %edi
jb 0x2db357
movl $0x1, %r10d
shll %cl, %r10d
orw %r10w, 0x1e(%rbx)
testb $0x1, 0x14(%r9)
je 0x2db372
movl $0x0, 0x3c(%r15)
andb $-0x2, 0x50(%r15)
movl $0x1, (%rbp)
movq 0x8(%rsp), %r9
incq %r8
addq $0xc, %rsi
cmpq %r8, %rax
jne 0x2db2cf
leal 0x1(%rdx), %eax
movw %ax, 0x2c(%rbx)
testl %edx, %edx
js 0x2db3bc
movq 0x38(%rbx), %rcx
xorl %edx, %edx
cmpq $0x0, (%rcx,%rdx,8)
je 0x2db411
incq %rdx
cmpq %rdx, %rax
jne 0x2db398
jmp 0x2db3bc
xorl %ebp, %ebp
jmp 0x2db4ed
movw $0x0, 0x1e(%rbx)
movw $0x0, 0x2c(%rbx)
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 0x2db439
movb 0x10(%r15), %al
jmp 0x2db43b
cmpl $0x204, %ebp            # imm = 0x204
je 0x2db50a
cmpl $0x65, %ebp
je 0x2db4fe
cmpl $0x64, %ebp
jne 0x2db516
leaq 0xff0d1(%rip), %rdx     # 0x3da4dd
jmp 0x2db249
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rdx
leaq 0xfd548(%rip), %rsi     # 0x3d896c
movq (%rsp), %rdi
xorl %eax, %eax
callq 0x27b48d
movl $0x1, %ebp
jmp 0x2db4ed
xorl %eax, %eax
movb %al, 0x1d(%rbx)
movw $0x0, 0x12(%rbx)
movsd 0x40(%r15), %xmm0
movsd 0x6add6(%rip), %xmm1    # 0x346228
ucomisd %xmm0, %xmm1
jae 0x2db47b
movsd 0xfa390(%rip), %xmm1    # 0x3d57f0
ucomisd %xmm0, %xmm1
jae 0x2db47f
movq %xmm0, %rax
shrq $0x34, %rax
addl %eax, %eax
leal (%rax,%rax,4), %eax
addl $0xffffd814, %eax       # imm = 0xFFFFD814
jmp 0x2db4a3
xorl %eax, %eax
jmp 0x2db4a3
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x6c88d(%rip), %xmm0    # 0x347d20
cvttsd2si %xmm0, %rdi
andq %rcx, %rdi
orq %rax, %rdi
callq 0x29d44f
movw %ax, 0x14(%rbx)
movq 0x48(%r15), %rdi
callq 0x29d44f
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 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x2db54b
movl %eax, %ebp
cmpb $0x0, 0x1c(%rbx)
je 0x2db4ed
movq 0x20(%rbx), %rdi
callq 0x272c00
movb $0x0, 0x1c(%rbx)
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xfefee(%rip), %rdx     # 0x3da4f3
jmp 0x2db249
leaq 0xfefb6(%rip), %rdx     # 0x3da4c7
jmp 0x2db249
movzbl %bpl, %eax
leaq 0xfef98(%rip), %rdx     # 0x3da4b9
cmpl $0x1c, %eax
ja 0x2db249
movl $0x1410004, %ecx        # imm = 0x1410004
btq %rax, %rcx
jb 0x2db249
movl %eax, %eax
leaq 0x1dcc9e(%rip), %rcx    # 0x4b81e0
movq (%rcx,%rax,8), %rdx
jmp 0x2db249