// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %rdi, %rbx
movq (%rdi), %rdi
movq 0x8(%rbx), %rax
movq %rax, -0x48(%rbp)
movq (%rdi), %rax
movq %rax, -0x40(%rbp)
movq 0x10(%rdi), %r12
movq %rdi, -0x60(%rbp)
callq 0x5f3a9
movq %rbx, -0x30(%rbp)
movzbl 0x39(%rbx), %r15d
testq %r15, %r15
je 0x5f05b
movq -0x30(%rbp), %rax
addq $0x340, %rax            # imm = 0x340
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x68(%rbp)
leaq 0x347f7(%rip), %r14     # 0x934f8
leaq -0x1(%r15), %rax
movq %rax, -0x38(%rbp)
imulq $0x58, %rax, %rax
movq -0x70(%rbp), %rcx
leaq (%rcx,%rax), %rbx
movq 0x48(%rcx,%rax), %r13
movq 0x30(%r12), %rax
movq 0x80(%rax), %rdx
testq %rdx, %rdx
je 0x5ed3c
movslq 0x18(%rbx), %rsi
movl 0x3c(%r12), %ecx
notq %rsi
movl %ecx, (%rdx,%rsi,4)
jmp 0x5ed41
movl 0x3c(%r12), %ecx
decl %ecx
movl %ecx, 0x68(%rax)
movzbl 0x2d(%rbx), %esi
cmpl $0xa1, %esi
je 0x5ed8e
movl 0x30(%rbx), %edx
movl 0x34(%rbx), %ecx
movzbl 0x2e(%rbx), %r8d
movq %r12, %rdi
callq 0x3ea9f
movq (%r12), %rax
cmpb $0x0, 0x51(%rax)
movq %r14, %rax
jne 0x5ed88
movslq 0x3c(%r12), %rax
movq 0x8(%r12), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
addq $-0x18, %rax
movb 0x2f(%rbx), %cl
movb %cl, 0x3(%rax)
testb $0x8, 0x29(%r13)
movq %r15, -0x58(%rbp)
movq %r13, -0x78(%rbp)
jne 0x5eda7
movq 0x30(%r12), %rax
jmp 0x5ee9b
cmpl $0x0, 0x38(%rbx)
movq 0x30(%r12), %rax
jle 0x5ee9b
movq 0x80(%rax), %rcx
testq %rcx, %rcx
je 0x5edd3
movslq 0x10(%rbx), %rsi
movl 0x3c(%r12), %edx
notq %rsi
movl %edx, (%rcx,%rsi,4)
jmp 0x5edd8
movl 0x3c(%r12), %edx
leal -0x1(%rdx), %ecx
movl %ecx, 0x68(%rax)
movslq 0x38(%rbx), %rcx
testq %rcx, %rcx
jle 0x5ee9b
movq 0x40(%rbx), %rdi
movq (%r12), %rsi
movb 0x51(%rsi), %sil
leaq (%rcx,%rcx,2), %r8
leaq (%rdi,%r8,4), %r13
addq $-0x4, %r13
leal 0x1(%rcx), %r15d
movl -0x4(%r13), %ecx
leal -0x1(%rdx), %edi
movl %edi, 0x68(%rax)
movq %r14, %rax
testb %sil, %sil
jne 0x5ee31
leal 0x1(%rcx), %eax
cmpl $-0x1, %ecx
cmovll %edi, %eax
cltq
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq 0x8(%r12), %rax
movl %edx, 0x8(%rax)
movzbl (%r13), %esi
movl -0x8(%r13), %edx
movq %r12, %rdi
xorl %r8d, %r8d
callq 0x3ea9f
movl -0x4(%r13), %ecx
movl 0x3c(%r12), %edx
leal -0x1(%rdx), %edi
movq 0x30(%r12), %rax
movl %edi, 0x68(%rax)
movq (%r12), %rsi
movb 0x51(%rsi), %sil
movq %r14, %r8
testb %sil, %sil
jne 0x5ee86
leal -0x1(%rcx), %r8d
testl %ecx, %ecx
cmovlel %edi, %r8d
movslq %r8d, %rcx
leaq (%rcx,%rcx,2), %r8
shlq $0x3, %r8
addq 0x8(%r12), %r8
movl %edx, 0x8(%r8)
addq $-0xc, %r13
decl %r15d
cmpl $0x1, %r15d
jg 0x5ee07
movq 0x80(%rax), %rcx
testq %rcx, %rcx
je 0x5eeb8
movslq 0xc(%rbx), %rsi
movl 0x3c(%r12), %edx
notq %rsi
movl %edx, (%rcx,%rsi,4)
jmp 0x5eebd
movl 0x3c(%r12), %edx
movq -0x58(%rbp), %r13
leal -0x1(%rdx), %ecx
movl %ecx, 0x68(%rax)
movl 0x14(%rbx), %ecx
testl %ecx, %ecx
je 0x5ef37
movq %r12, %rdi
movl $0xe, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x3ea9f
movl 0x3c(%r12), %edx
leal -0x1(%rdx), %eax
movq (%r12), %rsi
movq 0x30(%r12), %rcx
cmpb $0x0, 0x51(%rsi)
je 0x5ef02
movl %edx, 0x34603(%rip)     # 0x93500
movq %r14, %rsi
jmp 0x5ef31
movl 0x14(%rbx), %esi
testl %esi, %esi
movl %esi, %edi
cmovsl %eax, %edi
movq 0x8(%r12), %r8
movslq %edi, %rdi
leaq (%rdi,%rdi,2), %rdi
cmpl $0x2, %esi
leal -0x2(%rsi), %esi
cmovll %eax, %esi
movl %edx, 0x8(%r8,%rdi,8)
movslq %esi, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%r8,%rsi,8), %rsi
movl %eax, 0x68(%rcx)
movl %edx, 0x8(%rsi)
movl 0x28(%rbx), %ecx
testl %ecx, %ecx
je 0x5ef81
movq (%r12), %rax
cmpb $0x0, 0x51(%rax)
movq %r14, %rax
jne 0x5ef64
testl %ecx, %ecx
cmovgl %ecx, %edx
movq 0x8(%r12), %rax
movslq %edx, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rax
addq $-0x18, %rax
cmpl $0x1, 0x4(%rax)
movl $0x0, %esi
adcl $0x8e, %esi
movl 0x24(%rbx), %edx
movq %r12, %rdi
xorl %r8d, %r8d
callq 0x3ea9f
movl (%rbx), %edx
testl %edx, %edx
je 0x5f04d
movq %r12, %rdi
movl $0x8b, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl %eax, -0x4c(%rbp)
movq -0x78(%rbp), %r15
movl 0x28(%r15), %eax
testb $0x40, %al
jne 0x5efcf
imulq $0x70, -0x38(%rbp), %rax
movq -0x68(%rbp), %rcx
movl 0x44(%rcx,%rax), %edx
movq %r12, %rdi
movl $0x6a, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl 0x28(%r15), %eax
btl $0x9, %eax
jae 0x5efea
movl 0x8(%rbx), %edx
movq %r12, %rdi
movl $0x6a, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
cmpb $0x10, 0x2d(%rbx)
jne 0x5f000
movl 0x1c(%rbx), %ecx
movl 0x30(%rbx), %edx
movq %r12, %rdi
movl $0xf, %esi
jmp 0x5f00d
movl 0x1c(%rbx), %ecx
movq %r12, %rdi
movl $0xe, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x3ea9f
movl 0x3c(%r12), %eax
leal -0x1(%rax), %ecx
movq 0x30(%r12), %rdx
movl %ecx, 0x68(%rdx)
movq (%r12), %rdx
cmpb $0x0, 0x51(%rdx)
movq %r14, %rdx
jne 0x5f04a
movl -0x4c(%rbp), %edx
testl %edx, %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%r12), %rdx
movl %eax, 0x8(%rdx)
cmpq $0x1, %r13
movq -0x38(%rbp), %r15
jg 0x5ed01
movq 0x30(%r12), %rax
movq 0x80(%rax), %rdx
testq %rdx, %rdx
je 0x5f081
movq -0x30(%rbp), %rdi
movslq 0x44(%rdi), %rsi
movl 0x3c(%r12), %ecx
notq %rsi
movl %ecx, (%rdx,%rsi,4)
jmp 0x5f08a
movl 0x3c(%r12), %ecx
movq -0x30(%rbp), %rdi
decl %ecx
movl %ecx, 0x68(%rax)
cmpb $0x0, 0x39(%rdi)
movq %rdi, %rsi
je 0x5f2a2
leaq 0x340(%rsi), %rbx
addq $0x8, -0x48(%rbp)
xorl %r14d, %r14d
movzbl 0x2c(%rbx), %eax
imulq $0x70, %rax, %rcx
movq -0x48(%rbp), %rdx
leaq (%rdx,%rcx), %rax
movq 0x20(%rdx,%rcx), %r13
movq 0x48(%rbx), %r15
testb $0x10, 0x3d(%rdx,%rcx)
je 0x5f0d9
movq -0x40(%rbp), %rcx
cmpb $0x0, 0x51(%rcx)
je 0x5f276
testb $0x2, 0x46(%r13)
jne 0x5f14d
cmpq $0x0, 0x18(%r13)
jne 0x5f14d
movq -0x30(%rbp), %rcx
testb $0x10, 0x32(%rcx)
jne 0x5f14d
movl 0x28(%r15), %edx
movq -0x30(%rbp), %rcx
cmpb $0x0, 0x36(%rcx)
jne 0x5f121
movl %edx, %ecx
andl $0x40, %ecx
jne 0x5f121
movl %edx, -0x38(%rbp)
movl 0x44(%rax), %edx
movq %r12, %rdi
movl $0x3e, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl -0x38(%rbp), %edx
andl $0x4300, %edx           # imm = 0x4300
cmpl $0x200, %edx            # imm = 0x200
jne 0x5f14d
movl 0x8(%rbx), %edx
movq -0x30(%rbp), %rax
cmpl 0x50(%rax), %edx
je 0x5f14d
movq %r12, %rdi
movl $0x3e, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl 0x28(%r15), %eax
testl $0x240, %eax            # imm = 0x240
je 0x5f15e
addq $0x20, %r15
jmp 0x5f16c
btl $0xd, %eax
jae 0x5f28a
leaq 0x38(%rbx), %r15
movq (%r15), %rax
testq %rax, %rax
je 0x5f28a
movq -0x30(%rbp), %rcx
cmpb $0x0, 0x36(%rcx)
je 0x5f190
movq 0x18(%rax), %rcx
testb $0x20, 0x46(%rcx)
je 0x5f28a
movq -0x40(%rbp), %rcx
cmpb $0x0, 0x51(%rcx)
jne 0x5f28a
movl 0x3c(%r12), %ecx
movl 0x20(%rbx), %edx
movq (%r12), %rsi
cmpb $0x0, 0x51(%rsi)
leaq 0x34343(%rip), %rsi     # 0x934f8
jne 0x5f1cf
leal -0x1(%rcx), %esi
testl %edx, %edx
cmovnsl %edx, %esi
movslq %esi, %rsi
leaq (%rsi,%rsi,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r12), %rsi
cmpl %ecx, %edx
jge 0x5f28a
movl 0x4(%rbx), %edi
leaq 0x10(%r13), %r8
cmpl %edi, 0x4(%rsi)
jne 0x5f24f
movzbl (%rsi), %r9d
cmpl $0x69, %r9d
je 0x5f244
cmpl $0x30, %r9d
jne 0x5f24f
movl 0x8(%rsi), %r9d
testb $0x20, 0x46(%r13)
je 0x5f222
movslq %r9d, %r9
movq %r8, %r11
movq (%r11), %r10
movb 0x63(%r10), %r15b
andb $0x3, %r15b
leaq 0x28(%r10), %r11
cmpb $0x2, %r15b
jne 0x5f204
movq 0x8(%r10), %r10
movzwl (%r10,%r9,2), %r9d
movzwl 0x60(%rax), %r11d
testq %r11, %r11
je 0x5f24f
movq 0x8(%rax), %r15
xorl %r10d, %r10d
cmpw %r9w, (%r15,%r10,2)
je 0x5f25b
incq %r10
cmpq %r10, %r11
jne 0x5f233
jmp 0x5f24f
movl 0x8(%rbx), %r9d
movl %r9d, 0x4(%rsi)
movb $0x72, (%rsi)
incl %edx
addq $0x18, %rsi
cmpl %ecx, %edx
jne 0x5f1de
jmp 0x5f28a
testw %r10w, %r10w
js 0x5f24f
andl $0x7fff, %r10d          # imm = 0x7FFF
movl %r10d, 0x8(%rsi)
movl 0x8(%rbx), %r9d
movl %r9d, 0x4(%rsi)
jmp 0x5f24f
movl 0x4(%rbx), %edx
movl 0x20(%rbx), %esi
movl 0x38(%rax), %ecx
movq %r12, %rdi
xorl %r8d, %r8d
callq 0x687d7
incl %r14d
addq $0x58, %rbx
movq -0x30(%rbp), %rsi
movzbl 0x39(%rsi), %eax
cmpl %eax, %r14d
jb 0x5f0ab
movl 0x48(%rsi), %eax
movq -0x60(%rbp), %rcx
movl %eax, 0x1d4(%rcx)
movq -0x40(%rbp), %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x63f6e