// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: updateVirtualTable
static void updateVirtualTable(
  Parse *pParse,       /* The parsing context */
  SrcList *pSrc,       /* The virtual table to be modified */
  Table *pTab,         /* The virtual table */
  ExprList *pChanges,  /* The columns to change in the UPDATE statement */
  Expr *pRowid,        /* Expression used to recompute the rowid */
  int *aXRef,          /* Mapping from columns of pTab to entries in pChanges */
  Expr *pWhere,        /* WHERE clause of the UPDATE statement */
  int onError          /* ON CONFLICT strategy */
){
  Vdbe *v = pParse->pVdbe;  /* Virtual machine under construction */
  ExprList *pEList = 0;     /* The result set of the SELECT statement */
  Select *pSelect = 0;      /* The SELECT statement */
  Expr *pExpr;              /* Temporary expression */
  int ephemTab;             /* Table holding the result of the SELECT */
  int i;                    /* Loop counter */
  int addr;                 /* Address of top of loop */
  int iReg;                 /* First register in set passed to OP_VUpdate */
  sqlite3 *db = pParse->db; /* Database connection */
  const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
  SelectDest dest;

  /* Construct the SELECT statement that will find the new values for
  ** all updated rows. 
  */
  pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, "_rowid_"));
  if( pRowid ){
    pEList = sqlite3ExprListAppend(pParse, pEList,
                                   sqlite3ExprDup(db, pRowid, 0));
  }
  assert( pTab->iPKey<0 );
  for(i=0; i<pTab->nCol; i++){
    if( aXRef[i]>=0 ){
      pExpr = sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0);
    }else{
      pExpr = sqlite3Expr(db, TK_ID, pTab->aCol[i].zName);
    }
    pEList = sqlite3ExprListAppend(pParse, pEList, pExpr);
  }
  pSelect = sqlite3SelectNew(pParse, pEList, pSrc, pWhere, 0, 0, 0, 0, 0, 0);
  
  /* Create the ephemeral table into which the update results will
  ** be stored.
  */
  assert( v );
  ephemTab = pParse->nTab++;
  sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, pTab->nCol+1+(pRowid!=0));
  sqlite3VdbeChangeP5(v, BTREE_UNORDERED);

  /* fill the ephemeral table 
  */
  sqlite3SelectDestInit(&dest, SRT_Table, ephemTab);
  sqlite3Select(pParse, pSelect, &dest);

  /* Generate code to scan the ephemeral table and call VUpdate. */
  iReg = ++pParse->nMem;
  pParse->nMem += pTab->nCol+1;
  addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0);
  sqlite3VdbeAddOp3(v, OP_Column,  ephemTab, 0, iReg);
  sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);
  for(i=0; i<pTab->nCol; i++){
    sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
  }
  sqlite3VtabMakeWritable(pParse, pTab);
  sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
  sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
  sqlite3MayAbort(pParse);
  sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);
  sqlite3VdbeJumpHere(v, addr);
  sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);

  /* Cleanup */
  sqlite3SelectDelete(db, pSelect);  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, -0x30(%rbp)
movq %r8, %r12
movq %rcx, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rsi, -0x58(%rbp)
movq %rdi, %r15
movq (%rdi), %rbx
movq 0x58(%rdx), %rax
testq %rax, %rax
je 0x5eaa5
cmpq %rbx, (%rax)
je 0x5eaaf
movq 0x28(%rax), %rax
jmp 0x5ea95
movq $0x0, -0x48(%rbp)
jmp 0x5eab3
movq %rax, -0x48(%rbp)
movq 0x10(%r15), %rax
movq %rax, -0x80(%rbp)
leaq 0x1d330(%rip), %rax     # 0x7bdf2
leaq -0x90(%rbp), %rdx
movq %rax, (%rdx)
movl $0x7, 0x8(%rdx)
movq %rbx, %rdi
movl $0x1a, %esi
xorl %ecx, %ecx
callq 0x4aaef
movq (%r15), %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x3d962
movq %rax, %r14
testq %r12, %r12
je 0x5eb17
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4848c
movq (%r15), %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3d962
movq %rax, %r14
movq %r12, -0x50(%rbp)
movq %r15, -0x68(%rbp)
movq %rbx, -0x60(%rbp)
movq -0x40(%rbp), %rdx
cmpw $0x0, 0x42(%rdx)
jle 0x5eba5
xorl %r15d, %r15d
xorl %ebx, %ebx
movq -0x30(%rbp), %rax
movslq (%rax,%rbx,4), %rax
testq %rax, %rax
js 0x5eb62
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq -0x60(%rbp), %rdi
movq %rdx, %r12
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x4848c
jmp 0x5eb7b
movq 0x8(%rdx), %rax
movq %rdx, %r12
movq (%rax,%r15), %rdx
movq -0x60(%rbp), %rdi
movl $0x1a, %esi
callq 0x3db22
movq -0x68(%rbp), %rcx
movq (%rcx), %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3d962
movq %rax, %r14
incq %rbx
movswq 0x42(%r12), %rax
addq $0x30, %r15
cmpq %rax, %rbx
movq %r12, %rdx
jl 0x5eb33
xorl %r12d, %r12d
cmpq $0x0, -0x50(%rbp)
setne %r12b
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
movq -0x68(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %rdx, %rbx
movq -0x58(%rbp), %rdx
movq 0x10(%rbp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3d7c0
movq %rax, %r14
movl 0x54(%r13), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x54(%r13)
movswl 0x42(%rbx), %eax
movq %r12, -0x50(%rbp)
leal 0x1(%r12,%rax), %ecx
movq -0x80(%rbp), %r12
movq %r12, %rdi
movl $0x33, %esi
movq %rdx, -0x38(%rbp)
xorl %r8d, %r8d
callq 0x45f15
movq 0x8(%r12), %rax
testq %rax, %rax
je 0x5ec34
movslq 0x34(%r12), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $0x8, -0x15(%rax,%rcx,8)
leaq -0x90(%rbp), %rdx
movw $0x8, (%rdx)
movq -0x38(%rbp), %r15
movl %r15d, 0x4(%rdx)
movq $0x0, 0x8(%rdx)
movq %r13, %rdi
movq %r14, -0x58(%rbp)
movq %r14, %rsi
callq 0x3bffc
movl 0x58(%r13), %ecx
leal 0x1(%rcx), %ebx
movq -0x40(%rbp), %rax
movswl 0x42(%rax), %eax
leal 0x2(%rcx), %edx
movl %edx, -0x6c(%rbp)
movq %rcx, -0x30(%rbp)
addl %ecx, %eax
addl $0x2, %eax
movl %eax, 0x58(%r13)
xorl %r14d, %r14d
movq %r12, %rdi
movl $0x65, %esi
movl %r15d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq %rax, -0x78(%rbp)
movq %r12, %rdi
movl $0x29, %esi
movl %r15d, %edx
xorl %ecx, %ecx
movl %ebx, -0x70(%rbp)
movl %ebx, %r8d
callq 0x45f15
movq %r12, %r13
movq %r12, %rdi
movl $0x29, %esi
movq %r15, %rbx
movl %r15d, %edx
movq -0x50(%rbp), %r12
movl %r12d, %ecx
movl -0x6c(%rbp), %r8d
callq 0x45f15
movq -0x40(%rbp), %rsi
cmpw $0x0, 0x42(%rsi)
jle 0x5ed1d
movq -0x30(%rbp), %rax
addl $0x3, %eax
movq %rax, -0x30(%rbp)
incl %r12d
leal 0x1(%r14), %r15d
leal (%r12,%r14), %ecx
addl -0x30(%rbp), %r14d
movq %r13, %rdi
movl $0x29, %esi
movl %ebx, %edx
movl %r14d, %r8d
callq 0x45f15
movq -0x40(%rbp), %rsi
movswl 0x42(%rsi), %eax
movl %r15d, %r14d
cmpl %eax, %r15d
jl 0x5ecef
movq -0x68(%rbp), %rbx
movq %rbx, %rdi
movq %rsi, %r14
callq 0x5c3c5
movswl 0x42(%r14), %ecx
addl $0x2, %ecx
movq %r13, %rdi
movl $0xd, %esi
xorl %edx, %edx
movl -0x70(%rbp), %r8d
callq 0x45f15
movq %r13, %rdi
movl %eax, %esi
movq -0x48(%rbp), %rdx
movl $0xfffffff6, %ecx       # imm = 0xFFFFFFF6
callq 0x11a9f
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x5ed7d
movl 0x18(%rbp), %ecx
cmpl $0x63, %ecx
movl $0x2, %edx
cmovnel %ecx, %edx
movslq 0x34(%r13), %rcx
leaq (%rcx,%rcx,2), %rcx
movb %dl, -0x15(%rax,%rcx,8)
movq 0x1d8(%rbx), %rax
testq %rax, %rax
cmoveq %rbx, %rax
movb $0x1, 0x24(%rax)
movq -0x78(%rbp), %r12
leal 0x1(%r12), %ecx
movq %r13, %rdi
movl $0x7, %esi
movq -0x38(%rbp), %r15
movl %r15d, %edx
xorl %r8d, %r8d
callq 0x45f15
testl %r12d, %r12d
movq -0x60(%rbp), %rbx
movq -0x58(%rbp), %r14
js 0x5edd4
movl 0x34(%r13), %eax
cmpl %r12d, %eax
jbe 0x5edd4
movq 0x8(%r13), %rcx
movl %r12d, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
movq %r13, %rdi
movl $0x36, %esi
movl %r15d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x34827
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq