// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/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.
  */
  sqlite3ExprCacheClear(pParse);
  for(i=pWInfo->nLevel-1; i>=0; i--){
    pLevel = &pWInfo->a[i];
    pLoop = pLevel->pWLoop;
    sqlite3VdbeResolveLabel(v, pLevel->addrCont);
    if( pLevel->op!=OP_Noop ){
      sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
      sqlite3VdbeChangeP5(v, pLevel->p5);
    }
    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);
        sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
      }
      sqlite3DbFree(db, pLevel->u.in.aInLoop);
    }
    sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
    if( pLevel->iLeftJoin ){
      int addr;
      addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
      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{
        sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrFirst);
      }
      sqlite3VdbeJumpHere(v, addr);
    }
  }

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

  /* Close all of the cursors that were opened by sqlite3WhereBegin.
  */
  assert( pWInfo->nLevel<=pTabList->nSrc );
  for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
    Index *pIdx = 0;
    struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
    Table *pTab = pTabItem->pTab;
    assert( pTab!=0 );
    pLoop = pLevel->pWLoop;
    if( (pTab->tabFlags & TF_Ephemeral)==0
     && pTab->pSelect==0
     && (pWInfo->wctrlFlags & WHERE_OMIT_OPEN_CLOSE)==0
    ){
      int ws = pLoop->wsFlags;
      if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){
        sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
      }
      if( (ws & WHERE_INDEXED)!=0 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 ){
        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 && !db->mallocFailed ){
      int k, j, last;
      VdbeOp *pOp;

      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 ){
          for(j=0; j<pIdx->nColumn; j++){
            if( pOp->p2==pIdx->aiColumn[j] ){
              pOp->p2 = j;
              pOp->p1 = pLevel->iIdxCur;
              break;
            }
          }
          assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || j<pIdx->nColumn );
        }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
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6f480
movq -0x8(%rbp), %rax
movzbl 0x38(%rax), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x6f098
movq -0x8(%rbp), %rax
addq $0x338, %rax            # imm = 0x338
movslq -0x1c(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x14(%rax), %esi
callq 0x677f0
movq -0x28(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x95, %eax
je 0x6eee2
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x21(%rax), %esi
movq -0x28(%rbp), %rax
movl 0x24(%rax), %edx
movq -0x28(%rbp), %rax
movl 0x28(%rax), %ecx
callq 0x5e0c0
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x22(%rax), %esi
callq 0x5e540
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x6efad
movq -0x28(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jle 0x6efad
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x677f0
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x4c(%rbp)
jle 0x6ef9c
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rax
movl 0x4(%rax), %esi
addl $0x1, %esi
callq 0x5e090
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rax
movzbl 0x8(%rax), %esi
movq -0x48(%rbp), %rax
movl (%rax), %edx
movq -0x48(%rbp), %rax
movl 0x4(%rax), %ecx
callq 0x5e0c0
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rax
movl 0x4(%rax), %esi
subl $0x1, %esi
callq 0x5e090
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rax
addq $-0xc, %rax
movq %rax, -0x48(%rbp)
jmp 0x6ef3b
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x9cd0
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x677f0
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x6f088
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl (%rax), %edx
movl $0x7e, %esi
callq 0x5ecf0
movl %eax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x6f014
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
addq $0x8, %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movl 0x3c(%rax), %edx
movl $0x61, %esi
callq 0x5ecf0
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x6f03a
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
movl $0x61, %esi
callq 0x5ecf0
movq -0x28(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x10, %eax
jne 0x6f065
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x24(%rax), %edx
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
movl $0xf, %esi
callq 0x5e0c0
jmp 0x6f07c
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
movl $0xe, %esi
xorl %edx, %edx
callq 0x5e0c0
movq -0x18(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0x5e090
jmp 0x6f08a
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6ee64
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x44(%rax), %esi
callq 0x677f0
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
addq $0x338, %rax            # imm = 0x338
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl 0x38(%rcx), %ecx
cmpl %ecx, %eax
jge 0x6f2fd
movq $0x0, -0x58(%rbp)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq -0x28(%rbp), %rcx
movzbl 0x20(%rcx), %ecx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x68(%rbp), %rax
movzbl 0x46(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x6f19f
movq -0x68(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x6f19f
movq -0x8(%rbp), %rax
movzwl 0x32(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x6f19f
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x6c(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x35(%rax)
jne 0x6f16e
movl -0x6c(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x6f16e
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rax
movl 0x3c(%rax), %edx
movl $0x36, %esi
callq 0x5ecf0
movl -0x6c(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x6f19d
movl -0x6c(%rbp), %eax
andl $0x4100, %eax           # imm = 0x4100
cmpl $0x0, %eax
jne 0x6f19d
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
movl $0x36, %esi
callq 0x5ecf0
jmp 0x6f19f
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x240, %eax            # imm = 0x240
cmpl $0x0, %eax
je 0x6f1be
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x6f1dd
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x6f1db
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x6f1dd
cmpq $0x0, -0x58(%rbp)
je 0x6f2e1
movq -0x40(%rbp), %rax
cmpb $0x0, 0x50(%rax)
jne 0x6f2e1
movq -0x18(%rbp), %rdi
callq 0x5e520
movl %eax, -0x78(%rbp)
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x18(%rbp), %rdi
movl -0x70(%rbp), %esi
callq 0x6dad0
movq %rax, -0x80(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x78(%rbp), %eax
jge 0x6f2df
movq -0x80(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x6f23d
jmp 0x6f2c5
movq -0x80(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x29, %eax
jne 0x6f2a0
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x58(%rbp), %rcx
movzwl 0x54(%rcx), %ecx
cmpl %ecx, %eax
jge 0x6f29e
movq -0x80(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x58(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x74(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x6f291
movl -0x74(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x6f29e
jmp 0x6f293
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x6f250
jmp 0x6f2c3
movq -0x80(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x60, %eax
jne 0x6f2c1
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x80(%rbp), %rax
movb $0x69, (%rax)
jmp 0x6f2c3
jmp 0x6f2c5
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movq -0x80(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x80(%rbp)
jmp 0x6f21c
jmp 0x6f2e1
jmp 0x6f2e3
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x28(%rbp)
jmp 0x6f0bd
movq -0x8(%rbp), %rax
movl 0x48(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1e8(%rax)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x75220
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)