// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movq %rcx, -0x68(%rbp)
movl %edx, -0x2c(%rbp)
movq %rsi, %rbx
movq %rdi, %r15
movl 0x50(%rdi), %r14d
leal 0x1(%r14), %eax
movl %eax, 0x50(%rdi)
callq 0x4f63b
testb $0x8, 0x5(%rbx)
je 0x54401
movq 0x20(%rbx), %rsi
cmpl $0x0, 0x4c(%r15)
setne %cl
testq %rsi, %rsi
sete %dl
orb %cl, %dl
jne 0x54401
cmpq $0x0, 0x50(%rsi)
jne 0x54401
testb $0x9, 0xa(%rsi)
jne 0x54401
cmpq $0x0, 0x60(%rsi)
jne 0x54401
cmpq $0x0, 0x30(%rsi)
jne 0x54401
movq 0x28(%rsi), %rcx
cmpl $0x1, (%rcx)
jne 0x54401
cmpq $0x0, 0x30(%rcx)
je 0x54505
movl -0x2c(%rbp), %eax
testb $0x1, %al
je 0x5447a
testb $0x8, 0x5(%rbx)
jne 0x5447a
movq %r14, %r12
movq 0x10(%rbx), %r14
movq $0x0, 0x10(%rbx)
xorps %xmm0, %xmm0
leaq -0xa0(%rbp), %r13
movups %xmm0, 0x20(%r13)
movups %xmm0, 0x10(%r13)
movb $0x1, 0x24(%r13)
leaq -0xee8(%rip), %rax      # 0x53555
movq %rax, (%r13)
leaq -0xe7d(%rip), %rax      # 0x535cb
movq %rax, 0x8(%r13)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x535da
cmpb $0x0, 0x24(%r13)
movq %r14, 0x10(%rbx)
movl $0x5, %r13d
je 0x54474
movq 0x20(%rbx), %rax
cmpl $0x3, (%rax)
movl -0x2c(%rbp), %eax
jge 0x5447a
movl %r12d, 0x2c(%rbx)
jmp 0x544f3
movl 0x1d4(%r15), %r14d
testb $0x4, %al
jne 0x544a4
movl $0x2, %r13d
xorl %ecx, %ecx
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x544c6
movl 0x54(%r15), %edx
incl %edx
movl %edx, 0x54(%r15)
movl %edx, (%rax)
jmp 0x544e1
movl $0x0, 0x1d4(%r15)
movq 0x10(%rbx), %rax
movl $0x2, %r13d
xorl %edx, %edx
cmpw $0x0, 0x30(%rax)
js 0x544ca
xorl %ecx, %ecx
jmp 0x544e1
xorl %edx, %edx
jmp 0x544e1
movl $0x800, %eax            # imm = 0x800
andl 0x4(%rbx), %eax
movl %eax, %ecx
shrl $0xb, %ecx
xorl $0x1, %ecx
cmpl $0x1, %eax
sbbl $0x0, %r13d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x51cc7
movl %r14d, 0x1d4(%r15)
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rcx), %rdx
testq %rdx, %rdx
je 0x54401
testb $0x10, 0x46(%rdx)
jne 0x54401
movq (%rsi), %rcx
cmpl $0x1, (%rcx)
jne 0x54401
movq 0x8(%rcx), %rcx
movq (%rcx), %r13
cmpb $-0x68, (%r13)
jne 0x54401
movq %rax, -0x38(%rbp)
movq %r14, -0x48(%rbp)
movq (%r15), %rax
movq %rax, -0x58(%rbp)
movzwl 0x30(%r13), %eax
movq %rax, -0x60(%rbp)
movq %rdx, -0x50(%rbp)
movq 0x68(%rdx), %rcx
testq %rcx, %rcx
je 0x5458d
movq -0x58(%rbp), %rax
movl 0x28(%rax), %edx
testl %edx, %edx
jle 0x54594
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rsi
addq $0x18, %rsi
xorl %eax, %eax
cmpq %rcx, (%rsi)
je 0x54596
incq %rax
addq $0x20, %rsi
cmpq %rax, %rdx
jne 0x54578
movl %edx, %eax
jmp 0x54596
movl $0xfff0bdc0, %eax       # imm = 0xFFF0BDC0
jmp 0x54596
xorl %eax, %eax
movswl %ax, %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x548c0
movq -0x50(%rbp), %r14
movl 0x38(%r14), %edx
movq (%r14), %r8
movq %r15, %rdi
movl %r12d, -0x3c(%rbp)
movl %r12d, %esi
xorl %ecx, %ecx
callq 0x4fa6d
cmpw $0x0, -0x60(%rbp)
js 0x54613
movq 0x10(%rbx), %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x54122
movq %rax, -0x70(%rbp)
movq 0x8(%r14), %rax
movq -0x60(%rbp), %rcx
leaq (%rcx,%rcx,2), %r12
movl %r12d, %ecx
shll $0x4, %ecx
movb 0x29(%rax,%rcx), %r13b
movq %rbx, %rdi
callq 0x547f7
cmpb $0x41, %al
je 0x54683
movzbl %al, %eax
cmpl $0x42, %eax
jne 0x54687
cmpb $0x42, %r13b
sete %al
jmp 0x5468e
movq %r15, %rdi
callq 0x4f63b
movl 0x5c(%r15), %edx
leal 0x1(%rdx), %ecx
movl %ecx, 0x5c(%r15)
movq %rax, %rdi
movl $0x2d, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl %eax, %r12d
movq %r15, %rdi
movq -0x48(%rbp), %rsi
movl -0x3c(%rbp), %edx
movq %r14, %rcx
movl $0x37, %r8d
callq 0x4f965
movq -0x38(%rbp), %rsi
movl 0x3c(%rsi), %eax
leal -0x1(%rax), %ecx
movq 0x30(%rsi), %rdx
movl %ecx, 0x68(%rdx)
movq (%rsi), %rdx
cmpb $0x0, 0x51(%rdx)
je 0x546f7
movl $0x1, %r13d
leaq 0x3ee7a(%rip), %rcx     # 0x934f8
jmp 0x54717
movb $0x1, %al
jmp 0x5468e
cmpb $0x43, %r13b
setge %al
movq -0x50(%rbp), %rcx
movq 0x10(%rcx), %r13
testq %r13, %r13
movq -0x48(%rbp), %r14
je 0x54401
testb %al, %al
je 0x54401
movq 0x8(%r13), %rax
movq -0x60(%rbp), %rcx
cmpw %cx, (%rax)
jne 0x546e9
movq -0x58(%rbp), %rdi
movzbl 0x4e(%rdi), %esi
movq 0x40(%r13), %rax
movq (%rax), %rdx
xorl %ecx, %ecx
callq 0x4fd27
cmpq -0x70(%rbp), %rax
jne 0x546e9
testb $0x4, -0x2c(%rbp)
je 0x54723
cmpw $0x1, 0x5e(%r13)
jne 0x546e9
cmpb $0x0, 0x62(%r13)
jne 0x54723
movq 0x28(%r13), %r13
testq %r13, %r13
jne 0x546ab
jmp 0x54401
testl %r12d, %r12d
cmovnsl %r12d, %ecx
movl $0x1, %r13d
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
movq -0x38(%rbp), %rdx
addq 0x8(%rdx), %rcx
movl %eax, 0x8(%rcx)
movq -0x48(%rbp), %r12
jmp 0x54474
movq %r15, %rdi
callq 0x4f63b
movl 0x5c(%r15), %edx
leal 0x1(%rdx), %ecx
movl %ecx, 0x5c(%r15)
movq %rax, %rdi
movl $0x2d, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl %eax, -0x2c(%rbp)
movl 0x58(%r13), %ecx
movq -0x38(%rbp), %rdi
movl $0x37, %esi
movl %r14d, %edx
movl -0x3c(%rbp), %r8d
callq 0x3ea9f
movq 0x10(%r15), %r14
movq %r15, %rdi
movq %r13, %rsi
callq 0x4fb6d
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %rax, %rdx
movl $0xfffffffa, %ecx       # imm = 0xFFFFFFFA
callq 0x14b4f
movq 0x38(%r13), %rax
movzbl (%rax), %r13d
cmpq $0x0, -0x68(%rbp)
je 0x547c8
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
shll $0x4, %r12d
cmpb $0x0, 0x28(%rax,%r12)
jne 0x547c8
movl 0x54(%r15), %edx
incl %edx
movl %edx, 0x54(%r15)
movq -0x68(%rbp), %rax
movl %edx, (%rax)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x542d6
addl $0x3, %r13d
movq -0x38(%rbp), %rsi
movl 0x3c(%rsi), %eax
leal -0x1(%rax), %ecx
movq 0x30(%rsi), %rdx
movl %ecx, 0x68(%rdx)
movq (%rsi), %rdx
cmpb $0x0, 0x51(%rdx)
jne 0x54677
movl -0x2c(%rbp), %edx
testl %edx, %edx
cmovnsl %edx, %ecx
jmp 0x54704