// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rsi, %r13
movq %rdi, %r14
movq 0x18(%rsi), %r12
movl 0x54(%rdi), %eax
movq %rax, -0x38(%rbp)
addl $0x2, %eax
movl %eax, 0x54(%rdi)
movq (%rdi), %rax
movq 0x30(%rsi), %rcx
testq %rcx, %rcx
movl %edx, -0x30(%rbp)
je 0x4be57
movl 0x28(%rax), %edi
testl %edi, %edi
jle 0x4be5e
movq 0x20(%rax), %rsi
addq $0x18, %rsi
xorl %ebx, %ebx
cmpq %rcx, (%rsi)
je 0x4be60
incq %rbx
addq $0x20, %rsi
cmpq %rbx, %rdi
jne 0x4be42
movl %edi, %ebx
jmp 0x4be60
movl $0xfff0bdc0, %ebx       # imm = 0xFFF0BDC0
jmp 0x4be60
xorl %ebx, %ebx
movq (%r13), %rdx
movq 0x20(%rax), %rax
movslq %ebx, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %r8
movq %r14, %rdi
movl $0x1b, %esi
xorl %ecx, %ecx
callq 0x460eb
testl %eax, %eax
jne 0x4c1ba
movl 0x3c(%r12), %edx
movq (%r12), %r8
movq %r14, %rdi
movl %ebx, %esi
movl $0x1, %ecx
callq 0x46018
movq %r14, %rdi
callq 0x45ece
testq %rax, %rax
je 0x4c1ba
movq %rax, %r15
movq %r12, -0x48(%rbp)
movq -0x38(%rbp), %rax
incl %eax
movl %eax, -0x3c(%rbp)
movb $0x3, %al
movl -0x30(%rbp), %r12d
testl %r12d, %r12d
jns 0x4bee9
movl 0x50(%r13), %r12d
movq %r15, %rdi
movl $0x6d, %esi
movl %r12d, %edx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movb $0x1, %al
movb %al, -0x30(%rbp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x4c2fa
movq %r15, %rdi
movl $0x31, %esi
movl -0x3c(%rbp), %edx
movl %r12d, %ecx
movq %rax, %r12
movl %ebx, %r8d
callq 0x45f15
movq %r15, %rdi
movl %eax, %esi
movq %r12, %rdx
movl $0xfffffff0, %ecx       # imm = 0xFFFFFFF0
callq 0x11a9f
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x4bf3a
movslq 0x34(%r15), %rcx
leaq (%rcx,%rcx,2), %rcx
movb -0x30(%rbp), %dl
movb %dl, -0x15(%rax,%rcx,8)
movl 0x54(%r14), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x54(%r14)
movq %r15, %rdi
movl $0x34, %esi
movq %rdx, -0x30(%rbp)
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq %r15, %rdi
movl %eax, %esi
movq %r12, %rdx
movl $0xfffffffa, %ecx       # imm = 0xFFFFFFFA
callq 0x11a9f
movq %r14, %rdi
movq -0x38(%rbp), %r12
movl %r12d, %esi
movl %ebx, %edx
movq -0x48(%rbp), %rcx
movl $0x30, %r8d
callq 0x45fa0
movq %r15, %rdi
movl $0x65, %esi
movl %r12d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl %eax, %ebx
movb 0x1f(%r14), %al
testb %al, %al
je 0x4bfb7
decb %al
movb %al, 0x1f(%r14)
movzbl %al, %eax
movl 0x28(%r14,%rax,4), %r12d
jmp 0x4bfc2
movl 0x58(%r14), %r12d
incl %r12d
movl %r12d, 0x58(%r14)
leaq -0x50(%rbp), %r9
movq %r14, %rdi
movq %r13, %rsi
movq -0x38(%rbp), %rdx
movl %r12d, %ecx
movl $0x1, %r8d
callq 0x4c389
movq %r15, %rdi
movl $0x66, %esi
movq -0x30(%rbp), %rdx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x45f15
leaq -0x50(%rbp), %rax
movl (%rax), %eax
testl %eax, %eax
jns 0x4c013
movq 0x40(%r15), %rcx
testq %rcx, %rcx
je 0x4c013
notl %eax
movl 0x34(%r15), %edx
movl %eax, %eax
movl %edx, (%rcx,%rax,4)
leal 0x1(%rbx), %ecx
movq %r15, %rdi
movl $0x7, %esi
movq -0x38(%rbp), %rdx
xorl %r8d, %r8d
callq 0x45f15
testl %ebx, %ebx
js 0x4c044
movl 0x34(%r15), %eax
cmpl %ebx, %eax
jbe 0x4c044
movq 0x8(%r15), %rcx
movl %ebx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
movq %r15, %rdi
movl $0x63, %esi
movq -0x30(%rbp), %rbx
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl %eax, -0x48(%rbp)
cmpb $0x0, 0x56(%r13)
movl 0x34(%r15), %r13d
je 0x4c0c2
addl $0x3, %r13d
movq %r15, %rdi
movl $0xe, %esi
xorl %edx, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl 0x34(%r15), %eax
movl %eax, -0x4c(%rbp)
movq %r15, %rdi
movl $0x48, %esi
movl %ebx, %edx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x45f15
leaq 0x2f55e(%rip), %rcx     # 0x7b604
movq %r14, %rdi
movl $0x813, %esi            # imm = 0x813
movl $0x2, %edx
movl $0xfffffffe, %r8d       # imm = 0xFFFFFFFE
callq 0x4c573
movl -0x4c(%rbp), %r13d
movq %r15, %rdi
movl $0x51, %esi
movl %ebx, %edx
movl %r12d, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq %r15, %rdi
movl $0x67, %esi
movl -0x3c(%rbp), %ebx
movl %ebx, %edx
movl %r12d, %ecx
movl $0x1, %r8d
callq 0x45f15
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x4c108
movslq 0x34(%r15), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $0x10, -0x15(%rax,%rcx,8)
testl %r12d, %r12d
je 0x4c144
movzbl 0x1f(%r14), %eax
cmpq $0x7, %rax
ja 0x4c144
xorl %ecx, %ecx
cmpl %r12d, 0x84(%r14,%rcx)
je 0x4c13e
addq $0x18, %rcx
cmpl $0xf0, %ecx
jne 0x4c11a
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r14)
movl %r12d, 0x28(%r14,%rax,4)
jmp 0x4c144
movb $0x1, 0x7c(%r14,%rcx)
movq %r15, %rdi
movl $0x5, %esi
movq -0x30(%rbp), %r14
movl %r14d, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl -0x48(%rbp), %edx
testl %edx, %edx
js 0x4c17b
movl 0x34(%r15), %eax
cmpl %edx, %eax
jbe 0x4c17b
movq 0x8(%r15), %rcx
movl %edx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
movq %r15, %rdi
movl $0x36, %esi
movq -0x38(%rbp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq %r15, %rdi
movl $0x36, %esi
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq %r15, %rdi
movl $0x36, %esi
movl %r14d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq