// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: whereLoopOutputAdjust
static void whereLoopOutputAdjust(
  WhereClause *pWC,      /* The WHERE clause */
  WhereLoop *pLoop,      /* The loop to adjust downward */
  LogEst nRow            /* Number of rows in the entire table */
){
  WhereTerm *pTerm, *pX;
  Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
  int i, j;
  LogEst iReduce = 0;    /* pLoop->nOut should not exceed nRow-iReduce */

  assert( (pLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
  for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
    assert( pTerm!=0 );
    if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
    if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
    if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
    for(j=pLoop->nLTerm-1; j>=0; j--){
      pX = pLoop->aLTerm[j];
      if( pX==0 ) continue;
      if( pX==pTerm ) break;
      if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
    }
    if( j<0 ){
      if( pTerm->truthProb<=0 ){
        /* If a truth probability is specified using the likelihood() hints,
        ** then use the probability provided by the application. */
        pLoop->nOut += pTerm->truthProb;
      }else{
        /* In the absence of explicit truth probabilities, use heuristics to
        ** guess a reasonable truth probability. */
        pLoop->nOut--;
        if( (pTerm->eOperator&(WO_EQ|WO_IS))!=0
         && (pTerm->wtFlags & TERM_HIGHTRUTH)==0  /* tag-20200224-1 */
        ){
          Expr *pRight = pTerm->pExpr->pRight;
          int k = 0;
          testcase( pTerm->pExpr->op==TK_IS );
          if( sqlite3ExprIsInteger(pRight, &k) && k>=(-1) && k<=1 ){
            k = 10;
          }else{
            k = 20;
          }
          if( iReduce<k ){
            pTerm->wtFlags |= TERM_HEURTRUTH;
            iReduce = k;
          }
        }
      }
    }
  }
  if( pLoop->nOut > nRow-iReduce )  pLoop->nOut = nRow - iReduce;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl 0x14(%rdi), %r12d
testl %r12d, %r12d
jle 0x2dbc11
movq %rdi, %r14
movl %edx, 0x4(%rsp)
movq 0x8(%rbx), %r13
orq (%rbx), %r13
notq %r13
movq 0x20(%rdi), %rbp
xorl %r15d, %r15d
testb $0x2, 0x12(%rbp)
jne 0x2dbc07
movq 0x38(%rbp), %rax
testq %rax, 0x8(%rbx)
je 0x2dbbf1
andq %r13, %rax
jne 0x2dbbf1
movzwl 0x2c(%rbx), %eax
testq %rax, %rax
je 0x2dbb8b
movq 0x38(%rbx), %rcx
movq -0x8(%rcx,%rax,8), %rdx
testq %rdx, %rdx
je 0x2dbb86
cmpq %rbp, %rdx
je 0x2dbbf1
movslq 0x18(%rdx), %rdx
testq %rdx, %rdx
js 0x2dbb86
shlq $0x6, %rdx
addq 0x20(%r14), %rdx
cmpq %rbp, %rdx
je 0x2dbbf1
decq %rax
jne 0x2dbb5d
movzwl 0x10(%rbp), %ecx
movzwl 0x16(%rbx), %eax
testw %cx, %cx
jle 0x2dbbeb
decl %eax
movw %ax, 0x16(%rbx)
testb $-0x7e, 0x14(%rbp)
je 0x2dbbf1
movq (%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x0, (%rsp)
movq %rsp, %rsi
callq 0x2c95b7
movl (%rsp), %ecx
incl %ecx
cmpl $0x3, %ecx
movl $0x14, %ecx
movl $0xa, %edx
cmovbl %edx, %ecx
testl %eax, %eax
movl $0x14, %eax
cmovel %eax, %ecx
movzwl %r15w, %eax
cmpl %eax, %ecx
jbe 0x2dbbf1
orb $0x20, 0x13(%rbp)
movl %ecx, %r15d
jmp 0x2dbbf1
addl %ecx, %eax
movw %ax, 0x16(%rbx)
leal -0x1(%r12), %eax
addq $0x40, %rbp
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x2dbb2f
movzwl %r15w, %eax
movl 0x4(%rsp), %edx
jmp 0x2dbc13
xorl %eax, %eax
movswl 0x16(%rbx), %esi
movswl %dx, %ecx
subl %eax, %ecx
cmpl %esi, %ecx
jge 0x2dbc24
movw %cx, 0x16(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq