// File: /workspace/github_c_makefile_star2_O1/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 0x2e50f5
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 0x2e50eb
movq 0x38(%rbp), %rax
testq %rax, 0x8(%rbx)
je 0x2e5074
andq %r13, %rax
jne 0x2e5074
movzwl 0x2c(%rbx), %eax
testl %eax, %eax
je 0x2e5070
movq 0x38(%rbx), %rcx
movl %eax, %eax
movq -0x8(%rcx,%rax,8), %rdx
testq %rdx, %rdx
je 0x2e5061
cmpq %rbp, %rdx
je 0x2e5070
movslq 0x18(%rdx), %rdx
testq %rdx, %rdx
js 0x2e5061
shlq $0x6, %rdx
addq 0x20(%r14), %rdx
cmpq %rbp, %rdx
je 0x2e5070
decq %rax
leaq 0x1(%rax), %rdx
cmpq $0x1, %rdx
jg 0x2e503c
xorl %eax, %eax
testl %eax, %eax
jle 0x2e5088
leal -0x1(%r12), %eax
addq $0x40, %rbp
cmpl $0x1, %r12d
movl %eax, %r12d
jg 0x2e5015
jmp 0x2e50eb
movzwl 0x10(%rbp), %eax
testw %ax, %ax
jle 0x2e50e5
decw 0x16(%rbx)
testb $-0x7e, 0x14(%rbp)
je 0x2e5074
movq (%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x0, (%rsp)
movq %rsp, %rsi
callq 0x2d2e59
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
movl %ecx, (%rsp)
movzwl %r15w, %eax
cmpl %eax, %ecx
jbe 0x2e5074
orb $0x20, 0x13(%rbp)
movl %ecx, %r15d
jmp 0x2e5074
addw %ax, 0x16(%rbx)
jmp 0x2e5074
movzwl %r15w, %eax
movl 0x4(%rsp), %edx
jmp 0x2e50f7
xorl %eax, %eax
movswl 0x16(%rbx), %esi
movswl %dx, %ecx
subl %eax, %ecx
cmpl %esi, %ecx
jge 0x2e5108
movw %cx, 0x16(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq