// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rcx
movl 0x34(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x34(%rcx)
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rcx
movl 0x34(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x34(%rcx)
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
callq 0x3cb770
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x64(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %r8
movl $0x1b, %esi
xorl %eax, %eax
movl %eax, %ecx
callq 0x4338b0
cmpl $0x0, %eax
je 0x43d2ce
jmp 0x43d5eb
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %esi
movq -0x20(%rbp), %rax
movl 0x38(%rax), %edx
movq -0x20(%rbp), %rax
movq (%rax), %r8
movl $0x1, %ecx
callq 0x429f80
movq -0x8(%rbp), %rdi
callq 0x4299d0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x43d306
jmp 0x43d5eb
cmpl $0x0, -0x14(%rbp)
jl 0x43d314
movl -0x14(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x43d31e
movq -0x10(%rbp), %rax
movl 0x58(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x42a1a0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rcx
movl 0x34(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x34(%rcx)
movl %eax, -0x2c(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x5e(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x50(%rbp), %rdi
callq 0x43d960
movq -0x78(%rbp), %rdi
movl -0x70(%rbp), %edx
movl -0x6c(%rbp), %r8d
movq %rax, %r9
movl $0x6f, %esi
xorl %ecx, %ecx
movl $0xfffffff7, (%rsp)     # imm = 0xFFFFFFF7
callq 0x429aa0
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x64(%rbp), %edx
movq -0x20(%rbp), %rcx
movl $0x60, %r8d
callq 0x429e70
movq -0x48(%rbp), %rdi
movl -0x24(%rbp), %edx
movl $0x25, %esi
xorl %ecx, %ecx
callq 0x410100
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x42f190
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rdi
callq 0x43d980
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x24(%rbp), %edx
movl -0x54(%rbp), %ecx
xorl %r8d, %r8d
leaq -0x3c(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x43d9d0
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x54(%rbp), %ecx
movl $0x83, %esi
callq 0x410100
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x43dbd0
movq -0x48(%rbp), %rdi
movl -0x24(%rbp), %edx
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movl $0x5, %esi
callq 0x410100
movq -0x48(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x429a70
cmpl $0x0, -0x14(%rbp)
jge 0x43d451
movq -0x48(%rbp), %rdi
movl -0x38(%rbp), %edx
movl -0x64(%rbp), %ecx
movl $0x89, %esi
callq 0x410100
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %edx
movl -0x38(%rbp), %ecx
movl -0x64(%rbp), %r8d
movq -0x50(%rbp), %r9
movl $0x61, %esi
movl $0xfffffff7, (%rsp)     # imm = 0xFFFFFFF7
callq 0x429aa0
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %edx
xorl %eax, %eax
movl $0x10, %ecx
cmpl $0x0, %edx
cmovgel %ecx, %eax
orl $0x1, %eax
movzwl %ax, %esi
callq 0x3cb9f0
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl $0x23, %esi
xorl %ecx, %ecx
callq 0x410100
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x62(%rax), %eax
cmpl $0x0, %eax
je 0x43d514
movq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x429db0
movl %eax, -0x68(%rbp)
movq -0x48(%rbp), %rdi
callq 0x430ae0
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x68(%rbp), %ecx
movl -0x54(%rbp), %r8d
movq -0x10(%rbp), %rax
movzwl 0x5e(%rax), %r9d
movl $0x7c, %esi
callq 0x3cb970
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl $0x2, %esi
callq 0x43dc00
movq -0x48(%rbp), %rdi
movl -0x68(%rbp), %esi
callq 0x429a70
jmp 0x43d529
movq -0x8(%rbp), %rdi
callq 0x42e470
movq -0x48(%rbp), %rdi
callq 0x430ae0
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x54(%rbp), %ecx
movl -0x28(%rbp), %r8d
movl $0x7d, %esi
callq 0x410130
movq -0x10(%rbp), %rax
movw 0x63(%rax), %ax
shrw $0x9, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0x43d56a
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %edx
movl $0x81, %esi
callq 0x42ba70
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %edx
movl -0x54(%rbp), %ecx
movl $0x82, %esi
callq 0x410100
movq -0x48(%rbp), %rdi
movl $0x10, %esi
callq 0x3cb9f0
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x42e560
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x3, %esi
callq 0x410100
movq -0x48(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x429a70
movq -0x48(%rbp), %rdi
movl -0x24(%rbp), %edx
movl $0x74, %esi
callq 0x42ba70
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %edx
movl $0x74, %esi
callq 0x42ba70
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl $0x74, %esi
callq 0x42ba70
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)