// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %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 0x54(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x54(%rcx)
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rcx
movl 0x54(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x54(%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 0x13940
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 0x5e720
cmpl $0x0, %eax
je 0x6705b
jmp 0x67313
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %esi
movq -0x20(%rbp), %rax
movl 0x3c(%rax), %edx
movq -0x20(%rbp), %rax
movq (%rax), %r8
movl $0x1, %ecx
callq 0x5e580
movq -0x8(%rbp), %rdi
callq 0x5e000
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x67093
jmp 0x67313
cmpl $0x0, -0x14(%rbp)
jl 0x670a1
movl -0x14(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x670bf
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movl -0x38(%rbp), %edx
movl -0x64(%rbp), %ecx
movl $0x6d, %esi
callq 0x5e0c0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x67540
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %edx
movl -0x38(%rbp), %ecx
movl -0x64(%rbp), %r8d
movq -0x50(%rbp), %r9
movl $0x31, %esi
movl $0xfffffff0, (%rsp)     # imm = 0xFFFFFFF0
callq 0x5e1b0
movq -0x48(%rbp), %rdi
movl -0x14(%rbp), %edx
xorl %eax, %eax
movl $0x2, %ecx
cmpl $0x0, %edx
cmovgel %ecx, %eax
orl $0x1, %eax
movzbl %al, %esi
callq 0x5e540
movq -0x8(%rbp), %rcx
movl 0x54(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x54(%rcx)
movl %eax, -0x2c(%rbp)
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movq -0x50(%rbp), %r9
movl $0x34, %esi
xorl %r8d, %r8d
movl %r8d, %ecx
movl $0xfffffffa, (%rsp)     # imm = 0xFFFFFFFA
callq 0x5e1b0
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x64(%rbp), %edx
movq -0x20(%rbp), %rcx
movl $0x30, %r8d
callq 0x5e480
movq -0x48(%rbp), %rdi
movl -0x24(%rbp), %edx
movl $0x65, %esi
xorl %ecx, %ecx
callq 0x5e0c0
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x66a70
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x24(%rbp), %edx
movl -0x54(%rbp), %ecx
movl $0x1, %r8d
leaq -0x3c(%rbp), %r9
callq 0x67610
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x54(%rbp), %ecx
movl $0x66, %esi
callq 0x5e0c0
movq -0x48(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x677f0
movq -0x48(%rbp), %rdi
movl -0x24(%rbp), %edx
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movl $0x7, %esi
callq 0x5e0c0
movq -0x48(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x5e090
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl $0x63, %esi
xorl %ecx, %ecx
callq 0x5e0c0
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x56(%rax), %eax
cmpl $0x0, %eax
je 0x6726c
movq -0x48(%rbp), %rdi
callq 0x5e520
addl $0x3, %eax
movl %eax, -0x68(%rbp)
movq -0x48(%rbp), %rdi
movl -0x68(%rbp), %ecx
movl $0xe, %esi
xorl %edx, %edx
callq 0x5e0c0
movq -0x48(%rbp), %rdi
callq 0x5e520
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x68(%rbp), %ecx
movl -0x54(%rbp), %r8d
movl $0x48, %esi
callq 0x5e0f0
movq -0x8(%rbp), %rdi
movl $0x813, %esi            # imm = 0x813
movl $0x2, %edx
leaq 0x48ea1(%rip), %rcx     # 0xb0100
movl $0xfffffffe, %r8d       # imm = 0xFFFFFFFE
callq 0x67830
jmp 0x67278
movq -0x48(%rbp), %rdi
callq 0x5e520
movl %eax, -0x34(%rbp)
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x54(%rbp), %ecx
movl $0x51, %esi
callq 0x5e0c0
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %edx
movl -0x54(%rbp), %ecx
movl $0x67, %esi
movl $0x1, %r8d
callq 0x5e0f0
movq -0x48(%rbp), %rdi
movl $0x10, %esi
callq 0x5e540
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x66ac0
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x5, %esi
callq 0x5e0c0
movq -0x48(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x5e090
movq -0x48(%rbp), %rdi
movl -0x24(%rbp), %edx
movl $0x36, %esi
callq 0x5ecf0
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %edx
movl $0x36, %esi
callq 0x5ecf0
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl $0x36, %esi
callq 0x5ecf0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)