// File: /workspace/github_c_makefile_star2_O2/skeeto[P]flappy/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 */
  int 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 assemblied 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].zName ) ){
    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 = memRootPage;
  }else{
    tnum = pIndex->tnum;
  }
  pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);

  /* Open the sorter cursor if we are to use one. */
  iSorter = pParse->nTab++;
  sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (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);
  regRecord = sqlite3GetTempReg(pParse);

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

  addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
  assert( pKey!=0 || db->mallocFailed || pParse->nErr );
  if( pIndex->onError!=OE_None && pKey!=0 ){
    int j2 = sqlite3VdbeCurrentAddr(v) + 3;
    sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
    addr2 = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
                         pKey->nField - pIndex->nKeyCol);
    sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
  }else{
    addr2 = sqlite3VdbeCurrentAddr(v);
  }
  sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
  sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
  sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
  sqlite3ReleaseTempReg(pParse, regRecord);
  sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
  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, 0x14(%rsp)
movq %rsi, %r13
movq %rdi, %r14
movq 0x18(%rsi), %rbp
movl 0x54(%rdi), %ebx
leal 0x2(%rbx), %eax
movl %eax, 0x54(%rdi)
movq (%rdi), %r15
movq 0x30(%rsi), %rsi
movq %r15, %rdi
callq 0x10cd8
movl %eax, %r12d
movq (%r13), %rdx
movq 0x20(%r15), %rax
movslq %r12d, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %r8
pushq $0x1b
popq %rsi
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x4810e
testl %eax, %eax
jne 0x4c1ba
movl 0x3c(%rbp), %edx
movq (%rbp), %r8
pushq $0x1
popq %rcx
movq %r14, %rdi
movl %r12d, %esi
callq 0x4410c
movq %r14, %rdi
callq 0x43f1b
testq %rax, %rax
je 0x4c1ba
movq %rax, %r15
movl 0x14(%rsp), %eax
movl %eax, 0x18(%rsp)
testl %eax, %eax
jns 0x4bf2b
movl 0x58(%r13), %eax
movl %eax, 0x18(%rsp)
movq %rbx, 0x30(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x4421a
movq %rax, %r9
movl 0x54(%r14), %eax
movq %rax, 0x20(%rsp)
incl %eax
movl %eax, 0x54(%r14)
testq %r9, %r9
je 0x4bf55
incl (%r9)
movl $0xfffffffa, (%rsp)     # imm = 0xFFFFFFFA
pushq $0x36
popq %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r9, 0x38(%rsp)
callq 0x43fe6
pushq $0x32
popq %r8
movq %r14, %rdi
movq 0x30(%rsp), %rbx
movl %ebx, %esi
movl %r12d, %edx
movq %rbp, %rcx
callq 0x44068
pushq $0x67
popq %rsi
movq %r15, %rdi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x43f64
movq %rax, 0x28(%rsp)
movq %r14, %rdi
callq 0x46316
movl %eax, %ebp
leaq 0x44(%rsp), %r9
movq %r14, %rdi
movq %r13, %rsi
movl %ebx, %edx
movl %eax, %ecx
xorl %r8d, %r8d
movq %r9, %rbx
callq 0x4c34c
pushq $0x68
popq %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
movl %ebp, 0x1c(%rsp)
movl %ebp, %ecx
callq 0x43f64
movl (%rbx), %eax
testl %eax, %eax
jns 0x4bff7
movq 0x40(%r15), %rcx
testq %rcx, %rcx
je 0x4bff7
notl %eax
movl 0x34(%r15), %edx
movl %eax, %eax
movl %edx, (%rcx,%rax,4)
movq 0x28(%rsp), %rbp
leal 0x1(%rbp), %ecx
pushq $0x9
popq %rsi
movq %r15, %rdi
movq 0x30(%rsp), %rbx
movl %ebx, %edx
callq 0x43f64
movq %rbp, %rdx
testl %edx, %edx
movl 0x18(%rsp), %ebp
js 0x4c032
movl 0x34(%r15), %eax
cmpl %edx, %eax
jbe 0x4c032
movq 0x8(%r15), %rcx
movl %edx, %edx
imulq $0x18, %rdx, %rdx
movl %eax, 0x8(%rcx,%rdx)
incl %ebx
cmpl $0x0, 0x14(%rsp)
jns 0x4c04b
pushq $0x6f
popq %rsi
movq %r15, %rdi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x43f64
movl $0xfffffffa, (%rsp)     # imm = 0xFFFFFFFA
pushq $0x33
popq %rsi
movq %r15, %rdi
movl %ebx, 0x28(%rsp)
movl %ebx, %edx
movl %ebp, %ecx
movl %r12d, %r8d
movq 0x38(%rsp), %rbx
movq %rbx, %r9
callq 0x43fe6
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x4c091
cmpl $0x0, 0x14(%rsp)
setns %cl
addb %cl, %cl
incb %cl
movslq 0x34(%r15), %rdx
imulq $0x18, %rdx, %rdx
movb %cl, -0x15(%rax,%rdx)
pushq $0x65
popq %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
xorl %ecx, %ecx
callq 0x43f64
movl 0x34(%r15), %r12d
testq %rbx, %rbx
movl %eax, 0x14(%rsp)
je 0x4c111
cmpb $0x0, 0x62(%r13)
je 0x4c111
addl $0x3, %r12d
pushq $0x10
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x43f64
movl 0x34(%r15), %eax
movl %eax, 0x18(%rsp)
movzwl 0x6(%rbx), %r9d
movzwl 0x5e(%r13), %eax
subl %eax, %r9d
pushq $0x52
popq %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rbx
movl %ebx, %edx
movl %r12d, %ecx
movl 0x1c(%rsp), %ebp
movl %ebp, %r8d
callq 0x441d6
pushq $0x2
popq %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x4c4f5
movl 0x18(%rsp), %r12d
jmp 0x4c11a
movq 0x20(%rsp), %rbx
movl 0x1c(%rsp), %ebp
pushq $0x5d
popq %rsi
movq %r15, %rdi
movl %ebx, %edx
movl %ebp, %ecx
callq 0x43f64
pushq $0x69
popq %rsi
pushq $0x1
popq %r8
movq %r15, %rdi
movl 0x28(%rsp), %edx
movl %ebp, %ecx
callq 0x43f69
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x4c154
movslq 0x34(%r15), %rcx
imulq $0x18, %rcx, %rcx
movb $0x10, -0x15(%rax,%rcx)
movq %r14, %rdi
movl 0x1c(%rsp), %esi
callq 0x46333
pushq $0x5
popq %rsi
movq %r15, %rdi
movl %ebx, %edx
movl %r12d, %ecx
callq 0x43f64
movl 0x14(%rsp), %esi
testl %esi, %esi
movq 0x30(%rsp), %rdx
js 0x4c193
movl 0x34(%r15), %eax
cmpl %esi, %eax
jbe 0x4c193
movq 0x8(%r15), %rcx
movl %esi, %esi
imulq $0x18, %rsi, %rsi
movl %eax, 0x8(%rcx,%rsi)
pushq $0x38
popq %rbp
movq %r15, %rdi
movl %ebp, %esi
callq 0x457e7
movq %r15, %rdi
movl %ebp, %esi
movl 0x28(%rsp), %edx
callq 0x457e7
movq %r15, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x457e7
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq