// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movl %edx, 0xc(%rsp)
movq %rsi, %rbx
movq 0x8(%rsi), %rdx
orq (%rsi), %rdx
movq %rdi, %r14
notq %rdx
movl 0x14(%rdi), %r13d
movq 0x20(%rdi), %r15
xorl %ebp, %ebp
movq %rdx, 0x10(%rsp)
movzwl %bp, %r12d
testl %r13d, %r13d
jle 0x27ae4a
testb $0x2, 0x12(%r15)
jne 0x27ae4a
movq 0x38(%r15), %rax
testq %rax, 0x8(%rbx)
je 0x27ae3e
andq %rdx, %rax
jne 0x27ae3e
movzwl 0x2c(%rbx), %eax
subq $0x1, %rax
jb 0x27addb
movq 0x38(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
testq %rcx, %rcx
je 0x27adab
cmpq %r15, %rcx
je 0x27ae3e
movslq 0x18(%rcx), %rcx
testq %rcx, %rcx
js 0x27adab
shlq $0x6, %rcx
addq 0x20(%r14), %rcx
cmpq %r15, %rcx
jne 0x27adab
jmp 0x27ae3e
movzwl 0x10(%r15), %ecx
movzwl 0x16(%rbx), %eax
testw %cx, %cx
jle 0x27ae38
decl %eax
movw %ax, 0x16(%rbx)
testb $-0x7e, 0x14(%r15)
je 0x27ae3e
movq (%r15), %rax
movq 0x18(%rax), %rdi
andl $0x0, 0x8(%rsp)
leaq 0x8(%rsp), %rsi
callq 0x26f334
movl 0x8(%rsp), %ecx
incl %ecx
cmpl $0x3, %ecx
pushq $0x14
popq %rsi
movl %esi, %ecx
pushq $0xa
popq %rdx
cmovbl %edx, %ecx
testl %eax, %eax
cmovel %esi, %ecx
cmpl %r12d, %ecx
jbe 0x27ae31
orb $0x20, 0x13(%r15)
movl %ecx, %ebp
movq 0x10(%rsp), %rdx
jmp 0x27ae3e
addl %ecx, %eax
movw %ax, 0x16(%rbx)
decl %r13d
addq $0x40, %r15
jmp 0x27ad78
movswl 0x16(%rbx), %ecx
movswl 0xc(%rsp), %eax
subl %r12d, %eax
cmpl %ecx, %eax
jge 0x27ae5e
movw %ax, 0x16(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq