// File: /workspace/github_c_makefile_star2_O2/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: sqlite3FindInIndex
SQLITE_PRIVATE int sqlite3FindInIndex(Parse *pParse, Expr *pX, u32 inFlags, int *prRhsHasNull){
  Select *p;                            /* SELECT to the right of IN operator */
  int eType = 0;                        /* Type of RHS table. IN_INDEX_* */
  int iTab = pParse->nTab++;            /* Cursor of the RHS table */
  int mustBeUnique;                     /* True if RHS must be unique */
  Vdbe *v = sqlite3GetVdbe(pParse);     /* Virtual machine being coded */

  assert( pX->op==TK_IN );
  mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;

  /* Check to see if an existing table or index can be used to
  ** satisfy the query.  This is preferable to generating a new 
  ** ephemeral table.
  */
  p = (ExprHasProperty(pX, EP_xIsSelect) ? pX->x.pSelect : 0);
  if( pParse->nErr==0 && isCandidateForInOpt(p) ){
    sqlite3 *db = pParse->db;              /* Database connection */
    Table *pTab;                           /* Table <table>. */
    Expr *pExpr;                           /* Expression <column> */
    i16 iCol;                              /* Index of column <column> */
    i16 iDb;                               /* Database idx for pTab */

    assert( p );                        /* Because of isCandidateForInOpt(p) */
    assert( p->pEList!=0 );             /* Because of isCandidateForInOpt(p) */
    assert( p->pEList->a[0].pExpr!=0 ); /* Because of isCandidateForInOpt(p) */
    assert( p->pSrc!=0 );               /* Because of isCandidateForInOpt(p) */
    pTab = p->pSrc->a[0].pTab;
    pExpr = p->pEList->a[0].pExpr;
    iCol = (i16)pExpr->iColumn;
   
    /* Code an OP_Transaction and OP_TableLock for <table>. */
    iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
    sqlite3CodeVerifySchema(pParse, iDb);
    sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);

    /* This function is only called from two places. In both cases the vdbe
    ** has already been allocated. So assume sqlite3GetVdbe() is always
    ** successful here.
    */
    assert(v);
    if( iCol<0 ){
      int iAddr = sqlite3CodeOnce(pParse);
      VdbeCoverage(v);

      sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
      eType = IN_INDEX_ROWID;

      sqlite3VdbeJumpHere(v, iAddr);
    }else{
      Index *pIdx;                         /* Iterator variable */

      /* The collation sequence used by the comparison. If an index is to
      ** be used in place of a temp-table, it must be ordered according
      ** to this collation sequence.  */
      CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pExpr);

      /* Check that the affinity that will be used to perform the 
      ** comparison is the same as the affinity of the column. If
      ** it is not, it is not possible to use any index.
      */
      int affinity_ok = sqlite3IndexAffinityOk(pX, pTab->aCol[iCol].affinity);

      for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
        if( (pIdx->aiColumn[0]==iCol)
         && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
         && (!mustBeUnique || (pIdx->nKeyCol==1 && IsUniqueIndex(pIdx)))
        ){
          int iAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
          sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
          sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
          VdbeComment((v, "%s", pIdx->zName));
          assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
          eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];

          if( prRhsHasNull && !pTab->aCol[iCol].notNull ){
            *prRhsHasNull = ++pParse->nMem;
            sqlite3SetHasNullFlag(v, iTab, *prRhsHasNull);
          }
          sqlite3VdbeJumpHere(v, iAddr);
        }
      }
    }
  }

  /* If no preexisting index is available for the IN clause
  ** and IN_INDEX_NOOP is an allowed reply
  ** and the RHS of the IN operator is a list, not a subquery
  ** and the RHS is not contant or has two or fewer terms,
  ** then it is not worth creating an ephemeral table to evaluate
  ** the IN operator so return IN_INDEX_NOOP.
  */
  if( eType==0
   && (inFlags & IN_INDEX_NOOP_OK)
   && !ExprHasProperty(pX, EP_xIsSelect)
   && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
  ){
    eType = IN_INDEX_NOOP;
  }
     

  if( eType==0 ){
    /* Could not find an existing table or index to use as the RHS b-tree.
    ** We will have to generate an ephemeral table to do the job.
    */
    u32 savedNQueryLoop = pParse->nQueryLoop;
    int rMayHaveNull = 0;
    eType = IN_INDEX_EPH;
    if( inFlags & IN_INDEX_LOOP ){
      pParse->nQueryLoop = 0;
      if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
        eType = IN_INDEX_ROWID;
      }
    }else if( prRhsHasNull ){
      *prRhsHasNull = rMayHaveNull = ++pParse->nMem;
    }
    sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
    pParse->nQueryLoop = savedNQueryLoop;
  }else{
    pX->iTable = iTab;
  }
  return eType;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, -0x58(%rbp)
movl %edx, %r13d
movq %rsi, %rbx
movq %rdi, %r14
movl 0x50(%rdi), %r15d
leal 0x1(%r15), %eax
movl %eax, 0x50(%rdi)
callq 0x49f90
testb $0x8, 0x5(%rbx)
je 0x4df65
movq 0x20(%rbx), %rsi
cmpl $0x0, 0x4c(%r14)
setne %cl
testq %rsi, %rsi
sete %dl
orb %cl, %dl
jne 0x4df65
cmpq $0x0, 0x50(%rsi)
jne 0x4df65
testb $0x9, 0xa(%rsi)
jne 0x4df65
cmpq $0x0, 0x60(%rsi)
jne 0x4df65
cmpq $0x0, 0x30(%rsi)
jne 0x4df65
movq 0x28(%rsi), %rcx
cmpl $0x1, (%rcx)
jne 0x4df65
cmpq $0x0, 0x30(%rcx)
je 0x4e027
testb $0x1, %r13b
je 0x4df9d
testb $0x8, 0x5(%rbx)
jne 0x4df9d
movq 0x10(%rbx), %r12
andq $0x0, 0x10(%rbx)
movq %rbx, %rdi
callq 0x4bafa
movq %r12, 0x10(%rbx)
pushq $0x5
popq %r12
testl %eax, %eax
je 0x4df97
movq 0x20(%rbx), %rax
cmpl $0x3, (%rax)
jge 0x4df9d
movl %r15d, 0x2c(%rbx)
jmp 0x4e015
movl 0x1d4(%r14), %r15d
testb $0x4, %r13b
jne 0x4dfc7
pushq $0x2
popq %r12
xorl %ecx, %ecx
movq -0x58(%rbp), %rax
testq %rax, %rax
je 0x4dfe4
movl 0x54(%r14), %edx
incl %edx
movl %edx, 0x54(%r14)
movl %edx, (%rax)
jmp 0x4e003
andl $0x0, 0x1d4(%r14)
movq 0x10(%rbx), %rax
xorl %edx, %edx
cmpw $0x0, 0x30(%rax)
js 0x4dfe8
pushq $0x2
popq %r12
xorl %ecx, %ecx
jmp 0x4e003
xorl %edx, %edx
jmp 0x4e003
movl $0x800, %eax            # imm = 0x800
andl 0x4(%rbx), %eax
movl %eax, %ecx
shrl $0xb, %ecx
xorl $0x1, %ecx
cmpl $0x1, %eax
pushq $0x2
popq %r12
sbbl $0x0, %r12d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4bdec
movl %r15d, 0x1d4(%r14)
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rcx), %r12
testq %r12, %r12
je 0x4df65
testb $0x10, 0x46(%r12)
jne 0x4df65
movq (%rsi), %rcx
cmpl $0x1, (%rcx)
jne 0x4df65
movq 0x8(%rcx), %rcx
movq (%rcx), %rcx
cmpb $-0x68, (%rcx)
jne 0x4df65
movq %rax, -0x48(%rbp)
movq (%r14), %rdi
movq %rcx, -0x38(%rbp)
movswq 0x30(%rcx), %rax
movq %rax, -0x50(%rbp)
movq 0x68(%r12), %rsi
movq %rdi, -0x78(%rbp)
callq 0x136fb
movswl %ax, %esi
movl %esi, -0x2c(%rbp)
movq %r14, %rdi
callq 0x4e2fd
movl 0x38(%r12), %edx
movq (%r12), %r8
movq %r12, -0x40(%rbp)
xorl %r12d, %r12d
movq %r14, %rdi
movl -0x2c(%rbp), %esi
xorl %ecx, %ecx
callq 0x4a1b8
movq -0x50(%rbp), %rax
testq %rax, %rax
js 0x4e207
movq 0x10(%rbx), %rsi
movq %r14, %rdi
movq -0x38(%rbp), %rdx
callq 0x4dcde
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
imulq $0x30, -0x50(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movsbl 0x29(%rax,%rcx), %esi
movq %rbx, %rdi
callq 0x4e35a
movl %eax, -0x60(%rbp)
movq -0x40(%rbp), %rax
leaq 0x10(%rax), %rdx
movq (%rdx), %rdx
testq %rdx, %rdx
je 0x4e1f9
testl %r12d, %r12d
jne 0x4e1f9
cmpl $0x0, -0x60(%rbp)
je 0x4e1f9
movq 0x8(%rdx), %rax
xorl %r12d, %r12d
movq -0x50(%rbp), %rcx
cmpw %cx, (%rax)
jne 0x4e1f0
movq -0x78(%rbp), %rdi
movzbl 0x4e(%rdi), %esi
movq %rdx, -0x38(%rbp)
movq 0x40(%rdx), %rax
movq (%rax), %rdx
xorl %r12d, %r12d
xorl %ecx, %ecx
callq 0x4a430
cmpq -0x70(%rbp), %rax
jne 0x4e1ec
testb $0x4, %r13b
movq -0x38(%rbp), %rdx
je 0x4e16c
cmpw $0x1, 0x5e(%rdx)
jne 0x4e1f0
cmpb $0x0, 0x62(%rdx)
je 0x4e1f0
movq %r14, %rdi
movq %rdx, %r12
callq 0x4de0e
movl %eax, -0x5c(%rbp)
movl 0x58(%r12), %ecx
movq -0x48(%rbp), %rdi
pushq $0x37
popq %rsi
movl %r15d, %edx
movl -0x2c(%rbp), %r8d
callq 0x385b6
movq %r14, %rdi
movq %r12, %rsi
callq 0x4a28d
movq 0x38(%r12), %rax
movzbl (%rax), %r12d
cmpq $0x0, -0x58(%rbp)
je 0x4e1dc
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x68(%rbp), %rcx
cmpb $0x0, 0x28(%rax,%rcx)
jne 0x4e1dc
movl 0x54(%r14), %edx
incl %edx
movl %edx, 0x54(%r14)
movq -0x58(%rbp), %rax
movl %edx, (%rax)
movq -0x48(%rbp), %rdi
movl %r15d, %esi
callq 0x4de87
addl $0x3, %r12d
movq -0x48(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x4a022
movq -0x38(%rbp), %rdx
addq $0x28, %rdx
jmp 0x4e0f3
testl %r12d, %r12d
jne 0x4df97
jmp 0x4df65
movq %r14, %rdi
callq 0x4de0e
movl %eax, %r12d
pushq $0x37
popq %r8
movq %r14, %rdi
movl %r15d, %esi
movl -0x2c(%rbp), %edx
movq -0x40(%rbp), %rcx
callq 0x4a0e1
movq -0x48(%rbp), %rdi
movl %r12d, %esi
callq 0x4a022
pushq $0x1
popq %r12
jmp 0x4df97