// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/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 */
  int ephemTab;             /* Table holding the result of the SELECT */
  int i;                    /* Loop counter */
  sqlite3 *db = pParse->db; /* Database connection */
  const char *pVTab = (const char*)sqlite3GetVTable(db, pTab);
  WhereInfo *pWInfo = 0;
  int nArg = 2 + pTab->nCol;      /* Number of arguments to VUpdate */
  int regArg;                     /* First register in VUpdate arg array */
  int regRec;                     /* Register in which to assemble record */
  int regRowid;                   /* Register for ephem table rowid */
  int iCsr = pSrc->a[0].iCursor;  /* Cursor used for virtual table scan */
  int aDummy[2];                  /* Unused arg for sqlite3WhereOkOnePass() */
  int eOnePass;                   /* True to use onepass strategy */
  int addr;                       /* Address of OP_OpenEphemeral */

  /* Allocate nArg registers in which to gather the arguments for VUpdate. Then
  ** create and open the ephemeral table in which the records created from
  ** these arguments will be temporarily stored. */
  assert( v );
  ephemTab = pParse->nTab++;
  addr= sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, nArg);
  regArg = pParse->nMem + 1;
  pParse->nMem += nArg;
  if( pSrc->nSrc>1 ){
    Expr *pRow;
    ExprList *pList;
    if( pRowid ){
      pRow = sqlite3ExprDup(db, pRowid, 0);
    }else{
      pRow = sqlite3PExpr(pParse, TK_ROW, 0, 0);
    }
    pList = sqlite3ExprListAppend(pParse, 0, pRow);

    for(i=0; i<pTab->nCol; i++){
      if( aXRef[i]>=0 ){
        pList = sqlite3ExprListAppend(pParse, pList,
          sqlite3ExprDup(db, pChanges->a[aXRef[i]].pExpr, 0)
        );
      }else{
        pList = sqlite3ExprListAppend(pParse, pList, exprRowColumn(pParse, i));
      }
    }

    updateFromSelect(pParse, ephemTab, 0, pList, pSrc, pWhere, 0, 0);
    sqlite3ExprListDelete(db, pList);
    eOnePass = ONEPASS_OFF;
  }else{
    regRec = ++pParse->nMem;
    regRowid = ++pParse->nMem;

    /* Start scanning the virtual table */
    pWInfo = sqlite3WhereBegin(pParse, pSrc,pWhere,0,0,WHERE_ONEPASS_DESIRED,0);
    if( pWInfo==0 ) return;

    /* Populate the argument registers. */
    for(i=0; i<pTab->nCol; i++){
      assert( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 );
      if( aXRef[i]>=0 ){
        sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);
      }else{
        sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i);
        sqlite3VdbeChangeP5(v, OPFLAG_NOCHNG);/* For sqlite3_vtab_nochange() */
      }
    }
    if( HasRowid(pTab) ){
      sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);
      if( pRowid ){
        sqlite3ExprCode(pParse, pRowid, regArg+1);
      }else{
        sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1);
      }
    }else{
      Index *pPk;   /* PRIMARY KEY index */
      i16 iPk;      /* PRIMARY KEY column */
      pPk = sqlite3PrimaryKeyIndex(pTab);
      assert( pPk!=0 );
      assert( pPk->nKeyCol==1 );
      iPk = pPk->aiColumn[0];
      sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, iPk, regArg);
      sqlite3VdbeAddOp2(v, OP_SCopy, regArg+2+iPk, regArg+1);
    }

    eOnePass = sqlite3WhereOkOnePass(pWInfo, aDummy);

    /* There is no ONEPASS_MULTI on virtual tables */
    assert( eOnePass==ONEPASS_OFF || eOnePass==ONEPASS_SINGLE );

    if( eOnePass ){
      /* If using the onepass strategy, no-op out the OP_OpenEphemeral coded
      ** above. */
      sqlite3VdbeChangeToNoop(v, addr);
      sqlite3VdbeAddOp1(v, OP_Close, iCsr);
    }else{
      /* Create a record from the argument register contents and insert it into
      ** the ephemeral table. */
      sqlite3MultiWrite(pParse);
      sqlite3VdbeAddOp3(v, OP_MakeRecord, regArg, nArg, regRec);
#if defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_NULL_TRIM)
      /* Signal an assert() within OP_MakeRecord that it is allowed to
      ** accept no-change records with serial_type 10 */
      sqlite3VdbeChangeP5(v, OPFLAG_NOCHNG_MAGIC);
#endif
      sqlite3VdbeAddOp2(v, OP_NewRowid, ephemTab, regRowid);
      sqlite3VdbeAddOp3(v, OP_Insert, ephemTab, regRec, regRowid);
    }
  }


  if( eOnePass==ONEPASS_OFF ){
    /* End the virtual table scan */
    if( pSrc->nSrc==1 ){
      sqlite3WhereEnd(pWInfo);
    }

    /* Begin scannning through the ephemeral table. */
    addr = sqlite3VdbeAddOp1(v, OP_Rewind, ephemTab); VdbeCoverage(v);

    /* Extract arguments from the current row of the ephemeral table and
    ** invoke the VUpdate method.  */
    for(i=0; i<nArg; i++){
      sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i, regArg+i);
    }
  }
  sqlite3VtabMakeWritable(pParse, pTab);
  sqlite3VdbeAddOp4(v, OP_VUpdate, 0, nArg, regArg, pVTab, P4_VTAB);
  sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
  sqlite3MayAbort(pParse);

  /* End of the ephemeral table scan. Or, if using the onepass strategy,
  ** jump to here if the scan visited zero rows. */
  if( eOnePass==ONEPASS_OFF ){
    sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); VdbeCoverage(v);
    sqlite3VdbeJumpHere(v, addr);
    sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
  }else{
    sqlite3WhereEnd(pWInfo);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x38(%rsp)
movq %rcx, 0x28(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rbx
movq 0x10(%rdi), %rax
movq 0x60(%rdx), %r12
testq %r12, %r12
movq %rax, 0x58(%rsp)
movq %r8, 0x70(%rsp)
je 0x2ecf07
cmpq %rbx, (%r12)
je 0x2ecf07
movq 0x28(%r12), %r12
testq %r12, %r12
jne 0x2ecef7
movl 0xc8(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rdx, 0x40(%rsp)
movswl 0x46(%rdx), %r13d
leal 0x2(%r13), %ecx
movl 0x48(%r14), %eax
movl %eax, 0x14(%rsp)
movl 0x34(%r15), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x34(%r15)
movq 0x58(%rsp), %rdi
movl $0x64, %esi
movq %rdx, 0x30(%rsp)
movl %ecx, 0x24(%rsp)
xorl %r8d, %r8d
callq 0x2b200c
movq %rax, 0x60(%rsp)
movl 0x38(%r15), %ebp
leal 0x1(%rbp), %eax
movq %rax, 0x50(%rsp)
movq %r13, 0x80(%rsp)
addl %ebp, %r13d
addl $0x2, %r13d
movl %r13d, 0x38(%r15)
cmpl $0x2, (%r14)
movq %r14, 0x48(%rsp)
jl 0x2ecfb1
movq 0x18(%rsp), %rbp
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
je 0x2ed0cc
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2cbf97
movq %r15, %r14
jmp 0x2ed0e0
leal 0x2(%r13), %ebx
movl %ebx, 0x38(%r15)
movl $0x0, (%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl $0x4, %r9d
callq 0x2d7b05
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x2ed184
movl %ebx, 0x68(%rsp)
movq %r13, 0x78(%rsp)
movq 0x40(%rsp), %rcx
cmpw $0x0, 0x46(%rcx)
movq 0x58(%rsp), %r13
jle 0x2ed07f
leal 0x3(%rbp), %r14d
addq $0x8, 0x28(%rsp)
xorl %ebx, %ebx
movq 0x38(%rsp), %rax
movslq (%rax,%rbx,4), %rax
testq %rax, %rax
js 0x2ed038
leaq (%rax,%rax,2), %rax
movq 0x28(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
leal (%r14,%rbx), %edx
movq %r15, %rdi
callq 0x2c5f97
jmp 0x2ed06d
leal (%r14,%rbx), %r8d
movq %r13, %rdi
movl $0xa6, %esi
movl 0x14(%rsp), %edx
movl %ebx, %ecx
callq 0x2b200c
movslq 0x90(%r13), %rax
testq %rax, %rax
jle 0x2ed06d
movq 0x88(%r13), %rcx
leaq (%rax,%rax,2), %rax
movw $0x1, -0x16(%rcx,%rax,8)
incq %rbx
movq 0x40(%rsp), %rcx
movswq 0x46(%rcx), %rax
cmpq %rax, %rbx
jl 0x2ed00f
testb $-0x80, 0x40(%rcx)
movq 0x50(%rsp), %r8
jne 0x2ed1d3
movq %r13, %rdi
movl $0x7f, %esi
movl 0x14(%rsp), %ebx
movl %ebx, %edx
movl %r8d, %ecx
xorl %r8d, %r8d
callq 0x2b200c
addl $0x2, %ebp
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
movq 0x48(%rsp), %r14
je 0x2ed224
movq %r15, %rdi
movl %ebp, %edx
callq 0x2c5f97
jmp 0x2ed238
movq %r15, %r14
movq %r15, %rdi
movl $0x4b, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2b6fa0
movq %r14, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x2bb1a3
movq %rax, %r13
movq 0x40(%rsp), %rax
cmpw $0x0, 0x46(%rax)
jle 0x2ed196
addq $0x8, 0x28(%rsp)
xorl %r14d, %r14d
movq 0x38(%rsp), %rax
movslq (%rax,%r14,4), %rax
testq %rax, %rax
js 0x2ed13a
leaq (%rax,%rax,2), %rax
movq 0x28(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
testq %rsi, %rsi
je 0x2ed15d
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2cbf97
movq %rax, %rdx
jmp 0x2ed15f
movq %r15, %rdi
movl $0x4b, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2b6fa0
movq %rax, %rdx
testq %rax, %rax
je 0x2ed15f
leal 0x1(%r14), %eax
movw %ax, 0x30(%rdx)
jmp 0x2ed15f
xorl %edx, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x2bb1a3
movq %rax, %r13
incq %r14
movq 0x40(%rsp), %rax
movswq 0x46(%rax), %rax
cmpq %rax, %r14
movq %rbp, %r9
jl 0x2ed109
jmp 0x2ed199
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %r9
xorl %ebp, %ebp
movq %r15, %rdi
movq 0x30(%rsp), %rsi
xorl %edx, %edx
movq %r13, %rcx
movq 0x48(%rsp), %r14
movq %r14, %r8
callq 0x2ed46a
testq %r13, %r13
je 0x2ed1c7
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2b0183
xorl %ebp, %ebp
movq 0x58(%rsp), %r13
movb $0x1, %bl
jmp 0x2ed2db
movq 0x10(%rcx), %rax
testq %rax, %rax
movq 0x48(%rsp), %r14
je 0x2ed1f7
movzwl 0x63(%rax), %ecx
andl $0x3, %ecx
cmpw $0x2, %cx
je 0x2ed1f7
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x2ed1e1
movq 0x8(%rax), %rax
movswl (%rax), %ebx
movq %r13, %rdi
movl $0xa6, %esi
movl 0x14(%rsp), %edx
movl %ebx, %ecx
callq 0x2b200c
leal (%rbx,%rbp), %edx
addl $0x3, %edx
addl $0x2, %ebp
movq %r13, %rdi
movl $0x4e, %esi
jmp 0x2ed22e
movq %r13, %rdi
movl $0x7f, %esi
movl %ebx, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq 0x18(%rsp), %rax
cmpb $0x0, 0x42(%rax)
je 0x2ed26a
movq %r13, %rdi
movq 0x60(%rsp), %rsi
callq 0x2cbeef
xorl %ebx, %ebx
movq %r13, %rdi
movl $0x74, %esi
movl 0x14(%rsp), %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
jmp 0x2ed2d6
movq 0x78(%rsp), %rbp
incl %ebp
movq 0xa0(%r15), %rax
testq %rax, %rax
cmoveq %r15, %rax
movb $0x1, 0x20(%rax)
movq %r13, %rdi
movl $0x5b, %esi
movq 0x50(%rsp), %rdx
movl 0x24(%rsp), %ecx
movl %ebp, %r8d
callq 0x2b200c
movq %r13, %rdi
movl $0x78, %esi
movq 0x30(%rsp), %rbx
movl %ebx, %edx
movl 0x68(%rsp), %r14d
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %r13, %rdi
movl $0x79, %esi
movl %ebx, %edx
movl %ebp, %ecx
movl %r14d, %r8d
movq 0x48(%rsp), %r14
callq 0x2b200c
movb $0x1, %bl
movq 0x18(%rsp), %rbp
testb %bl, %bl
je 0x2ed35c
movl %ebx, 0x38(%rsp)
cmpl $0x1, (%r14)
jne 0x2ed2f1
movq %rbp, %rdi
callq 0x2daa07
xorl %ebx, %ebx
movq %r13, %rdi
movl $0x25, %esi
movq 0x30(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq %rax, 0x60(%rsp)
cmpw $-0x1, 0x80(%rsp)
jl 0x2ed358
movq %r15, 0x28(%rsp)
movq %rbp, 0x18(%rsp)
movl 0x24(%rsp), %ebp
movq 0x50(%rsp), %r14
movq 0x30(%rsp), %r15
leal (%r14,%rbx), %r8d
movq %r13, %rdi
movl $0x59, %esi
movl %r15d, %edx
movl %ebx, %ecx
callq 0x2b200c
incl %ebx
cmpl %ebx, %ebp
jne 0x2ed332
movq 0x18(%rsp), %rbp
movq 0x28(%rsp), %r15
movl 0x38(%rsp), %ebx
movq %r15, %rdi
movq 0x40(%rsp), %rsi
callq 0x2ea09f
movq %r13, %rdi
movl $0xa, %esi
xorl %edx, %edx
movl 0x24(%rsp), %ecx
movq 0x50(%rsp), %r8
callq 0x2b200c
movq %r13, %rdi
movl %eax, %esi
movq %r12, %rdx
movl $0xfffffff4, %ecx       # imm = 0xFFFFFFF4
callq 0x285198
movslq 0x90(%r13), %rax
testq %rax, %rax
jle 0x2ed3be
movl 0x6c(%rsp), %edx
cmpl $0xb, %edx
movl $0x2, %ecx
cmovnel %edx, %ecx
movq 0x88(%r13), %rdx
leaq (%rax,%rax,2), %rax
movw %cx, -0x16(%rdx,%rax,8)
movq 0xa0(%r15), %rax
testq %rax, %rax
cmoveq %r15, %rax
movb $0x1, 0x21(%rax)
testb %bl, %bl
je 0x2ed40e
movq 0x60(%rsp), %rbx
leal 0x1(%rbx), %ecx
movq %r13, %rdi
movl $0x5, %esi
movq 0x30(%rsp), %r14
movl %r14d, %edx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x90(%r13), %eax
movq (%r13), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2ed427
leaq 0x1dca7c(%rip), %rcx    # 0x4c9e88
jmp 0x2ed441
movq %rbp, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2daa07
leal -0x1(%rax), %ecx
testl %ebx, %ebx
cmovnsl %ebx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r13), %rcx
movl %eax, 0x8(%rcx)
movq %r13, %rdi
movl $0x74, %esi
movl %r14d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2b200c