// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: allocateIndexInfo
static sqlite3_index_info *allocateIndexInfo(
  Parse *pParse,
  WhereClause *pWC,
  struct SrcList_item *pSrc,
  ExprList *pOrderBy
){
  int i, j;
  int nTerm;
  struct sqlite3_index_constraint *pIdxCons;
  struct sqlite3_index_orderby *pIdxOrderBy;
  struct sqlite3_index_constraint_usage *pUsage;
  WhereTerm *pTerm;
  int nOrderBy;
  sqlite3_index_info *pIdxInfo;

  /* 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;
    assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
    testcase( pTerm->eOperator & WO_IN );
    testcase( pTerm->eOperator & WO_ISNULL );
    if( pTerm->eOperator & (WO_ISNULL) ) continue;
    if( pTerm->wtFlags & TERM_VNULL ) continue;
    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 );
  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.
  */
  pIdxCons = (struct sqlite3_index_constraint*)&pIdxInfo[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;

  for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
    u8 op;
    if( pTerm->leftCursor != pSrc->iCursor ) continue;
    assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
    testcase( pTerm->eOperator & WO_IN );
    testcase( pTerm->eOperator & WO_ISNULL );
    if( pTerm->eOperator & (WO_ISNULL) ) continue;
    if( pTerm->wtFlags & TERM_VNULL ) continue;
    pIdxCons[j].iColumn = pTerm->u.leftColumn;
    pIdxCons[j].iTermOffset = i;
    op = (u8)pTerm->eOperator & WO_ALL;
    if( op==WO_IN ) op = WO_EQ;
    pIdxCons[j].op = 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( WO_MATCH==SQLITE_INDEX_CONSTRAINT_MATCH );
    assert( pTerm->eOperator & (WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) );
    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;
  }

  return pIdxInfo;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x78d29
movq -0x58(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
je 0x78ce3
jmp 0x78d12
movq -0x58(%rbp), %rax
movzwl 0x18(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x78cf7
jmp 0x78d12
movq -0x58(%rbp), %rax
movzbl 0x1a(%rax), %eax
andl $0x0, %eax
cmpl $0x0, %eax
je 0x78d09
jmp 0x78d12
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x58(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x58(%rbp)
jmp 0x78cc5
movl $0x0, -0x5c(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x78da6
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x78d96
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x98, %eax
jne 0x78d87
movq -0x78(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
je 0x78d89
jmp 0x78d96
jmp 0x78d8b
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x78d47
movl -0x2c(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jne 0x78da4
movl -0x6c(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0x78da6
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movslq -0x34(%rbp), %rax
imulq $0x14, %rax, %rax
addq $0x48, %rax
movslq -0x5c(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movl %eax, %esi
callq 0x11ca0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x78df5
movq -0x10(%rbp), %rdi
leaq 0x3547a(%rip), %rsi     # 0xae25b
movb $0x0, %al
callq 0x136f0
movq $0x0, -0x8(%rbp)
jmp 0x78fbf
movq -0x68(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movslq -0x5c(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl -0x34(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movl -0x5c(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x50(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x20(%rax)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x78f48
movq -0x58(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
je 0x78e9d
jmp 0x78f2e
movq -0x58(%rbp), %rax
movzwl 0x18(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x78eb1
jmp 0x78f2e
movq -0x58(%rbp), %rax
movzbl 0x1a(%rax), %eax
andl $0x0, %eax
cmpl $0x0, %eax
je 0x78ec3
jmp 0x78f2e
movq -0x58(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x40(%rbp), %rax
movslq -0x30(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x2c(%rbp), %ecx
movq -0x40(%rbp), %rax
movslq -0x30(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rax
movw 0x18(%rax), %ax
movzbl %al, %eax
andl $0xfff, %eax            # imm = 0xFFF
movb %al, -0x79(%rbp)
movzbl -0x79(%rbp), %eax
cmpl $0x1, %eax
jne 0x78f10
movb $0x2, -0x79(%rbp)
movb -0x79(%rbp), %cl
movq -0x40(%rbp), %rax
movslq -0x30(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x4(%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x58(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x58(%rbp)
jmp 0x78e78
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x78fb7
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movswl 0x30(%rax), %edx
movq -0x48(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movb 0x18(%rax), %dl
movq -0x48(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb %dl, 0x4(%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x78f4f
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)