// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3RefillIndex
static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
  Table *pTab = pIndex->pTable;  /* The table that is indexed */
  int iTab = pParse->nTab++;     /* Btree cursor used for pTab */
  int iIdx = pParse->nTab++;     /* Btree cursor used for pIndex */
  int iSorter;                   /* Cursor opened by OpenSorter (if in use) */
  int addr1;                     /* Address of top of loop */
  int addr2;                     /* Address to jump to for next iteration */
  Pgno tnum;                     /* Root page of index */
  int iPartIdxLabel;             /* Jump to this label to skip a row */
  Vdbe *v;                       /* Generate code into this virtual machine */
  KeyInfo *pKey;                 /* KeyInfo for index */
  int regRecord;                 /* Register holding assembled index record */
  sqlite3 *db = pParse->db;      /* The database connection */
  int iDb = sqlite3SchemaToIndex(db, pIndex->pSchema);

#ifndef SQLITE_OMIT_AUTHORIZATION
  if( sqlite3AuthCheck(pParse, SQLITE_REINDEX, pIndex->zName, 0,
      db->aDb[iDb].zDbSName ) ){
    return;
  }
#endif

  /* Require a write-lock on the table to perform this operation */
  sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);

  v = sqlite3GetVdbe(pParse);
  if( v==0 ) return;
  if( memRootPage>=0 ){
    tnum = (Pgno)memRootPage;
  }else{
    tnum = pIndex->tnum;
  }
  pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
  assert( pKey!=0 || db->mallocFailed || pParse->nErr );

  /* Open the sorter cursor if we are to use one. */
  iSorter = pParse->nTab++;
  sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
                    sqlite3KeyInfoRef(pKey), P4_KEYINFO);

  /* Open the table. Loop through all rows of the table, inserting index
  ** records into the sorter. */
  sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
  addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
  regRecord = sqlite3GetTempReg(pParse);
  sqlite3MultiWrite(pParse);

  sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
  sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
  sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel);
  sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
  sqlite3VdbeJumpHere(v, addr1);
  if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
  sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, (int)tnum, iDb,
                    (char *)pKey, P4_KEYINFO);
  sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));

  addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
  if( IsUniqueIndex(pIndex) ){
    int j2 = sqlite3VdbeGoto(v, 1);
    addr2 = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeVerifyAbortable(v, OE_Abort);
    sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
                         pIndex->nKeyCol); VdbeCoverage(v);
    sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
    sqlite3VdbeJumpHere(v, j2);
  }else{
    /* Most CREATE INDEX and REINDEX statements that are not UNIQUE can not
    ** abort. The exception is if one of the indexed expressions contains a
    ** user function that throws an exception when it is evaluated. But the
    ** overhead of adding a statement journal to a CREATE INDEX statement is
    ** very small (since most of the pages written do not contain content that
    ** needs to be restored if the statement aborts), so we call
    ** sqlite3MayAbort() for all CREATE INDEX statements.  */
    sqlite3MayAbort(pParse);
    addr2 = sqlite3VdbeCurrentAddr(v);
  }
  sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
  if( !pIndex->bAscKeyBug ){
    /* This OP_SeekEnd opcode makes index insert for a REINDEX go much
    ** faster by avoiding unnecessary seeks.  But the optimization does
    ** not work for UNIQUE constraint indexes on WITHOUT ROWID tables
    ** with DESC primary keys, since those indexes have there keys in
    ** a different order from the main table.
    ** See ticket: https://www.sqlite.org/src/info/bba7b69f9849b5bf
    */
    sqlite3VdbeAddOp1(v, OP_SeekEnd, iIdx);
  }
  sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdx, regRecord);
  sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
  sqlite3ReleaseTempReg(pParse, regRecord);
  sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
  sqlite3VdbeJumpHere(v, addr1);

  sqlite3VdbeAddOp1(v, OP_Close, iTab);
  sqlite3VdbeAddOp1(v, OP_Close, iIdx);
  sqlite3VdbeAddOp1(v, OP_Close, iSorter);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0x18(%rsi), %rbp
