// File: /workspace/github_c_makefile_star2_O2/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: generateOutputSubroutine
static int generateOutputSubroutine(
  Parse *pParse,          /* Parsing context */
  Select *p,              /* The SELECT statement */
  SelectDest *pIn,        /* Coroutine supplying data */
  SelectDest *pDest,      /* Where to send the data */
  int regReturn,          /* The return address register */
  int regPrev,            /* Previous result register.  No uniqueness if 0 */
  KeyInfo *pKeyInfo,      /* For comparing with previous entry */
  int iBreak              /* Jump here if we hit the LIMIT */
){
  Vdbe *v = pParse->pVdbe;
  int iContinue;
  int addr;

  addr = sqlite3VdbeCurrentAddr(v);
  iContinue = sqlite3VdbeMakeLabel(v);

  /* Suppress duplicates for UNION, EXCEPT, and INTERSECT 
  */
  if( regPrev ){
    int addr1, addr2;
    addr1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
    addr2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
                              (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
    sqlite3VdbeAddOp3(v, OP_Jump, addr2+2, iContinue, addr2+2); VdbeCoverage(v);
    sqlite3VdbeJumpHere(v, addr1);
    sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
    sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
  }
  if( pParse->db->mallocFailed ) return 0;

  /* Suppress the first OFFSET entries if there is an OFFSET clause
  */
  codeOffset(v, p->iOffset, iContinue);

  assert( pDest->eDest!=SRT_Exists );
  assert( pDest->eDest!=SRT_Table );
  switch( pDest->eDest ){
    /* Store the result as data using a unique key.
    */
    case SRT_EphemTab: {
      int r1 = sqlite3GetTempReg(pParse);
      int r2 = sqlite3GetTempReg(pParse);
      sqlite3VdbeAddOp3(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst, r1);
      sqlite3VdbeAddOp2(v, OP_NewRowid, pDest->iSDParm, r2);
      sqlite3VdbeAddOp3(v, OP_Insert, pDest->iSDParm, 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: {
      int r1;
      assert( pIn->nSdst==1 || pParse->nErr>0 );
      pDest->affSdst = 
         sqlite3CompareAffinity(p->pEList->a[0].pExpr, pDest->affSdst);
      r1 = sqlite3GetTempReg(pParse);
      sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, 1, r1, &pDest->affSdst,1);
      sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, 1);
      sqlite3VdbeAddOp2(v, OP_IdxInsert, pDest->iSDParm, r1);
      sqlite3ReleaseTempReg(pParse, r1);
      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( pIn->nSdst==1 || pParse->nErr>0 );  testcase( pIn->nSdst!=1 );
      sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, 1);
      /* The LIMIT clause will jump out of the loop for us */
      break;
    }
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */

    /* The results are stored in a sequence of registers
    ** starting at pDest->iSdst.  Then the co-routine yields.
    */
    case SRT_Coroutine: {
      if( pDest->iSdst==0 ){
        pDest->iSdst = sqlite3GetTempRange(pParse, pIn->nSdst);
        pDest->nSdst = pIn->nSdst;
      }
      sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSdst, pIn->nSdst);
      sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
      break;
    }

    /* If none of the above, then the result destination must be
    ** SRT_Output.  This routine is never called with any other
    ** destination other than the ones handled above or SRT_Output.
    **
    ** For SRT_Output, results are stored in a sequence of registers.  
    ** Then the OP_ResultRow opcode is used to cause sqlite3_step() to
    ** return the next row of result.
    */
    default: {
      assert( pDest->eDest==SRT_Output );
      sqlite3VdbeAddOp2(v, OP_ResultRow, pIn->iSdst, pIn->nSdst);
      sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, pIn->nSdst);
      break;
    }
  }

  /* Jump to the end of the loop if the LIMIT is reached.
  */
  if( p->iLimit ){
    sqlite3VdbeAddOp2(v, OP_DecrJumpZero, p->iLimit, iBreak); VdbeCoverage(v);
  }

  /* Generate the subroutine return
  */
  sqlite3VdbeResolveLabel(v, iContinue);
  sqlite3VdbeAddOp1(v, OP_Return, regReturn);

  return addr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r15d
movl %r8d, %r12d
movq %rcx, -0x50(%rbp)
movq %rdx, %r13
movq %rsi, -0x58(%rbp)
movq %rdi, %rbx
movq 0x10(%rdi), %r14
movl 0x3c(%r14), %eax
movl %eax, -0x2c(%rbp)
movq %r14, %rdi
callq 0x4b9c2
movl %eax, %edx
testl %r15d, %r15d
movq %r13, -0x40(%rbp)
movl %eax, -0x44(%rbp)
je 0x57e3d
movq %rbx, -0x38(%rbp)
movl %r12d, -0x60(%rbp)
movq 0x10(%rbp), %r12
pushq $0x2f
popq %rsi
movq %r14, %rdi
movl %r15d, %edx
callq 0x4b9b3
movl %eax, -0x5c(%rbp)
movl 0x8(%r13), %edx
movl 0xc(%r13), %r8d
leal 0x1(%r15), %ebx
testq %r12, %r12
je 0x57dcc
incl (%r12)
movl $0xfffffffa, (%rsp)     # imm = 0xFFFFFFFA
pushq $0x2b
popq %rsi
movq %r14, %rdi
movl %ebx, %ecx
movq %r12, %r9
callq 0x4a044
leal 0x2(%rax), %edx
pushq $0x2c
popq %rsi
movq %r14, %rdi
movl -0x44(%rbp), %r12d
movl %r12d, %ecx
movl %edx, %r8d
callq 0x385b6
movq %r14, %rdi
movl -0x5c(%rbp), %esi
callq 0x4a022
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edx
movl 0xc(%rax), %r8d
decl %r8d
pushq $0x1f
popq %rsi
movq %r14, %rdi
movl %ebx, %ecx
callq 0x385b6
pushq $0x17
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
movl %r15d, %ecx
callq 0x4a1ab
movl %r12d, %edx
movl -0x60(%rbp), %r12d
movq -0x38(%rbp), %rbx
movq (%rbx), %rcx
xorl %eax, %eax
cmpb $0x0, 0x51(%rcx)
jne 0x58060
movq -0x58(%rbp), %r15
movl 0x10(%r15), %esi
movq %r14, %rdi
callq 0x57d31
movq -0x50(%rbp), %rdx
movzbl (%rdx), %eax
addl $-0xa, %eax
cmpl $0x3, %eax
ja 0x57fc4
leaq 0x11402(%rip), %rcx     # 0x69278
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x40(%rbp), %rax
movl 0x8(%rax), %esi
movl 0x4(%rdx), %edx
pushq $0x1
popq %rcx
movq %rbx, %rdi
callq 0x57296
jmp 0x57feb
movq %rbx, %rdi
movq %rdx, %r15
callq 0x4c550
movl %eax, %r13d
movq %rbx, %rdi
callq 0x4c550
movq %rbx, -0x38(%rbp)
movl %eax, %ebx
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edx
movl 0xc(%rax), %ecx
pushq $0x32
popq %rsi
movq %r14, %rdi
movl %r13d, %r8d
callq 0x385b6
movl 0x4(%r15), %edx
pushq $0x54
popq %rsi
movq %r14, %rdi
movl %ebx, %ecx
callq 0x4a1ab
movl 0x4(%r15), %edx
pushq $0x5f
popq %rsi
movq %r14, %rdi
movl %r13d, %ecx
movl %ebx, %r8d
callq 0x385b6
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x13770
movq -0x38(%rbp), %r15
movq %r15, %rdi
movl %ebx, %esi
callq 0x4c573
movq %r15, %rdi
movl %r13d, %esi
movq -0x58(%rbp), %r15
jmp 0x57fbd
movq %rbx, %rax
movq %rdx, %r13
movl 0x8(%rdx), %edx
movq -0x40(%rbp), %rsi
movl 0xc(%rsi), %ecx
testl %edx, %edx
movl -0x2c(%rbp), %ebx
je 0x57ff0
movq %rax, %rdi
jmp 0x58013
movq (%r15), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
leaq 0x1(%rdx), %r15
movsbl 0x1(%rdx), %esi
movq %rdx, %r13
callq 0x4dda0
movb %al, 0x1(%r13)
movq %rbx, %rdi
callq 0x4c550
movq %rbx, -0x38(%rbp)
movl %eax, %ebx
movq -0x40(%rbp), %r13
movl 0x8(%r13), %edx
movl $0x1, (%rsp)
pushq $0x32
popq %rsi
pushq $0x1
popq %rcx
movq %r14, %rdi
movl %eax, %r8d
movq %r15, %r9
movq -0x58(%rbp), %r15
callq 0x4a044
movl 0x8(%r13), %esi
movq -0x38(%rbp), %r13
movq %r13, %rdi
pushq $0x1
popq %rdx
callq 0x4ba18
movq -0x50(%rbp), %rax
movl 0x4(%rax), %edx
pushq $0x70
popq %rsi
movq %r14, %rdi
movl %ebx, %ecx
callq 0x4a1ab
movq %r13, %rdi
movl %ebx, %esi
callq 0x4c573
jmp 0x57feb
movq -0x40(%rbp), %r13
movl 0x8(%r13), %edx
movl 0xc(%r13), %ecx
pushq $0x22
popq %rsi
movq %r14, %rdi
callq 0x4a1ab
movl 0x8(%r13), %esi
movl 0xc(%r13), %edx
movq %rbx, %rdi
callq 0x4ba18
movl -0x2c(%rbp), %ebx
jmp 0x5802d
movq %rax, %rdi
movq %rax, -0x38(%rbp)
movl %ecx, %esi
callq 0x4bc61
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl %eax, %edx
movl %eax, 0x8(%r13)
movl 0xc(%rsi), %ecx
movl %ecx, 0xc(%r13)
movl 0x8(%rsi), %esi
callq 0x57296
movq -0x50(%rbp), %rax
movl 0x4(%rax), %edx
pushq $0x14
popq %rsi
movq %r14, %rdi
callq 0x4b9b3
movl 0xc(%r15), %edx
testl %edx, %edx
je 0x58045
movl 0x18(%rbp), %ecx
movq %r14, %rdi
movl $0x8e, %esi
callq 0x4a1ab
movq %r14, %rdi
movl -0x44(%rbp), %esi
callq 0x4bacf
pushq $0x10
popq %rsi
movq %r14, %rdi
movl %r12d, %edx
callq 0x4b9b3
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq