// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %rdx, %rbp
movq (%rdi), %rax
movq 0x8(%rdi), %r10
movq 0x8(%rax), %rcx
movq 0x18(%rdi), %rdx
movq %rdx, 0x50(%rsp)
movzbl 0x10(%rdx), %edx
imulq $0x70, %rdx, %rdx
leaq (%rcx,%rdx), %r15
addq $0x8, %r15
movq %rdi, 0x30(%rsp)
movq 0x10(%rdi), %rbx
movl 0x14(%r10), %ecx
xorl %r11d, %r11d
testl %ecx, %ecx
jle 0x2e343e
movq 0x20(%r10), %rdx
movl 0x40(%r15), %r9d
addq $0x14, %rdx
xorl %edi, %edi
cmpl %r9d, 0x8(%rdx)
jne 0x2e3431
testq %rbp, 0x1c(%rdx)
jne 0x2e3431
movzwl (%rdx), %r8d
andl $0xf7ff, %r8d           # imm = 0xF7FF
cmpw $0x1, %r8w
sbbl $-0x1, %edi
addq $0x40, %rdx
decl %ecx
jne 0x2e3412
movslq %edi, %r12
jmp 0x2e3441
xorl %r12d, %r12d
movq %r10, 0x40(%rsp)
movq (%rax), %r14
testq %rbx, %rbx
je 0x2e348d
movl (%rbx), %eax
xorl %r11d, %r11d
movl $0x0, %ecx
testl %eax, %eax
jle 0x2e3487
leaq 0x18(%rbx), %rdx
xorl %ecx, %ecx
movq -0x10(%rdx), %rdi
cmpb $-0x5c, (%rdi)
jne 0x2e3487
movl 0x2c(%rdi), %edi
cmpl 0x40(%r15), %edi
jne 0x2e3487
testb $0x2, (%rdx)
jne 0x2e3487
incq %rcx
addq $0x18, %rdx
cmpq %rcx, %rax
jne 0x2e3462
movl %eax, %ecx
cmpl %eax, %ecx
cmovel %eax, %r11d
movq %r15, 0x10(%rsp)
movq %rsi, 0x38(%rsp)
movq (%r14), %rdi
leaq (%r12,%r12,4), %rax
movq %r11, 0x48(%rsp)
movslq %r11d, %r15
leaq (,%r15,8), %rcx
leaq (%rcx,%rax,4), %rsi
addq $0x70, %rsi
callq 0x283569
testq %rax, %rax
je 0x2e3650
movq %rax, %r13
leaq 0x70(%rax), %rdx
leaq (%r12,%r12,2), %rax
movq %rax, 0x58(%rsp)
leaq 0x70(,%rax,4), %rcx
addq %r13, %rcx
leaq (%rcx,%r15,8), %rsi
movl %r15d, 0x10(%r13)
movq %rdx, 0x8(%r13)
movq %rcx, 0x18(%r13)
movq %rsi, 0x20(%r13)
movq 0x40(%rsp), %rcx
movq %rcx, 0x60(%r13)
movq %r14, 0x68(%r13)
movl 0x14(%rcx), %esi
testl %esi, %esi
jle 0x2e366a
movq 0x20(%rcx), %rdi
movq 0x10(%rsp), %r15
movl 0x40(%r15), %r8d
xorl %r11d, %r11d
xorl %ecx, %ecx
movl $0x0, 0x20(%rsp)
cmpl %r8d, 0x1c(%rdi)
jne 0x2e35b3
testq %rbp, 0x30(%rdi)
jne 0x2e35b3
movzwl 0x14(%rdi), %r12d
testl $0xf7ff, %r12d          # imm = 0xF7FF
je 0x2e35b3
testb $0x8, 0x3c(%r15)
je 0x2e3554
movq (%rdi), %r9
testb $0x1, 0x4(%r9)
je 0x2e35b3
movl 0x28(%rdi), %r10d
movslq %ecx, %r9
leaq (%r9,%r9,2), %r9
leaq (%rdx,%r9,4), %r9
movl %r10d, (%r9)
movl %r11d, 0x8(%r9)
andl $0x1fff, %r12d          # imm = 0x1FFF
cmpl $0x1, %r12d
movl %r12d, %r10d
movl $0x2, %eax
cmovel %eax, %r10d
cmpw $0x40, %r10w
jne 0x2e358e
movb 0x17(%rdi), %r10b
jmp 0x2e35ad
testl $0x180, %r10d           # imm = 0x180
je 0x2e35c8
cmpl $0x100, %r10d           # imm = 0x100
sete %r15b
movb $0x48, %r10b
subb %r15b, %r10b
movq 0x10(%rsp), %r15
movb %r10b, 0x4(%r9)
incl %ecx
incl %r11d
addq $0x40, %rdi
cmpl %r11d, %esi
jne 0x2e3525
jmp 0x2e3674
movb %r10b, 0x4(%r9)
testb $0x3c, %r10b
je 0x2e35b1
movq (%rdi), %r10
movq 0x18(%r10), %r10
movb (%r10), %r15b
cmpb $-0x53, %r15b
jne 0x2e35e6
movb 0x2(%r10), %r15b
cmpb $-0x52, %r15b
je 0x2e35fd
movzbl %r15b, %r15d
cmpl $0x88, %r15d
jne 0x2e363e
movq 0x20(%r10), %r10
movq 0x10(%rsp), %r15
movq 0x20(%r10), %r10
cmpl $0x2, (%r10)
jl 0x2e35b1
movl $0x1, %r10d
shll %cl, %r10d
cmpl $0x10, %ecx
movl $0x0, %eax
cmovgel %eax, %r10d
orl %r10d, 0x20(%rsp)
cmpl $0x10, %r12d
je 0x2e3648
cmpl $0x4, %r12d
jne 0x2e35b1
movb $0x20, %r10b
jmp 0x2e35ad
movq 0x10(%rsp), %r15
jmp 0x2e35b1
movb $0x8, %r10b
jmp 0x2e35ad
leaq 0x99f4a(%rip), %rsi     # 0x37d5a1
xorl %r13d, %r13d
movq %r14, %rdi
xorl %eax, %eax
callq 0x284eb8
movl %eax, 0x20(%rsp)
jmp 0x2e36c3
movl $0x0, 0x20(%rsp)
xorl %ecx, %ecx
movl %ecx, (%r13)
movq 0x48(%rsp), %rcx
testl %ecx, %ecx
jle 0x2e36c3
movl %ecx, %ecx
movq 0x58(%rsp), %rax
leaq 0x74(,%rax,4), %rax
addq %r13, %rax
addq $0x18, %rbx
xorl %edx, %edx
movq 0x50(%rsp), %r12
movq -0x10(%rbx), %rsi
movswl 0x30(%rsi), %esi
movl %esi, -0x4(%rax,%rdx,8)
movb (%rbx), %sil
andb $0x1, %sil
movb %sil, (%rax,%rdx,8)
incq %rdx
addq $0x18, %rbx
cmpq %rdx, %rcx
jne 0x2e369e
jmp 0x2e36c8
movq 0x50(%rsp), %r12
testq %r13, %r13
je 0x2e37c0
xorl %eax, %eax
movw %ax, 0x12(%r12)
movl $0x400, 0x28(%r12)      # imm = 0x400
movw %ax, 0x2c(%r12)
movb $0x0, 0x1c(%r12)
movl (%r13), %r15d
movq (%r14), %rdi
movq %r12, %rsi
movl %r15d, %edx
callq 0x2e450c
movl $0x7, %ebx
testl %eax, %eax
jne 0x2e3973
movq %r15, 0x10(%rsp)
movq %r14, 0x48(%rsp)
leaq 0xc(%rsp), %r14
movq %r14, (%rsp)
movzwl 0x20(%rsp), %ebp
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %r15
movq %r15, %rsi
movq $-0x1, %rdx
xorl %ecx, %ecx
movq %r13, %r8
movl %ebp, %r9d
callq 0x2e458a
movl %eax, %ebx
testl %eax, %eax
jne 0x2e395e
notq %r15
movq (%r12), %r11
andq %r15, %r11
setne %cl
movl 0xc(%rsp), %eax
testl %eax, %eax
setne %dl
orb %cl, %dl
movl $0x0, %ebx
cmpb $0x1, %dl
jne 0x2e395e
testl %eax, %eax
movl %ebp, 0x2c(%rsp)
je 0x2e37ca
movq %r14, (%rsp)
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq $-0x1, %rdx
movl $0x1, %ecx
movq %r13, %r8
movl %ebp, %r9d
movq %r11, %rbx
callq 0x2e458a
movq %rbx, %r11
movl %eax, %ebx
movq (%r12), %rax
xorl %r12d, %r12d
andq %r15, %rax
movq %rax, 0x20(%rsp)
sete %r12b
jmp 0x2e37d8
movl $0x7, %ebx
jmp 0x2e397e
xorl %ebx, %ebx
xorl %r12d, %r12d
movq $0x0, 0x20(%rsp)
movq 0x40(%rsp), %r9
movq 0x10(%rsp), %r10
leaq (,%r10,4), %rax
leaq (%rax,%rax,2), %r14
xorl %ebp, %ebp
movl %r12d, 0x1c(%rsp)
movq %r11, 0x60(%rsp)
testl %ebx, %ebx
jne 0x2e38e9
testl %r10d, %r10d
jle 0x2e3845
movq 0x20(%r9), %rcx
movq 0x8(%r13), %rdx
movq $-0x1, %rax
xorl %esi, %esi
movslq 0x8(%rdx,%rsi), %rdi
shlq $0x6, %rdi
movq 0x30(%rcx,%rdi), %rdi
andq %r15, %rdi
cmpq %rax, %rdi
movq %rax, %r8
cmovbq %rdi, %r8
cmpq %rbp, %rdi
cmovaq %r8, %rax
addq $0xc, %rsi
cmpq %rsi, %r14
jne 0x2e3818
jmp 0x2e384c
movq $-0x1, %rax
movq %rax, %rbp
xorl %ebx, %ebx
cmpq $-0x1, %rax
je 0x2e38df
cmpq %r11, %rbp
je 0x2e38df
cmpq 0x20(%rsp), %rbp
je 0x2e38df
movl %r12d, 0x58(%rsp)
movq %rbp, %rdx
movq 0x38(%rsp), %r12
orq %r12, %rdx
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
xorl %ecx, %ecx
movq %r13, %r8
movl 0x2c(%rsp), %r9d
callq 0x2e458a
movl %eax, %ebx
movq 0x50(%rsp), %rax
cmpq %r12, (%rax)
jne 0x2e38cb
cmpl $0x0, 0xc(%rsp)
movl $0x1, %r12d
movl 0x1c(%rsp), %eax
cmovel %r12d, %eax
movl %eax, 0x1c(%rsp)
movq 0x40(%rsp), %r9
movq 0x10(%rsp), %r10
movq 0x60(%rsp), %r11
jmp 0x2e38df
movq 0x40(%rsp), %r9
movq 0x10(%rsp), %r10
movq 0x60(%rsp), %r11
movl 0x58(%rsp), %r12d
cmpq $-0x1, %rbp
jne 0x2e37fa
orl %ebx, %r12d
jne 0x2e392a
leaq 0xc(%rsp), %r14
movq %r14, (%rsp)
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
movq %rdx, %rsi
xorl %ecx, %ecx
movq %r13, %r8
movl 0x2c(%rsp), %ebp
movl %ebp, %r9d
callq 0x2e458a
cmpl $0x0, 0xc(%rsp)
movl %eax, %ebx
movl $0x1, %eax
movl 0x1c(%rsp), %ecx
cmovel %eax, %ecx
jmp 0x2e3937
movl 0x2c(%rsp), %ebp
leaq 0xc(%rsp), %r14
movl 0x1c(%rsp), %ecx
orl %ebx, %ecx
movq 0x38(%rsp), %rdx
jne 0x2e395e
movq %r14, (%rsp)
movq 0x30(%rsp), %rdi
movq %rdx, %rsi
movl $0x1, %ecx
movq %r13, %r8
movl %ebp, %r9d
callq 0x2e458a
movl %eax, %ebx
cmpl $0x0, 0x38(%r13)
je 0x2e396e
movq 0x30(%r13), %rdi
callq 0x27c490
movq 0x48(%rsp), %r14
movq (%r14), %rdi
movq %r13, %rsi
callq 0x28c3e7
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq