// File: /workspace/github_c_makefile_star2_O1/skeeto[P]flappy/sqlite3.c
// Function: codeAllEqualityTerms
static int codeAllEqualityTerms(
  Parse *pParse,        /* Parsing context */
  WhereLevel *pLevel,   /* Which nested loop of the FROM we are coding */
  int bRev,             /* Reverse the order of IN operators */
  int nExtraReg,        /* Number of extra registers to allocate */
  char **pzAff          /* OUT: Set to point to affinity string */
){
  u16 nEq;                      /* The number of == or IN constraints to code */
  u16 nSkip;                    /* Number of left-most columns to skip */
  Vdbe *v = pParse->pVdbe;      /* The vm under construction */
  Index *pIdx;                  /* The index being used for this loop */
  WhereTerm *pTerm;             /* A single constraint term */
  WhereLoop *pLoop;             /* The WhereLoop object */
  int j;                        /* Loop counter */
  int regBase;                  /* Base register */
  int nReg;                     /* Number of registers to allocate */
  char *zAff;                   /* Affinity string to return */

  /* This module is only called on query plans that use an index. */
  pLoop = pLevel->pWLoop;
  assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
  nEq = pLoop->u.btree.nEq;
  nSkip = pLoop->u.btree.nSkip;
  pIdx = pLoop->u.btree.pIndex;
  assert( pIdx!=0 );

  /* Figure out how many memory cells we will need then allocate them.
  */
  regBase = pParse->nMem + 1;
  nReg = pLoop->u.btree.nEq + nExtraReg;
  pParse->nMem += nReg;

  zAff = sqlite3DbStrDup(pParse->db, sqlite3IndexAffinityStr(v, pIdx));
  if( !zAff ){
    pParse->db->mallocFailed = 1;
  }

  if( nSkip ){
    int iIdxCur = pLevel->iIdxCur;
    sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
    VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
    j = sqlite3VdbeAddOp0(v, OP_Goto);
    pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt),
                            iIdxCur, 0, regBase, nSkip);
    sqlite3VdbeJumpHere(v, j);
    for(j=0; j<nSkip; j++){
      sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
      assert( pIdx->aiColumn[j]>=0 );
      VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
    }
  }    

  /* Evaluate the equality constraints
  */
  assert( zAff==0 || (int)strlen(zAff)>=nEq );
  for(j=nSkip; j<nEq; j++){
    int r1;
    pTerm = pLoop->aLTerm[j];
    assert( pTerm!=0 );
    /* The following testcase is true for indices with redundant columns. 
    ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
    testcase( (pTerm->wtFlags & TERM_CODED)!=0 );
    testcase( pTerm->wtFlags & TERM_VIRTUAL );
    r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, bRev, regBase+j);
    if( r1!=regBase+j ){
      if( nReg==1 ){
        sqlite3ReleaseTempReg(pParse, regBase);
        regBase = r1;
      }else{
        sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
      }
    }
    testcase( pTerm->eOperator & WO_ISNULL );
    testcase( pTerm->eOperator & WO_IN );
    if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
      Expr *pRight = pTerm->pExpr->pRight;
      sqlite3ExprCodeIsNullJump(v, pRight, regBase+j, pLevel->addrBrk);
      if( zAff ){
        if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
          zAff[j] = SQLITE_AFF_NONE;
        }
        if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
          zAff[j] = SQLITE_AFF_NONE;
        }
      }
    }
  }
  *pzAff = zAff;
  return regBase;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, 0x48(%rsp)
movl %edx, 0xc(%rsp)
movq %rdi, %r12
movq (%rdi), %r15
movq 0x10(%rdi), %rdi
movq %rsi, 0x18(%rsp)
movq 0x40(%rsi), %rax
movzwl 0x18(%rax), %edx
movzwl 0x1a(%rax), %ebx
movq %rax, 0x50(%rsp)
movq 0x20(%rax), %rsi
movl 0x58(%r12), %r14d
movq %rdx, 0x30(%rsp)
addl %edx, %ecx
movq %rcx, 0x40(%rsp)
leal (%r14,%rcx), %eax
movl %eax, 0x58(%r12)
movq %rdi, 0x20(%rsp)
callq 0x5246d
movq %r15, %rdi
movq %rax, %rsi
callq 0x104cc
movq %rax, 0x10(%rsp)
testq %rax, %rax
jne 0x5e5df
movq (%r12), %rax
movb $0x1, 0x50(%rax)
movq %r12, 0x38(%rsp)
incl %r14d
testq %rbx, %rbx
movq 0x20(%rsp), %r12
je 0x5e6b6
movq 0x18(%rsp), %rax
movl 0x8(%rax), %ebp
xorl %r13d, %r13d
cmpl $0x0, 0xc(%rsp)
sete %r13b
leal 0x64(%r13,%r13,2), %esi
xorl %r15d, %r15d
movq %r12, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x47fb1
movq %r12, %rdi
movl $0x10, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x47fb1
movl %eax, 0x2c(%rsp)
leal 0x39(%r13,%r13,2), %esi
movq %r12, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
movl %r14d, %r8d
callq 0x47fb1
movl %eax, %r13d
movq %r12, %rdi
movl %eax, %esi
movq %rbx, %rdx
movl $0xfffffff2, %ecx       # imm = 0xFFFFFFF2
callq 0x11ea3
movl 0x2c(%rsp), %edx
movq 0x18(%rsp), %rax
movl %r13d, 0x14(%rax)
testl %edx, %edx
js 0x5e68a
movl 0x34(%r12), %eax
cmpl %edx, %eax
jbe 0x5e68a
movq 0x8(%r12), %rcx
movl %edx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
cmpw $0x2, %bx
movl $0x1, %r13d
cmovael %ebx, %r13d
leal (%r14,%r15), %r8d
movq %r12, %rdi
movl $0x2b, %esi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x47fb1
incl %r15d
cmpl %r15d, %r13d
jne 0x5e698
cmpw 0x30(%rsp), %bx
jae 0x5e7d1
movq 0x40(%rsp), %r13
movq 0x38(%rsp), %r12
movq 0x50(%rsp), %rax
movq 0x30(%rax), %rax
movq (%rax,%rbx,8), %rbp
leal (%r14,%rbx), %r15d
movq %r12, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movl %ebx, %ecx
movl 0xc(%rsp), %r8d
movl %r15d, %r9d
callq 0x5e35e
cmpl %r15d, %eax
je 0x5e75b
cmpl $0x1, %r13d
jne 0x5e739
testl %r14d, %r14d
je 0x5e758
movzbl 0x1f(%r12), %ecx
cmpq $0x7, %rcx
ja 0x5e758
xorl %edx, %edx
cmpl %r14d, 0x84(%r12,%rdx)
je 0x5e752
addq $0x18, %rdx
cmpl $0xf0, %edx
jne 0x5e714
leal 0x1(%rcx), %edx
movb %dl, 0x1f(%r12)
movl %r14d, 0x28(%r12,%rcx,4)
jmp 0x5e758
movq 0x20(%rsp), %rdi
movl $0x1f, %esi
movl %eax, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x47fb1
jmp 0x5e75b
movb $0x1, 0x7c(%r12,%rdx)
movl %eax, %r14d
testb $-0x7f, 0x1a(%rbp)
je 0x5e771
incq %rbx
cmpq 0x30(%rsp), %rbx
jne 0x5e6cb
jmp 0x5e7d1
movq (%rbp), %rax
movq 0x18(%rax), %r15
leal (%r14,%rbx), %edx
movq 0x18(%rsp), %rax
movl 0xc(%rax), %ecx
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x5e7f0
cmpq $0x0, 0x10(%rsp)
je 0x5e761
movq 0x10(%rsp), %rbp
movsbl (%rbp,%rbx), %esi
movq %r15, %rdi
callq 0x4c12f
cmpb $0x62, %al
jne 0x5e7b5
movb $0x62, (%rbp,%rbx)
movsbl (%rbp,%rbx), %esi
movq %r15, %rdi
callq 0x5e83e
testl %eax, %eax
je 0x5e761
movq 0x10(%rsp), %rax
movb $0x62, (%rax,%rbx)
jmp 0x5e761
movq 0x48(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq