// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: whereLoopAddVirtual
static int whereLoopAddVirtual(
  WhereLoopBuilder *pBuilder,  /* WHERE clause information */
  Bitmask mPrereq,             /* Tables that must be scanned before this one */
  Bitmask mUnusable            /* Tables that must be scanned after this one */
){
  int rc = SQLITE_OK;          /* Return code */
  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 */
  sqlite3_index_info *p;       /* Object to pass to xBestIndex() */
  int nConstraint;             /* Number of constraints in p */
  int bIn;                     /* True if plan uses IN(...) operator */
  WhereLoop *pNew;
  Bitmask mBest;               /* Tables used by best possible plan */
  u16 mNoOmit;

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

  /* First call xBestIndex() with all constraints usable. */
  WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
  WHERETRACE(0x40, ("  VirtualOne: all usable\n"));
  rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);

  /* If the call to xBestIndex() with all terms enabled produced a plan
  ** that does not require any source tables (IOW: a plan with mBest==0)
  ** and does not use an IN(...) operator, then there is no point in making
  ** any further calls to xBestIndex() since they will all return the same
  ** result (if the xBestIndex() implementation is sane). */
  if( rc==SQLITE_OK && ((mBest = (pNew->prereq & ~mPrereq))!=0 || bIn) ){
    int seenZero = 0;             /* True if a plan with no prereqs seen */
    int seenZeroNoIN = 0;         /* Plan with no prereqs and no IN(...) seen */
    Bitmask mPrev = 0;
    Bitmask mBestNoIn = 0;

    /* If the plan produced by the earlier call uses an IN(...) term, call
    ** xBestIndex again, this time with IN(...) terms disabled. */
    if( bIn ){
      WHERETRACE(0x40, ("  VirtualOne: all usable w/o IN\n"));
      rc = whereLoopAddVirtualOne(
          pBuilder, mPrereq, ALLBITS, WO_IN, p, mNoOmit, &bIn);
      assert( bIn==0 );
      mBestNoIn = pNew->prereq & ~mPrereq;
      if( mBestNoIn==0 ){
        seenZero = 1;
        seenZeroNoIN = 1;
      }
    }

    /* Call xBestIndex once for each distinct value of (prereqRight & ~mPrereq)
    ** in the set of terms that apply to the current virtual table.  */
    while( rc==SQLITE_OK ){
      int i;
      Bitmask mNext = ALLBITS;
      assert( mNext>0 );
      for(i=0; i<nConstraint; i++){
        Bitmask mThis = (
            pWC->a[p->aConstraint[i].iTermOffset].prereqRight & ~mPrereq
        );
        if( mThis>mPrev && mThis<mNext ) mNext = mThis;
      }
      mPrev = mNext;
      if( mNext==ALLBITS ) break;
      if( mNext==mBest || mNext==mBestNoIn ) continue;
      WHERETRACE(0x40, ("  VirtualOne: mPrev=%04llx mNext=%04llx\n",
                       (sqlite3_uint64)mPrev, (sqlite3_uint64)mNext));
      rc = whereLoopAddVirtualOne(
          pBuilder, mPrereq, mNext|mPrereq, 0, p, mNoOmit, &bIn);
      if( pNew->prereq==mPrereq ){
        seenZero = 1;
        if( bIn==0 ) seenZeroNoIN = 1;
      }
    }

    /* If the calls to xBestIndex() in the above loop did not find a plan
    ** that requires no source tables at all (i.e. one guaranteed to be
    ** usable), make a call here with all source tables disabled */
    if( rc==SQLITE_OK && seenZero==0 ){
      WHERETRACE(0x40, ("  VirtualOne: all disabled\n"));
      rc = whereLoopAddVirtualOne(
          pBuilder, mPrereq, mPrereq, 0, p, mNoOmit, &bIn);
      if( bIn==0 ) seenZeroNoIN = 1;
    }

    /* If the calls to xBestIndex() have so far failed to find a plan
    ** that requires no source tables at all and does not use an IN(...)
    ** operator, make a final call to obtain one here.  */
    if( rc==SQLITE_OK && seenZeroNoIN==0 ){
      WHERETRACE(0x40, ("  VirtualOne: all disabled and w/o IN\n"));
      rc = whereLoopAddVirtualOne(
          pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
    }
  }

  if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
  sqlite3DbFreeNN(pParse->db, p);
  WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc));
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, 0x30(%rsp)
movq (%rdi), %rax
movq 0x8(%rdi), %rsi
movq (%rax), %r13
movq 0x8(%rax), %rax
movq 0x18(%rdi), %rcx
movq %rcx, 0x50(%rsp)
movzbl 0x10(%rcx), %ecx
imulq $0x70, %rcx, %rcx
leaq (%rax,%rcx), %r12
addq $0x8, %r12
movq %rdi, 0x38(%rsp)
movq 0x10(%rdi), %r15
movq 0x20(%rsi), %rcx
movq %rsi, 0x58(%rsp)
movl 0x14(%rsi), %edi
xorl %eax, %eax
testl %edi, %edi
cmovlel %eax, %edi
addq $0x14, %rcx
subl $0x1, %edi
jb 0x27938e
movl 0x8(%rcx), %esi
cmpl 0x40(%r12), %esi
jne 0x279388
testq %rdx, 0x1c(%rcx)
jne 0x279388
movzwl (%rcx), %esi
andl $0xf7ff, %esi           # imm = 0xF7FF
cmpw $0x1, %si
sbbl $-0x1, %eax
addq $0x40, %rcx
jmp 0x279363
testq %r15, %r15
movq %rdx, 0x20(%rsp)
je 0x2793e2
movl (%r15), %ecx
xorl %esi, %esi
testl %ecx, %ecx
movl $0x0, %r9d
cmovgl %ecx, %r9d
leaq 0x18(%r15), %rdi
cmpq %rsi, %r9
je 0x2793d8
movq -0x10(%rdi), %r8
cmpb $-0x5c, (%r8)
jne 0x2793d5
movl 0x2c(%r8), %r8d
cmpl 0x40(%r12), %r8d
jne 0x2793d5
testb $0x2, (%rdi)
jne 0x2793d5
incq %rsi
addq $0x18, %rdi
jmp 0x2793ad
movl %esi, %r9d
xorl %ebp, %ebp
cmpl %ecx, %r9d
cmovel %ecx, %ebp
jmp 0x2793e4
xorl %ebp, %ebp
movq (%r13), %rdi
movslq %eax, %r14
imulq $0x14, %r14, %rax
movslq %ebp, %rbx
leaq (%rax,%rbx,8), %rsi
addq $0x70, %rsi
callq 0x2258ed
testq %rax, %rax
je 0x27962b
movq %rbp, 0x48(%rsp)
leaq 0x70(%rax), %rdi
imulq $0xc, %r14, %r8
leaq (%rax,%r8), %rdx
addq $0x70, %rdx
leaq (%rdx,%rbx,8), %rcx
movl %ebx, 0x10(%rax)
movq %rdi, 0x8(%rax)
movq %rdx, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq 0x58(%rsp), %rcx
movq %rcx, 0x60(%rax)
movq %r13, 0x70(%rsp)
movq %r13, 0x68(%rax)
movq 0x20(%rcx), %rbx
movl 0x14(%rcx), %r13d
xorl %ecx, %ecx
testl %r13d, %r13d
cmovlel %ecx, %r13d
pushq $0x2
popq %r9
movl $0x0, 0x10(%rsp)
xorl %ecx, %ecx
xorl %ebp, %ebp
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rsi
cmpl %ebp, %r13d
je 0x2795af
movl 0x1c(%rbx), %edx
cmpl 0x40(%r12), %edx
jne 0x2794f4
testq %rsi, 0x30(%rbx)
jne 0x2794f4
movzwl 0x14(%rbx), %r14d
testw $0xf7ff, %r14w          # imm = 0xF7FF
je 0x2794f4
testb $0x8, 0x3c(%r12)
je 0x2794a4
movq (%rbx), %rdx
testb $0x1, 0x4(%rdx)
je 0x2794f4
movl 0x28(%rbx), %edx
movslq %ecx, %r10
imulq $0xc, %r10, %r10
leaq (%rdi,%r10), %r11
movl %edx, (%rdi,%r10)
movl %ebp, 0x8(%rdi,%r10)
andl $0x1fff, %r14d          # imm = 0x1FFF
cmpl $0x1, %r14d
movl %r14d, %edx
cmovel %r9d, %edx
cmpw $0x40, %dx
jne 0x2794d8
movb 0x17(%rbx), %dl
jmp 0x2794ee
testw $0x180, %dx             # imm = 0x180
je 0x2794ff
cmpl $0x100, %edx            # imm = 0x100
sete %r10b
movb $0x48, %dl
subb %r10b, %dl
movb %dl, 0x4(%r11)
incl %ecx
incl %ebp
addq $0x40, %rbx
jmp 0x27946d
movb %dl, 0x4(%r11)
testb $0x3c, %dl
je 0x2794f2
movq %r11, 0x60(%rsp)
movl %ecx, 0x44(%rsp)
movq %rdi, 0x68(%rsp)
movq %r8, 0x28(%rsp)
movq (%rbx), %rax
movq 0x18(%rax), %rdi
callq 0x2661b9
testl %eax, %eax
je 0x279573
pushq $0x1
popq %rax
movl 0x44(%rsp), %ecx
shll %cl, %eax
cmpl $0x10, %ecx
movl $0x0, %edx
cmovgel %edx, %eax
orl %eax, 0x10(%rsp)
cmpl $0x10, %r14d
movq 0x68(%rsp), %rdi
pushq $0x2
popq %r9
je 0x279594
cmpl $0x4, %r14d
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %r8
movq 0x60(%rsp), %r11
jne 0x2794f2
movb $0x20, %dl
jmp 0x2794ee
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %r8
movq 0x68(%rsp), %rdi
pushq $0x2
popq %r9
movl 0x44(%rsp), %ecx
jmp 0x2794f2
movb $0x8, %dl
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %r8
movq 0x60(%rsp), %r11
jmp 0x2794ee
movl %ecx, (%rax)
xorl %esi, %esi
movq 0x48(%rsp), %rdi
testl %edi, %edi
cmovlel %esi, %edi
leaq (%rax,%r8), %rcx
addq $0x74, %rcx
addq $0x18, %r15
movq 0x70(%rsp), %rbx
cmpq %rsi, %rdi
je 0x2795f1
movq -0x10(%r15), %rdx
movswl 0x30(%rdx), %edx
movl %edx, -0x4(%rcx,%rsi,8)
movb (%r15), %dl
andb $0x1, %dl
movb %dl, (%rcx,%rsi,8)
incq %rsi
addq $0x18, %r15
jmp 0x2795ce
movq 0x50(%rsp), %rsi
andw $0x0, 0x12(%rsi)
movl $0x400, 0x28(%rsi)      # imm = 0x400
andw $0x0, 0x2c(%rsi)
movb $0x0, 0x1c(%rsi)
movl (%rax), %ebp
movq (%rbx), %rdi
movl %ebp, %edx
movq %rax, %r12
callq 0x27a36d
testl %eax, %eax
je 0x279645
movq (%rbx), %rdi
movq %r12, %rsi
callq 0x22d0fc
jmp 0x27963c
leaq 0x9afff(%rip), %rsi     # 0x314631
movq %r13, %rdi
xorl %eax, %eax
callq 0x226dce
pushq $0x7
popq %r14
jmp 0x279896
leaq 0x14(%rsp), %rax
movq %rax, (%rsp)
movzwl 0x10(%rsp), %r9d
pushq $-0x1
popq %rdx
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
xorl %ecx, %ecx
movq %r12, %r8
movl %r9d, 0x20(%rsp)
callq 0x27a3e9
movl %eax, %r14d
testl %eax, %eax
movq 0x58(%rsp), %r15
movq %r12, %rsi
jne 0x279875
movq 0x30(%rsp), %rbx
notq %rbx
movq 0x50(%rsp), %rax
movq (%rax), %r12
andq %rbx, %r12
setne %cl
movl 0x14(%rsp), %eax
testl %eax, %eax
setne %dl
orb %cl, %dl
movl $0x0, %r14d
cmpb $0x1, %dl
jne 0x279875
xorl %r13d, %r13d
testl %eax, %eax
je 0x279701
leaq 0x14(%rsp), %rax
movq %rax, (%rsp)
pushq $-0x1
popq %rdx
pushq $0x1
popq %rcx
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x18(%rsp), %r8
movl 0x20(%rsp), %r9d
callq 0x27a3e9
movq 0x18(%rsp), %rsi
movl %eax, %r14d
movq 0x50(%rsp), %rax
movq (%rax), %rcx
xorl %eax, %eax
andq %rbx, %rcx
movq %rcx, 0x48(%rsp)
sete %al
jmp 0x27970f
xorl %r14d, %r14d
xorl %eax, %eax
movq $0x0, 0x48(%rsp)
testl %ebp, %ebp
cmovlel %r13d, %ebp
movl %eax, 0x10(%rsp)
testl %eax, %eax
sete %al
movl %eax, 0x28(%rsp)
imulq $0xc, %rbp, %rbp
movq %r13, %rax
testl %r14d, %r14d
jne 0x279875
xorl %ecx, %ecx
pushq $-0x1
popq %r13
cmpq %rcx, %rbp
je 0x27976d
movq 0x20(%r15), %rdx
movq 0x8(%rsi), %rdi
movslq 0x8(%rdi,%rcx), %rdi
shlq $0x6, %rdi
movq 0x30(%rdx,%rdi), %rdx
andq %rbx, %rdx
cmpq %r13, %rdx
movq %r13, %rdi
cmovbq %rdx, %rdi
cmpq %rax, %rdx
cmovaq %rdi, %r13
addq $0xc, %rcx
jmp 0x279738
xorl %r14d, %r14d
cmpq $-0x1, %r13
je 0x2797f3
movq %r13, %rax
cmpq %r12, %r13
je 0x279729
movq %r13, %rax
cmpq 0x48(%rsp), %r13
je 0x279729
movq %r13, %rdx
movq 0x30(%rsp), %r15
orq %r15, %rdx
leaq 0x14(%rsp), %rax
movq %rax, (%rsp)
movq 0x38(%rsp), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
movq 0x18(%rsp), %r8
movl 0x20(%rsp), %r9d
callq 0x27a3e9
movq 0x18(%rsp), %rsi
movl %eax, %r14d
movq %r13, %rax
movq 0x50(%rsp), %rcx
cmpq %r15, (%rcx)
movq 0x58(%rsp), %r15
jne 0x279729
cmpl $0x0, 0x14(%rsp)
pushq $0x1
popq %rax
movl 0x10(%rsp), %ecx
cmovel %eax, %ecx
movl %ecx, 0x10(%rsp)
movl $0x0, 0x28(%rsp)
jmp 0x279726
testb $0x1, 0x28(%rsp)
je 0x27983c
leaq 0x14(%rsp), %rax
movq %rax, (%rsp)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rdx
movq %rdx, %rsi
xorl %ecx, %ecx
movq 0x18(%rsp), %r8
movl 0x20(%rsp), %r9d
callq 0x27a3e9
movq 0x18(%rsp), %rsi
movl %eax, %r14d
cmpl $0x0, 0x14(%rsp)
pushq $0x1
popq %rax
movl 0x10(%rsp), %ecx
cmovel %eax, %ecx
movl %ecx, %eax
jmp 0x279840
movl 0x10(%rsp), %eax
orl %r14d, %eax
jne 0x279875
leaq 0x14(%rsp), %rax
movq %rax, (%rsp)
pushq $0x1
popq %rcx
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rdx
movq %rdx, %rsi
movq 0x18(%rsp), %r8
movl 0x20(%rsp), %r9d
callq 0x27a3e9
movq 0x18(%rsp), %rsi
movl %eax, %r14d
cmpl $0x0, 0x38(%rsi)
je 0x279889
movq 0x30(%rsi), %rdi
callq 0x21f7f9
movq 0x18(%rsp), %rsi
movq 0x70(%rsp), %rax
movq (%rax), %rdi
callq 0x22d0fc
movl %r14d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq