// File: /workspace/github_c_makefile_star2_O2/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: sqlite3WhereEnd
SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo *pWInfo){
  Parse *pParse = pWInfo->pParse;
  Vdbe *v = pParse->pVdbe;
  int i;
  WhereLevel *pLevel;
  WhereLoop *pLoop;
  SrcList *pTabList = pWInfo->pTabList;
  sqlite3 *db = pParse->db;

  /* Generate loop termination code.
  */
  VdbeModuleComment((v, "End WHERE-core"));
  sqlite3ExprCacheClear(pParse);
  for(i=pWInfo->nLevel-1; i>=0; i--){
    int addr;
    pLevel = &pWInfo->a[i];
    pLoop = pLevel->pWLoop;
    sqlite3VdbeResolveLabel(v, pLevel->addrCont);
    if( pLevel->op!=OP_Noop ){
      sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
      sqlite3VdbeChangeP5(v, pLevel->p5);
      VdbeCoverage(v);
      VdbeCoverageIf(v, pLevel->op==OP_Next);
      VdbeCoverageIf(v, pLevel->op==OP_Prev);
      VdbeCoverageIf(v, pLevel->op==OP_VNext);
    }
    if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
      struct InLoop *pIn;
      int j;
      sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
      for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
        sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
        sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
        VdbeCoverage(v);
        VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
        VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
        sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
      }
    }
    sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
    if( pLevel->addrSkip ){
      sqlite3VdbeGoto(v, pLevel->addrSkip);
      VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
      sqlite3VdbeJumpHere(v, pLevel->addrSkip);
      sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
    }
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
    if( pLevel->addrLikeRep ){
      int op;
      if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){
        op = OP_DecrJumpZero;
      }else{
        op = OP_JumpZeroIncr;
      }
      sqlite3VdbeAddOp2(v, op, pLevel->iLikeRepCntr, pLevel->addrLikeRep);
      VdbeCoverage(v);
    }
#endif
    if( pLevel->iLeftJoin ){
      addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
      assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
           || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
      if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
        sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
      }
      if( pLoop->wsFlags & WHERE_INDEXED ){
        sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
      }
      if( pLevel->op==OP_Return ){
        sqlite3VdbeAddOp2(v, OP_Gosub, pLevel->p1, pLevel->addrFirst);
      }else{
        sqlite3VdbeGoto(v, pLevel->addrFirst);
      }
      sqlite3VdbeJumpHere(v, addr);
    }
    VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
                     pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
  }

  /* The "break" point is here, just past the end of the outer loop.
  ** Set it.
  */
  sqlite3VdbeResolveLabel(v, pWInfo->iBreak);

  assert( pWInfo->nLevel<=pTabList->nSrc );
  for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
    int k, last;
    VdbeOp *pOp;
    Index *pIdx = 0;
    struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
    Table *pTab = pTabItem->pTab;
    assert( pTab!=0 );
    pLoop = pLevel->pWLoop;

    /* For a co-routine, change all OP_Column references to the table of
    ** the co-routine into OP_Copy of result contained in a register.
    ** OP_Rowid becomes OP_Null.
    */
    if( pTabItem->fg.viaCoroutine && !db->mallocFailed ){
      translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
                            pTabItem->regResult, 0);
      continue;
    }

    /* Close all of the cursors that were opened by sqlite3WhereBegin.
    ** Except, do not close cursors that will be reused by the OR optimization
    ** (WHERE_OMIT_OPEN_CLOSE).  And do not close the OP_OpenWrite cursors
    ** created for the ONEPASS optimization.
    */
    if( (pTab->tabFlags & TF_Ephemeral)==0
     && pTab->pSelect==0
     && (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0
    ){
      int ws = pLoop->wsFlags;
      if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
        sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
      }
      if( (ws & WHERE_INDEXED)!=0
       && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 
       && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1]
      ){
        sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
      }
    }

    /* If this scan uses an index, make VDBE code substitutions to read data
    ** from the index instead of from the table where possible.  In some cases
    ** this optimization prevents the table from ever being read, which can
    ** yield a significant performance boost.
    ** 
    ** Calls to the code generator in between sqlite3WhereBegin and
    ** sqlite3WhereEnd will have created code that references the table
    ** directly.  This loop scans all that code looking for opcodes
    ** that reference the table and converts them into opcodes that
    ** reference the index.
    */
    if( pLoop->wsFlags & (WHERE_INDEXED|WHERE_IDX_ONLY) ){
      pIdx = pLoop->u.btree.pIndex;
    }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
      pIdx = pLevel->u.pCovidx;
    }
    if( pIdx
     && (pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable))
     && !db->mallocFailed
    ){
      last = sqlite3VdbeCurrentAddr(v);
      k = pLevel->addrBody;
      pOp = sqlite3VdbeGetOp(v, k);
      for(; k<last; k++, pOp++){
        if( pOp->p1!=pLevel->iTabCur ) continue;
        if( pOp->opcode==OP_Column ){
          int x = pOp->p2;
          assert( pIdx->pTable==pTab );
          if( !HasRowid(pTab) ){
            Index *pPk = sqlite3PrimaryKeyIndex(pTab);
            x = pPk->aiColumn[x];
            assert( x>=0 );
          }
          x = sqlite3ColumnOfIndex(pIdx, x);
          if( x>=0 ){
            pOp->p2 = x;
            pOp->p1 = pLevel->iIdxCur;
          }
          assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 );
        }else if( pOp->opcode==OP_Rowid ){
          pOp->p1 = pLevel->iIdxCur;
          pOp->opcode = OP_IdxRowid;
        }
      }
    }
  }

  /* Final cleanup
  */
  pParse->nQueryLoop = pWInfo->savedNQueryLoop;
  whereInfoFree(db, pWInfo);
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq (%rdi), %rdi
movq 0x8(%rbx), %r14
movq (%rdi), %rax
movq %rax, -0x50(%rbp)
movq 0x10(%rdi), %r12
movq %rdi, -0x60(%rbp)
callq 0x5721e
movzbl 0x39(%rbx), %eax
movq %rbx, -0x38(%rbp)
leaq 0x340(%rbx), %r13
addq $0x8, %r14
movq %r14, -0x58(%rbp)
movq %rax, %r14
testq %r14, %r14
jle 0x56f36
decq %r14
movq %r14, -0x48(%rbp)
imulq $0x58, %r14, %rbx
leaq (%rbx,%r13), %r15
movq 0x48(%r13,%rbx), %r14
movl 0x18(%r13,%rbx), %esi
movq %r12, %rdi
callq 0x4bacf
movzbl 0x2d(%r13,%rbx), %esi
cmpl $0xa1, %esi
je 0x56dd0
movl 0x30(%r15), %edx
movl 0x34(%r15), %ecx
movzbl 0x2e(%r15), %r8d
movq %r12, %rdi
callq 0x385b6
movzbl 0x2f(%r15), %esi
movq %r12, %rdi
callq 0x13770
movq %r14, -0x40(%rbp)
testb $0x8, 0x29(%r14)
je 0x56e3e
cmpl $0x0, 0x38(%r15)
jle 0x56e3e
movl 0x10(%r15), %esi
movq %r12, %rdi
callq 0x4bacf
movslq 0x38(%r15), %rbx
movq 0x40(%r15), %rax
imulq $0xc, %rbx, %rcx
leaq (%rax,%rcx), %r14
addq $-0x4, %r14
testl %ebx, %ebx
jle 0x56e3e
movl -0x4(%r14), %esi
incl %esi
movq %r12, %rdi
callq 0x4a022
movzbl (%r14), %esi
movl -0x8(%r14), %edx
movl -0x4(%r14), %ecx
movq %r12, %rdi
callq 0x4a1ab
movl -0x4(%r14), %esi
decl %esi
movq %r12, %rdi
callq 0x4a022
decl %ebx
addq $-0xc, %r14
jmp 0x56e02
movl 0xc(%r15), %esi
movq %r12, %rdi
callq 0x4bacf
movl 0x14(%r15), %esi
testl %esi, %esi
je 0x56e75
movq %r12, %rdi
callq 0x4a0cb
movl 0x14(%r15), %esi
movq %r12, %rdi
callq 0x4a022
movl 0x14(%r15), %esi
addl $-0x2, %esi
movq %r12, %rdi
callq 0x4a022
movl 0x28(%r15), %ebx
testl %ebx, %ebx
movq -0x48(%rbp), %r14
je 0x56ea9
leal -0x1(%rbx), %esi
movq %r12, %rdi
callq 0x386ca
cmpl $0x1, 0x4(%rax)
movl $0x0, %esi
adcl $0x8e, %esi
movl 0x24(%r15), %edx
movq %r12, %rdi
movl %ebx, %ecx
callq 0x4a1ab
movl (%r15), %edx
testl %edx, %edx
je 0x56d76
movq %r12, %rdi
movl $0x8b, %esi
callq 0x4b9b3
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rbx
movl 0x28(%rbx), %eax
testb $0x40, %al
jne 0x56ee9
imulq $0x70, %r14, %rax
movq -0x58(%rbp), %rcx
movl 0x44(%rcx,%rax), %edx
movq %r12, %rdi
pushq $0x6a
popq %rsi
callq 0x4b9b3
movl 0x28(%rbx), %eax
btl $0x9, %eax
jae 0x56efe
movl 0x8(%r15), %edx
movq %r12, %rdi
pushq $0x6a
popq %rsi
callq 0x4b9b3
cmpb $0x10, 0x2d(%r15)
jne 0x56f1a
movl 0x1c(%r15), %ecx
movl 0x30(%r15), %edx
movq %r12, %rdi
pushq $0xf
popq %rsi
callq 0x4a1ab
jmp 0x56f26
movl 0x1c(%r15), %esi
movq %r12, %rdi
callq 0x4a0cb
movq %r12, %rdi
movl -0x2c(%rbp), %esi
callq 0x4a022
jmp 0x56d76
movq -0x38(%rbp), %rax
movl 0x44(%rax), %esi
movq %r12, %rdi
callq 0x4bacf
xorl %esi, %esi
movq -0x38(%rbp), %rax
movzbl 0x39(%rax), %eax
cmpl %eax, %esi
jae 0x57121
movzbl 0x2c(%r13), %eax
imulq $0x70, %rax, %rcx
movq -0x58(%rbp), %rdx
leaq (%rdx,%rcx), %rax
movq 0x20(%rdx,%rcx), %rdi
movq 0x48(%r13), %rbx
testb $0x10, 0x3d(%rdx,%rcx)
je 0x56f86
movq -0x50(%rbp), %rcx
cmpb $0x0, 0x51(%rcx)
je 0x570fc
testb $0x2, 0x46(%rdi)
jne 0x57003
cmpq $0x0, 0x18(%rdi)
jne 0x57003
movq -0x38(%rbp), %rcx
testb $0x10, 0x32(%rcx)
jne 0x57003
movl 0x28(%rbx), %r14d
movq -0x38(%rbp), %rcx
cmpb $0x0, 0x36(%rcx)
jne 0x56fcf
movl %r14d, %ecx
andl $0x40, %ecx
jne 0x56fcf
movl 0x44(%rax), %edx
movq %rdi, -0x40(%rbp)
movq %r12, %rdi
movl %esi, %r15d
pushq $0x3e
popq %rsi
callq 0x4b9b3
movq -0x40(%rbp), %rdi
movl %r15d, %esi
andl $0x4300, %r14d          # imm = 0x4300
cmpl $0x200, %r14d           # imm = 0x200
jne 0x57003
movl 0x8(%r13), %edx
movq -0x38(%rbp), %rax
cmpl 0x50(%rax), %edx
je 0x57003
movq %rdi, %r15
movq %r12, %rdi
movl %esi, %r14d
pushq $0x3e
popq %rsi
callq 0x4b9b3
movq %r15, %rdi
movl %r14d, %esi
movl 0x28(%rbx), %eax
testw $0x240, %ax             # imm = 0x240
je 0x57012
addq $0x20, %rbx
jmp 0x57020
btl $0xd, %eax
jae 0x57116
leaq 0x38(%r13), %rbx
movq (%rbx), %rax
movq %rax, -0x48(%rbp)
testq %rax, %rax
je 0x57116
movq -0x38(%rbp), %rax
cmpb $0x0, 0x36(%rax)
je 0x5704c
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
testb $0x20, 0x46(%rax)
je 0x57116
movq -0x50(%rbp), %rax
cmpb $0x0, 0x51(%rax)
jne 0x57116
movl 0x3c(%r12), %r14d
movl 0x20(%r13), %r15d
movq %rdi, -0x40(%rbp)
movq %r12, %rdi
movl %esi, -0x2c(%rbp)
movl %r15d, %esi
callq 0x386ca
movq -0x40(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq %rax, %rbx
addq $0x8, %rbx
cmpl %r14d, %r15d
jge 0x57116
movl -0x4(%rbx), %eax
cmpl 0x4(%r13), %eax
jne 0x570f3
movzbl -0x8(%rbx), %eax
cmpl $0x69, %eax
je 0x570e8
cmpl $0x30, %eax
jne 0x570f3
movl (%rbx), %eax
testb $0x20, 0x46(%rdi)
je 0x570c2
cltq
movq %rax, -0x68(%rbp)
callq 0x363b8
movq 0x8(%rax), %rax
movq -0x68(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
movswl %ax, %esi
movq -0x48(%rbp), %rdi
callq 0x4ca46
testw %ax, %ax
movl -0x2c(%rbp), %esi
movq -0x40(%rbp), %rdi
js 0x570f3
movzwl %ax, %eax
movl %eax, (%rbx)
movl 0x8(%r13), %eax
movl %eax, -0x4(%rbx)
jmp 0x570f3
movl 0x8(%r13), %eax
movl %eax, -0x4(%rbx)
movb $0x72, -0x8(%rbx)
incl %r15d
addq $0x18, %rbx
jmp 0x57083
movl 0x4(%r13), %edx
movl %esi, %ebx
movl 0x20(%r13), %esi
movl 0x38(%rax), %ecx
movq %r12, %rdi
xorl %r8d, %r8d
callq 0x5cc09
movl %ebx, %esi
incl %esi
addq $0x58, %r13
jmp 0x56f47
movq -0x38(%rbp), %rsi
movl 0x48(%rsi), %eax
movq -0x60(%rbp), %rcx
movl %eax, 0x1d4(%rcx)
movq -0x50(%rbp), %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x58c2c