// File: /workspace/github_c_makefile_star2_O1/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
movq %rcx, %r13
movq %rsi, %rbp
movq %rdi, %r12
movq 0x10(%rdi), %r14
movl 0x90(%r14), %eax
movl %eax, 0x30(%rsp)
movl 0x44(%rdi), %eax
decl %eax
movl %eax, 0xc(%rsp)
movl %eax, 0x44(%rdi)
testl %r9d, %r9d
movq %rdx, 0x10(%rsp)
movl %r8d, 0x34(%rsp)
je 0x2dcbbf
movl %r9d, %r15d
movq %rdx, %rbx
movq %r13, 0x18(%rsp)
movq %rbp, 0x20(%rsp)
movq 0x70(%rsp), %rbp
movq %r14, %rdi
movl $0x14, %esi
movl %r9d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl %eax, 0x2c(%rsp)
movl 0xc(%rbx), %edx
movl 0x10(%rbx), %r8d
leal 0x1(%r15), %r13d
testq %rbp, %rbp
je 0x2dcb07
incl (%rbp)
movq %r14, %rdi
movl $0x56, %esi
movl %r13d, %ecx
callq 0x2b200c
movl %eax, %ebx
movq %r14, %rdi
movl %eax, %esi
movq %rbp, %rdx
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x285198
addl $0x2, %ebx
movq %r14, %rdi
movl $0x10, %esi
movl %ebx, %edx
movl 0xc(%rsp), %ecx
movl %ebx, %r8d
callq 0x2b200c
movl 0x90(%r14), %eax
movq (%r14), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2dcb5d
leaq 0x1ed32d(%rip), %rcx    # 0x4c9e88
jmp 0x2dcb7b
leal -0x1(%rax), %ecx
movl 0x2c(%rsp), %edx
testl %edx, %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r14), %rcx
movq 0x20(%rsp), %rbp
movq 0x10(%rsp), %rsi
movl %eax, 0x8(%rcx)
movl 0xc(%rsi), %edx
movl 0x10(%rsi), %r8d
decl %r8d
movq %r14, %rdi
movl $0x4d, %esi
movl %r13d, %ecx
callq 0x2b200c
movq %r14, %rdi
movl $0x45, %esi
movl $0x1, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movq 0x18(%rsp), %r13
movq (%r12), %rcx
xorl %eax, %eax
cmpb $0x0, 0x61(%rcx)
jne 0x2dcd33
movl 0xc(%rbp), %edx
testl %edx, %edx
jle 0x2dcbed
movq %r14, %rdi
movl $0x30, %esi
movl 0xc(%rsp), %ecx
movl $0x1, %r8d
callq 0x2b200c
movzbl (%r13), %eax
addl $-0xa, %eax
cmpl $0x3, %eax
ja 0x2dccd7
leaq 0xfdcc7(%rip), %rcx     # 0x3da8cc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq 0x10(%rsp), %rsi
jmpq *%rax
cmpl $0x0, 0x30(%r12)
jne 0x2dccf2
movl 0x4(%r13), %ecx
movl 0xc(%rsi), %edx
movl 0x10(%rsi), %r8d
movq 0x10(%r12), %rdi
movl $0x4c, %esi
jmp 0x2dcced
movb 0x1f(%r12), %al
testb %al, %al
je 0x2dcd42
decb %al
movb %al, 0x1f(%r12)
movzbl %al, %eax
movl 0xd4(%r12,%rax,4), %ebx
jmp 0x2dcd4e
cmpl $0x0, 0xc(%r13)
jne 0x2dcc84
movq 0x10(%rsp), %rax
movl 0x10(%rax), %esi
movq %r12, %rdi
callq 0x2c8275
movq 0x10(%rsp), %rsi
movl %eax, 0xc(%r13)
movl 0x10(%rsi), %eax
movl %eax, 0x10(%r13)
movl 0xc(%r13), %ecx
movl 0xc(%rsi), %edx
movl 0x10(%rsi), %r8d
movq 0x10(%r12), %rdi
movl $0x4c, %esi
callq 0x2b200c
movl 0x4(%r13), %edx
movq %r14, %rdi
movl $0xe, %esi
xorl %ecx, %ecx
jmp 0x2dccea
movb 0x1f(%r12), %al
testb %al, %al
movq %rbp, 0x20(%rsp)
je 0x2dce31
decb %al
movb %al, 0x1f(%r12)
movzbl %al, %eax
movl 0xd4(%r12,%rax,4), %r15d
jmp 0x2dce3e
movq 0x10(%rsp), %rax
movl 0xc(%rax), %edx
movl 0x10(%rax), %ecx
movq %r14, %rdi
movl $0x50, %esi
xorl %r8d, %r8d
callq 0x2b200c
movl 0x8(%rbp), %edx
testl %edx, %edx
je 0x2dcd0d
movl 0x78(%rsp), %ecx
movq %r14, %rdi
movl $0x3b, %esi
xorl %r8d, %r8d
callq 0x2b200c
movq %r14, %rdi
movl 0xc(%rsp), %esi
callq 0x2c91a7
movq %r14, %rdi
movl $0x41, %esi
movl 0x34(%rsp), %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x30(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x38(%r12), %ebx
incl %ebx
movl %ebx, 0x38(%r12)
movq %r13, 0x18(%rsp)
movb 0x1f(%r12), %al
testb %al, %al
je 0x2dcd70
decb %al
movb %al, 0x1f(%r12)
movzbl %al, %eax
movl 0xd4(%r12,%rax,4), %r13d
jmp 0x2dcd7d
movl 0x38(%r12), %r13d
incl %r13d
movl %r13d, 0x38(%r12)
movl 0xc(%rsi), %edx
movl 0x10(%rsi), %ecx
movq %r14, %rdi
movl $0x5b, %esi
movl %ebx, %r8d
callq 0x2b200c
movq 0x18(%rsp), %r15
movl 0x4(%r15), %edx
movq %r14, %rdi
movl $0x78, %esi
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x2b200c
movl 0x4(%r15), %edx
movq %r14, %rdi
movl $0x79, %esi
movl %ebx, %ecx
movl %r13d, %r8d
callq 0x2b200c
movslq 0x90(%r14), %rax
testq %rax, %rax
jle 0x2dcde3
movq 0x88(%r14), %rcx
leaq (%rax,%rax,2), %rax
movw $0x8, -0x16(%rcx,%rax,8)
testl %r13d, %r13d
je 0x2dce04
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x2dce04
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r12)
movl %r13d, 0xd4(%r12,%rax,4)
testl %ebx, %ebx
je 0x2dccf2
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x2dccf2
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r12)
movl %ebx, 0xd4(%r12,%rax,4)
jmp 0x2dccf2
movl 0x38(%r12), %r15d
incl %r15d
movl %r15d, 0x38(%r12)
movl 0xc(%rsi), %edx
movl 0x10(%rsi), %ebx
movq 0x18(%r13), %rax
movq %rax, 0x18(%rsp)
movq %r14, %rdi
movq %rsi, %rbp
movl $0x5b, %esi
movl %ebx, %ecx
movl %r15d, %r8d
callq 0x2b200c
movq %r14, %rdi
movl %eax, %esi
movq 0x18(%rsp), %rdx
movl %ebx, %ecx
callq 0x285198
movl 0x4(%r13), %edx
movl 0xc(%rbp), %r8d
movl 0x10(%rbp), %ebx
movq %r14, %rdi
movl $0x82, %esi
movl %r15d, %ecx
callq 0x2b200c
movq (%r14), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2dcead
movq 0x88(%r14), %rcx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rcx,%rax,8)
movl %ebx, 0x10(%rcx,%rax,8)
testl %r15d, %r15d
movq 0x20(%rsp), %rbp
je 0x2dccf2
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x2dccf2
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r12)
movl %r15d, 0xd4(%r12,%rax,4)
jmp 0x2dccf2