// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3FindInIndex
SQLITE_PRIVATE int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
  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 = (prNotFound==0);   /* True if RHS must be unique */
  Vdbe *v = sqlite3GetVdbe(pParse);     /* Virtual machine being coded */

  assert( pX->op==TK_IN );

  /* 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( ALWAYS(pParse->nErr==0) && isCandidateForInOpt(p) ){
    sqlite3 *db = pParse->db;              /* Database connection */
    Table *pTab;                           /* Table <table>. */
    Expr *pExpr;                           /* Expression <column> */
    int iCol;                              /* Index of column <column> */
    int 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 = pExpr->iColumn;
   
    /* Code an OP_VerifyCookie 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;

      iAddr = sqlite3CodeOnce(pParse);

      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->nColumn==1 && pIdx->onError!=OE_None))
        ){
          int iAddr;
          char *pKey;
  
          pKey = (char *)sqlite3IndexKeyinfo(pParse, pIdx);
          iAddr = sqlite3CodeOnce(pParse);
  
          sqlite3VdbeAddOp4(v, OP_OpenRead, iTab, pIdx->tnum, iDb,
                               pKey,P4_KEYINFO_HANDOFF);
          VdbeComment((v, "%s", pIdx->zName));
          assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
          eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];

          sqlite3VdbeJumpHere(v, iAddr);
          if( prNotFound && !pTab->aCol[iCol].notNull ){
            *prNotFound = ++pParse->nMem;
            sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
          }
        }
      }
    }
  }

  if( eType==0 ){
    /* Could not found 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( prNotFound ){
      *prNotFound = rMayHaveNull = ++pParse->nMem;
      sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
    }else{
      testcase( pParse->nQueryLoop>0 );
      pParse->nQueryLoop = 0;
      if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
        eType = IN_INDEX_ROWID;
      }
    }
    sqlite3CodeSubselect(pParse, pX, rMayHaveNull, eType==IN_INDEX_ROWID);
    pParse->nQueryLoop = savedNQueryLoop;
  }else{
    pX->iTable = iTab;
  }
  return eType;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rcx
movl 0x54(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x54(%rcx)
movl %eax, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5e000
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x2(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x800, %eax            # imm = 0x800
jne 0x6ac62
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x90(%rbp)
jmp 0x6ac6d
xorl %eax, %eax
movq %rax, -0x90(%rbp)
jmp 0x6ac6d
movq -0x90(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x6af00
movq -0x20(%rbp), %rdi
callq 0x6b0e0
cmpl $0x0, %eax
je 0x6af00
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movswl 0x30(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x13940
movl %eax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x5eb40
movq -0x8(%rbp), %rdi
movl -0x58(%rbp), %esi
movq -0x48(%rbp), %rax
movl 0x3c(%rax), %edx
movq -0x48(%rbp), %rax
movq (%rax), %r8
xorl %ecx, %ecx
callq 0x5e580
cmpl $0x0, -0x54(%rbp)
jge 0x6ad4f
movq -0x8(%rbp), %rdi
callq 0x6aa40
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x58(%rbp), %edx
movq -0x48(%rbp), %rcx
movl $0x30, %r8d
callq 0x5e480
movl $0x1, -0x24(%rbp)
movq -0x38(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x5e090
jmp 0x6aefe
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x50(%rbp), %rdx
callq 0x6aa80
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movsbl 0x29(%rax), %esi
callq 0x6b210
movl %eax, -0x74(%rbp)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x68(%rbp)
movb %al, -0x91(%rbp)
je 0x6adc1
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x91(%rbp)
jne 0x6adc1
cmpl $0x0, -0x74(%rbp)
setne %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x6add0
jmp 0x6aefc
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %eax
cmpl -0x54(%rbp), %eax
jne 0x6aee9
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x18(%rax), %rax
movb 0x71(%rax), %al
movq -0x68(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq (%rcx), %rdx
xorl %ecx, %ecx
movzbl %al, %esi
callq 0x65d70
cmpq -0x70(%rbp), %rax
jne 0x6aee9
cmpl $0x0, -0x2c(%rbp)
je 0x6ae3d
movq -0x68(%rbp), %rax
movzwl 0x54(%rax), %eax
cmpl $0x1, %eax
jne 0x6aee9
movq -0x68(%rbp), %rax
movzbl 0x56(%rax), %eax
cmpl $0x0, %eax
je 0x6aee9
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x67540
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6aa40
movl %eax, -0x78(%rbp)
movq -0x38(%rbp), %rdi
movl -0x28(%rbp), %edx
movq -0x68(%rbp), %rax
movl 0x50(%rax), %ecx
movl -0x58(%rbp), %r8d
movq -0x80(%rbp), %r9
movl $0x30, %esi
movl $0xfffffff0, (%rsp)     # imm = 0xFFFFFFF0
callq 0x5e1b0
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rax
movzbl (%rax), %eax
addl $0x3, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rdi
movl -0x78(%rbp), %esi
callq 0x5e090
cmpq $0x0, -0x18(%rbp)
je 0x6aee7
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x28(%rax)
jne 0x6aee7
movq -0x8(%rbp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movl $0x18, %esi
xorl %edx, %edx
callq 0x5e0c0
jmp 0x6aee9
jmp 0x6aeeb
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x6ad97
jmp 0x6aefe
jmp 0x6af00
cmpl $0x0, -0x24(%rbp)
jne 0x6afce
movq -0x8(%rbp), %rax
movl 0x1e8(%rax), %eax
movl %eax, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movl $0x2, -0x24(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x6af63
movq -0x8(%rbp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
movl %ecx, -0x88(%rbp)
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movl $0x18, %esi
xorl %edx, %edx
callq 0x5e0c0
jmp 0x6af9d
movq -0x8(%rbp), %rax
movl $0x0, 0x1e8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movswl 0x30(%rax), %eax
cmpl $0x0, %eax
jge 0x6af9b
movq -0x10(%rbp), %rax
movzwl 0x2(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0x6af9b
movl $0x1, -0x24(%rbp)
jmp 0x6af9d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x88(%rbp), %edx
cmpl $0x1, -0x24(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x6a0c0
movl -0x84(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1e8(%rax)
jmp 0x6afd8
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x24(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)