// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %r8, 0x30(%rsp)
movl %edx, 0x4(%rsp)
movq %rdi, %r12
movq (%rdi), %r15
movq 0x10(%rdi), %r13
movq %rsi, 0x10(%rsp)
movq 0x40(%rsi), %rax
movzwl 0x18(%rax), %edx
movzwl 0x1a(%rax), %ebx
movq %rax, 0x40(%rsp)
movq 0x20(%rax), %rsi
movl 0x58(%rdi), %r14d
movq %rdx, 0x28(%rsp)
addl %edx, %ecx
movq %rcx, 0x38(%rsp)
leal (%r14,%rcx), %eax
movl %eax, 0x58(%rdi)
movq %r13, %rdi
callq 0x52a33
movq %r15, %rdi
movq %rax, %rsi
callq 0x10656
movq %rax, 0x8(%rsp)
testq %rax, %rax
jne 0x5ee0d
movq (%r12), %rax
movb $0x1, 0x50(%rax)
incl %r14d
testq %rbx, %rbx
je 0x5eed8
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ebp
xorl %eax, %eax
cmpl $0x0, 0x4(%rsp)
sete %al
movq %rax, 0x18(%rsp)
leal (%rax,%rax,2), %esi
addl $0x64, %esi
xorl %r15d, %r15d
movq %r13, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x487d8
movq %r13, %rdi
movl $0x10, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x487d8
movl %eax, 0x24(%rsp)
movq 0x18(%rsp), %rax
leal (%rax,%rax,2), %esi
addl $0x39, %esi
movq %r13, %rdi
movl %ebp, %edx
xorl %ecx, %ecx
movl %r14d, %r8d
callq 0x487d8
movl %eax, 0x18(%rsp)
movq %r13, %rdi
movl %eax, %esi
movq %rbx, %rdx
movl $0xfffffff2, %ecx       # imm = 0xFFFFFFF2
callq 0x12044
movl 0x24(%rsp), %edx
movq 0x10(%rsp), %rax
movl 0x18(%rsp), %ecx
movl %ecx, 0x14(%rax)
testl %edx, %edx
js 0x5eeba
movl 0x34(%r13), %eax
cmpl %edx, %eax
jbe 0x5eeba
movq 0x8(%r13), %rcx
movl %edx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
leal (%r14,%r15), %r8d
movq %r13, %rdi
movl $0x2b, %esi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x487d8
incl %r15d
cmpl %r15d, %ebx
jne 0x5eeba
cmpw 0x28(%rsp), %bx
jae 0x5efec
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rax
movq (%rax,%rbx,8), %rbp
leal (%r14,%rbx), %r15d
movq %r12, %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %rdx
movl %ebx, %ecx
movl 0x4(%rsp), %r8d
movl %r15d, %r9d
callq 0x5eb90
cmpl %r15d, %eax
je 0x5ef72
cmpl $0x1, 0x38(%rsp)
jne 0x5ef52
testl %r14d, %r14d
je 0x5ef6f
movzbl 0x1f(%r12), %ecx
cmpq $0x7, %rcx
ja 0x5ef6f
xorl %edx, %edx
cmpl %r14d, 0x84(%r12,%rdx)
je 0x5ef69
addq $0x18, %rdx
cmpl $0xf0, %edx
jne 0x5ef2d
leal 0x1(%rcx), %edx
movb %dl, 0x1f(%r12)
movl %r14d, 0x28(%r12,%rcx,4)
jmp 0x5ef6f
movq %r13, %rdi
movl $0x1f, %esi
movl %eax, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x487d8
jmp 0x5ef72
movb $0x1, 0x7c(%r12,%rdx)
movl %eax, %r14d
testb $-0x7f, 0x1a(%rbp)
je 0x5ef88
incq %rbx
cmpq 0x28(%rsp), %rbx
jne 0x5eee3
jmp 0x5efec
movq (%rbp), %rax
movq 0x18(%rax), %r15
leal (%r14,%rbx), %edx
movq 0x10(%rsp), %rax
movl 0xc(%rax), %ecx
movq %r13, %rdi
movq %r15, %rsi
callq 0x5f00b
cmpq $0x0, 0x8(%rsp)
je 0x5ef78
movq 0x8(%rsp), %rbp
movsbl (%rbp,%rbx), %esi
movq %r15, %rdi
callq 0x4c8c6
cmpb $0x62, %al
jne 0x5efce
movb $0x62, (%rbp,%rbx)
movb $0x62, %al
jmp 0x5efd2
movb (%rbp,%rbx), %al
movsbl %al, %esi
movq %r15, %rdi
callq 0x5f059
testl %eax, %eax
je 0x5ef78
movq 0x8(%rsp), %rax
movb $0x62, (%rax,%rbx)
jmp 0x5ef78
movq 0x30(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq