// File: /workspace/github_c_makefile_star2_O2/ukontainer[P]sqlite-bench/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"));
  for(i=pWInfo->nLevel-1; i>=0; i--){
    int addr;
    pLevel = &pWInfo->a[i];
    pLoop = pLevel->pWLoop;
    if( pLevel->op!=OP_Noop ){
#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
      int addrSeek = 0;
      Index *pIdx;
      int n;
      if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
       && i==pWInfo->nLevel-1  /* Ticket [ef9318757b152e3] 2017-10-21 */
       && (pLoop->wsFlags & WHERE_INDEXED)!=0
       && (pIdx = pLoop->u.btree.pIndex)->hasStat1
       && (n = pLoop->u.btree.nIdxCol)>0
       && pIdx->aiRowLogEst[n]>=36
      ){
        int r1 = pParse->nMem+1;
        int j, op;
        for(j=0; j<n; j++){
          sqlite3VdbeAddOp3(v, OP_Column, pLevel->iIdxCur, j, r1+j);
        }
        pParse->nMem += n+1;
        op = pLevel->op==OP_Prev ? OP_SeekLT : OP_SeekGT;
        addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
        VdbeCoverageIf(v, op==OP_SeekLT);
        VdbeCoverageIf(v, op==OP_SeekGT);
        sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
      }
#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
      /* The common case: Advance to the next row */
      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
      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);
#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
      if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
#endif
    }else{
      sqlite3VdbeResolveLabel(v, pLevel->addrCont);
    }
    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);
        if( pIn->eEndLoopOp!=OP_Noop ){
          if( pIn->nPrefix ){
            assert( pLoop->wsFlags & WHERE_IN_EARLYOUT );
            sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur,
                              sqlite3VdbeCurrentAddr(v)+2,
                              pIn->iBase, pIn->nPrefix);
            VdbeCoverage(v);
          }
          sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
          VdbeCoverage(v);
          VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev);
          VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Next);
        }
        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 ){
      sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
                        pLevel->addrLikeRep);
      VdbeCoverage(v);
    }
#endif
    if( pLevel->iLeftJoin ){
      int ws = pLoop->wsFlags;
      addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
      assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
      if( (ws & WHERE_IDX_ONLY)==0 ){
        assert( pLevel->iTabCur==pTabList->a[pLevel->iFrom].iCursor );
        sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iTabCur);
      }
      if( (ws & WHERE_INDEXED) 
       || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx) 
      ){
        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 ){
      testcase( pParse->db->mallocFailed );
      translateColumnToCopy(pParse, pLevel->addrBody, pLevel->iTabCur,
                            pTabItem->regResult, 0);
      continue;
    }

    /* 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;
#ifdef SQLITE_DEBUG
      if( db->flags & SQLITE_VdbeAddopTrace ){
        printf("TRANSLATE opcodes in range %d..%d\n", k, last-1);
      }
#endif
      pOp = sqlite3VdbeGetOp(v, k);
      for(; k<last; k++, pOp++){
        if( pOp->p1!=pLevel->iTabCur ) continue;
        if( pOp->opcode==OP_Column
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
         || pOp->opcode==OP_Offset
#endif
        ){
          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;
            OpcodeRewriteTrace(db, k, pOp);
          }
          assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 
              || pWInfo->eOnePass );
        }else if( pOp->opcode==OP_Rowid ){
          pOp->p1 = pLevel->iIdxCur;
          pOp->opcode = OP_IdxRowid;
          OpcodeRewriteTrace(db, k, pOp);
        }else if( pOp->opcode==OP_IfNullRow ){
          pOp->p1 = pLevel->iIdxCur;
          OpcodeRewriteTrace(db, k, pOp);
        }
      }
#ifdef SQLITE_DEBUG
      if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n");
#endif
    }
  }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rcx
movq %rcx, 0x28(%rsp)
movq %rax, 0x20(%rsp)
movq 0x10(%rax), %r12
movzbl 0x42(%rdi), %eax
movq %rdi, (%rsp)
leaq 0x398(%rdi), %rbx
testq %rax, %rax
jle 0x456f92
leaq -0x1(%rax), %rcx
movq %rcx, 0x10(%rsp)
imulq $0x58, %rcx, %rcx
leaq (%rbx,%rcx), %r14
movq 0x48(%rbx,%rcx), %r15
cmpb $-0x55, 0x2d(%rbx,%rcx)
jne 0x456c9e
movq 0x18(%r12), %rax
movq 0x50(%rax), %rax
testq %rax, %rax
je 0x456dd7
movslq 0x18(%r14), %rcx
movl 0xb8(%r12), %edx
notq %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x456dd7
xorl %ebp, %ebp
movq (%rsp), %rcx
cmpb $0x2, 0x47(%rcx)
jne 0x456d6f
movzbl 0x42(%rcx), %ecx
cmpq %rcx, %rax
jne 0x456d6f
testb $0x2, 0x29(%r15)
je 0x456d6f
movq 0x20(%r15), %rax
testb $-0x80, 0x63(%rax)
je 0x456d6f
movzwl 0x1e(%r15), %r13d
testl %r13d, %r13d
je 0x456d6f
movq 0x10(%rax), %rax
movl %r13d, %ecx
cmpw $0x24, (%rax,%rcx,2)
jl 0x456d6f
movq %r15, 0x18(%rsp)
movq 0x20(%rsp), %rax
movl 0x38(%rax), %ebp
incl %ebp
xorl %r15d, %r15d
cmpl %r15d, %r13d
je 0x456d22
movl 0x8(%r14), %edx
leal (%r15,%rbp), %r8d
movq %r12, %rdi
pushq $0x5a
popq %rsi
movl %r15d, %ecx
callq 0x432a44
incl %r15d
jmp 0x456d02
movq 0x20(%rsp), %rcx
movl 0x38(%rcx), %eax
addl %r13d, %eax
incl %eax
movl %eax, 0x38(%rcx)
xorl %eax, %eax
cmpb $0x4, 0x2d(%r14)
setne %al
leal (%rax,%rax,2), %esi
addl $0x16, %esi
movl 0x8(%r14), %edx
movq %r12, %rdi
xorl %ecx, %ecx
movl %ebp, %r8d
movl %r13d, %r9d
callq 0x40c85b
movl %eax, %ebp
movl 0x34(%r14), %ecx
movq %r12, %rdi
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x432a3f
movq 0x18(%rsp), %r15
movq 0x18(%r12), %rax
movq 0x50(%rax), %rax
testq %rax, %rax
je 0x456d8f
movslq 0x18(%r14), %rcx
movl 0xb8(%r12), %edx
notq %rcx
movl %edx, (%rax,%rcx,4)
movzbl 0x2d(%r14), %esi
movl 0x30(%r14), %edx
movl 0x34(%r14), %ecx
movzbl 0x2e(%r14), %r8d
movq %r12, %rdi
callq 0x432a44
movslq 0xb8(%r12), %rax
testq %rax, %rax
jle 0x456dc9
movzbl 0x2f(%r14), %ecx
movq 0x68(%r12), %rdx
imulq $0x18, %rax, %rax
movw %cx, -0x16(%rdx,%rax)
testl %ebp, %ebp
je 0x456dd7
movq %r12, %rdi
movl %ebp, %esi
callq 0x4485a5
movq %r15, %r13
testb $0x8, 0x29(%r15)
je 0x456e94
movl 0x38(%r14), %ebp
testl %ebp, %ebp
jle 0x456e94
movq 0x18(%r12), %rax
movq 0x50(%rax), %rax
testq %rax, %rax
je 0x456e15
movslq 0x10(%r14), %rcx
movl 0xb8(%r12), %edx
notq %rcx
movl %edx, (%rax,%rcx,4)
movl 0x38(%r14), %ebp
movq 0x40(%r14), %rax
movslq %ebp, %rcx
imulq $0x14, %rcx, %rcx
leaq (%rax,%rcx), %r15
addq $-0x4, %r15
testl %ebp, %ebp
jle 0x456e94
movl -0xc(%r15), %esi
incl %esi
movq %r12, %rdi
callq 0x4485a5
movb (%r15), %al
cmpb $-0x55, %al
je 0x456e7e
movl -0x4(%r15), %r9d
testl %r9d, %r9d
je 0x456e6b
movl 0x8(%r14), %edx
movl 0xb8(%r12), %ecx
addl $0x2, %ecx
movl -0x8(%r15), %r8d
movq %r12, %rdi
pushq $0x1a
popq %rsi
callq 0x40c85b
movb (%r15), %al
movzbl %al, %esi
movl -0x10(%r15), %edx
movl -0xc(%r15), %ecx
movq %r12, %rdi
callq 0x432a3f
movl -0xc(%r15), %esi
decl %esi
movq %r12, %rdi
callq 0x4485a5
decl %ebp
addq $-0x14, %r15
jmp 0x456e28
movq 0x18(%r12), %rax
movq 0x50(%rax), %rax
testq %rax, %rax
je 0x456eb4
movslq 0xc(%r14), %rcx
movl 0xb8(%r12), %edx
notq %rcx
movl %edx, (%rax,%rcx,4)
movl 0x14(%r14), %esi
testl %esi, %esi
je 0x456edf
movq %r12, %rdi
callq 0x44863d
movl 0x14(%r14), %esi
movq %r12, %rdi
callq 0x4485a5
movl 0x14(%r14), %esi
addl $-0x2, %esi
movq %r12, %rdi
callq 0x4485a5
movl 0x28(%r14), %ecx
testl %ecx, %ecx
je 0x456ef8
movl 0x24(%r14), %edx
shrl %edx
movq %r12, %rdi
pushq $0x31
popq %rsi
callq 0x432a3f
movl (%r14), %edx
movq 0x10(%rsp), %rax
testl %edx, %edx
je 0x456c4f
movl 0x28(%r13), %r15d
movq %r12, %rdi
pushq $0x2f
popq %rsi
callq 0x449fcc
movl %eax, %ebp
testb $0x40, %r15b
jne 0x456f30
movl 0x4(%r14), %edx
movq %r12, %rdi
movl $0x82, %esi
callq 0x449fcc
btl $0x9, %r15d
jb 0x456f45
btl $0xd, %r15d
jae 0x456f56
cmpq $0x0, 0x38(%r14)
je 0x456f56
movl 0x8(%r14), %edx
movq %r12, %rdi
movl $0x82, %esi
callq 0x449fcc
cmpb $0x42, 0x2d(%r14)
jne 0x456f72
movl 0x1c(%r14), %ecx
movl 0x30(%r14), %edx
movq %r12, %rdi
pushq $0xc
popq %rsi
callq 0x432a3f
jmp 0x456f7e
movl 0x1c(%r14), %esi
movq %r12, %rdi
callq 0x44863d
movq %r12, %rdi
movl %ebp, %esi
callq 0x4485a5
movq 0x10(%rsp), %rax
jmp 0x456c4f
movq 0x18(%r12), %rax
movq 0x50(%rax), %rax
testq %rax, %rax
je 0x456fb6
movq (%rsp), %rcx
movslq 0x38(%rcx), %rcx
movl 0xb8(%r12), %edx
notq %rcx
movl %edx, (%rax,%rcx,4)
movq 0x8(%rsp), %rdx
addq $0x8, %rdx
xorl %r15d, %r15d
movq (%rsp), %rsi
movq %rdx, 0x8(%rsp)
movzbl 0x42(%rsi), %eax
cmpl %eax, %r15d
jae 0x457122
movzbl 0x2c(%rbx), %eax
imulq $0x70, %rax, %rax
testb $0x10, 0x3d(%rdx,%rax)
jne 0x457000
movq 0x20(%rdx,%rax), %rdi
movq 0x48(%rbx), %rax
movl 0x28(%rax), %ecx
testw $0x240, %cx             # imm = 0x240
je 0x457024
addq $0x20, %rax
jmp 0x45702e
addq %rdx, %rax
movl 0x4(%rbx), %edx
movl 0x20(%rbx), %esi
movl 0x38(%rax), %ecx
movq 0x20(%rsp), %rdi
xorl %r8d, %r8d
callq 0x45db6b
movq 0x8(%rsp), %rdx
movq (%rsp), %rsi
jmp 0x45705b
btl $0xd, %ecx
jae 0x45705b
leaq 0x38(%rbx), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x45705b
cmpb $0x0, 0x45(%rsi)
je 0x457050
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
testb $0x20, 0x40(%rax)
je 0x45705b
movq 0x28(%rsp), %rax
cmpb $0x0, 0x61(%rax)
je 0x457067
incl %r15d
addq $0x58, %rbx
jmp 0x456fcb
movl 0xb8(%r12), %r13d
movl 0x20(%rbx), %ebp
movq %rdi, 0x18(%rsp)
movq %r12, %rdi
movl %ebp, %esi
callq 0x44864c
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rdx
movq (%rsp), %rsi
movq %rax, %r14
addq $0x8, %r14
cmpl %r13d, %ebp
jge 0x45705b
movl -0x4(%r14), %eax
cmpl 0x4(%rbx), %eax
jne 0x457117
movzbl -0x8(%r14), %eax
cmpl $0x15, %eax
je 0x457102
cmpl $0x81, %eax
je 0x45710b
cmpl $0x5a, %eax
jne 0x457117
movl (%r14), %eax
testb $0x20, 0x40(%rdi)
je 0x4570dc
cltq
movq %rax, 0x30(%rsp)
callq 0x40f0e7
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
movswl %ax, %esi
movq 0x10(%rsp), %rdi
callq 0x44b4cd
testw %ax, %ax
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x18(%rsp), %rdi
js 0x457117
movzwl %ax, %eax
movl %eax, (%r14)
movl 0x8(%rbx), %eax
movl %eax, -0x4(%r14)
jmp 0x457117
movl 0x8(%rbx), %eax
movl %eax, -0x4(%r14)
movb $-0x78, -0x8(%r14)
incl %ebp
addq $0x18, %r14
jmp 0x457096
movl 0x3c(%rsi), %eax
movq 0x20(%rsp), %rcx
movl %eax, 0xb4(%rcx)
movq 0x28(%rsp), %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x458f75