// File: /workspace/github_c_makefile_star2_O3/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
movb 0x19(%rdi), %al
movb 0x1a(%rdi), %cl
cmpb %al, %cl
jbe 0x59228
xorl %r15d, %r15d
jmp 0x59470
movq %rdi, %rbx
movl 0x20(%rdi), %r15d
movq 0x8(%rdi), %r13
testq %r13, %r13
je 0x5944c
movzbl %cl, %eax
movl 0x1c(%rbx,%rax,4), %r10d
movl 0x20(%rbx,%rax,4), %r11d
movl %r10d, -0x34(%rbp)
movl %r11d, -0x30(%rbp)
cmpl 0x14(%r13), %r15d
jge 0x59432
movslq %r15d, %rax
imulq $0x38, %rax, %r14
addq 0x20(%r13), %r14
cmpl %r10d, 0xc(%r14)
jne 0x5941d
cmpl %r11d, 0x10(%r14)
jne 0x5941d
movzwl 0x18(%r14), %eax
btl $0xa, %eax
jae 0x59316
movzbl 0x19(%rbx), %ecx
cmpl $0x15, %ecx
ja 0x59316
movq (%r14), %rdx
movq 0x18(%rdx), %rdx
testq %rdx, %rdx
je 0x592b5
movzbl (%rdx), %esi
cmpl $0x5c, %esi
je 0x592af
cmpl $0x18, %esi
jne 0x592b7
movq 0x10(%rdx), %rdx
jmp 0x5929d
xorl %edx, %edx
testq %rcx, %rcx
je 0x592e9
movl 0x2c(%rdx), %edi
leal -0x1(%rcx), %esi
andl $-0x2, %esi
addl $0x2, %esi
xorl %r8d, %r8d
cmpl %edi, 0x24(%rbx,%r8,4)
jne 0x592de
movswl 0x30(%rdx), %r9d
cmpl %r9d, 0x28(%rbx,%r8,4)
je 0x592ed
addq $0x2, %r8
cmpq %rcx, %r8
jb 0x592cb
jmp 0x592f0
xorl %esi, %esi
jmp 0x592f0
movl %r8d, %esi
cmpl %ecx, %esi
jne 0x59316
movl 0x2c(%rdx), %esi
movl %ecx, %edi
movl %esi, 0x24(%rbx,%rdi,4)
movswl 0x30(%rdx), %edx
leal (,%rcx,4), %esi
orq $0x4, %rsi
movl %edx, 0x24(%rbx,%rsi)
addl $0x2, %ecx
movb %cl, 0x19(%rbx)
testl %eax, 0x1c(%rbx)
je 0x5941d
testb %al, %al
js 0x593fc
cmpq $0x0, 0x10(%rbx)
je 0x593fc
movq (%r13), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq (%r14), %r12
movb 0x18(%rbx), %al
movb %al, -0x29(%rbp)
movq %r12, %rdi
callq 0x4f3c0
cmpb $0x61, %al
je 0x5936d
movzbl %al, %eax
cmpl $0x62, %eax
movl -0x34(%rbp), %r10d
movl -0x30(%rbp), %r11d
je 0x5937f
cmpb $0x62, -0x29(%rbp)
jg 0x5937f
jmp 0x5941d
cmpb $0x61, -0x29(%rbp)
movl -0x34(%rbp), %r10d
movl -0x30(%rbp), %r11d
jne 0x5941d
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
movq -0x40(%rbp), %r12
movq %r12, %rdi
callq 0x4ef2c
testq %rax, %rax
jne 0x593a2
movq (%r12), %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
movq 0x10(%rbx), %rax
movb (%rcx), %dl
testb %dl, %dl
movl -0x34(%rbp), %r10d
movl -0x30(%rbp), %r11d
je 0x593e1
incq %rcx
leaq 0x1ccef(%rip), %r8      # 0x760b0
movzbl %dl, %edx
movb (%rdx,%r8), %sil
movzbl (%rax), %edi
cmpb (%rdi,%r8), %sil
jne 0x593ea
incq %rax
movb (%rcx), %dl
incq %rcx
testb %dl, %dl
jne 0x593c1
xorl %edx, %edx
jmp 0x593ea
xorl %edx, %edx
leaq 0x1ccc6(%rip), %r8      # 0x760b0
movb (%rdx,%r8), %cl
movzbl (%rax), %eax
cmpb (%rax,%r8), %cl
jne 0x5941d
movzwl 0x18(%r14), %eax
testb $0x2, %al
je 0x59466
movq (%r14), %rax
movq 0x18(%rax), %rax
cmpb $-0x68, (%rax)
jne 0x59466
movl 0x2c(%rax), %ecx
cmpl 0x24(%rbx), %ecx
jne 0x59466
movswl 0x30(%rax), %eax
cmpl %eax, 0x28(%rbx)
jne 0x59466
incl %r15d
addq $0x38, %r14
cmpl 0x14(%r13), %r15d
jl 0x59266
movq 0x8(%rbx), %r13
movq 0x8(%r13), %r13
movq %r13, 0x8(%rbx)
xorl %r15d, %r15d
testq %r13, %r13
jne 0x59251
movb 0x19(%rbx), %al
movb 0x1a(%rbx), %cl
movq (%rbx), %r13
movq %r13, 0x8(%rbx)
addb $0x2, %cl
movb %cl, 0x1a(%rbx)
xorl %r15d, %r15d
cmpb %al, %cl
jbe 0x59233
jmp 0x59470
incl %r15d
movl %r15d, 0x20(%rbx)
movq %r14, %r15
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq