// File: /workspace/github_c_makefile_star2_O1/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 0x1a(%rdi), %al
cmpb 0x19(%rdi), %al
jbe 0x5922f
xorl %r15d, %r15d
jmp 0x59465
movq %rdi, %rbx
movl 0x20(%rdi), %r15d
movq 0x8(%rbx), %r13
testq %r13, %r13
je 0x5943e
movzbl %al, %eax
movl 0x1c(%rbx,%rax,4), %r11d
movl 0x20(%rbx,%rax,4), %r8d
movl %r8d, -0x30(%rbp)
movl %r11d, -0x34(%rbp)
cmpl 0x14(%r13), %r15d
jge 0x59426
movslq %r15d, %rax
imulq $0x38, %rax, %r14
addq 0x20(%r13), %r14
cmpl %r11d, 0xc(%r14)
jne 0x59415
cmpl %r8d, 0x10(%r14)
jne 0x59415
movzwl 0x18(%r14), %eax
btl $0xa, %eax
jae 0x59312
movzbl 0x19(%rbx), %ecx
cmpl $0x15, %ecx
ja 0x59312
movq (%r14), %rdx
movq 0x18(%rdx), %rdx
testq %rdx, %rdx
je 0x592b8
movzbl (%rdx), %esi
cmpl $0x5c, %esi
je 0x592b2
cmpl $0x18, %esi
jne 0x592b8
movq 0x10(%rdx), %rdx
jmp 0x592a0
testl %ecx, %ecx
je 0x592ec
movl 0x2c(%rdx), %edi
movl %ecx, %r8d
leal -0x1(%rcx), %esi
andl $-0x2, %esi
addl $0x2, %esi
xorl %r9d, %r9d
cmpl %edi, 0x24(%rbx,%r9,4)
jne 0x592e1
movswl 0x30(%rdx), %r10d
cmpl %r10d, 0x28(%rbx,%r9,4)
je 0x592f0
addq $0x2, %r9
cmpq %r8, %r9
jb 0x592ce
jmp 0x592f3
xorl %esi, %esi
jmp 0x592f7
movl %r9d, %esi
movl -0x30(%rbp), %r8d
cmpl %ecx, %esi
jne 0x59312
movl 0x2c(%rdx), %edi
movl %esi, %esi
movl %edi, 0x24(%rbx,%rsi,4)
movswl 0x30(%rdx), %edx
movl %edx, 0x28(%rbx,%rsi,4)
addb $0x2, %cl
movb %cl, 0x19(%rbx)
testl %eax, 0x1c(%rbx)
je 0x59415
testb %al, %al
js 0x593f1
cmpq $0x0, 0x10(%rbx)
je 0x593f1
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 0x4f3ae
movl -0x30(%rbp), %r8d
movl -0x34(%rbp), %r11d
cmpb $0x62, %al
je 0x59376
movzbl %al, %eax
cmpl $0x61, %eax
jne 0x59367
cmpb $0x61, -0x29(%rbp)
sete %al
jmp 0x5936e
cmpb $0x63, -0x29(%rbp)
setge %al
testb %al, %al
je 0x59415
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
movq -0x40(%rbp), %r12
movq %r12, %rdi
callq 0x4eea5
testq %rax, %rax
jne 0x59399
movq (%r12), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdx
movq 0x10(%rbx), %rax
movb (%rdx), %cl
testb %cl, %cl
je 0x593d2
incq %rdx
leaq 0x1ccb0(%rip), %r8      # 0x76060
movl -0x34(%rbp), %r11d
movzbl %cl, %esi
movb (%rsi,%r8), %sil
movzbl (%rax), %edi
cmpb (%rdi,%r8), %sil
jne 0x593dd
incq %rax
movb (%rdx), %cl
incq %rdx
testb %cl, %cl
jne 0x593b4
jmp 0x593dd
leaq 0x1cc87(%rip), %r8      # 0x76060
movl -0x34(%rbp), %r11d
movzbl %cl, %ecx
movb (%rcx,%r8), %cl
movzbl (%rax), %eax
cmpb (%rax,%r8), %cl
movl -0x30(%rbp), %r8d
jne 0x59415
testb $0x2, 0x18(%r14)
je 0x5945b
movq (%r14), %rax
movq 0x18(%rax), %rax
cmpb $-0x68, (%rax)
jne 0x5945b
movl 0x2c(%rax), %ecx
cmpl 0x24(%rbx), %ecx
jne 0x5945b
movswl 0x30(%rax), %eax
cmpl %eax, 0x28(%rbx)
jne 0x5945b
incl %r15d
addq $0x38, %r14
cmpl 0x14(%r13), %r15d
jl 0x5926d
movq 0x8(%rbx), %rax
movq 0x8(%rax), %r13
movq %r13, 0x8(%rbx)
xorl %r15d, %r15d
testq %r13, %r13
jne 0x59258
movq (%rbx), %rax
movq %rax, 0x8(%rbx)
movb 0x1a(%rbx), %al
addb $0x2, %al
movb %al, 0x1a(%rbx)
xorl %r15d, %r15d
cmpb 0x19(%rbx), %al
jbe 0x59236
jmp 0x59465
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