// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movq %r9, 0x18(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, %r14
movq %rdi, %r15
movq (%rdi), %r13
movq 0x10(%rdi), %rdi
movq 0x60(%rdx), %r12
testq %r12, %r12
movq %r8, 0x68(%rsp)
je 0x2e3c51
cmpq %r13, (%r12)
je 0x2e3c54
movq 0x28(%r12), %r12
testq %r12, %r12
jne 0x2e3c41
xorl %r12d, %r12d
movl 0xb8(%rsp), %eax
movl %eax, 0x64(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x10(%rsp)
movswl 0x46(%r14), %ebx
leal 0x2(%rbx), %ecx
movl 0x48(%rsi), %eax
movl %eax, 0xc(%rsp)
movl 0x34(%r15), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x34(%r15)
movq %rdi, 0x30(%rsp)
movq %rsi, 0x58(%rsp)
movl $0x64, %esi
movq %rdx, 0x38(%rsp)
movl %ecx, 0x8(%rsp)
xorl %r8d, %r8d
callq 0x2a83e1
movq 0x58(%rsp), %rsi
movq %rax, 0x50(%rsp)
movl 0x38(%r15), %ebp
leal 0x1(%rbp), %eax
movq %rax, 0x48(%rsp)
movq %rbx, 0x70(%rsp)
addl %ebp, %ebx
addl $0x2, %ebx
movl %ebx, 0x38(%r15)
cmpl $0x2, (%rsi)
jl 0x2e3cfb
movq 0x10(%rsp), %rbp
movq 0x68(%rsp), %rsi
testq %rsi, %rsi
movq %r14, 0x20(%rsp)
je 0x2e3e39
movq %r13, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2c2864
movq %r15, %rbx
jmp 0x2e3e4d
leal 0x2(%rbx), %r13d
movl %r13d, 0x38(%r15)
movl $0x0, (%rsp)
movq %r15, %rdi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl $0x4, %r9d
callq 0x2ce2c4
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2e3eef
movl %r13d, 0x60(%rsp)
movq %rbx, 0x40(%rsp)
movq %r14, 0x20(%rsp)
cmpw $0x0, 0x46(%r14)
movq 0x38(%rsp), %r13
jle 0x2e3ddc
leal 0x3(%rbp), %ebx
addq $0x8, 0x28(%rsp)
xorl %r14d, %r14d
movq 0x18(%rsp), %rax
movslq (%rax,%r14,4), %rax
testq %rax, %rax
js 0x2e3d85
leaq (%rax,%rax,2), %rax
movq 0x28(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
leal (%rbx,%r14), %edx
movq %r15, %rdi
callq 0x2bc7e9
jmp 0x2e3dca
leal (%rbx,%r14), %r8d
movq 0x30(%rsp), %r13
movq %r13, %rdi
movl $0xa6, %esi
movl 0xc(%rsp), %edx
movl %r14d, %ecx
callq 0x2a83e1
movslq 0x90(%r13), %rax
movq 0x38(%rsp), %r13
testq %rax, %rax
jle 0x2e3dca
movq 0x30(%rsp), %rcx
movq 0x88(%rcx), %rcx
leaq (%rax,%rax,2), %rax
movw $0x1, -0x16(%rcx,%rax,8)
incq %r14
movq 0x20(%rsp), %rax
movswq 0x46(%rax), %rax
cmpq %rax, %r14
jl 0x2e3d5c
movq %rbp, 0x18(%rsp)
movq 0x20(%rsp), %rax
testb $-0x80, 0x40(%rax)
jne 0x2e3f4d
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movl $0x7f, %esi
movl 0xc(%rsp), %r14d
movl %r14d, %edx
movq 0x48(%rsp), %rbp
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq 0x18(%rsp), %rcx
addl $0x2, %ecx
movq 0x68(%rsp), %rsi
testq %rsi, %rsi
je 0x2e3fa7
movq %r15, %rdi
movl %ecx, %edx
callq 0x2bc7e9
jmp 0x2e3fba
movq %r15, %rbx
movq %r15, %rdi
movl $0x4b, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2ad3b5
movq (%rbx), %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x2b1a3f
movq %rax, %r14
movq 0x20(%rsp), %rax
cmpw $0x0, 0x46(%rax)
jle 0x2e3efe
addq $0x8, 0x28(%rsp)
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
movslq (%rax,%rbx,4), %rax
testq %rax, %rax
js 0x2e3ea6
leaq (%rax,%rax,2), %rax
movq 0x28(%rsp), %rcx
movq (%rcx,%rax,8), %rsi
testq %rsi, %rsi
je 0x2e3ec8
movq %r13, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2c2864
movq %rax, %rdx
jmp 0x2e3eca
movq %r15, %rdi
movl $0x4b, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2ad3b5
movq %rax, %rdx
testq %rax, %rax
je 0x2e3eca
leal 0x1(%rbx), %eax
movw %ax, 0x30(%rdx)
jmp 0x2e3eca
xorl %edx, %edx
movq (%r15), %rdi
movq %r14, %rsi
callq 0x2b1a3f
movq %rax, %r14
incq %rbx
movq 0x20(%rsp), %rax
movswq 0x46(%rax), %rax
cmpq %rax, %rbx
movq %rbp, %r9
jl 0x2e3e75
jmp 0x2e3f01
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %r9
movq $0x0, 0x10(%rsp)
movq %r15, %rdi
movq 0x38(%rsp), %rsi
xorl %edx, %edx
movq %r14, %rcx
movq 0x58(%rsp), %r8
callq 0x2e41f7
testq %r14, %r14
movq 0x30(%rsp), %rbx
movq 0x48(%rsp), %rbp
je 0x2e4065
movq %r13, %rdi
movq %r14, %rsi
callq 0x2a65a3
movq $0x0, 0x10(%rsp)
jmp 0x2e4065
leaq 0x10(%rax), %rcx
movq 0x30(%rsp), %rbx
movq 0x48(%rsp), %rbp
movq (%rcx), %rax
movzwl 0x63(%rax), %edx
andl $0x3, %edx
leaq 0x28(%rax), %rcx
cmpw $0x2, %dx
jne 0x2e3f5b
movq 0x8(%rax), %rax
movswl (%rax), %r14d
movq %rbx, %rdi
movl $0xa6, %esi
movl 0xc(%rsp), %edx
movl %r14d, %ecx
movl %ebp, %r8d
callq 0x2a83e1
movq 0x18(%rsp), %rcx
leal (%rcx,%r14), %edx
addl $0x3, %edx
addl $0x2, %ecx
movq %rbx, %rdi
movl $0x4e, %esi
jmp 0x2e3fb2
movq %rbx, %rdi
movl $0x7f, %esi
movl %r14d, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x8(%rsp), %r14d
movq 0x10(%rsp), %rax
cmpb $0x0, 0x42(%rax)
je 0x2e3fff
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
callq 0x2c27bc
movl $0x0, 0x18(%rsp)
movq %rbx, %rdi
movl $0x74, %esi
movl 0xc(%rsp), %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq 0x20(%rsp), %rsi
jmp 0x2e40f6
movq 0x40(%rsp), %rax
incl %eax
movq %rax, %r8
movq %rax, 0x40(%rsp)
movq 0xa0(%r15), %rax
testq %rax, %rax
cmoveq %r15, %rax
movb $0x1, 0x20(%rax)
movq %rbx, %rdi
movl $0x5b, %esi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x2a83e1
movq %rbx, %rdi
movl $0x78, %esi
movl %r13d, %edx
movl 0x60(%rsp), %r14d
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %rbx, %rdi
movl $0x79, %esi
movl %r13d, %edx
movq 0x40(%rsp), %rcx
movl %r14d, %r8d
callq 0x2a83e1
movq 0x58(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x2e4079
movq 0x10(%rsp), %rdi
callq 0x2d11fa
xorl %r14d, %r14d
movq %rbx, %rdi
movl $0x25, %esi
movq 0x38(%rsp), %r13
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq %rax, 0x50(%rsp)
movb $0x1, %al
movl %eax, 0x18(%rsp)
cmpw $-0x1, 0x70(%rsp)
jl 0x2e40ec
movq %r15, 0x28(%rsp)
movq %r13, %r15
movq %rbp, %r13
movl 0x8(%rsp), %ebp
leal (%r14,%r13), %r8d
movq %rbx, %rdi
movl $0x59, %esi
movl %r15d, %edx
movl %r14d, %ecx
callq 0x2a83e1
incl %r14d
cmpl %r14d, %ebp
jne 0x2e40b8
movq 0x20(%rsp), %rsi
movl %ebp, %r14d
movq %r13, %rbp
movq %r15, %r13
movq 0x28(%rsp), %r15
jmp 0x2e40f6
movq 0x20(%rsp), %rsi
movl 0x8(%rsp), %r14d
movq %r15, %rdi
callq 0x2e0de0
movq %rbx, %rdi
movl $0xa, %esi
xorl %edx, %edx
movl %r14d, %ecx
movl %ebp, %r8d
callq 0x2a83e1
movq %rbx, %rdi
movl %eax, %esi
movq %r12, %rdx
movl $0xfffffff4, %ecx       # imm = 0xFFFFFFF4
callq 0x27b778
movslq 0x90(%rbx), %rax
testq %rax, %rax
jle 0x2e4150
movl 0x64(%rsp), %edx
cmpl $0xb, %edx
movl $0x2, %ecx
cmovnel %edx, %ecx
movq 0x88(%rbx), %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)
cmpb $0x0, 0x18(%rsp)
je 0x2e419d
movq 0x50(%rsp), %r14
leal 0x1(%r14), %ecx
movq %rbx, %rdi
movl $0x5, %esi
movl %r13d, %edx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x90(%rbx), %eax
movq (%rbx), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2e41b5
leaq 0x1daced(%rip), %rcx    # 0x4bee88
jmp 0x2e41d1
movq 0x10(%rsp), %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d11fa
leal -0x1(%rax), %ecx
testl %r14d, %r14d
cmovnsl %r14d, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%rbx), %rcx
movl %eax, 0x8(%rcx)
movq %rbx, %rdi
movl $0x74, %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2a83e1