// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/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(pParse);

  /* 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 ...)".
    */
    case SRT_Set: {
      int r1;
      testcase( pIn->nSdst>1 );
      r1 = sqlite3GetTempReg(pParse);
      sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
          r1, pDest->zAffSdst, pIn->nSdst);
      sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
                           pIn->iSdst, pIn->nSdst);
      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.  Note that the select might return multiple columns
    ** if it is the RHS of a row-value IN operator.
    */
    case SRT_Mem: {
      if( pParse->nErr==0 ){
        testcase( pIn->nSdst>1 );
        sqlite3ExprCodeMove(pParse, pIn->iSdst, pDest->iSDParm, pIn->nSdst);
      }
      /* 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);
      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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %ebp
movq %rcx, 0x20(%rsp)
movq %rdx, %rbx
movq %rsi, %r13
movq 0x10(%rdi), %r14
movl 0x90(%r14), %r12d
movl 0x44(%rdi), %eax
decl %eax
movl %eax, 0x1c(%rsp)
movl %eax, 0x44(%rdi)
testl %r9d, %r9d
movq %rdi, 0x10(%rsp)
je 0x2760bf
movl %r9d, %r15d
movq %r13, 0x30(%rsp)
movl %r12d, 0x2c(%rsp)
movl %ebp, 0x18(%rsp)
movq 0x70(%rsp), %r12
pushq $0x14
popq %rsi
movq %r14, %rdi
movl %r9d, %edx
callq 0x265d5c
movl %eax, %ebp
movl 0xc(%rbx), %edx
movl 0x10(%rbx), %r8d
leal 0x1(%r15), %r13d
testq %r12, %r12
je 0x27604c
incl (%r12)
movl $0xfffffff7, (%rsp)     # imm = 0xFFFFFFF7
pushq $0x56
popq %rsi
movq %r14, %rdi
movl %r13d, %ecx
movq %r12, %r9
callq 0x264609
leal 0x2(%rax), %edx
pushq $0x10
popq %rsi
movq %r14, %rdi
movl 0x1c(%rsp), %ecx
movl %edx, %r8d
callq 0x24d51f
movq %r14, %rdi
movl %ebp, %esi
callq 0x2645f8
movl 0xc(%rbx), %edx
movl 0x10(%rbx), %r8d
decl %r8d
pushq $0x4d
popq %rsi
movq %r14, %rdi
movl %r13d, %ecx
callq 0x24d51f
pushq $0x45
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
movl %r15d, %ecx
callq 0x24d51a
movl 0x18(%rsp), %ebp
movl 0x2c(%rsp), %r12d
movq 0x30(%rsp), %r13
movq 0x10(%rsp), %rdi
movq (%rdi), %rcx
xorl %eax, %eax
cmpb $0x0, 0x61(%rcx)
jne 0x2762ea
movl 0xc(%r13), %esi
movq %r14, %rdi
movl 0x1c(%rsp), %edx
callq 0x275fbc
movq 0x20(%rsp), %r15
movzbl (%r15), %eax
addl $-0xa, %eax
cmpl $0x3, %eax
ja 0x2762a6
leaq 0xfb46a(%rip), %rcx     # 0x371564
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%rsp), %rdi
cmpl $0x0, 0x30(%rdi)
jne 0x2762b7
movl 0x4(%r15), %edx
movl 0xc(%rbx), %esi
movl 0x10(%rbx), %ecx
callq 0x275256
jmp 0x2762b7
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x267d61
movl %eax, 0x18(%rsp)
movq %r15, %rdi
callq 0x267d61
movl %eax, %r15d
movl 0xc(%rbx), %edx
movl 0x10(%rbx), %ecx
pushq $0x5b
popq %rsi
movq %r14, %rdi
movl 0x18(%rsp), %r8d
callq 0x24d51f
movq 0x20(%rsp), %rbx
movl 0x4(%rbx), %edx
pushq $0x78
popq %rsi
movq %r14, %rdi
movl %r15d, %ecx
callq 0x24d51a
movl 0x4(%rbx), %edx
pushq $0x79
popq %rsi
movq %r14, %rdi
movl 0x18(%rsp), %ecx
movl %ecx, %ebx
movl %r15d, %r8d
callq 0x24d51f
movslq 0x90(%r14), %rax
testq %rax, %rax
jle 0x2761a3
movq 0x88(%r14), %rcx
imulq $0x18, %rax, %rax
movw $0x8, -0x16(%rcx,%rax)
testl %r15d, %r15d
movq 0x10(%rsp), %rdx
je 0x2761c5
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x2761c5
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %r15d, 0xd4(%rdx,%rax,4)
testl %ebx, %ebx
je 0x2762b7
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x2762b7
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %ebx, 0xd4(%rdx,%rax,4)
jmp 0x2762b7
movl 0xc(%r15), %edx
movl 0x10(%rbx), %ecx
testl %edx, %edx
movq 0x10(%rsp), %rdi
jne 0x27621b
movq 0x10(%rsp), %rdi
movl %ecx, %esi
callq 0x266492
movq 0x10(%rsp), %rdi
movl %eax, %edx
movl %eax, 0xc(%r15)
movl 0x10(%rbx), %ecx
movl %ecx, 0x10(%r15)
movl 0xc(%rbx), %esi
callq 0x275256
movl 0x4(%r15), %edx
pushq $0xe
popq %rsi
movq %r14, %rdi
callq 0x265d5c
jmp 0x2762b7
movq 0x10(%rsp), %rdi
callq 0x267d61
movq %r15, %rsi
movl %eax, %r15d
movl 0xc(%rbx), %edx
movl 0x10(%rbx), %ecx
movq 0x18(%rsi), %r9
movl %ecx, (%rsp)
pushq $0x5b
popq %rsi
movq %r14, %rdi
movl %eax, %r8d
callq 0x264609
movq 0x20(%rsp), %rax
movl 0x4(%rax), %edx
movl 0xc(%rbx), %r8d
movl 0x10(%rbx), %r9d
movq %r14, %rdi
movl $0x82, %esi
movl %r15d, %ecx
callq 0x226fc2
movq 0x10(%rsp), %rdx
testl %r15d, %r15d
je 0x2762b7
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x2762b7
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %r15d, 0xd4(%rdx,%rax,4)
jmp 0x2762b7
movl 0xc(%rbx), %edx
movl 0x10(%rbx), %ecx
pushq $0x50
popq %rsi
movq %r14, %rdi
callq 0x24d51a
movl 0x8(%r13), %edx
testl %edx, %edx
je 0x2762ce
movl 0x78(%rsp), %ecx
pushq $0x3b
popq %rsi
movq %r14, %rdi
callq 0x24d51a
movq %r14, %rdi
movl 0x1c(%rsp), %esi
callq 0x266fe1
pushq $0x41
popq %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x265d5c
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq