// File: /workspace/github_c_makefile_star2_O0/ukontainer[P]sqlite-bench/sqlite3.c
// Function: allocateIndexInfo
static sqlite3_index_info *allocateIndexInfo(
  Parse *pParse,                  /* The parsing context */
  WhereClause *pWC,               /* The WHERE clause being analyzed */
  Bitmask mUnusable,              /* Ignore terms with these prereqs */
  struct SrcList_item *pSrc,      /* The FROM clause term that is the vtab */
  ExprList *pOrderBy,             /* The ORDER BY clause */
  u16 *pmNoOmit                   /* Mask of terms not to omit */
){
  int i, j;
  int nTerm;
  struct sqlite3_index_constraint *pIdxCons;
  struct sqlite3_index_orderby *pIdxOrderBy;
  struct sqlite3_index_constraint_usage *pUsage;
  struct HiddenIndexInfo *pHidden;
  WhereTerm *pTerm;
  int nOrderBy;
  sqlite3_index_info *pIdxInfo;
  u16 mNoOmit = 0;

  /* Count the number of possible WHERE clause constraints referring
  ** to this virtual table */
  for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
    if( pTerm->leftCursor != pSrc->iCursor ) continue;
    if( pTerm->prereqRight & mUnusable ) continue;
    assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
    testcase( pTerm->eOperator & WO_IN );
    testcase( pTerm->eOperator & WO_ISNULL );
    testcase( pTerm->eOperator & WO_IS );
    testcase( pTerm->eOperator & WO_ALL );
    if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
    if( pTerm->wtFlags & TERM_VNULL ) continue;
    assert( pTerm->u.leftColumn>=(-1) );
    nTerm++;
  }

  /* If the ORDER BY clause contains only columns in the current 
  ** virtual table then allocate space for the aOrderBy part of
  ** the sqlite3_index_info structure.
  */
  nOrderBy = 0;
  if( pOrderBy ){
    int n = pOrderBy->nExpr;
    for(i=0; i<n; i++){
      Expr *pExpr = pOrderBy->a[i].pExpr;
      if( pExpr->op!=TK_COLUMN || pExpr->iTable!=pSrc->iCursor ) break;
    }
    if( i==n){
      nOrderBy = n;
    }
  }

  /* Allocate the sqlite3_index_info structure
  */
  pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
                           + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
                           + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
  if( pIdxInfo==0 ){
    sqlite3ErrorMsg(pParse, "out of memory");
    return 0;
  }

  /* Initialize the structure.  The sqlite3_index_info structure contains
  ** many fields that are declared "const" to prevent xBestIndex from
  ** changing them.  We have to do some funky casting in order to
  ** initialize those fields.
  */
  pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
  pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
  pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
  pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
  *(int*)&pIdxInfo->nConstraint = nTerm;
  *(int*)&pIdxInfo->nOrderBy = nOrderBy;
  *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;
  *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
  *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
                                                                   pUsage;

  pHidden->pWC = pWC;
  pHidden->pParse = pParse;
  for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
    u16 op;
    if( pTerm->leftCursor != pSrc->iCursor ) continue;
    if( pTerm->prereqRight & mUnusable ) continue;
    assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
    testcase( pTerm->eOperator & WO_IN );
    testcase( pTerm->eOperator & WO_IS );
    testcase( pTerm->eOperator & WO_ISNULL );
    testcase( pTerm->eOperator & WO_ALL );
    if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
    if( pTerm->wtFlags & TERM_VNULL ) continue;
    if( (pSrc->fg.jointype & JT_LEFT)!=0
     && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
     && (pTerm->eOperator & (WO_IS|WO_ISNULL))
    ){
      /* An "IS" term in the WHERE clause where the virtual table is the rhs
      ** of a LEFT JOIN. Do not pass this term to the virtual table
      ** implementation, as this can lead to incorrect results from SQL such
      ** as:
      **
      **   "LEFT JOIN vtab WHERE vtab.col IS NULL"  */
      testcase( pTerm->eOperator & WO_ISNULL );
      testcase( pTerm->eOperator & WO_IS );
      continue;
    }
    assert( pTerm->u.leftColumn>=(-1) );
    pIdxCons[j].iColumn = pTerm->u.leftColumn;
    pIdxCons[j].iTermOffset = i;
    op = pTerm->eOperator & WO_ALL;
    if( op==WO_IN ) op = WO_EQ;
    if( op==WO_AUX ){
      pIdxCons[j].op = pTerm->eMatchOp;
    }else if( op & (WO_ISNULL|WO_IS) ){
      if( op==WO_ISNULL ){
        pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
      }else{
        pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_IS;
      }
    }else{
      pIdxCons[j].op = (u8)op;
      /* The direct assignment in the previous line is possible only because
      ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical.  The
      ** following asserts verify this fact. */
      assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
      assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
      assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
      assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
      assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
      assert( pTerm->eOperator&(WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_AUX) );

      if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
       && sqlite3ExprIsVector(pTerm->pExpr->pRight) 
      ){
        if( i<16 ) mNoOmit |= (1 << i);
        if( op==WO_LT ) pIdxCons[j].op = WO_LE;
        if( op==WO_GT ) pIdxCons[j].op = WO_GE;
      }
    }

    j++;
  }
  for(i=0; i<nOrderBy; i++){
    Expr *pExpr = pOrderBy->a[i].pExpr;
    pIdxOrderBy[i].iColumn = pExpr->iColumn;
    pIdxOrderBy[i].desc = pOrderBy->a[i].sortOrder;
  }

  *pmNoOmit = mNoOmit;
  return pIdxInfo;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movw $0x0, -0x82(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x70(%rbp)
movl -0x3c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x48f10e
movq -0x70(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x40(%rcx), %eax
je 0x48f0b4
jmp 0x48f0f7
movq -0x70(%rbp), %rax
movq 0x30(%rax), %rax
andq -0x20(%rbp), %rax
cmpq $0x0, %rax
je 0x48f0c8
jmp 0x48f0f7
movq -0x70(%rbp), %rax
movzwl 0x14(%rax), %eax
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
cmpl $0x0, %eax
jne 0x48f0dc
jmp 0x48f0f7
movq -0x70(%rbp), %rax
movzwl 0x12(%rax), %eax
andl $0x0, %eax
cmpl $0x0, %eax
je 0x48f0ee
jmp 0x48f0f7
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x70(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x70(%rbp)
jmp 0x48f096
movl $0x0, -0x74(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x48f1a4
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x88(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x88(%rbp), %eax
jge 0x48f18e
movq -0x30(%rbp), %rax
addq $0x8, %rax
movslq -0x3c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x9e, %eax
jne 0x48f17f
movq -0x90(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x40(%rcx), %eax
je 0x48f181
jmp 0x48f18e
jmp 0x48f183
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x48f133
movl -0x3c(%rbp), %eax
cmpl -0x88(%rbp), %eax
jne 0x48f1a2
movl -0x88(%rbp), %eax
movl %eax, -0x74(%rbp)
jmp 0x48f1a4
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movslq -0x44(%rbp), %rax
imulq $0x14, %rax, %rsi
addq $0x60, %rsi
movslq -0x74(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
addq $0x10, %rsi
callq 0x40ee70
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x48f1f5
movq -0x10(%rbp), %rdi
leaq 0xefe13(%rip), %rsi     # 0x57eff4
movb $0x0, %al
callq 0x4110b0
movq $0x0, -0x8(%rbp)
jmp 0x48f555
movq -0x80(%rbp), %rax
addq $0x60, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movslq -0x74(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl -0x44(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, (%rax)
movl -0x74(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x50(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x60(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x70(%rbp)
movl -0x3c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x48f4d0
movq -0x70(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x40(%rcx), %eax
je 0x48f2c0
jmp 0x48f4b6
movq -0x70(%rbp), %rax
movq 0x30(%rax), %rax
andq -0x20(%rbp), %rax
cmpq $0x0, %rax
je 0x48f2d7
jmp 0x48f4b6
movq -0x70(%rbp), %rax
movzwl 0x14(%rax), %eax
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
cmpl $0x0, %eax
jne 0x48f2ee
jmp 0x48f4b6
movq -0x70(%rbp), %rax
movzwl 0x12(%rax), %eax
andl $0x0, %eax
cmpl $0x0, %eax
je 0x48f303
jmp 0x48f4b6
movq -0x28(%rbp), %rax
movzbl 0x3c(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x48f33c
movq -0x70(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x48f33c
movq -0x70(%rbp), %rax
movzwl 0x14(%rax), %eax
andl $0x180, %eax            # imm = 0x180
cmpl $0x0, %eax
je 0x48f33c
jmp 0x48f4b6
movq -0x70(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %ecx
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x70(%rbp), %rax
movzwl 0x14(%rax), %eax
andl $0x1fff, %eax           # imm = 0x1FFF
movw %ax, -0x92(%rbp)
movzwl -0x92(%rbp), %eax
cmpl $0x1, %eax
jne 0x48f392
movw $0x2, -0x92(%rbp)
movzwl -0x92(%rbp), %eax
cmpl $0x40, %eax
jne 0x48f3bc
movq -0x70(%rbp), %rax
movb 0x17(%rax), %cl
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x4(%rax)
jmp 0x48f4ad
movzwl -0x92(%rbp), %eax
andl $0x180, %eax            # imm = 0x180
cmpl $0x0, %eax
je 0x48f408
movzwl -0x92(%rbp), %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x48f3f0
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movb $0x47, 0x4(%rax)
jmp 0x48f403
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movb $0x48, 0x4(%rax)
jmp 0x48f4ab
movw -0x92(%rbp), %ax
movb %al, %cl
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x4(%rax)
movzwl -0x92(%rbp), %eax
andl $0x3c, %eax
cmpl $0x0, %eax
je 0x48f4a9
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdi
callq 0x46df00
cmpl $0x0, %eax
je 0x48f4a9
cmpl $0x10, -0x3c(%rbp)
jge 0x48f469
movl -0x3c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movzwl -0x82(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x82(%rbp)
movzwl -0x92(%rbp), %eax
cmpl $0x10, %eax
jne 0x48f488
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movb $0x8, 0x4(%rax)
movzwl -0x92(%rbp), %eax
cmpl $0x4, %eax
jne 0x48f4a7
movq -0x50(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movb $0x20, 0x4(%rax)
jmp 0x48f4a9
jmp 0x48f4ab
jmp 0x48f4ad
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x70(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x70(%rbp)
jmp 0x48f29b
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x48f53f
movq -0x30(%rbp), %rax
addq $0x8, %rax
movslq -0x3c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movswl 0x30(%rax), %edx
movq -0x58(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
addq $0x8, %rax
movslq -0x3c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movb 0x18(%rax), %dl
movq -0x58(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb %dl, 0x4(%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x48f4d7
movw -0x82(%rbp), %cx
movq -0x38(%rbp), %rax
movw %cx, (%rax)
movq -0x80(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)