// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: selectInnerLoop
static void selectInnerLoop(
  Parse *pParse,          /* The parser context */
  Select *p,              /* The complete select statement being coded */
  ExprList *pEList,       /* List of values being extracted */
  int srcTab,             /* Pull data from this table */
  int nColumn,            /* Number of columns in the source table */
  ExprList *pOrderBy,     /* If not NULL, sort results using this key */
  DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */
  SelectDest *pDest,      /* How to dispose of the results */
  int iContinue,          /* Jump here to continue with next row */
  int iBreak              /* Jump here to break out of the inner loop */
){
  Vdbe *v = pParse->pVdbe;
  int i;
  int hasDistinct;        /* True if the DISTINCT keyword is present */
  int regResult;              /* Start of memory holding result set */
  int eDest = pDest->eDest;   /* How to dispose of results */
  int iParm = pDest->iSDParm; /* First argument to disposal method */
  int nResultCol;             /* Number of result columns */

  assert( v );
  if( NEVER(v==0) ) return;
  assert( pEList!=0 );
  hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
  if( pOrderBy==0 && !hasDistinct ){
    codeOffset(v, p, iContinue);
  }

  /* Pull the requested columns.
  */
  if( nColumn>0 ){
    nResultCol = nColumn;
  }else{
    nResultCol = pEList->nExpr;
  }
  if( pDest->iSdst==0 ){
    pDest->iSdst = pParse->nMem+1;
    pDest->nSdst = nResultCol;
    pParse->nMem += nResultCol;
  }else{ 
    assert( pDest->nSdst==nResultCol );
  }
  regResult = pDest->iSdst;
  if( nColumn>0 ){
    for(i=0; i<nColumn; i++){
      sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
    }
  }else if( eDest!=SRT_Exists ){
    /* If the destination is an EXISTS(...) expression, the actual
    ** values returned by the SELECT are not required.
    */
    sqlite3ExprCacheClear(pParse);
    sqlite3ExprCodeExprList(pParse, pEList, regResult, eDest==SRT_Output);
  }
  nColumn = nResultCol;

  /* If the DISTINCT keyword was present on the SELECT statement
  ** and this row has been seen before, then do not make this row
  ** part of the result.
  */
  if( hasDistinct ){
    assert( pEList!=0 );
    assert( pEList->nExpr==nColumn );
    switch( pDistinct->eTnctType ){
      case WHERE_DISTINCT_ORDERED: {
        VdbeOp *pOp;            /* No longer required OpenEphemeral instr. */
        int iJump;              /* Jump destination */
        int regPrev;            /* Previous row content */

        /* Allocate space for the previous row */
        regPrev = pParse->nMem+1;
        pParse->nMem += nColumn;

        /* Change the OP_OpenEphemeral coded earlier to an OP_Null
        ** sets the MEM_Cleared bit on the first register of the
        ** previous value.  This will cause the OP_Ne below to always
        ** fail on the first iteration of the loop even if the first
        ** row is all NULLs.
        */
        sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
        pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct);
        pOp->opcode = OP_Null;
        pOp->p1 = 1;
        pOp->p2 = regPrev;

        iJump = sqlite3VdbeCurrentAddr(v) + nColumn;
        for(i=0; i<nColumn; i++){
          CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
          if( i<nColumn-1 ){
            sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
          }else{
            sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
          }
          sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
          sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
        }
        assert( sqlite3VdbeCurrentAddr(v)==iJump );
        sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nColumn-1);
        break;
      }

      case WHERE_DISTINCT_UNIQUE: {
        sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
        break;
      }

      default: {
        assert( pDistinct->eTnctType==WHERE_DISTINCT_UNORDERED );
        codeDistinct(pParse, pDistinct->tabTnct, iContinue, nColumn, regResult);
        break;
      }
    }
    if( pOrderBy==0 ){
      codeOffset(v, p, iContinue);
    }
  }

  switch( eDest ){
    /* In this mode, write each query result to the key of the temporary
    ** table iParm.
    */
#ifndef SQLITE_OMIT_COMPOUND_SELECT
    case SRT_Union: {
      int r1;
      r1 = sqlite3GetTempReg(pParse);
      sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
      sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
      sqlite3ReleaseTempReg(pParse, r1);
      break;
    }

    /* Construct a record from the query result, but instead of
    ** saving that record, use it as a key to delete elements from
    ** the temporary table iParm.
    */
    case SRT_Except: {
      sqlite3VdbeAddOp3(v, OP_IdxDelete, iParm, regResult, nColumn);
      break;
    }
#endif

    /* Store the result as data using a unique key.
    */
    case SRT_Table:
    case SRT_EphemTab: {
      int r1 = sqlite3GetTempReg(pParse);
      testcase( eDest==SRT_Table );
      testcase( eDest==SRT_EphemTab );
      sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
      if( pOrderBy ){
        pushOntoSorter(pParse, pOrderBy, p, r1);
      }else{
        int r2 = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, r2);
        sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, r2);
        sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
        sqlite3ReleaseTempReg(pParse, r2);
      }
      sqlite3ReleaseTempReg(pParse, r1);
      break;
    }

#ifndef SQLITE_OMIT_SUBQUERY
    /* If we are creating a set for an "expr IN (SELECT ...)" construct,
    ** then there should be a single item on the stack.  Write this
    ** item into the set table with bogus data.
    */
    case SRT_Set: {
      assert( nColumn==1 );
      pDest->affSdst =
                  sqlite3CompareAffinity(pEList->a[0].pExpr, pDest->affSdst);
      if( pOrderBy ){
        /* At first glance you would think we could optimize out the
        ** ORDER BY in this case since the order of entries in the set
        ** does not matter.  But there might be a LIMIT clause, in which
        ** case the order does matter */
        pushOntoSorter(pParse, pOrderBy, p, regResult);
      }else{
        int r1 = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult,1,r1, &pDest->affSdst, 1);
        sqlite3ExprCacheAffinityChange(pParse, regResult, 1);
        sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
        sqlite3ReleaseTempReg(pParse, r1);
      }
      break;
    }

    /* If any row exist in the result set, record that fact and abort.
    */
    case SRT_Exists: {
      sqlite3VdbeAddOp2(v, OP_Integer, 1, iParm);
      /* The LIMIT clause will terminate the loop for us */
      break;
    }

    /* If this is a scalar select that is part of an expression, then
    ** store the results in the appropriate memory cell and break out
    ** of the scan loop.
    */
    case SRT_Mem: {
      assert( nColumn==1 );
      if( pOrderBy ){
        pushOntoSorter(pParse, pOrderBy, p, regResult);
      }else{
        sqlite3ExprCodeMove(pParse, regResult, iParm, 1);
        /* The LIMIT clause will jump out of the loop for us */
      }
      break;
    }
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */

    /* Send the data to the callback function or to a subroutine.  In the
    ** case of a subroutine, the subroutine itself is responsible for
    ** popping the data from the stack.
    */
    case SRT_Coroutine:
    case SRT_Output: {
      testcase( eDest==SRT_Coroutine );
      testcase( eDest==SRT_Output );
      if( pOrderBy ){
        int r1 = sqlite3GetTempReg(pParse);
        sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
        pushOntoSorter(pParse, pOrderBy, p, r1);
        sqlite3ReleaseTempReg(pParse, r1);
      }else if( eDest==SRT_Coroutine ){
        sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
      }else{
        sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nColumn);
        sqlite3ExprCacheAffinityChange(pParse, regResult, nColumn);
      }
      break;
    }

#if !defined(SQLITE_OMIT_TRIGGER)
    /* Discard the results.  This is used for SELECT statements inside
    ** the body of a TRIGGER.  The purpose of such selects is to call
    ** user-defined functions that have side effects.  We do not care
    ** about the actual results of the select.
    */
    default: {
      assert( eDest==SRT_Discard );
      break;
    }
#endif
  }

  /* Jump to the end of the loop if the LIMIT is reached.  Except, if
  ** there is a sorter, in which case the sorter has already limited
  ** the output for us.
  */
  if( pOrderBy==0 && p->iLimit ){
    sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq 0x18(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x40(%rbp)
movq 0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x6e81c
jmp 0x6edc6
cmpq $0x0, 0x10(%rbp)
je 0x6e830
movq 0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, -0x78(%rbp)
jmp 0x6e837
xorl %eax, %eax
movl %eax, -0x78(%rbp)
jmp 0x6e837
movl -0x78(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6e85a
cmpl $0x0, -0x38(%rbp)
jne 0x6e85a
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl 0x20(%rbp), %edx
callq 0x71b50
cmpl $0x0, -0x20(%rbp)
jle 0x6e868
movl -0x20(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x6e871
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movq 0x18(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x6e8a5
movq -0x8(%rbp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x48(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x48(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x58(%rax), %ecx
movl %ecx, 0x58(%rax)
jmp 0x6e8a7
jmp 0x6e8a7
movq 0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x6e8ef
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x6e8ed
movq -0x30(%rbp), %rdi
movl -0x1c(%rbp), %edx
movl -0x34(%rbp), %ecx
movl -0x3c(%rbp), %r8d
addl -0x34(%rbp), %r8d
movl $0x29, %esi
callq 0x5e0f0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6e8be
jmp 0x6e91c
cmpl $0x3, -0x40(%rbp)
je 0x6e91a
movq -0x8(%rbp), %rdi
callq 0x6f480
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x3c(%rbp), %edx
cmpl $0x5, -0x40(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x69d90
jmp 0x6e91c
movl -0x48(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x6ead2
movq 0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, -0x7c(%rbp)
subl $0x1, %eax
je 0x6ea8d
jmp 0x6e942
movl -0x7c(%rbp), %eax
subl $0x2, %eax
jne 0x6ea9f
jmp 0x6e950
movq -0x8(%rbp), %rax
movl 0x58(%rax), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x58(%rax), %ecx
movl %ecx, 0x58(%rax)
movq -0x30(%rbp), %rdi
movq 0x10(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x13e60
movq -0x30(%rbp), %rdi
movq 0x10(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x6dad0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movb $0x18, (%rax)
movq -0x50(%rbp), %rax
movl $0x1, 0x4(%rax)
movl -0x58(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rdi
callq 0x5e520
addl -0x20(%rbp), %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x6ea6f
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x659b0
movq %rax, -0x60(%rbp)
movl -0x34(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x6ea1d
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %edx
addl -0x34(%rbp), %edx
movl -0x54(%rbp), %ecx
movl -0x58(%rbp), %r8d
addl -0x34(%rbp), %r8d
movl $0x4b, %esi
callq 0x5e0f0
jmp 0x6ea3c
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %edx
addl -0x34(%rbp), %edx
movl 0x20(%rbp), %ecx
movl -0x58(%rbp), %r8d
addl -0x34(%rbp), %r8d
movl $0x4c, %esi
callq 0x5e0f0
movq -0x30(%rbp), %rdi
movq -0x60(%rbp), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
callq 0x13c20
movq -0x30(%rbp), %rdi
movl $0x80, %esi
callq 0x5e540
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6e9c0
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x58(%rbp), %ecx
movl -0x20(%rbp), %r8d
subl $0x1, %r8d
movl $0x1c, %esi
callq 0x5e0f0
jmp 0x6eab9
movq -0x30(%rbp), %rdi
movq 0x10(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x13e60
jmp 0x6eab9
movq -0x8(%rbp), %rdi
movq 0x10(%rbp), %rax
movl 0x4(%rax), %esi
movl 0x20(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x3c(%rbp), %r8d
callq 0x7bb80
cmpq $0x0, -0x28(%rbp)
jne 0x6ead0
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl 0x20(%rbp), %edx
callq 0x71b50
jmp 0x6ead2
movl -0x40(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x88(%rbp)
subl $0x9, %eax
ja 0x6ed95
movq -0x88(%rbp), %rax
leaq 0x3bb85(%rip), %rcx     # 0xaa67c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
callq 0x66a70
movl %eax, -0x64(%rbp)
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x64(%rbp), %r8d
movl $0x2b, %esi
callq 0x5e0f0
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x64(%rbp), %ecx
movl $0x67, %esi
callq 0x5e0c0
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x66ac0
jmp 0x6ed97
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x3c(%rbp), %ecx
movl -0x20(%rbp), %r8d
movl $0x68, %esi
callq 0x5e0f0
jmp 0x6ed97
movq -0x8(%rbp), %rdi
callq 0x66a70
movl %eax, -0x68(%rbp)
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x68(%rbp), %r8d
movl $0x2b, %esi
callq 0x5e0f0
cmpq $0x0, -0x28(%rbp)
je 0x6eba7
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdx
movl -0x68(%rbp), %ecx
callq 0x7bc10
jmp 0x6ebf9
movq -0x8(%rbp), %rdi
callq 0x66a70
movl %eax, -0x6c(%rbp)
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x6c(%rbp), %ecx
movl $0x41, %esi
callq 0x5e0c0
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x68(%rbp), %ecx
movl -0x6c(%rbp), %r8d
movl $0x42, %esi
callq 0x5e0f0
movq -0x30(%rbp), %rdi
movl $0x8, %esi
callq 0x5e540
movq -0x8(%rbp), %rdi
movl -0x6c(%rbp), %esi
callq 0x66ac0
movq -0x8(%rbp), %rdi
movl -0x68(%rbp), %esi
callq 0x66ac0
jmp 0x6ed97
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq 0x18(%rbp), %rax
movsbl 0x1(%rax), %esi
callq 0x6ab70
movb %al, %cl
movq 0x18(%rbp), %rax
movb %cl, 0x1(%rax)
cmpq $0x0, -0x28(%rbp)
je 0x6ec48
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdx
movl -0x3c(%rbp), %ecx
callq 0x7bc10
jmp 0x6ecae
movq -0x8(%rbp), %rdi
callq 0x66a70
movl %eax, -0x70(%rbp)
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x70(%rbp), %r8d
movq 0x18(%rbp), %r9
addq $0x1, %r9
movl $0x2b, %esi
movl $0x1, %ecx
movl $0x1, (%rsp)
callq 0x5e1b0
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl $0x1, %edx
callq 0x69c40
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x70(%rbp), %ecx
movl $0x67, %esi
callq 0x5e0c0
movq -0x8(%rbp), %rdi
movl -0x70(%rbp), %esi
callq 0x66ac0
jmp 0x6ed97
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %ecx
movl $0x15, %esi
movl $0x1, %edx
callq 0x5e0c0
jmp 0x6ed97
cmpq $0x0, -0x28(%rbp)
je 0x6eceb
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdx
movl -0x3c(%rbp), %ecx
callq 0x7bc10
jmp 0x6ecff
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x44(%rbp), %edx
movl $0x1, %ecx
callq 0x6f4f0
jmp 0x6ed97
cmpq $0x0, -0x28(%rbp)
je 0x6ed51
movq -0x8(%rbp), %rdi
callq 0x66a70
movl %eax, -0x74(%rbp)
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x74(%rbp), %r8d
movl $0x2b, %esi
callq 0x5e0f0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdx
movl -0x74(%rbp), %ecx
callq 0x7bc10
movq -0x8(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x66ac0
jmp 0x6ed93
cmpl $0xa, -0x40(%rbp)
jne 0x6ed6e
movq -0x30(%rbp), %rdi
movq 0x18(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x11, %esi
callq 0x5ecf0
jmp 0x6ed91
movq -0x30(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl $0x1e, %esi
callq 0x5e0c0
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x69c40
jmp 0x6ed93
jmp 0x6ed97
jmp 0x6ed97
cmpq $0x0, -0x28(%rbp)
jne 0x6edc6
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x6edc6
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edx
movl 0x28(%rbp), %ecx
movl $0x80, %esi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x5e0f0
addq $0x90, %rsp
popq %rbp
retq
nop