// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movl %edx, 0xc(%rsp)
movq %rsi, %r13
movq %rdi, %r14
movq 0x18(%rsi), %r12
movl 0x54(%rdi), %ebx
leal 0x2(%rbx), %eax
movl %eax, 0x54(%rdi)
movq (%rdi), %rax
movq 0x30(%rsi), %rcx
testq %rcx, %rcx
je 0x521a6
movl 0x28(%rax), %edx
testl %edx, %edx
jle 0x521ad
movq 0x20(%rax), %rsi
addq $0x18, %rsi
xorl %ebp, %ebp
cmpq %rcx, (%rsi)
je 0x521af
incq %rbp
addq $0x20, %rsi
cmpq %rbp, %rdx
jne 0x52191
movl %edx, %ebp
jmp 0x521af
movl $0xfff0bdc0, %ebp       # imm = 0xFFF0BDC0
jmp 0x521af
xorl %ebp, %ebp
movq (%r13), %rdx
movq 0x20(%rax), %rax
movslq %ebp, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %r8
movq %r14, %rdi
movl $0x1b, %esi
xorl %ecx, %ecx
callq 0x4d23f
testl %eax, %eax
jne 0x5255a
movl 0x3c(%r12), %edx
movq (%r12), %r8
movq %r14, %rdi
movl %ebp, %esi
movl $0x1, %ecx
callq 0x48985
movq %r14, %rdi
callq 0x48791
testq %rax, %rax
je 0x5255a
movq %rax, %r15
movq %r12, 0x18(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
testl %eax, %eax
jns 0x5221e
movl 0x58(%r13), %eax
movl %eax, 0x8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x48a99
movq %rax, %r12
movl 0x54(%r14), %eax
movq %rax, 0x10(%rsp)
incl %eax
movl %eax, 0x54(%r14)
testq %r12, %r12
je 0x52244
incl (%r12)
movq %r15, %rdi
movl $0x36, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x487d8
movq %r15, %rdi
movl %eax, %esi
movq %r12, 0x30(%rsp)
movq %r12, %rdx
movl $0xfffffffa, %ecx       # imm = 0xFFFFFFFA
callq 0x12044
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
movq 0x18(%rsp), %rcx
movl $0x32, %r8d
callq 0x488b9
movq %r15, %rdi
movl $0x67, %esi
movq %rbx, 0x18(%rsp)
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x487d8
movl %eax, %ebx
movb 0x1f(%r14), %al
testb %al, %al
je 0x522bc
decb %al
movb %al, 0x1f(%r14)
movzbl %al, %eax
movl 0x28(%r14,%rax,4), %r12d
jmp 0x522c7
movl 0x58(%r14), %r12d
incl %r12d
movl %r12d, 0x58(%r14)
leaq 0x2c(%rsp), %r9
movq %r14, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x526f0
movq %r15, %rdi
movl $0x68, %esi
movq 0x10(%rsp), %rdx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x487d8
leaq 0x2c(%rsp), %rax
movl (%rax), %eax
testl %eax, %eax
jns 0x52319
movq 0x40(%r15), %rcx
testq %rcx, %rcx
je 0x52319
notl %eax
movl 0x34(%r15), %edx
movl %eax, %eax
movl %edx, (%rcx,%rax,4)
leal 0x1(%rbx), %ecx
movq %r15, %rdi
movl $0x9, %esi
movq 0x18(%rsp), %rdx
xorl %r8d, %r8d
callq 0x487d8
testl %ebx, %ebx
js 0x5234b
movl 0x34(%r15), %eax
cmpl %ebx, %eax
jbe 0x5234b
movq 0x8(%r15), %rcx
movl %ebx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
movq 0x18(%rsp), %rax
leal 0x1(%rax), %edx
cmpl $0x0, 0xc(%rsp)
jns 0x52374
movq %r15, %rdi
movl $0x6f, %esi
movl %edx, %ebx
movl 0x8(%rsp), %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x487d8
movl %ebx, %edx
movq %r15, %rdi
movl $0x33, %esi
movl %edx, 0x24(%rsp)
movl 0x8(%rsp), %ecx
movl %ebp, %r8d
callq 0x487d8
movq %r15, %rdi
movl %eax, %esi
movq 0x30(%rsp), %rbx
movq %rbx, %rdx
movl $0xfffffffa, %ecx       # imm = 0xFFFFFFFA
callq 0x12044
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x523c4
cmpl $0x0, 0xc(%rsp)
setns %cl
addb %cl, %cl
incb %cl
movslq 0x34(%r15), %rdx
leaq (%rdx,%rdx,2), %rdx
movb %cl, -0x15(%rax,%rdx,8)
movq %r15, %rdi
movl $0x65, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x487d8
movl 0x34(%r15), %ecx
testq %rbx, %rbx
movl %eax, 0xc(%rsp)
je 0x5245f
cmpb $0x0, 0x62(%r13)
je 0x5245f
addl $0x3, %ecx
movq %r15, %rdi
movl $0x10, %esi
movl %ecx, 0x28(%rsp)
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x487d8
movl 0x34(%r15), %eax
movl %eax, 0x8(%rsp)
movzwl 0x6(%rbx), %ebx
movzwl 0x5e(%r13), %eax
subq %rax, %rbx
movq %r15, %rdi
movl $0x52, %esi
movq 0x10(%rsp), %rbp
movl %ebp, %edx
movl 0x28(%rsp), %ecx
movl %r12d, %r8d
callq 0x487d8
movq %r15, %rdi
movl %eax, %esi
movq %rbx, %rdx
movl $0xfffffff2, %ecx       # imm = 0xFFFFFFF2
callq 0x12044
movq %r14, %rdi
movl $0x2, %esi
movq %r13, %rdx
callq 0x5291b
movl 0x8(%rsp), %ebx
jmp 0x52466
movl %ecx, %ebx
movq 0x10(%rsp), %rbp
movq %r15, %rdi
movl $0x5d, %esi
movl %ebp, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x487d8
movq %r15, %rdi
movl $0x69, %esi
movl 0x24(%rsp), %edx
movl %r12d, %ecx
movl $0x1, %r8d
callq 0x487d8
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x524ab
movslq 0x34(%r15), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $0x10, -0x15(%rax,%rcx,8)
testl %r12d, %r12d
je 0x524e7
movzbl 0x1f(%r14), %eax
cmpq $0x7, %rax
ja 0x524e7
xorl %ecx, %ecx
cmpl %r12d, 0x84(%r14,%rcx)
je 0x524e1
addq $0x18, %rcx
cmpl $0xf0, %ecx
jne 0x524bd
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r14)
movl %r12d, 0x28(%r14,%rax,4)
jmp 0x524e7
movb $0x1, 0x7c(%r14,%rcx)
movq %r15, %rdi
movl $0x5, %esi
movl %ebp, %edx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x487d8
movl 0xc(%rsp), %edx
testl %edx, %edx
js 0x52519
movl 0x34(%r15), %eax
cmpl %edx, %eax
jbe 0x52519
movq 0x8(%r15), %rcx
movl %edx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
movq %r15, %rdi
movl $0x38, %esi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x487d8
movq %r15, %rdi
movl $0x38, %esi
movl 0x24(%rsp), %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x487d8
movq %r15, %rdi
movl $0x38, %esi
movl %ebp, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x487d8
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq