// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %r9, -0x30(%rbp)
movq %r8, %r12
movq %rcx, -0x38(%rbp)
movq %rsi, -0x58(%rbp)
movq %rdi, %r14
movq (%rdi), %rbx
movq 0x58(%rdx), %rax
testq %rax, %rax
je 0x5ec12
cmpq %rbx, (%rax)
je 0x5ec12
movq 0x28(%rax), %rax
jmp 0x5ec02
movq %rax, -0x70(%rbp)
movq %rdx, -0x40(%rbp)
movq 0x10(%r14), %r13
leaq 0x1d1cd(%rip), %rax     # 0x7bdf2
leaq -0x80(%rbp), %rdx
movq %rax, (%rdx)
movl $0x7, 0x8(%rdx)
movq %rbx, %rdi
movl $0x1a, %esi
xorl %ecx, %ecx
callq 0x4a949
movq %r14, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x3d42f
movq %rax, %r15
testq %r12, %r12
je 0x5ec77
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x48163
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x3d42f
movq %rax, %r15
movq %r12, -0x50(%rbp)
movq %r14, -0x48(%rbp)
movq %rbx, -0x60(%rbp)
movq -0x40(%rbp), %rdx
cmpw $0x0, 0x42(%rdx)
jle 0x5ed02
xorl %r14d, %r14d
xorl %ebx, %ebx
movq -0x30(%rbp), %rax
movslq (%rax,%rbx,4), %rax
testq %rax, %rax
js 0x5ecc2
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 0x48163
jmp 0x5ecdb
movq 0x8(%rdx), %rax
movq %rdx, %r12
movq (%rax,%r14), %rdx
movq -0x60(%rbp), %rdi
movl $0x1a, %esi
callq 0x3d5ef
movq -0x48(%rbp), %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x3d42f
movq %rax, %r15
incq %rbx
movswq 0x42(%r12), %rax
addq $0x30, %r14
cmpq %rax, %rbx
movq %r12, %rdx
jl 0x5ec93
xorl %r12d, %r12d
cmpq $0x0, -0x50(%rbp)
setne %r12b
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %rdx, %r14
movq -0x58(%rbp), %rdx
movq 0x10(%rbp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x3d28c
movq %rax, -0x38(%rbp)
movl 0x54(%rbx), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x54(%rbx)
movswl 0x42(%r14), %eax
movq %r12, -0x58(%rbp)
leal 0x1(%r12,%rax), %ecx
movq %r13, %r14
movq %r13, %rdi
movl $0x33, %esi
movq %rdx, %r13
xorl %r8d, %r8d
callq 0x45b9e
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x5ed8d
movslq 0x34(%r14), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $0x8, -0x15(%rax,%rcx,8)
leaq -0x80(%rbp), %rdx
movw $0x8, (%rdx)
movl %r13d, 0x4(%rdx)
movq $0x0, 0x8(%rdx)
movq -0x48(%rbp), %r15
movq %r15, %rdi
movq -0x38(%rbp), %rsi
callq 0x3ba12
movl 0x58(%r15), %ecx
leal 0x1(%rcx), %ebx
movl %ebx, 0x58(%r15)
movq -0x40(%rbp), %rax
movswl 0x42(%rax), %eax
leal 0x2(%rcx), %edx
movl %edx, -0x64(%rbp)
movq %rcx, -0x30(%rbp)
addl %ecx, %eax
addl $0x2, %eax
movl %eax, 0x58(%r15)
xorl %r15d, %r15d
movq %r14, %rdi
movl $0x65, %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movq %rax, -0x50(%rbp)
movq %r14, %rdi
movl $0x29, %esi
movl %r13d, %edx
xorl %ecx, %ecx
movl %ebx, -0x68(%rbp)
movl %ebx, %r8d
callq 0x45b9e
movq %r14, %rdi
movl $0x29, %esi
movl %r13d, %edx
movq -0x58(%rbp), %r12
movl %r12d, %ecx
movl -0x64(%rbp), %r8d
callq 0x45b9e
movq -0x40(%rbp), %rsi
cmpw $0x0, 0x42(%rsi)
movq %r14, %rbx
jle 0x5ee72
movq -0x30(%rbp), %rax
addl $0x3, %eax
movq %rax, -0x30(%rbp)
incl %r12d
leal 0x1(%r15), %r14d
leal (%r12,%r15), %ecx
addl -0x30(%rbp), %r15d
movq %rbx, %rdi
movl $0x29, %esi
movl %r13d, %edx
movl %r15d, %r8d
callq 0x45b9e
movq -0x40(%rbp), %rsi
movswl 0x42(%rsi), %eax
movl %r14d, %r15d
cmpl %eax, %r14d
jl 0x5ee43
movq %r13, %r12
movq -0x48(%rbp), %r15
movq %r15, %rdi
movq %rsi, %r14
callq 0x5c4d9
movswl 0x42(%r14), %ecx
addl $0x2, %ecx
movq %rbx, %rdi
movl $0xd, %esi
xorl %edx, %edx
movl -0x68(%rbp), %r8d
callq 0x45b9e
movq %rbx, %rdi
movl %eax, %esi
movq -0x70(%rbp), %rdx
movl $0xfffffff6, %ecx       # imm = 0xFFFFFFF6
callq 0x11975
movq 0x8(%rbx), %rax
testq %rax, %rax
movq %rbx, %r13
je 0x5eed8
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(%r15), %rax
testq %rax, %rax
cmoveq %r15, %rax
movb $0x1, 0x24(%rax)
movq -0x50(%rbp), %r15
leal 0x1(%r15), %ecx
movq %r13, %rdi
movl $0x7, %esi
movl %r12d, %edx
xorl %r8d, %r8d
callq 0x45b9e
testl %r15d, %r15d
movq -0x60(%rbp), %rbx
movq -0x38(%rbp), %r14
js 0x5ef2a
movl 0x34(%r13), %eax
cmpl %r15d, %eax
jbe 0x5ef2a
movq 0x8(%r13), %rcx
movl %r15d, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
movq %r13, %rdi
movl $0x36, %esi
movl %r12d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45b9e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x340e4
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq