// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movl %edx, (%rsp)
movq %rsi, %r13
movq %rdi, %r14
movq 0x18(%rsi), %rbp
movl 0x34(%rdi), %ebx
leal 0x2(%rbx), %eax
movl %eax, 0x34(%rdi)
movq (%rdi), %rax
movq 0x30(%rsi), %rcx
movq 0x20(%rax), %rax
testq %rcx, %rcx
je 0x2c9ed7
leaq 0x18(%rax), %rdx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
incl %r12d
leaq 0x20(%rdx), %rsi
cmpq %rcx, (%rdx)
movq %rsi, %rdx
jne 0x2c9ec6
jmp 0x2c9edd
movl $0xffff8000, %r12d      # imm = 0xFFFF8000
movq (%r13), %rdx
movslq %r12d, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %r8
movq %r14, %rdi
movl $0x1b, %esi
xorl %ecx, %ecx
callq 0x2c37ba
testl %eax, %eax
jne 0x2ca33e
movl 0x38(%rbp), %edx
movq (%rbp), %r8
movq %r14, %rdi
movl %r12d, %esi
movl $0x1, %ecx
callq 0x2bc937
movq %r14, %rdi
callq 0x2bc630
testq %rax, %rax
je 0x2ca33e
movq %rax, %r15
movl (%rsp), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
jns 0x2c9f41
movl 0x58(%r13), %eax
movl %eax, 0x4(%rsp)
movq %rbp, 0x8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x2bca75
movq %rax, %rbp
movl 0x34(%r14), %ecx
movq %rcx, 0x10(%rsp)
incl %ecx
movl %ecx, 0x34(%r14)
movzwl 0x5e(%r13), %r8d
testq %rax, %rax
je 0x2c9f70
incl (%rbp)
movq %r15, %rdi
movl $0x6f, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2a83e1
movq %r15, %rdi
movl %eax, %esi
movq %rbp, 0x28(%rsp)
movq %rbp, %rdx
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x27b778
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
movq 0x8(%rsp), %rcx
movl $0x60, %r8d
callq 0x2bc82f
movq %r15, %rdi
movl $0x25, %esi
movq %rbx, 0x18(%rsp)
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %rax, 0x20(%rsp)
movb 0x1f(%r14), %al
testb %al, %al
je 0x2c9fec
decb %al
movb %al, 0x1f(%r14)
movzbl %al, %eax
movl 0xd4(%r14,%rax,4), %ebx
jmp 0x2c9ff6
movl 0x38(%r14), %ebx
incl %ebx
movl %ebx, 0x38(%r14)
movq 0xa0(%r14), %rax
testq %rax, %rax
cmoveq %r14, %rax
movb $0x1, 0x20(%rax)
leaq 0x34(%rsp), %rbp
movq %r14, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movl %ebx, %ecx
xorl %r8d, %r8d
movq %rbp, %r9
pushq $0x0
pushq $0x0
callq 0x2ca5e6
addq $0x10, %rsp
movq %r15, %rdi
movl $0x83, %esi
movq 0x10(%rsp), %rdx
movl %ebx, 0x8(%rsp)
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl (%rbp), %esi
testl %esi, %esi
je 0x2ca058
movq 0x10(%r14), %rdi
callq 0x2bfa39
movq 0x20(%rsp), %rbx
leal 0x1(%rbx), %ecx
movq %r15, %rdi
movl $0x5, %esi
movq 0x18(%rsp), %rbp
movl %ebp, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x90(%r15), %eax
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2ca090
leaq 0x1f4dfa(%rip), %rcx    # 0x4bee88
jmp 0x2ca0aa
leal -0x1(%rax), %ecx
testl %ebx, %ebx
cmovnsl %ebx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r15), %rcx
movq %r13, %rbx
incl %ebp
movl %eax, 0x8(%rcx)
cmpl $0x0, (%rsp)
movl 0x4(%rsp), %r13d
jns 0x2ca0d3
movq %r15, %rdi
movl $0x89, %esi
movl %r13d, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %r15, %rdi
movl $0x61, %esi
movl %ebp, 0x20(%rsp)
movl %ebp, %edx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x2a83e1
movq %r15, %rdi
movl %eax, %esi
movq 0x28(%rsp), %rdx
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x27b778
movslq 0x90(%r15), %rax
testq %rax, %rax
jle 0x2ca12a
xorl %ecx, %ecx
cmpl $0x0, (%rsp)
setns %cl
shll $0x4, %ecx
incl %ecx
movq 0x88(%r15), %rdx
leaq (%rax,%rax,2), %rax
movw %cx, -0x16(%rdx,%rax,8)
movq %r15, %rdi
movl $0x23, %esi
movq 0x10(%rsp), %r12
movl %r12d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl %eax, 0x4(%rsp)
cmpb $0x0, 0x62(%rbx)
je 0x2ca1dd
movq %rbx, %r13
movq %r15, %rdi
movl $0xb, %esi
xorl %edx, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %r12, %rdx
movl %eax, %r12d
movl 0x90(%r15), %eax
movl %eax, (%rsp)
movzwl 0x5e(%rbx), %ebp
movq %r15, %rdi
movl $0x7c, %esi
movl %r12d, %ecx
movl 0x8(%rsp), %r8d
callq 0x2a83e1
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2ca1b4
movq 0x88(%r15), %rcx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rcx,%rax,8)
movl %ebp, 0x10(%rcx,%rax,8)
movq %r14, %rdi
movl $0x2, %esi
movq %r13, %rdx
callq 0x2ca80f
movl 0x90(%r15), %eax
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2ca1ff
leaq 0x1f4cad(%rip), %rcx    # 0x4bee88
jmp 0x2ca21b
movq 0xa0(%r14), %rax
testq %rax, %rax
cmoveq %r14, %rax
movb $0x1, 0x21(%rax)
movl 0x90(%r15), %eax
movl %eax, (%rsp)
movl 0x8(%rsp), %ebp
jmp 0x2ca227
leal -0x1(%rax), %ecx
testl %r12d, %r12d
cmovnsl %r12d, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r15), %rcx
movq 0x10(%rsp), %r12
movl 0x8(%rsp), %ebp
movl %eax, 0x8(%rcx)
movq %r15, %rdi
movl $0x7d, %esi
movl %r12d, %edx
movl %ebp, %ecx
movl 0x20(%rsp), %r13d
movl %r13d, %r8d
callq 0x2a83e1
testb $0x2, 0x64(%rbx)
jne 0x2ca25c
movq %r15, %rdi
movl $0x81, %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %r15, %rdi
movl $0x82, %esi
movl %r13d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movslq 0x90(%r15), %rax
testq %rax, %rax
jle 0x2ca28f
movq 0x88(%r15), %rcx
leaq (%rax,%rax,2), %rax
movw $0x10, -0x16(%rcx,%rax,8)
testl %ebp, %ebp
je 0x2ca2ad
movzbl 0x1f(%r14), %eax
cmpq $0x7, %rax
ja 0x2ca2ad
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r14)
movl %ebp, 0xd4(%r14,%rax,4)
movq %r15, %rdi
movl $0x3, %esi
movl %r12d, %edx
movl (%rsp), %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x90(%r15), %eax
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2ca2dc
leaq 0x1f4bae(%rip), %rcx    # 0x4bee88
jmp 0x2ca2fa
leal -0x1(%rax), %ecx
movl 0x4(%rsp), %edx
testl %edx, %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r15), %rcx
movq 0x18(%rsp), %rdx
movl %eax, 0x8(%rcx)
movq %r15, %rdi
movl $0x74, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %r15, %rdi
movl $0x74, %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %r15, %rdi
movl $0x74, %esi
movl %r12d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq