// File: /workspace/github_c_makefile_star2_O3/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, 0x40(%rsp)
movq %rsi, 0x18(%rsp)
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq 0x18(%rdi), %rbp
movq 0x20(%rcx), %rdx
movq %rcx, 0x50(%rsp)
movslq 0x14(%rcx), %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0xb0(%rsp)
testq %rcx, %rcx
jle 0x2db01a
movq %rdi, %r13
shlq $0x6, %rcx
addq %rdx, %rcx
movq %rcx, (%rsp)
movzbl 0x10(%rbp), %ecx
imulq $0x70, %rcx, %rcx
movq 0x8(%rax), %rax
addq %rax, %rcx
addq $0x8, %rcx
movq (%rsp), %rsi
movq %rcx, 0x58(%rsp)
movl 0x40(%rcx), %ecx
movl %ecx, 0x28(%rsp)
leaq 0x18(%rbp), %rcx
movq %rcx, 0x48(%rsp)
xorl %r14d, %r14d
movq %rdi, 0x38(%rsp)
movq %rbp, 0x30(%rsp)
testb $0x2, 0x15(%rdx)
jne 0x2dac99
xorl %edi, %edi
jmp 0x2db005
movq %rdx, 0x8(%rsp)
movq 0x28(%rdx), %rax
movq 0x8(%rbp), %rcx
testq %rcx, 0x228(%rax)
je 0x2daf3c
movslq 0x14(%rax), %rdx
shlq $0x6, %rdx
addq 0x20(%rax), %rdx
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), %rsi
xorl %eax, %eax
movq %rdx, 0x60(%rsp)
cmpq %rdx, %rsi
jae 0x2daf5a
movq %rsi, %rcx
xorl %eax, %eax
movl $0x1, %ebp
testb $0x4, 0x15(%rcx)
jne 0x2dad7f
movl %eax, 0x14(%rsp)
movl 0x28(%rsp), %eax
cmpl %eax, 0x1c(%rcx)
movq %rcx, %rax
jne 0x2daf1b
movq 0x50(%rsp), %rcx
movq %rax, %rdx
movq (%rcx), %rax
movq %rax, 0x160(%rsp)
movq %rcx, 0x168(%rsp)
movb $0x2c, 0x170(%rsp)
movl $0x1, 0x174(%rsp)
movq %rdx, 0x20(%rsp)
movq %rdx, 0x180(%rsp)
leaq 0x160(%rsp), %rax
jmp 0x2dad88
movq %rcx, 0x20(%rsp)
movq 0x28(%rcx), %rax
movq %rax, 0xc8(%rsp)
movw $0x0, 0xf0(%rsp)
movq 0x58(%rsp), %rax
movq 0x20(%rax), %rax
cmpl $0x0, 0x54(%rax)
je 0x2dadc2
leaq 0xc0(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x2d9f67
jmp 0x2dadd4
leaq 0xc0(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x2da518
testl %eax, %eax
jne 0x2dadef
leaq 0xc0(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x2dabe2
movzwl 0xf0(%rsp), %edx
testq %rdx, %rdx
je 0x2daf43
movl %eax, 0x14(%rsp)
testl %ebp, %ebp
jne 0x2daef4
movzwl 0x80(%rsp), %ebx
movl %ebx, %edx
shll $0x4, %edx
leaq 0x130(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x17660
movw $0x0, 0x80(%rsp)
movq %rbx, 0x68(%rsp)
testl %ebx, %ebx
je 0x2daf14
movw $0x1, %ax
xorl %ecx, %ecx
testw %ax, %ax
je 0x2daee2
movq %rcx, 0x70(%rsp)
movq %rcx, %rax
shlq $0x4, %rax
leaq 0x130(%rsp), %rcx
movq (%rcx,%rax), %rdx
movq %rdx, 0x78(%rsp)
movswl 0x8(%rcx,%rax), %edx
movl %edx, 0x2c(%rsp)
movswl 0xa(%rcx,%rax), %r15d
leaq 0x102(%rsp), %rbx
xorl %r13d, %r13d
leaq 0x80(%rsp), %r14
movq -0xa(%rbx), %r12
orq 0x78(%rsp), %r12
movswl -0x2(%rbx), %esi
movl 0x2c(%rsp), %edi
callq 0x2d31ea
movl %eax, %ebp
movswl (%rbx), %esi
movl %r15d, %edi
callq 0x2d31ea
movswl %bp, %edx
movswl %ax, %ecx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2db796
incq %r13
movzwl 0xf0(%rsp), %eax
addq $0x10, %rbx
cmpq %rax, %r13
jb 0x2dae93
movq 0x70(%rsp), %rcx
jmp 0x2daee4
xorl %eax, %eax
incq %rcx
cmpq 0x68(%rsp), %rcx
jne 0x2dae4b
jmp 0x2daf14
movw %dx, 0x80(%rsp)
shll $0x4, %edx
leaq 0x88(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x17660
xorl %ebp, %ebp
movq 0x20(%rsp), %rax
addq $0x40, %rax
cmpq 0x60(%rsp), %rax
movq %rax, %rcx
movl 0x14(%rsp), %eax
jb 0x2dad20
movzwl 0x80(%rsp), %r14d
jmp 0x2daf50
xorl %edi, %edi
jmp 0x2daffc
movw $0x0, 0x80(%rsp)
xorl %r14d, %r14d
movq 0x38(%rsp), %r13
movq 0x30(%rsp), %rbp
movw $0x1, 0x2c(%rbp)
movl %eax, %edx
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 0x48(%rsp), %rax
movups %xmm0, (%rax)
testl %edx, %edx
sete %al
testw %r14w, %r14w
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2daffa
movzwl %r14w, %ebx
movl $0x1, %r15d
leaq 0x92(%rsp), %r12
movl -0x2(%r12), %eax
incl %eax
movw %ax, 0x14(%rbp)
movzwl (%r12), %eax
movw %ax, 0x16(%rbp)
movq -0xa(%r12), %rax
movq %rax, (%rbp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2db54b
movl %eax, %ecx
testl %eax, %eax
jne 0x2dafed
addq $0x10, %r12
leaq 0x1(%r15), %rax
cmpq %rbx, %r15
movq %rax, %r15
jb 0x2dafaf
movq 0x8(%rsp), %rdx
movq (%rsp), %rsi
movl %ecx, %edi
jmp 0x2db005
movl %edx, %edi
movq 0x8(%rsp), %rdx
movq (%rsp), %rsi
movl %edi, %eax
testl %edi, %edi
jne 0x2db01c
addq $0x40, %rdx
cmpq %rsi, %rdx
jb 0x2dac8c
jmp 0x2db01c
xorl %eax, %eax
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq