// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: whereScanNext
static WhereTerm *whereScanNext(WhereScan *pScan){
  int iCur;            /* The cursor on the LHS of the term */
  int iColumn;         /* The column on the LHS of the term.  -1 for IPK */
  Expr *pX;            /* An expression being tested */
  WhereClause *pWC;    /* Shorthand for pScan->pWC */
  WhereTerm *pTerm;    /* The term being tested */
  int k = pScan->k;    /* Where to start scanning */

  while( pScan->iEquiv<=pScan->nEquiv ){
    iCur = pScan->aEquiv[pScan->iEquiv-2];
    iColumn = pScan->aEquiv[pScan->iEquiv-1];
    while( (pWC = pScan->pWC)!=0 ){
      for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
        if( pTerm->leftCursor==iCur && pTerm->u.leftColumn==iColumn ){
          if( (pTerm->eOperator & WO_EQUIV)!=0
           && pScan->nEquiv<ArraySize(pScan->aEquiv)
          ){
            int j;
            pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
            assert( pX->op==TK_COLUMN );
            for(j=0; j<pScan->nEquiv; j+=2){
              if( pScan->aEquiv[j]==pX->iTable
               && pScan->aEquiv[j+1]==pX->iColumn ){
                  break;
              }
            }
            if( j==pScan->nEquiv ){
              pScan->aEquiv[j] = pX->iTable;
              pScan->aEquiv[j+1] = pX->iColumn;
              pScan->nEquiv += 2;
            }
          }
          if( (pTerm->eOperator & pScan->opMask)!=0 ){
            /* Verify the affinity and collating sequence match */
            if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
              CollSeq *pColl;
              Parse *pParse = pWC->pWInfo->pParse;
              pX = pTerm->pExpr;
              if( !sqlite3IndexAffinityOk(pX, pScan->idxaff) ){
                continue;
              }
              assert(pX->pLeft);
              pColl = sqlite3BinaryCompareCollSeq(pParse,
                                                  pX->pLeft, pX->pRight);
              if( pColl==0 ) pColl = pParse->db->pDfltColl;
              if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){
                continue;
              }
            }
            if( (pTerm->eOperator & WO_EQ)!=0
             && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN
             && pX->iTable==pScan->aEquiv[0]
             && pX->iColumn==pScan->aEquiv[1]
            ){
              continue;
            }
            pScan->k = k+1;
            return pTerm;
          }
        }
      }
      pScan->pWC = pScan->pWC->pOuter;
      k = 0;
    }
    pScan->pWC = pScan->pOrigWC;
    k = 0;
    pScan->iEquiv += 2;
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x20(%rdi), %r13d
movb 0x1a(%rdi), %al
cmpb 0x19(%rbx), %al
ja 0x50796
movzbl %al, %eax
movl 0x1c(%rbx,%rax,4), %esi
movl 0x20(%rbx,%rax,4), %edi
movq 0x8(%rbx), %r15
movl %esi, -0x30(%rbp)
movl %edi, -0x2c(%rbp)
testq %r15, %r15
je 0x50766
movslq %r13d, %rax
imulq $0x38, %rax, %r14
addq 0x20(%r15), %r14
cmpl 0x14(%r15), %r13d
jge 0x50752
cmpl %esi, 0xc(%r14)
jne 0x50746
cmpl %edi, 0x10(%r14)
jne 0x50746
movzwl 0x18(%r14), %r12d
btl $0xa, %r12d
jae 0x506ac
movzbl 0x19(%rbx), %ecx
cmpl $0x15, %ecx
ja 0x506ac
movq (%r14), %rax
movq 0x18(%rax), %rdi
movq %rcx, -0x38(%rbp)
callq 0x45e0b
movq -0x38(%rbp), %r8
movl %r8d, %ecx
xorl %edx, %edx
cmpq %rcx, %rdx
jae 0x50680
movl 0x24(%rbx,%rdx,4), %esi
cmpl 0x2c(%rax), %esi
jne 0x5067a
movswl 0x30(%rax), %esi
cmpl %esi, 0x28(%rbx,%rdx,4)
je 0x50680
addq $0x2, %rdx
jmp 0x50662
cmpl %edx, %ecx
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edi
jne 0x506ac
movl 0x2c(%rax), %edx
movl %edx, 0x24(%rbx,%rcx,4)
movswl 0x30(%rax), %eax
leal (,%r8,4), %ecx
orq $0x4, %rcx
movl %eax, 0x24(%rbx,%rcx)
leal 0x2(%r8), %eax
movb %al, 0x19(%rbx)
testl %r12d, 0x1c(%rbx)
je 0x50746
testb %r12b, %r12b
js 0x50723
cmpq $0x0, 0x10(%rbx)
je 0x50723
movq (%r15), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq (%r14), %r12
movsbl 0x18(%rbx), %esi
movq %r12, %rdi
callq 0x4a030
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
testl %eax, %eax
je 0x50746
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
movq -0x38(%rbp), %r12
movq %r12, %rdi
callq 0x49bae
testq %rax, %rax
jne 0x50708
movq (%r12), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq 0x10(%rbx), %rsi
callq 0xb1bf
testl %eax, %eax
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edi
jne 0x50746
movzwl 0x18(%r14), %r12d
testb $0x2, %r12b
je 0x5077d
movq (%r14), %rax
movq 0x18(%rax), %rax
cmpb $-0x68, (%rax)
jne 0x5077d
movl 0x2c(%rax), %ecx
cmpl 0x24(%rbx), %ecx
jne 0x5077d
movswl 0x30(%rax), %eax
cmpl %eax, 0x28(%rbx)
jne 0x5077d
incl %r13d
addq $0x38, %r14
jmp 0x50616
movq 0x8(%rbx), %rax
movq 0x8(%rax), %r15
movq %r15, 0x8(%rbx)
xorl %r13d, %r13d
jmp 0x50602
movq (%rbx), %rax
movq %rax, 0x8(%rbx)
movb 0x1a(%rbx), %al
addb $0x2, %al
movb %al, 0x1a(%rbx)
xorl %r13d, %r13d
jmp 0x505e4
incl %r13d
movl %r13d, 0x20(%rbx)
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
jmp 0x50784