// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: whereLoopAddOr
static int whereLoopAddOr(
  WhereLoopBuilder *pBuilder,
  Bitmask mPrereq,
  Bitmask mUnusable
){
  WhereInfo *pWInfo = pBuilder->pWInfo;
  WhereClause *pWC;
  WhereLoop *pNew;
  WhereTerm *pTerm, *pWCEnd;
  int rc = SQLITE_OK;
  int iCur;
  WhereClause tempWC;
  WhereLoopBuilder sSubBuild;
  WhereOrSet sSum, sCur;
  struct SrcList_item *pItem;

  pWC = pBuilder->pWC;
  pWCEnd = pWC->a + pWC->nTerm;
  pNew = pBuilder->pNew;
  memset(&sSum, 0, sizeof(sSum));
  pItem = pWInfo->pTabList->a + pNew->iTab;
  iCur = pItem->iCursor;

  for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){
    if( (pTerm->eOperator & WO_OR)!=0
     && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0
    ){
      WhereClause * const pOrWC = &pTerm->u.pOrInfo->wc;
      WhereTerm * const pOrWCEnd = &pOrWC->a[pOrWC->nTerm];
      WhereTerm *pOrTerm;
      int once = 1;
      int i, j;

      sSubBuild = *pBuilder;
      sSubBuild.pOrderBy = 0;
      sSubBuild.pOrSet = &sCur;

      WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
      for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
        if( (pOrTerm->eOperator & WO_AND)!=0 ){
          sSubBuild.pWC = &pOrTerm->u.pAndInfo->wc;
        }else if( pOrTerm->leftCursor==iCur ){
          tempWC.pWInfo = pWC->pWInfo;
          tempWC.pOuter = pWC;
          tempWC.op = TK_AND;
          tempWC.nTerm = 1;
          tempWC.a = pOrTerm;
          sSubBuild.pWC = &tempWC;
        }else{
          continue;
        }
        sCur.n = 0;
#ifdef WHERETRACE_ENABLED
        WHERETRACE(0x200, ("OR-term %d of %p has %d subterms:\n",
                   (int)(pOrTerm-pOrWC->a), pTerm, sSubBuild.pWC->nTerm));
        if( sqlite3WhereTrace & 0x400 ){
          sqlite3WhereClausePrint(sSubBuild.pWC);
        }
#endif
#ifndef SQLITE_OMIT_VIRTUALTABLE
        if( IsVirtual(pItem->pTab) ){
          rc = whereLoopAddVirtual(&sSubBuild, mPrereq, mUnusable);
        }else
#endif
        {
          rc = whereLoopAddBtree(&sSubBuild, mPrereq);
        }
        if( rc==SQLITE_OK ){
          rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable);
        }
        assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 );
        testcase( rc==SQLITE_DONE );
        if( sCur.n==0 ){
          sSum.n = 0;
          break;
        }else if( once ){
          whereOrMove(&sSum, &sCur);
          once = 0;
        }else{
          WhereOrSet sPrev;
          whereOrMove(&sPrev, &sSum);
          sSum.n = 0;
          for(i=0; i<sPrev.n; i++){
            for(j=0; j<sCur.n; j++){
              whereOrInsert(&sSum, sPrev.a[i].prereq | sCur.a[j].prereq,
                            sqlite3LogEstAdd(sPrev.a[i].rRun, sCur.a[j].rRun),
                            sqlite3LogEstAdd(sPrev.a[i].nOut, sCur.a[j].nOut));
            }
          }
        }
      }
      pNew->nLTerm = 1;
      pNew->aLTerm[0] = pTerm;
      pNew->wsFlags = WHERE_MULTI_OR;
      pNew->rSetup = 0;
      pNew->iSortIdx = 0;
      memset(&pNew->u, 0, sizeof(pNew->u));
      for(i=0; rc==SQLITE_OK && i<sSum.n; i++){
        /* TUNING: Currently sSum.a[i].rRun is set to the sum of the costs
        ** of all sub-scans required by the OR-scan. However, due to rounding
        ** errors, it may be that the cost of the OR-scan is equal to its
        ** most expensive sub-scan. Add the smallest possible penalty
        ** (equivalent to multiplying the cost by 1.07) to ensure that
        ** this does not happen. Otherwise, for WHERE clauses such as the
        ** following where there is an index on "y":
        **
        **     WHERE likelihood(x=?, 0.99) OR y=?
        **
        ** the planner may elect to "OR" together a full-table scan and an
        ** index lookup. And other similarly odd results.  */
        pNew->rRun = sSum.a[i].rRun + 1;
        pNew->nOut = sSum.a[i].nOut;
        pNew->prereq = sSum.a[i].prereq;
        rc = whereLoopInsert(pBuilder, pNew);
      }
      WHERETRACE(0x200, ("End processing OR-clause %p\n", pTerm));
    }
  }
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x388, %rsp            # imm = 0x388
movq %rdx, 0x20(%rsp)
movq %rsi, %r12
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq 0x18(%rdi), %rbp
movq 0x20(%rcx), %rdx
movq %rcx, 0x40(%rsp)
movslq 0x14(%rcx), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0xb0(%rsp)
testq %rsi, %rsi
jle 0x2e44ae
movq %rdi, %r13
shlq $0x6, %rsi
addq %rdx, %rsi
movzbl 0x10(%rbp), %ecx
imulq $0x70, %rcx, %rcx
movq 0x8(%rax), %rax
addq %rcx, %rax
addq $0x8, %rax
movq %rax, 0x60(%rsp)
movl 0x40(%rax), %eax
movl %eax, 0x18(%rsp)
leaq 0x18(%rbp), %rax
movq %rax, 0x28(%rsp)
movq %r12, 0x50(%rsp)
movq %rdi, 0x38(%rsp)
movq %rbp, 0x30(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x8(%rsp)
testb $0x2, 0x15(%rdx)
movl $0x0, %edi
je 0x2e4491
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rbp), %rcx
testq %rcx, 0x228(%rax)
je 0x2e4491
movslq 0x14(%rax), %rbx
shlq $0x6, %rbx
addq 0x20(%rax), %rbx
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movaps %xmm1, 0xd0(%rsp)
movaps %xmm2, 0xe0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movq $0x0, 0xd0(%rsp)
leaq 0xf0(%rsp), %rcx
movq %rcx, 0xe0(%rsp)
movq 0x20(%rax), %r14
xorl %edi, %edi
cmpq %rbx, %r14
jae 0x2e43f3
xorl %edi, %edi
movl $0x1, %ebp
movq %rbx, 0x58(%rsp)
testb $0x4, 0x15(%r14)
jne 0x2e4221
movl 0x18(%rsp), %eax
cmpl %eax, 0x1c(%r14)
jne 0x2e43da
movq 0x40(%rsp), %rcx
movq (%rcx), %rax
movq %rax, 0x160(%rsp)
movq %rcx, 0x168(%rsp)
movb $0x2c, 0x170(%rsp)
movl $0x1, 0x174(%rsp)
movq %r14, 0x180(%rsp)
leaq 0x160(%rsp), %rax
jmp 0x2e4225
movq 0x28(%r14), %rax
movq %rax, 0xc8(%rsp)
movw $0x0, 0xf0(%rsp)
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, 0x54(%rax)
je 0x2e425d
leaq 0xc0(%rsp), %rdi
movq %r12, %rsi
movq 0x20(%rsp), %rdx
callq 0x2e33bb
jmp 0x2e426d
leaq 0xc0(%rsp), %rdi
movq %r12, %rsi
callq 0x2e398f
movl %eax, %edi
testl %eax, %eax
jne 0x2e428a
leaq 0xc0(%rsp), %rdi
movq %r12, %rsi
movq 0x20(%rsp), %rdx
callq 0x2e4090
movl %eax, %edi
movzwl 0xf0(%rsp), %edx
testq %rdx, %rdx
je 0x2e43e9
movl %edi, 0x4(%rsp)
testl %ebp, %ebp
jne 0x2e43b4
movq %r14, 0x68(%rsp)
movzwl 0x80(%rsp), %ebx
movw %bx, 0x128(%rsp)
movl %ebx, %edx
shll $0x4, %edx
leaq 0x130(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x17660
movw $0x0, 0x80(%rsp)
movq %rbx, 0x70(%rsp)
testl %ebx, %ebx
je 0x2e439d
movq $0x0, 0x10(%rsp)
cmpw $0x0, 0xf0(%rsp)
leaq 0x80(%rsp), %r14
je 0x2e4385
movq 0x10(%rsp), %rax
shlq $0x4, %rax
leaq 0x130(%rsp), %rcx
movq (%rcx,%rax), %rdx
movq %rdx, 0x78(%rsp)
movswl 0x8(%rcx,%rax), %edx
movl %edx, 0x1c(%rsp)
movswl 0xa(%rcx,%rax), %r15d
leaq 0x102(%rsp), %rbx
xorl %r13d, %r13d
movq -0xa(%rbx), %r12
orq 0x78(%rsp), %r12
movswl -0x2(%rbx), %esi
movl 0x1c(%rsp), %edi
callq 0x2dc90b
movl %eax, %ebp
movswl (%rbx), %esi
movl %r15d, %edi
callq 0x2dc90b
movswl %bp, %edx
movswl %ax, %ecx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2e4c5b
incq %r13
movzwl 0xf0(%rsp), %eax
addq $0x10, %rbx
cmpq %rax, %r13
jb 0x2e433d
movq 0x10(%rsp), %rcx
incq %rcx
movq %rcx, 0x10(%rsp)
cmpq 0x70(%rsp), %rcx
jne 0x2e42f6
xorl %ebp, %ebp
movq 0x50(%rsp), %r12
movl 0x4(%rsp), %edi
movq 0x58(%rsp), %rbx
movq 0x68(%rsp), %r14
jmp 0x2e43da
movw %dx, 0x80(%rsp)
shll $0x4, %edx
leaq 0x88(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x17660
xorl %ebp, %ebp
movl 0x4(%rsp), %edi
addq $0x40, %r14
cmpq %rbx, %r14
jb 0x2e41cf
jmp 0x2e43f3
movw $0x0, 0x80(%rsp)
movq 0x30(%rsp), %rbp
movw $0x1, 0x2c(%rbp)
movq 0x38(%rbp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movl $0x2000, 0x28(%rbp)     # imm = 0x2000
movw $0x0, 0x12(%rbp)
movb $0x0, 0x11(%rbp)
xorps %xmm0, %xmm0
movq 0x28(%rsp), %rax
movups %xmm0, (%rax)
movzwl 0x80(%rsp), %eax
testl %edi, %edi
sete %cl
testw %ax, %ax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
movq 0x38(%rsp), %r13
jne 0x2e4491
movzwl %ax, %ebx
movl $0x1, %r14d
leaq 0x92(%rsp), %r15
movl -0x2(%r15), %eax
incl %eax
movw %ax, 0x14(%rbp)
movzwl (%r15), %eax
movw %ax, 0x16(%rbp)
movq -0xa(%r15), %rax
movq %rax, (%rbp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2e4a10
movl %eax, %edi
testl %eax, %eax
jne 0x2e4491
addq $0x10, %r15
leaq 0x1(%r14), %rax
cmpq %rbx, %r14
movq %rax, %r14
jb 0x2e4456
testl %edi, %edi
jne 0x2e44b0
movq 0x8(%rsp), %rdx
addq $0x40, %rdx
movq 0x48(%rsp), %rsi
cmpq %rsi, %rdx
jb 0x2e4137
jmp 0x2e44b0
xorl %edi, %edi
movl %edi, %eax
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq