// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %rdx, %rbp
movq (%rdi), %rax
movq 0x8(%rdi), %r11
movq 0x8(%rax), %rcx
movq 0x18(%rdi), %rdx
movq %rdx, 0x48(%rsp)
movzbl 0x10(%rdx), %edx
imulq $0x70, %rdx, %rdx
leaq (%rcx,%rdx), %r8
addq $0x8, %r8
movq 0x10(%rdi), %rbx
movl 0x14(%r11), %ecx
xorl %r15d, %r15d
testl %ecx, %ecx
movq %r8, 0x18(%rsp)
jle 0x2d9fec
movq 0x20(%r11), %rdx
movl 0x40(%r8), %r9d
addq $0x14, %rdx
xorl %r10d, %r10d
cmpl %r9d, 0x8(%rdx)
jne 0x2d9fdf
testq %rbp, 0x1c(%rdx)
jne 0x2d9fdf
movzwl (%rdx), %r8d
andl $0xf7ff, %r8d           # imm = 0xF7FF
cmpw $0x1, %r8w
sbbl $-0x1, %r10d
addq $0x40, %rdx
decl %ecx
jne 0x2d9fbf
movslq %r10d, %r12
jmp 0x2d9fef
xorl %r12d, %r12d
movq %r11, 0x28(%rsp)
movq (%rax), %r14
testq %rbx, %rbx
je 0x2da042
movl (%rbx), %eax
xorl %r15d, %r15d
movl $0x0, %ecx
testl %eax, %eax
jle 0x2da03c
leaq 0x18(%rbx), %rdx
xorl %ecx, %ecx
movq 0x18(%rsp), %r9
movq -0x10(%rdx), %r8
cmpb $-0x5c, (%r8)
jne 0x2da03c
movl 0x2c(%r8), %r8d
cmpl 0x40(%r9), %r8d
jne 0x2da03c
testb $0x2, (%rdx)
jne 0x2da03c
incq %rcx
addq $0x18, %rdx
cmpq %rcx, %rax
jne 0x2da015
movl %eax, %ecx
cmpl %eax, %ecx
cmovel %eax, %r15d
movq %rdi, 0x20(%rsp)
movq %rsi, 0x38(%rsp)
movq (%r14), %rdi
leaq (%r12,%r12,4), %rax
movq %r15, 0x40(%rsp)
movslq %r15d, %r15
leaq (,%r15,8), %rcx
leaq (%rcx,%rax,4), %rsi
addq $0x70, %rsi
callq 0x279b27
testq %rax, %rax
je 0x2da20d
movq %rax, %r13
leaq 0x70(%rax), %rdx
leaq (%r12,%r12,2), %rax
movq %rax, 0x10(%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 0x28(%rsp), %rcx
movq %rcx, 0x60(%r13)
movq %r14, 0x68(%r13)
movl 0x14(%rcx), %esi
testl %esi, %esi
jle 0x2da223
movq 0x20(%rcx), %rdi
movq 0x18(%rsp), %r10
movl 0x40(%r10), %r8d
xorl %r11d, %r11d
xorl %ecx, %ecx
xorl %r15d, %r15d
cmpl %r8d, 0x1c(%rdi)
jne 0x2da16d
testq %rbp, 0x30(%rdi)
jne 0x2da16d
movzwl 0x14(%rdi), %r12d
testl $0xf7ff, %r12d          # imm = 0xF7FF
je 0x2da16d
testb $0x8, 0x3c(%r10)
je 0x2da108
movq (%rdi), %r9
testb $0x1, 0x4(%r9)
je 0x2da16d
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 0x2da142
movb 0x17(%rdi), %r10b
jmp 0x2da162
testl $0x180, %r10d           # imm = 0x180
je 0x2da182
cmpl $0x100, %r10d           # imm = 0x100
movl %r15d, %r12d
sete %r15b
movb $0x48, %r10b
subb %r15b, %r10b
movl %r12d, %r15d
movb %r10b, 0x4(%r9)
incl %ecx
movq 0x18(%rsp), %r10
incl %r11d
addq $0x40, %rdi
cmpl %r11d, %esi
jne 0x2da0d5
jmp 0x2da228
movb %r10b, 0x4(%r9)
testb $0x3c, %r10b
je 0x2da166
movl %r15d, 0x8(%rsp)
movq (%rdi), %r10
movq 0x18(%r10), %r10
movb (%r10), %r15b
cmpb $-0x53, %r15b
jne 0x2da1a5
movb 0x2(%r10), %r15b
cmpb $-0x52, %r15b
je 0x2da1bc
movzbl %r15b, %r15d
cmpl $0x88, %r15d
jne 0x2da1fb
movq 0x20(%r10), %r10
movl 0x8(%rsp), %r15d
movq 0x20(%r10), %r10
cmpl $0x2, (%r10)
jl 0x2da166
movl $0x1, %r10d
shll %cl, %r10d
cmpl $0x10, %ecx
movl $0x0, %eax
cmovgel %eax, %r10d
orl %r10d, %r15d
cmpl $0x10, %r12d
je 0x2da205
cmpl $0x4, %r12d
jne 0x2da166
movb $0x20, %r10b
jmp 0x2da162
movl 0x8(%rsp), %r15d
jmp 0x2da166
movb $0x8, %r10b
jmp 0x2da162
leaq 0x9a10d(%rip), %rsi     # 0x374321
movq %r14, %rdi
xorl %eax, %eax
callq 0x27b48d
jmp 0x2da2aa
xorl %r15d, %r15d
xorl %ecx, %ecx
movl %ecx, (%r13)
movq 0x40(%rsp), %rcx
testl %ecx, %ecx
jle 0x2da270
movl %ecx, %ecx
movq 0x10(%rsp), %rax
leaq 0x74(,%rax,4), %rax
addq %r13, %rax
addq $0x18, %rbx
xorl %edx, %edx
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 0x2da24d
xorl %eax, %eax
movq 0x48(%rsp), %rbp
movw %ax, 0x12(%rbp)
movl $0x400, 0x28(%rbp)      # imm = 0x400
movw %ax, 0x2c(%rbp)
movb $0x0, 0x1c(%rbp)
movl (%r13), %ebx
movq (%r14), %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq 0x2db076
testl %eax, %eax
je 0x2da2b4
movq (%r14), %rdi
movq %r13, %rsi
callq 0x282904
movl $0x7, %ebx
jmp 0x2da507
movq %rbx, 0x18(%rsp)
movq %r14, 0x40(%rsp)
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
movzwl %r15w, %r15d
xorl %ebx, %ebx
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %r14
movq %r14, %rsi
movq $-0x1, %rdx
xorl %ecx, %ecx
movq %r13, %r8
movl %r15d, %r9d
callq 0x2db0f4
testl %eax, %eax
je 0x2da2f9
movl %eax, %ebx
jmp 0x2da4e7
movl %r15d, 0x10(%rsp)
movq %r14, %r15
notq %r15
movq (%rbp), %r11
andq %r15, %r11
setne %cl
movl 0xc(%rsp), %eax
testl %eax, %eax
setne %dl
orb %cl, %dl
cmpb $0x1, %dl
movq 0x28(%rsp), %r10
jne 0x2da4e7
movq %r14, %rsi
testl %eax, %eax
je 0x2da387
movq %r11, %r12
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq $-0x1, %rdx
movl $0x1, %ecx
movq %r13, %r8
movq %rsi, %r14
movl 0x10(%rsp), %r9d
callq 0x2db0f4
movl %eax, %ebx
xorl %ecx, %ecx
movq 0x48(%rsp), %rax
movq (%rax), %rdx
andq %r15, %rdx
sete %al
testl %ebx, %ebx
jne 0x2da4e7
movb %al, %cl
movq %r14, %rsi
movq 0x28(%rsp), %r10
movq %r12, %r11
movq %rdx, %r12
jmp 0x2da38c
xorl %r12d, %r12d
xorl %ecx, %ecx
movq 0x18(%rsp), %rax
leaq (,%rax,4), %rax
leaq (%rax,%rax,2), %r14
xorl %ebp, %ebp
movl %ecx, 0x8(%rsp)
movl %ecx, 0x34(%rsp)
movq %r12, 0x50(%rsp)
cmpl $0x0, 0x18(%rsp)
jle 0x2da474
movq %rbp, %rax
movq 0x20(%r10), %rcx
movq 0x8(%r13), %rdx
movq $-0x1, %rbp
xorl %r9d, %r9d
movq %rbp, %rdi
movslq 0x8(%rdx,%r9), %r8
shlq $0x6, %r8
movq 0x30(%rcx,%r8), %r8
andq %r15, %r8
cmpq %rbp, %r8
cmovbq %r8, %rbp
cmpq %rax, %r8
cmovbeq %rdi, %rbp
addq $0xc, %r9
cmpq %r9, %r14
jne 0x2da3cc
cmpq $-0x1, %rbp
je 0x2da474
xorl %ebx, %ebx
cmpq %r11, %rbp
je 0x2da46a
cmpq %r12, %rbp
je 0x2da46a
movq %r11, %r12
movq %rbp, %rdx
orq %rsi, %rdx
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
xorl %ecx, %ecx
movq %r13, %r8
movl 0x10(%rsp), %r9d
callq 0x2db0f4
movq 0x38(%rsp), %rsi
movl %eax, %ebx
movq 0x48(%rsp), %rax
cmpq %rsi, (%rax)
jne 0x2da45d
cmpl $0x0, 0xc(%rsp)
movl $0x1, %ecx
movl 0x8(%rsp), %eax
movl $0x1, 0x34(%rsp)
cmovel %ecx, %eax
movl %eax, 0x8(%rsp)
movq 0x28(%rsp), %r10
movq %r12, %r11
movq 0x50(%rsp), %r12
testl %ebx, %ebx
je 0x2da3ac
jmp 0x2da4e7
xorl %ebx, %ebx
cmpl $0x0, 0x34(%rsp)
je 0x2da483
movl 0x8(%rsp), %ecx
jmp 0x2da4bb
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq %rsi, %rdx
xorl %ecx, %ecx
movq %r13, %r8
movl 0x10(%rsp), %r9d
callq 0x2db0f4
movq 0x38(%rsp), %rsi
cmpl $0x0, 0xc(%rsp)
movl %eax, %ebx
movl $0x1, %eax
movl 0x8(%rsp), %ecx
cmovel %eax, %ecx
orl %ebx, %ecx
jne 0x2da4e7
leaq 0xc(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq %rsi, %rdx
movl $0x1, %ecx
movq %r13, %r8
movl 0x10(%rsp), %r9d
callq 0x2db0f4
jmp 0x2da2f2
cmpl $0x0, 0x38(%r13)
je 0x2da4f7
movq 0x30(%r13), %rdi
callq 0x272c00
movq 0x40(%rsp), %rax
movq (%rax), %rdi
movq %r13, %rsi
callq 0x282904
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq