// File: /workspace/github_c_makefile_star2_O0/skeeto[P]flappy/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 ){
      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->addrSkip ){
      sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
      VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
      sqlite3VdbeJumpHere(v, pLevel->addrSkip);
      sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
    }
    if( pLevel->iLeftJoin ){
      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);
    }
    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++){
    Index *pIdx = 0;
    struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
    Table *pTab = pTabItem->pTab;
    assert( pTab!=0 );
    pLoop = pLevel->pWLoop;

    /* 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->okOnePass && (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 && !db->mallocFailed ){
      int k, 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 ){
          int x = pOp->p2;
          assert( pIdx->pTable==pTab );
          if( !HasRowid(pTab) ){
            Index *pPk = sqlite3PrimaryKeyIndex(pTab);
            x = pPk->aiColumn[x];
          }
          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
subq $0xa0, %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 0x761c0
movq -0x8(%rbp), %rax
movzbl 0x38(%rax), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x75d6c
movq -0x8(%rbp), %rax
addq $0x340, %rax            # imm = 0x340
movslq -0x1c(%rbp), %rcx
imulq $0x50, %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 0x18(%rax), %esi
callq 0x66470
movq -0x28(%rbp), %rax
movzbl 0x25(%rax), %eax
cmpl $0x97, %eax
je 0x75b72
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x25(%rax), %esi
movq -0x28(%rbp), %rax
movl 0x28(%rax), %edx
movq -0x28(%rbp), %rax
movl 0x2c(%rax), %ecx
callq 0x63980
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movzbl 0x26(%rax), %esi
callq 0x63ec0
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x75c3d
movq -0x28(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jle 0x75c3d
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x66470
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x54(%rbp)
jle 0x75c2c
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x4(%rax), %esi
addl $0x1, %esi
callq 0x63950
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rax
movzbl 0x8(%rax), %esi
movq -0x50(%rbp), %rax
movl (%rax), %edx
movq -0x50(%rbp), %rax
movl 0x4(%rax), %ecx
callq 0x63980
movq -0x18(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x4(%rax), %esi
subl $0x1, %esi
callq 0x63950
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
addq $-0xc, %rax
movq %rax, -0x50(%rbp)
jmp 0x75bcb
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0xc760
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x66470
movq -0x28(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0x75c91
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x14(%rax), %ecx
movl $0x10, %esi
xorl %edx, %edx
callq 0x63980
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x14(%rax), %esi
callq 0x63950
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x14(%rax), %esi
subl $0x2, %esi
callq 0x63950
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x75d5c
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl (%rax), %edx
movl $0x80, %esi
callq 0x66020
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x75ce8
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 $0x63, %esi
callq 0x66020
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x75d0e
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
movl $0x63, %esi
callq 0x66020
movq -0x28(%rbp), %rax
movzbl 0x25(%rax), %eax
cmpl $0x12, %eax
jne 0x75d39
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x28(%rax), %edx
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %ecx
movl $0x11, %esi
callq 0x63980
jmp 0x75d50
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %ecx
movl $0x10, %esi
xorl %edx, %edx
callq 0x63980
movq -0x18(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x63950
jmp 0x75d5e
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x75af4
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x44(%rax), %esi
callq 0x66470
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
addq $0x340, %rax            # imm = 0x340
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movzbl 0x38(%rcx), %ecx
cmpl %ecx, %eax
jge 0x7603b
movq $0x0, -0x60(%rbp)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq -0x28(%rbp), %rcx
movzbl 0x24(%rcx), %ecx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x70(%rbp), %rax
movzbl 0x48(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x75e87
movq -0x70(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x75e87
movq -0x8(%rbp), %rax
movzwl 0x32(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x75e87
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x74(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x35(%rax)
jne 0x75e46
movl -0x74(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x75e46
movq -0x18(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x3c(%rax), %edx
movl $0x38, %esi
callq 0x66020
movl -0x74(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x75e85
movl -0x74(%rbp), %eax
andl $0x4100, %eax           # imm = 0x4100
cmpl $0x0, %eax
jne 0x75e85
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x50(%rcx), %eax
je 0x75e85
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
movl $0x38, %esi
callq 0x66020
jmp 0x75e87
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x240, %eax            # imm = 0x240
cmpl $0x0, %eax
je 0x75ea6
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x75ec5
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x75ec3
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x75ec5
cmpq $0x0, -0x60(%rbp)
je 0x7601f
movq -0x40(%rbp), %rax
cmpb $0x0, 0x50(%rax)
jne 0x7601f
movq -0x18(%rbp), %rdi
callq 0x63ea0
movl %eax, -0x7c(%rbp)
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
movl -0x78(%rbp), %esi
callq 0x6bac0
movq %rax, -0x88(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jge 0x7601d
movq -0x88(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x75f2b
jmp 0x75ffd
movq -0x88(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x75fcf
movq -0x88(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x70(%rbp), %rax
movzbl 0x48(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x75f8a
movq -0x70(%rbp), %rdi
callq 0x4b190
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x8c(%rbp), %rcx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x8c(%rbp)
movq -0x60(%rbp), %rdi
movl -0x8c(%rbp), %eax
movswl %ax, %esi
callq 0x67b20
cwtl
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
jl 0x75fcd
movl -0x8c(%rbp), %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x75ffb
movq -0x88(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x62, %eax
jne 0x75ff9
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x88(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x88(%rbp), %rax
movb $0x6b, (%rax)
jmp 0x75ffb
jmp 0x75ffd
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movq -0x88(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x88(%rbp)
jmp 0x75f07
jmp 0x7601f
jmp 0x76021
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x28(%rbp)
jmp 0x75d91
movq -0x8(%rbp), %rax
movl 0x48(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f8(%rax)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x7c0b0
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)