// File: /workspace/github_c_makefile_star2_O0/skeeto[P]flappy/sqlite3.c
// Function: constructAutomaticIndex
static void constructAutomaticIndex(
  Parse *pParse,              /* The parsing context */
  WhereClause *pWC,           /* The WHERE clause */
  struct SrcList_item *pSrc,  /* The FROM clause term to get the next index */
  Bitmask notReady,           /* Mask of cursors that are not available */
  WhereLevel *pLevel          /* Write new index here */
){
  int nKeyCol;                /* Number of columns in the constructed index */
  WhereTerm *pTerm;           /* A single term of the WHERE clause */
  WhereTerm *pWCEnd;          /* End of pWC->a[] */
  Index *pIdx;                /* Object describing the transient index */
  Vdbe *v;                    /* Prepared statement under construction */
  int addrInit;               /* Address of the initialization bypass jump */
  Table *pTable;              /* The table being indexed */
  int addrTop;                /* Top of the index fill loop */
  int regRecord;              /* Register holding an index record */
  int n;                      /* Column counter */
  int i;                      /* Loop counter */
  int mxBitCol;               /* Maximum column in pSrc->colUsed */
  CollSeq *pColl;             /* Collating sequence to on a column */
  WhereLoop *pLoop;           /* The Loop object */
  char *zNotUsed;             /* Extra space on the end of pIdx */
  Bitmask idxCols;            /* Bitmap of columns used for indexing */
  Bitmask extraCols;          /* Bitmap of additional columns */
  u8 sentWarning = 0;         /* True if a warnning has been issued */

  /* Generate code to skip over the creation and initialization of the
  ** transient index on 2nd and subsequent iterations of the loop. */
  v = pParse->pVdbe;
  assert( v!=0 );
  addrInit = sqlite3CodeOnce(pParse);

  /* Count the number of columns that will be added to the index
  ** and used to match WHERE clause constraints */
  nKeyCol = 0;
  pTable = pSrc->pTab;
  pWCEnd = &pWC->a[pWC->nTerm];
  pLoop = pLevel->pWLoop;
  idxCols = 0;
  for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
    if( termCanDriveIndex(pTerm, pSrc, notReady) ){
      int iCol = pTerm->u.leftColumn;
      Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
      testcase( iCol==BMS );
      testcase( iCol==BMS-1 );
      if( !sentWarning ){
        sqlite3_log(SQLITE_WARNING_AUTOINDEX,
            "automatic index on %s(%s)", pTable->zName,
            pTable->aCol[iCol].zName);
        sentWarning = 1;
      }
      if( (idxCols & cMask)==0 ){
        if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return;
        pLoop->aLTerm[nKeyCol++] = pTerm;
        idxCols |= cMask;
      }
    }
  }
  assert( nKeyCol>0 );
  pLoop->u.btree.nEq = pLoop->nLTerm = nKeyCol;
  pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED
                     | WHERE_AUTO_INDEX;

  /* Count the number of additional columns needed to create a
  ** covering index.  A "covering index" is an index that contains all
  ** columns that are needed by the query.  With a covering index, the
  ** original table never needs to be accessed.  Automatic indices must
  ** be a covering index because the index will not be updated if the
  ** original table changes and the index and table cannot both be used
  ** if they go out of sync.
  */
  extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
  mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
  testcase( pTable->nCol==BMS-1 );
  testcase( pTable->nCol==BMS-2 );
  for(i=0; i<mxBitCol; i++){
    if( extraCols & MASKBIT(i) ) nKeyCol++;
  }
  if( pSrc->colUsed & MASKBIT(BMS-1) ){
    nKeyCol += pTable->nCol - BMS + 1;
  }
  pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY;

  /* Construct the Index object to describe this index */
  pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
  if( pIdx==0 ) return;
  pLoop->u.btree.pIndex = pIdx;
  pIdx->zName = "auto-index";
  pIdx->pTable = pTable;
  n = 0;
  idxCols = 0;
  for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
    if( termCanDriveIndex(pTerm, pSrc, notReady) ){
      int iCol = pTerm->u.leftColumn;
      Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
      testcase( iCol==BMS-1 );
      testcase( iCol==BMS );
      if( (idxCols & cMask)==0 ){
        Expr *pX = pTerm->pExpr;
        idxCols |= cMask;
        pIdx->aiColumn[n] = pTerm->u.leftColumn;
        pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
        pIdx->azColl[n] = ALWAYS(pColl) ? pColl->zName : "BINARY";
        n++;
      }
    }
  }
  assert( (u32)n==pLoop->u.btree.nEq );

  /* Add additional columns needed to make the automatic index into
  ** a covering index */
  for(i=0; i<mxBitCol; i++){
    if( extraCols & MASKBIT(i) ){
      pIdx->aiColumn[n] = i;
      pIdx->azColl[n] = "BINARY";
      n++;
    }
  }
  if( pSrc->colUsed & MASKBIT(BMS-1) ){
    for(i=BMS-1; i<pTable->nCol; i++){
      pIdx->aiColumn[n] = i;
      pIdx->azColl[n] = "BINARY";
      n++;
    }
  }
  assert( n==nKeyCol );
  pIdx->aiColumn[n] = -1;
  pIdx->azColl[n] = "BINARY";

  /* Create the automatic index */
  assert( pLevel->iIdxCur>=0 );
  pLevel->iIdxCur = pParse->nTab++;
  sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
  sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
  VdbeComment((v, "for %s", pTable->zName));

  /* Fill the automatic index with content */
  addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
  regRecord = sqlite3GetTempReg(pParse);
  sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0);
  sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
  sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
  sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
  sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
  sqlite3VdbeJumpHere(v, addrTop);
  sqlite3ReleaseTempReg(pParse, regRecord);
  
  /* Jump here when skipping the initialization */
  sqlite3VdbeJumpHere(v, addrInit);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movb $0x0, -0xa1(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
callq 0x69be0
movl %eax, -0x54(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x14(%rcx), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x79c5d
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x806f0
cmpl $0x0, %eax
je 0x79c4a
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0xa8(%rbp)
cmpl $0x40, -0xa8(%rbp)
jl 0x79b73
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
movq %rax, -0xd0(%rbp)
jmp 0x79b8a
movl -0xa8(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpb $0x0, -0xa1(%rbp)
jne 0x79bdb
movq -0x60(%rbp), %rax
movq (%rax), %rdx
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xa8(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movl $0x11c, %edi            # imm = 0x11C
leaq 0x2197a(%rip), %rsi     # 0x9b547
movb $0x0, %al
callq 0xf2d0
movb $0x1, -0xa1(%rbp)
movq -0x98(%rbp), %rax
andq -0xb0(%rbp), %rax
cmpq $0x0, %rax
jne 0x79c48
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x88(%rbp), %rsi
movl -0x2c(%rbp), %edx
addl $0x1, %edx
callq 0x7fdb0
cmpl $0x0, %eax
je 0x79c12
jmp 0x7a11e
movq -0x38(%rbp), %rdx
movq -0x88(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xb0(%rbp), %rax
orq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x79c4a
jmp 0x79c4c
movq -0x38(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x38(%rbp)
jmp 0x79b22
movl -0x2c(%rbp), %eax
movw %ax, %cx
movq -0x88(%rbp), %rax
movw %cx, 0x2c(%rax)
movq -0x88(%rbp), %rax
movw %cx, 0x18(%rax)
movq -0x88(%rbp), %rax
movl $0x4241, 0x28(%rax)     # imm = 0x4241
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x98(%rbp), %rcx
xorq $-0x1, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
orq %rdx, %rcx
andq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x60(%rbp), %rax
movswl 0x42(%rax), %eax
cmpl $0x3f, %eax
jl 0x79ccb
movl $0x3f, %eax
movl %eax, -0xd4(%rbp)
jmp 0x79cd9
movq -0x60(%rbp), %rax
movswl 0x42(%rax), %eax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, -0x74(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x79d25
movq -0xa0(%rbp), %rax
movl -0x70(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x79d18
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x79d1a
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x79ce9
movq -0x18(%rbp), %rcx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq 0x50(%rcx), %rax
cmpq $0x0, %rax
je 0x79d51
movq -0x60(%rbp), %rax
movswl 0x42(%rax), %eax
subl $0x40, %eax
addl $0x1, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x88(%rbp), %rax
movl 0x28(%rax), %ecx
orl $0x41, %ecx
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl -0x2c(%rbp), %eax
addl $0x1, %eax
xorl %edx, %edx
leaq -0x90(%rbp), %rcx
movswl %ax, %esi
callq 0x715f0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x79d8f
jmp 0x7a11e
movq -0x48(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x48(%rbp), %rax
leaq 0x217b8(%rip), %rcx     # 0x9b561
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x0, -0x6c(%rbp)
movq $0x0, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x79f20
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x806f0
cmpl $0x0, %eax
je 0x79f0d
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0xb4(%rbp)
cmpl $0x40, -0xb4(%rbp)
jl 0x79e27
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
movq %rax, -0xe0(%rbp)
jmp 0x79e3e
movl -0xb4(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x98(%rbp), %rax
andq -0xc0(%rbp), %rax
cmpq $0x0, %rax
jne 0x79f0b
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rax
orq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movw %ax, %dx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x6c(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movq -0x8(%rbp), %rdi
movq -0xc8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0xc8(%rbp), %rax
movq 0x18(%rax), %rdx
callq 0x698b0
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x79edb
movq -0x80(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xe8(%rbp)
jmp 0x79eeb
leaq 0x1f703(%rip), %rax     # 0x995e5
movq %rax, -0xe8(%rbp)
jmp 0x79eeb
movq -0xe8(%rbp), %rdx
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x6c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x79f0d
jmp 0x79f0f
movq -0x38(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x38(%rbp)
jmp 0x79dd6
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x79f90
movq -0xa0(%rbp), %rax
movl -0x70(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x79f83
movl -0x70(%rbp), %eax
movw %ax, %dx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x6c(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x6c(%rbp), %rcx
leaq 0x1f66f(%rip), %rdx     # 0x995e5
movq %rdx, (%rax,%rcx,8)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x79f85
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x79f27
movq -0x18(%rbp), %rcx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq 0x50(%rcx), %rax
cmpq $0x0, %rax
je 0x7a001
movl $0x3f, -0x70(%rbp)
movl -0x70(%rbp), %eax
movq -0x60(%rbp), %rcx
movswl 0x42(%rcx), %ecx
cmpl %ecx, %eax
jge 0x79fff
movl -0x70(%rbp), %eax
movw %ax, %dx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x6c(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x6c(%rbp), %rcx
leaq 0x1f5fe(%rip), %rdx     # 0x995e5
movq %rdx, (%rax,%rcx,8)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x79faf
jmp 0x7a001
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x6c(%rbp), %rcx
movw $0xffff, (%rax,%rcx,2)  # imm = 0xFFFF
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x6c(%rbp), %rcx
leaq 0x1f5bf(%rip), %rdx     # 0x995e5
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movl 0x54(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x54(%rax)
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movl $0x34, %esi
callq 0x63980
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x64100
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x67, %esi
callq 0x66020
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rdi
callq 0x67350
movl %eax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movl -0x68(%rbp), %ecx
xorl %r8d, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x71db0
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
movl -0x68(%rbp), %ecx
movl $0x69, %esi
callq 0x63980
movq -0x50(%rbp), %rdi
movl $0x10, %esi
callq 0x63ec0
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movl -0x64(%rbp), %ecx
addl $0x1, %ecx
movl $0x9, %esi
callq 0x63980
movq -0x50(%rbp), %rdi
movl $0x3, %esi
callq 0x63ec0
movq -0x50(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x63950
movq -0x8(%rbp), %rdi
movl -0x68(%rbp), %esi
callq 0x673a0
movq -0x50(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x63950
addq $0xf0, %rsp
popq %rbp
retq
nopw (%rax,%rax)