// File: /workspace/github_c_makefile_star2_O1/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
testq %rcx, %rcx
je 0x2d379f
movq 0x20(%rax), %rdx
addq $0x18, %rdx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
incl %r12d
leaq 0x20(%rdx), %rsi
cmpq %rcx, (%rdx)
movq %rsi, %rdx
jne 0x2d378e
jmp 0x2d37a5
movl $0xffff8000, %r12d      # imm = 0xFFFF8000
movq (%r13), %rdx
movq 0x20(%rax), %rax
movslq %r12d, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %r8
movq %r14, %rdi
movl $0x1b, %esi
xorl %ecx, %ecx
callq 0x2cceea
testl %eax, %eax
jne 0x2d3c0a
movl 0x38(%rbp), %edx
movq (%rbp), %r8
movq %r14, %rdi
movl %r12d, %esi
movl $0x1, %ecx
callq 0x2c60e2
movq %r14, %rdi
callq 0x2c5ddf
testq %rax, %rax
je 0x2d3c0a
movq %rax, %r15
movl (%rsp), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
jns 0x2d380d
movl 0x58(%r13), %eax
movl %eax, 0x4(%rsp)
movq %rbp, 0x8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x2c6228
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 0x2d383c
incl (%rbp)
movq %r15, %rdi
movl $0x6f, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x2b200c
movq %r15, %rdi
movl %eax, %esi
movq %rbp, 0x28(%rsp)
movq %rbp, %rdx
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x285198
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
movq 0x8(%rsp), %rcx
movl $0x60, %r8d
callq 0x2c5fdd
movq %r15, %rdi
movl $0x25, %esi
movq %rbx, 0x18(%rsp)
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %rax, 0x20(%rsp)
movb 0x1f(%r14), %al
testb %al, %al
je 0x2d38b8
decb %al
movb %al, 0x1f(%r14)
movzbl %al, %eax
movl 0xd4(%r14,%rax,4), %ebx
jmp 0x2d38c2
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 0x2d3ed1
addq $0x10, %rsp
movq %r15, %rdi
movl $0x83, %esi
movq 0x10(%rsp), %rdx
movl %ebx, 0x8(%rsp)
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl (%rbp), %esi
testl %esi, %esi
je 0x2d3924
movq 0x10(%r14), %rdi
callq 0x2c91a7
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 0x2b200c
movl 0x90(%r15), %eax
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2d395c
leaq 0x1f652e(%rip), %rcx    # 0x4c9e88
jmp 0x2d3976
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 0x2d399f
movq %r15, %rdi
movl $0x89, %esi
movl %r13d, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %r15, %rdi
movl $0x61, %esi
movl %ebp, 0x20(%rsp)
movl %ebp, %edx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x2b200c
movq %r15, %rdi
movl %eax, %esi
movq 0x28(%rsp), %rdx
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x285198
movslq 0x90(%r15), %rax
testq %rax, %rax
jle 0x2d39f6
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 0x2b200c
movl %eax, 0x4(%rsp)
cmpb $0x0, 0x62(%rbx)
je 0x2d3aa9
movq %rbx, %r13
movq %r15, %rdi
movl $0xb, %esi
xorl %edx, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x2b200c
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 0x2b200c
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2d3a80
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 0x2d40f5
movl 0x90(%r15), %eax
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2d3acb
leaq 0x1f63e1(%rip), %rcx    # 0x4c9e88
jmp 0x2d3ae7
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 0x2d3af3
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 0x2b200c
testb $0x2, 0x64(%rbx)
jne 0x2d3b28
movq %r15, %rdi
movl $0x81, %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %r15, %rdi
movl $0x82, %esi
movl %r13d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movslq 0x90(%r15), %rax
testq %rax, %rax
jle 0x2d3b5b
movq 0x88(%r15), %rcx
leaq (%rax,%rax,2), %rax
movw $0x10, -0x16(%rcx,%rax,8)
testl %ebp, %ebp
je 0x2d3b79
movzbl 0x1f(%r14), %eax
cmpq $0x7, %rax
ja 0x2d3b79
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 0x2b200c
movl 0x90(%r15), %eax
movq (%r15), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2d3ba8
leaq 0x1f62e2(%rip), %rcx    # 0x4c9e88
jmp 0x2d3bc6
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 0x2b200c
movq %r15, %rdi
movl $0x74, %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %r15, %rdi
movl $0x74, %esi
movl %r12d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq