// File: /workspace/github_c_makefile_star2_O2/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, 0x28(%rsp)
movq %rsi, 0x8(%rsp)
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq %rdi, 0x38(%rsp)
movq 0x18(%rdi), %rdx
movq 0x20(%rcx), %rsi
movq %rcx, 0x58(%rsp)
movslq 0x14(%rcx), %rcx
shlq $0x6, %rcx
addq %rsi, %rcx
movq %rcx, 0x50(%rsp)
xorps %xmm0, %xmm0
leaq 0xb8(%rsp), %rcx
movaps %xmm0, 0x18(%rcx)
movaps %xmm0, 0x8(%rcx)
movaps %xmm0, -0x8(%rcx)
andq $0x0, 0x28(%rcx)
movq 0x8(%rax), %rax
movzbl 0x10(%rdx), %ecx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, 0x60(%rsp)
movl 0x40(%rax), %eax
movl %eax, 0x1c(%rsp)
movq %rdx, 0x10(%rsp)
leaq 0x18(%rdx), %rax
movq %rax, 0x48(%rsp)
xorl %eax, %eax
leaq 0xb0(%rsp), %r13
testl %eax, %eax
jne 0x27a317
cmpq 0x50(%rsp), %rsi
jae 0x27a317
xorl %edx, %edx
testb $0x2, 0x15(%rsi)
movq %rsi, 0x20(%rsp)
je 0x27a306
movq 0x28(%rsi), %rax
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
testq %rcx, 0x228(%rax)
je 0x27a306
movslq 0x14(%rax), %rcx
shlq $0x6, %rcx
addq 0x20(%rax), %rcx
movq %rcx, 0x68(%rsp)
movq 0x38(%rsp), %rcx
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movaps %xmm1, 0x90(%rsp)
movaps %xmm2, 0xa0(%rsp)
movaps %xmm0, 0x80(%rsp)
andq $0x0, 0x90(%rsp)
leaq 0xf0(%rsp), %rcx
movq %rcx, 0xa0(%rsp)
movq 0x20(%rax), %rbx
xorl %esi, %esi
pushq $0x1
popq %r15
cmpq 0x68(%rsp), %rbx
jae 0x27a271
testb $0x4, 0x15(%rbx)
jne 0x27a0eb
movq %rsi, 0x40(%rsp)
movl 0x1c(%rsp), %eax
cmpl %eax, 0x1c(%rbx)
jne 0x27a263
movq 0x58(%rsp), %rcx
movq (%rcx), %rax
movq %rax, 0x160(%rsp)
movq %rcx, 0x168(%rsp)
movb $0x2c, 0x170(%rsp)
movl $0x1, 0x174(%rsp)
movq %rbx, 0x180(%rsp)
leaq 0x160(%rsp), %rax
jmp 0x27a0ef
movq 0x28(%rbx), %rax
andw $0x0, 0xf0(%rsp)
movq %rax, 0x88(%rsp)
movq 0x60(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, 0x54(%rax)
je 0x27a128
leaq 0x80(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x279309
jmp 0x27a13a
leaq 0x80(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x2798a8
movq %rbx, 0x30(%rsp)
testl %eax, %eax
jne 0x27a15a
leaq 0x80(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x279f5a
movzwl 0xf0(%rsp), %r14d
testq %r14, %r14
je 0x27a27b
movq %rax, 0x40(%rsp)
testl %r15d, %r15d
jne 0x27a236
movzwl 0xb0(%rsp), %edx
movq %rdx, 0x70(%rsp)
shll $0x4, %edx
leaq 0x130(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x17630
andw $0x0, 0xb0(%rsp)
xorl %ebp, %ebp
cmpq 0x70(%rsp), %rbp
je 0x27a25b
movq %rbp, 0x78(%rsp)
shlq $0x4, %rbp
leaq 0x130(%rsp), %rax
addq %rax, %rbp
leaq 0x102(%rsp), %r12
xorl %ebx, %ebx
movzwl %r14w, %eax
cmpq %rax, %rbx
jae 0x27a229
movq -0xa(%r12), %r14
orq (%rbp), %r14
movswl 0x8(%rbp), %edi
movswl -0x2(%r12), %esi
callq 0x275e47
movl %eax, %r15d
movswl 0xa(%rbp), %edi
movswl (%r12), %esi
callq 0x275e47
movswl %r15w, %edx
movswl %ax, %ecx
movq %r13, %rdi
movq %r14, %rsi
callq 0x27a9d7
incq %rbx
movzwl 0xf0(%rsp), %r14d
addq $0x10, %r12
jmp 0x27a1d3
movq 0x78(%rsp), %rbp
incq %rbp
jmp 0x27a1aa
movw %r14w, 0xb0(%rsp)
shll $0x4, %r14d
leaq 0xb8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
movq %r14, %rdx
callq 0x17630
xorl %r15d, %r15d
movq 0x30(%rsp), %rbx
addq $0x40, %rbx
movq 0x40(%rsp), %rsi
jmp 0x27a08b
movzwl 0xb0(%rsp), %ebx
jmp 0x27a289
movq %rax, %rsi
andw $0x0, 0xb0(%rsp)
xorl %ebx, %ebx
movq 0x10(%rsp), %rcx
movw $0x1, 0x2c(%rcx)
movq 0x38(%rcx), %rax
movq 0x20(%rsp), %rdx
movq %rdx, (%rax)
movl $0x2000, 0x28(%rcx)     # imm = 0x2000
andw $0x0, 0x12(%rcx)
movb $0x0, 0x11(%rcx)
xorps %xmm0, %xmm0
movq 0x48(%rsp), %rax
movups %xmm0, (%rax)
leaq 0xc2(%rsp), %r14
xorl %r15d, %r15d
movq %rsi, %rax
movq %rax, %rdx
testl %eax, %eax
jne 0x27a306
cmpq %rbx, %r15
jae 0x27a306
movl -0x2(%r14), %eax
incl %eax
movq 0x10(%rsp), %rsi
movw %ax, 0x14(%rsi)
movzwl (%r14), %eax
movw %ax, 0x16(%rsi)
movq -0xa(%r14), %rax
movq %rax, (%rsi)
movq 0x38(%rsp), %rdi
callq 0x27a7bb
incq %r15
addq $0x10, %r14
jmp 0x27a2c9
movq 0x20(%rsp), %rsi
addq $0x40, %rsi
movq %rdx, %rax
jmp 0x279ff1
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq