// File: /workspace/github_c_makefile_star2_O1/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), %rax
movq %rax, -0x48(%rbp)
movq (%rdi), %rax
movq %rax, -0x40(%rbp)
movq 0x10(%rdi), %r12
movq %rdi, -0x50(%rbp)
callq 0x60980
movq %rbx, -0x30(%rbp)
movzbl 0x39(%rbx), %ecx
testq %rcx, %rcx
je 0x60624
movq -0x30(%rbp), %rax
addq $0x340, %rax            # imm = 0x340
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x58(%rbp)
leaq 0x35221(%rip), %r14     # 0x954e8
movq %rcx, -0x70(%rbp)
leaq -0x1(%rcx), %r15
imulq $0x58, %r15, %rax
movq -0x60(%rbp), %rcx
leaq (%rcx,%rax), %rbx
movq 0x48(%rcx,%rax), %r13
movq 0x30(%r12), %rax
movq 0x80(%rax), %rcx
testq %rcx, %rcx
je 0x60300
movslq 0x18(%rbx), %rdx
movl 0x3c(%r12), %esi
notq %rdx
movl %esi, (%rcx,%rdx,4)
movl 0x3c(%r12), %ecx
decl %ecx
movl %ecx, 0x68(%rax)
movzbl 0x2d(%rbx), %esi
cmpl $0xa1, %esi
je 0x60352
movl 0x30(%rbx), %edx
movl 0x34(%rbx), %ecx
movzbl 0x2e(%rbx), %r8d
movq %r12, %rdi
callq 0x3fa9e
movq (%r12), %rax
cmpb $0x0, 0x51(%rax)
movq %r14, %rax
jne 0x6034c
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)
movq %r15, -0x68(%rbp)
movq %r13, -0x38(%rbp)
testb $0x8, 0x29(%r13)
je 0x60458
cmpl $0x0, 0x38(%rbx)
jle 0x60458
movq 0x30(%r12), %rax
movq 0x80(%rax), %rcx
testq %rcx, %rcx
je 0x6038f
movslq 0x10(%rbx), %rdx
movl 0x3c(%r12), %esi
notq %rdx
movl %esi, (%rcx,%rdx,4)
movl 0x3c(%r12), %ecx
decl %ecx
movl %ecx, 0x68(%rax)
movslq 0x38(%rbx), %rax
testq %rax, %rax
jle 0x60458
movq 0x40(%rbx), %rcx
leaq (%rax,%rax,2), %rdx
leaq (%rcx,%rdx,4), %r13
addq $-0x4, %r13
leal 0x1(%rax), %r15d
movl -0x4(%r13), %ecx
movl 0x3c(%r12), %eax
leal -0x1(%rax), %edx
movq 0x30(%r12), %rsi
movl %edx, 0x68(%rsi)
movq (%r12), %rsi
cmpb $0x0, 0x51(%rsi)
movq %r14, %rsi
jne 0x603f4
leal 0x1(%rcx), %esi
cmpl $-0x1, %ecx
cmovll %edx, %esi
movslq %esi, %rdx
leaq (%rdx,%rdx,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r12), %rsi
movl %eax, 0x8(%rsi)
movzbl (%r13), %esi
movl -0x8(%r13), %edx
movq %r12, %rdi
xorl %r8d, %r8d
callq 0x3fa9e
movl -0x4(%r13), %ecx
movl 0x3c(%r12), %eax
leal -0x1(%rax), %edx
movq 0x30(%r12), %rsi
movl %edx, 0x68(%rsi)
movq (%r12), %rsi
cmpb $0x0, 0x51(%rsi)
movq %r14, %rsi
jne 0x60444
leal -0x1(%rcx), %esi
testl %ecx, %ecx
cmovlel %edx, %esi
movslq %esi, %rcx
leaq (%rcx,%rcx,2), %rsi
shlq $0x3, %rsi
addq 0x8(%r12), %rsi
movl %eax, 0x8(%rsi)
addq $-0xc, %r13
decl %r15d
cmpl $0x1, %r15d
jg 0x603ba
movq 0x30(%r12), %rax
movq 0x80(%rax), %rcx
testq %rcx, %rcx
je 0x60478
movslq 0xc(%rbx), %rdx
movl 0x3c(%r12), %esi
notq %rdx
movl %esi, (%rcx,%rdx,4)
movl 0x3c(%r12), %ecx
decl %ecx
movl %ecx, 0x68(%rax)
movl 0x14(%rbx), %ecx
testl %ecx, %ecx
movq -0x68(%rbp), %r15
je 0x60501
movq %r12, %rdi
movl $0xe, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x3fa9e
movl 0x14(%rbx), %edx
movl 0x3c(%r12), %eax
leal -0x1(%rax), %ecx
movq 0x30(%r12), %rsi
movl %ecx, 0x68(%rsi)
movq (%r12), %rdi
cmpb $0x0, 0x51(%rdi)
je 0x604ca
movl %eax, 0x3502e(%rip)     # 0x954f0
movl %ecx, 0x68(%rsi)
movq %r14, %rcx
jmp 0x604fe
testl %edx, %edx
movl %edx, %edi
cmovsl %ecx, %edi
movq 0x8(%r12), %r8
movslq %edi, %rdi
leaq (%rdi,%rdi,2), %rdi
movl %eax, 0x8(%r8,%rdi,8)
movl %ecx, 0x68(%rsi)
leal -0x2(%rdx), %esi
cmpl $0x2, %edx
cmovll %ecx, %esi
movslq %esi, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%r12), %rcx
movl %eax, 0x8(%rcx)
movl 0x28(%rbx), %ecx
testl %ecx, %ecx
je 0x6054e
movl %ecx, %eax
jg 0x60511
movl 0x3c(%r12), %eax
movq (%r12), %rdx
cmpb $0x0, 0x51(%rdx)
movq %r14, %rdx
jne 0x60531
movq 0x8(%r12), %rdx
cltq
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rdx
addq $-0x18, %rdx
cmpl $0x1, 0x4(%rdx)
movl $0x0, %esi
adcl $0x8e, %esi
movl 0x24(%rbx), %edx
movq %r12, %rdi
xorl %r8d, %r8d
callq 0x3fa9e
movl (%rbx), %edx
testl %edx, %edx
je 0x60616
movq %r12, %rdi
movl $0x8b, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl %eax, %r13d
movq -0x38(%rbp), %rax
testb $0x40, 0x28(%rax)
jne 0x60595
imulq $0x70, %r15, %rax
movq -0x58(%rbp), %rcx
movl 0x44(%rcx,%rax), %edx
movq %r12, %rdi
movl $0x6a, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movq -0x38(%rbp), %rax
testb $0x2, 0x29(%rax)
je 0x605b4
movl 0x8(%rbx), %edx
movq %r12, %rdi
movl $0x6a, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
cmpb $0x10, 0x2d(%rbx)
jne 0x605ca
movl 0x1c(%rbx), %ecx
movl 0x30(%rbx), %edx
movq %r12, %rdi
movl $0xf, %esi
jmp 0x605d7
movl 0x1c(%rbx), %ecx
movq %r12, %rdi
movl $0xe, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x3fa9e
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 0x60613
testl %r13d, %r13d
cmovnsl %r13d, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%r12), %rdx
movl %eax, 0x8(%rdx)
cmpq $0x1, -0x70(%rbp)
movq %r15, %rcx
jg 0x602c7
movq 0x30(%r12), %rax
movq 0x80(%rax), %rcx
testq %rcx, %rcx
movq -0x30(%rbp), %rdi
je 0x60648
movslq 0x44(%rdi), %rdx
movl 0x3c(%r12), %esi
notq %rdx
movl %esi, (%rcx,%rdx,4)
movl 0x3c(%r12), %ecx
decl %ecx
movl %ecx, 0x68(%rax)
cmpb $0x0, 0x39(%rdi)
movq %rdi, %rsi
je 0x6087a
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 0x6069c
movq -0x40(%rbp), %rcx
cmpb $0x0, 0x51(%rcx)
je 0x6072b
testb $0x2, 0x46(%r13)
jne 0x60710
cmpq $0x0, 0x18(%r13)
jne 0x60710
movq -0x30(%rbp), %rcx
testb $0x10, 0x32(%rcx)
jne 0x60710
movl 0x28(%r15), %edx
movq -0x30(%rbp), %rcx
cmpb $0x0, 0x36(%rcx)
jne 0x606e4
movl %edx, %ecx
andl $0x40, %ecx
jne 0x606e4
movl %edx, -0x38(%rbp)
movl 0x44(%rax), %edx
movq %r12, %rdi
movl $0x3e, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl -0x38(%rbp), %edx
andl $0x4300, %edx           # imm = 0x4300
cmpl $0x200, %edx            # imm = 0x200
jne 0x60710
movl 0x8(%rbx), %edx
movq -0x30(%rbp), %rax
cmpl 0x50(%rax), %edx
je 0x60710
movq %r12, %rdi
movl $0x3e, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl 0x28(%r15), %eax
testl $0x240, %eax            # imm = 0x240
je 0x60721
addq $0x20, %r15
jmp 0x60748
btl $0xd, %eax
jb 0x60744
xorl %eax, %eax
jmp 0x6074b
movl 0x4(%rbx), %edx
movl 0x20(%rbx), %esi
movl 0x38(%rax), %ecx
movq %r12, %rdi
xorl %r8d, %r8d
callq 0x69d85
jmp 0x60862
leaq 0x38(%rbx), %r15
movq (%r15), %rax
testq %rax, %rax
je 0x60862
movq -0x30(%rbp), %rcx
cmpb $0x0, 0x36(%rcx)
je 0x6076c
movq 0x18(%rax), %rcx
testb $0x20, 0x46(%rcx)
je 0x60862
movq -0x40(%rbp), %rcx
cmpb $0x0, 0x51(%rcx)
jne 0x60862
movl 0x3c(%r12), %ecx
movl 0x20(%rbx), %edx
movq (%r12), %rsi
cmpb $0x0, 0x51(%rsi)
leaq 0x34d57(%rip), %rsi     # 0x954e8
jne 0x607ab
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 0x60862
movl 0x4(%rbx), %edi
cmpl %edi, 0x4(%rsi)
jne 0x60854
movzbl (%rsi), %r8d
cmpl $0x69, %r8d
je 0x607fb
cmpl $0x30, %r8d
jne 0x60854
movl 0x8(%rsi), %r8d
testb $0x20, 0x46(%r13)
je 0x60814
movq 0x10(%r13), %r9
testq %r9, %r9
je 0x60808
movb 0x63(%r9), %r10b
andb $0x3, %r10b
cmpb $0x2, %r10b
je 0x60808
movq 0x28(%r9), %r9
jmp 0x607e2
movl 0x8(%rbx), %r8d
movl %r8d, 0x4(%rsi)
movb $0x72, (%rsi)
jmp 0x60854
movslq %r8d, %r8
movq 0x8(%r9), %r9
movzwl (%r9,%r8,2), %r8d
movzwl 0x60(%rax), %r10d
movw $0xffff, %r9w           # imm = 0xFFFF
testq %r10, %r10
je 0x6083e
movq 0x8(%rax), %r15
xorl %r11d, %r11d
cmpw %r8w, (%r15,%r11,2)
je 0x6083b
incq %r11
cmpq %r11, %r10
jne 0x6082a
jmp 0x6083e
movl %r11d, %r9d
testw %r9w, %r9w
js 0x60854
movzwl %r9w, %r8d
movl %r8d, 0x8(%rsi)
movl 0x8(%rbx), %r8d
movl %r8d, 0x4(%rsi)
incl %edx
addq $0x18, %rsi
cmpl %ecx, %edx
jne 0x607b6
incl %r14d
addq $0x58, %rbx
movq -0x30(%rbp), %rsi
movzbl 0x39(%rsi), %eax
cmpl %eax, %r14d
jb 0x6066e
movl 0x48(%rsi), %eax
movq -0x50(%rbp), %rcx
movl %eax, 0x1d4(%rcx)
movq -0x40(%rbp), %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x654a6