movl 0x34(%rdi), %r12d
leal 0x2(%r12), %eax
movl %eax, 0x34(%rdi)
movq (%rdi), %r15
movq 0x30(%rsi), %rsi
movq %r15, %rdi
callq 0x226e9e
movl %eax, %r13d
movq (%rbx), %rdx
movq 0x20(%r15), %rax
movslq %r13d, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %r8
pushq $0x1b
popq %rsi
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x26a651
testl %eax, %eax
jne 0x26fe73
movl 0x38(%rbp), %edx
movq (%rbp), %r8
pushq $0x1
popq %rcx
movq %r14, %rdi
movl %r13d, %esi
callq 0x264778
movq %r14, %rdi
callq 0x2645be
testq %rax, %rax
je 0x26fe73
movq %rax, %r15
movl 0x18(%rsp), %eax
movl %eax, 0x14(%rsp)
testl %eax, %eax
jns 0x26fba7
movl 0x58(%rbx), %eax
movl %eax, 0x14(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x264892
movl 0x34(%r14), %ecx
movq %rcx, 0x20(%rsp)
incl %ecx
movl %ecx, 0x34(%r14)
movzwl 0x5e(%rbx), %r8d
testq %rax, %rax
je 0x26fbcd
incl (%rax)
leal 0x1(%r12), %ecx
movl %ecx, 0x28(%rsp)
movl $0xfffffff7, (%rsp)     # imm = 0xFFFFFFF7
pushq $0x6f
popq %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
xorl %ecx, %ecx
movq %rax, %r9
movq %rax, 0x38(%rsp)
callq 0x264609
pushq $0x60
popq %r8
movq %r14, %rdi
movl %r12d, %esi
movl %r13d, %edx
movq %rbp, %rcx
callq 0x2646bb
pushq $0x25
popq %rsi
movq %r15, %rdi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x24d51a
movq %rax, 0x30(%rsp)
movq %r14, %rdi
callq 0x267d61
movl %eax, %ebp
movq 0xa0(%r14), %rax
testq %rax, %rax
cmoveq %r14, %rax
movb $0x1, 0x20(%rax)
andl $0x0, 0x8(%rsp)
andq $0x0, (%rsp)
leaq 0x2c(%rsp), %r9
movq %r14, %rdi
movq %rbx, %rsi
movl %r12d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x270051
movq %r15, %rdi
movl $0x83, %esi
movq 0x20(%rsp), %rdx
movl %ebp, 0x1c(%rsp)
movl %ebp, %ecx
callq 0x24d51a
leaq 0x2c(%rsp), %rax
movl (%rax), %esi
movq %r14, %rdi
callq 0x27022e
movq 0x30(%rsp), %rbp
leal 0x1(%rbp), %ecx
pushq $0x5
popq %rsi
movq %r15, %rdi
movq %r12, 0x40(%rsp)
movl %r12d, %edx
callq 0x24d51a
movq %r15, %rdi
movl %ebp, %esi
callq 0x2645f8
cmpl $0x0, 0x18(%rsp)
movl 0x14(%rsp), %ebp
jns 0x26fcc8
movq %r15, %rdi
movl $0x89, %esi
movl %ebp, %edx
movl %r13d, %ecx
callq 0x24d51a
movl $0xfffffff7, (%rsp)     # imm = 0xFFFFFFF7
pushq $0x61
popq %rsi
movq %r15, %rdi
movl 0x28(%rsp), %edx
movl %edx, %r12d
movl %ebp, %ecx
movl %r13d, %r8d
movq 0x38(%rsp), %r9
callq 0x264609
movslq 0x90(%r15), %rax
testq %rax, %rax
jle 0x26fd16
xorl %ecx, %ecx
cmpl $0x0, 0x18(%rsp)
setns %cl
shll $0x4, %ecx
incl %ecx
movq 0x88(%r15), %rdx
imulq $0x18, %rax, %rax
movw %cx, -0x16(%rdx,%rax)
pushq $0x23
popq %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rbp
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x24d51a
movl %eax, 0x18(%rsp)
cmpb $0x0, 0x62(%rbx)
je 0x26fd8a
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x264680
movl %eax, %ebp
movl 0x90(%r15), %eax
movl %eax, 0x14(%rsp)
movzwl 0x5e(%rbx), %r9d
pushq $0x7c
popq %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
movl %ebp, %ecx
movl 0x1c(%rsp), %r13d
movl %r13d, %r8d
callq 0x226fc2
pushq $0x2
popq %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x27023c
movq %r15, %rdi
movl %ebp, %esi
movq 0x20(%rsp), %rbp
callq 0x2645f8
jmp 0x26fdac
movq 0xa0(%r14), %rax
testq %rax, %rax
cmoveq %r14, %rax
movb $0x1, 0x21(%rax)
movl 0x90(%r15), %eax
movl %eax, 0x14(%rsp)
movl 0x1c(%rsp), %r13d
pushq $0x7d
popq %rsi
movq %r15, %rdi
movl %ebp, %edx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x24d51f
testb $0x2, 0x64(%rbx)
jne 0x26fdd5
movq %r15, %rdi
movl $0x81, %esi
movl %r12d, %edx
callq 0x265d5c
movq %r15, %rdi
movl $0x82, %esi
movl %r12d, %edx
movl 0x1c(%rsp), %ebx
movl %ebx, %ecx
callq 0x24d51a
movslq 0x90(%r15), %rax
testq %rax, %rax
jle 0x26fe09
movq 0x88(%r15), %rcx
imulq $0x18, %rax, %rax
movw $0x10, -0x16(%rcx,%rax)
testl %ebx, %ebx
je 0x26fe27
movzbl 0x1f(%r14), %eax
cmpq $0x7, %rax
ja 0x26fe27
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r14)
movl %ebx, 0xd4(%r14,%rax,4)
pushq $0x3
popq %rsi
movq %r15, %rdi
movl %ebp, %edx
movl 0x14(%rsp), %ecx
callq 0x24d51a
movq %r15, %rdi
movl 0x18(%rsp), %esi
callq 0x2645f8
movq %rbp, %r14
pushq $0x74
popq %rbp
movq %r15, %rdi
movl %ebp, %esi
movq 0x40(%rsp), %rdx
callq 0x265d5c
movq %r15, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x265d5c
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x265d5c
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq