// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/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;
    sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
  }
  pKey = sqlite3IndexKeyinfo(pParse, pIndex);
  sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb, 
                    (char *)pKey, P4_KEYINFO_HANDOFF);
  sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));

  /* Open the sorter cursor if we are to use one. */
  iSorter = pParse->nTab++;
  sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, 0, (char*)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, 1, &iPartIdxLabel);
  sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
  sqlite3VdbeResolveLabel(v, iPartIdxLabel);
  sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
  sqlite3VdbeJumpHere(v, addr1);
  addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
  if( pIndex->onError!=OE_None ){
    int j2 = sqlite3VdbeCurrentAddr(v) + 3;
    sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
    addr2 = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeAddOp3(v, OP_SorterCompare, iSorter, j2, regRecord);
    sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_UNIQUE,
        OE_Abort, "indexed columns are not unique", P4_STATIC
    );
  }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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, -0x30(%rbp)
movq %rsi, %r12
movq %rdi, %r14
movq 0x18(%rsi), %r13
movl 0x54(%rdi), %eax
movq %rax, -0x48(%rbp)
addl $0x2, %eax
movl %eax, 0x54(%rdi)
movq (%rdi), %r15
movq 0x30(%rsi), %rsi
movq %r15, %rdi
callq 0x1064e
movl %eax, %ebx
movq (%r12), %rdx
movq 0x20(%r15), %rax
movslq %ebx, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %r8
pushq $0x1b
popq %rsi
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x42151
testl %eax, %eax
jne 0x47575
movl 0x3c(%r13), %edx
movq (%r13), %r8
pushq $0x1
popq %rcx
movq %r14, %rdi
movl %ebx, %esi
callq 0x4207f
movq %r14, %rdi
callq 0x41ef4
testq %rax, %rax
je 0x47575
movq %rax, %r15
movq %r13, -0x40(%rbp)
movq -0x48(%rbp), %rax
incl %eax
movl %eax, -0x34(%rbp)
movb $0x3, %al
movl -0x30(%rbp), %r13d
testl %r13d, %r13d
jns 0x47339
movl 0x50(%r12), %r13d
pushq $0x6d
popq %rsi
movq %r15, %rdi
movl %r13d, %edx
movl %ebx, %ecx
callq 0x41f42
movb $0x1, %al
movb %al, -0x30(%rbp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x476ae
movl $0xfffffff0, (%rsp)     # imm = 0xFFFFFFF0
pushq $0x31
popq %rsi
movq %r15, %rdi
movl -0x34(%rbp), %edx
movl %r13d, %ecx
movq %rax, %r13
movl %ebx, %r8d
movq %rax, %r9
callq 0x41fd2
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x47380
movslq 0x34(%r15), %rcx
imulq $0x18, %rcx, %rcx
movb -0x30(%rbp), %dl
movb %dl, -0x15(%rax,%rcx)
movl 0x54(%r14), %edx
movq %rdx, -0x30(%rbp)
leal 0x1(%rdx), %eax
movl %eax, 0x54(%r14)
movl $0xfffffffa, (%rsp)     # imm = 0xFFFFFFFA
pushq $0x34
popq %rsi
movq %r15, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x41fd2
pushq $0x30
popq %r8
movq %r14, %rdi
movq -0x48(%rbp), %r13
movl %r13d, %esi
movl %ebx, %edx
movq -0x40(%rbp), %rcx
callq 0x4200b
pushq $0x65
popq %rsi
movq %r15, %rdi
movl %r13d, %edx
xorl %ecx, %ecx
callq 0x41f42
movq %rax, -0x50(%rbp)
movq %r14, %rdi
callq 0x46ff9
movl %eax, %ebx
pushq $0x1
popq %r8
leaq -0x54(%rbp), %r9
movq %r14, %rdi
movq %r12, %rsi
movl %r13d, %edx
movl %eax, %ecx
movq %r9, %r13
callq 0x47732
pushq $0x66
popq %rsi
movq %r15, %rdi
movq -0x30(%rbp), %rdx
movl %ebx, -0x40(%rbp)
movl %ebx, %ecx
callq 0x41f42
movl (%r13), %eax
testl %eax, %eax
jns 0x4742b
movq 0x40(%r15), %rcx
testq %rcx, %rcx
je 0x4742b
notl %eax
movl 0x34(%r15), %edx
movl %eax, %eax
movl %edx, (%rcx,%rax,4)
movq -0x50(%rbp), %rbx
leal 0x1(%rbx), %ecx
pushq $0x7
popq %rsi
movq %r15, %rdi
movq -0x48(%rbp), %rdx
callq 0x41f42
testl %ebx, %ebx
js 0x4745b
movl 0x34(%r15), %eax
cmpl %ebx, %eax
jbe 0x4745b
movq 0x8(%r15), %rcx
movl %ebx, %edx
imulq $0x18, %rdx, %rdx
movl %eax, 0x8(%rcx,%rdx)
pushq $0x63
popq %rsi
movq %r15, %rdi
movq -0x30(%rbp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
callq 0x41f42
movl %eax, -0x50(%rbp)
cmpb $0x0, 0x56(%r12)
movl 0x34(%r15), %r12d
je 0x474d2
addl $0x3, %r12d
pushq $0xe
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x41f42
movl 0x34(%r15), %ebx
pushq $0x48
popq %rsi
movq %r15, %rdi
movq -0x30(%rbp), %rdx
movl %r12d, %ecx
movl -0x40(%rbp), %r13d
movl %r13d, %r8d
callq 0x41f4c
leaq 0x2616f(%rip), %rcx     # 0x6d624
pushq $0x2
popq %rdx
pushq $-0x2
popq %r8
movq %r14, %rdi
movl $0x813, %esi            # imm = 0x813
callq 0x478d0
movl %ebx, %r12d
movq -0x30(%rbp), %rbx
jmp 0x474d6
movl -0x40(%rbp), %r13d
pushq $0x51
popq %rsi
movq %r15, %rdi
movl %ebx, %edx
movl %r13d, %ecx
callq 0x41f42
pushq $0x67
popq %rsi
pushq $0x1
popq %r8
movq %r15, %rdi
movl -0x34(%rbp), %edx
movl %r13d, %ecx
callq 0x41f4c
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x47511
movslq 0x34(%r15), %rcx
imulq $0x18, %rcx, %rcx
movb $0x10, -0x15(%rax,%rcx)
movq %r14, %rdi
movl -0x40(%rbp), %esi
callq 0x4701c
pushq $0x5
popq %rsi
movq %r15, %rdi
movl %ebx, %edx
movl %r12d, %ecx
callq 0x41f42
movl -0x50(%rbp), %edx
testl %edx, %edx
js 0x47549
movl 0x34(%r15), %eax
cmpl %edx, %eax
jbe 0x47549
movq 0x8(%r15), %rcx
movl %edx, %edx
imulq $0x18, %rdx, %rdx
movl %eax, 0x8(%rcx,%rdx)
pushq $0x36
popq %rbx
movq %r15, %rdi
movl %ebx, %esi
movq -0x48(%rbp), %rdx
callq 0x42436
movq %r15, %rdi
movl %ebx, %esi
movl -0x34(%rbp), %edx
callq 0x42436
movq %r15, %rdi
movl %ebx, %esi
movq -0x30(%rbp), %rdx
callq 0x42436
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq