// File: /workspace/github_c_makefile_star2_O0/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
subq $0xd0, %rsp
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x49880
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rdi
movl $0x1a, %esi
leaq 0x30e31(%rip), %rdx     # 0xb08ee
callq 0x548b0
movq -0x88(%rbp), %rdi
movq %rax, %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x54650
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x7fb1f
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x68(%rbp), %rdi
movq -0x28(%rbp), %rsi
xorl %edx, %edx
callq 0x61690
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq %rax, %rdx
callq 0x54650
movq %rax, -0x40(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x18(%rbp), %rcx
movswl 0x42(%rcx), %ecx
cmpl %ecx, %eax
jge 0x7fbc1
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0x7fb76
movq -0x68(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x30(%rbp), %rcx
movslq -0x58(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
xorl %edx, %edx
callq 0x61690
movq %rax, -0x50(%rbp)
jmp 0x7fb9e
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x58(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movl $0x1a, %esi
callq 0x548b0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x54650
movq %rax, -0x40(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x7fb26
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq 0x10(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
xorl %eax, %eax
movq %r9, %r8
movq $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
callq 0x54490
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rcx
movl 0x54(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x54(%rcx)
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rdi
movl -0x54(%rbp), %edx
movq -0x18(%rbp), %rax
movswl 0x42(%rax), %ecx
addl $0x1, %ecx
cmpq $0x0, -0x28(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, %ecx
movl $0x33, %esi
callq 0x5e0c0
movq -0x38(%rbp), %rdi
movl $0x8, %esi
callq 0x5e540
movl -0x54(%rbp), %edx
leaq -0x80(%rbp), %rdi
movl $0x8, %esi
callq 0x5ef20
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x529a0
movq -0x8(%rbp), %rcx
movl 0x58(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x58(%rcx)
movl %eax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movswl 0x42(%rax), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
addl 0x58(%rax), %ecx
movl %ecx, 0x58(%rax)
movq -0x38(%rbp), %rdi
movl -0x54(%rbp), %edx
movl $0x65, %esi
xorl %ecx, %ecx
callq 0x5e0c0
movl %eax, -0x5c(%rbp)
movq -0x38(%rbp), %rdi
movl -0x54(%rbp), %edx
movl -0x60(%rbp), %r8d
movl $0x29, %esi
xorl %ecx, %ecx
callq 0x5e0f0
movq -0x38(%rbp), %rdi
movl -0x54(%rbp), %edx
movq -0x28(%rbp), %rsi
xorl %ecx, %ecx
movl $0x1, %eax
cmpq $0x0, %rsi
cmovnel %eax, %ecx
movl -0x60(%rbp), %r8d
addl $0x1, %r8d
movl $0x29, %esi
callq 0x5e0f0
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x18(%rbp), %rcx
movswl 0x42(%rcx), %ecx
cmpl %ecx, %eax
jge 0x7fd43
movq -0x38(%rbp), %rdi
movl -0x54(%rbp), %edx
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
cmpq $0x0, -0x28(%rbp)
setne %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, %ecx
movl -0x60(%rbp), %r8d
addl $0x2, %r8d
addl -0x58(%rbp), %r8d
movl $0x29, %esi
callq 0x5e0f0
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x7fcf7
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x7cb90
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movswl 0x42(%rax), %ecx
addl $0x2, %ecx
movl -0x60(%rbp), %r8d
movq -0x70(%rbp), %r9
movl $0xd, %esi
xorl %edx, %edx
movl $0xfffffff6, (%rsp)     # imm = 0xFFFFFFF6
callq 0x5e1b0
movq -0x38(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpl $0x63, 0x18(%rbp)
jne 0x7fd98
movl $0x2, %eax
movl %eax, -0xa4(%rbp)
jmp 0x7fda1
movl 0x18(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0xa0(%rbp), %rdi
movl -0xa4(%rbp), %eax
movzbl %al, %esi
callq 0x5e540
movq -0x8(%rbp), %rdi
callq 0x6a6f0
movq -0x38(%rbp), %rdi
movl -0x54(%rbp), %edx
movl -0x5c(%rbp), %ecx
addl $0x1, %ecx
movl $0x7, %esi
callq 0x5e0c0
movq -0x38(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x5e090
movq -0x38(%rbp), %rdi
movl -0x54(%rbp), %edx
movl $0x36, %esi
xorl %ecx, %ecx
callq 0x5e0c0
movq -0x68(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x47420
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)