// File: /workspace/github_c_makefile_star2_O3/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, 0x20(%rsp)
movq %rsi, %r12
movq %rdi, %r13
movq 0x10(%rdi), %r14
movl 0x90(%r14), %eax
movl %eax, 0x30(%rsp)
movl 0x44(%rdi), %ebx
decl %ebx
movl %ebx, 0x44(%rdi)
testl %r9d, %r9d
movq %rdx, 0x8(%rsp)
movl %r8d, 0x34(%rsp)
je 0x2d349c
movl %r9d, %r15d
movq %rdx, %rbp
movq %r13, 0x18(%rsp)
movq %r12, 0x10(%rsp)
movl %ebx, %r12d
movq 0x70(%rsp), %rbx
movq %r14, %rdi
movl $0x14, %esi
movl %r9d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl %eax, 0x2c(%rsp)
movl 0xc(%rbp), %edx
movl 0x10(%rbp), %r8d
leal 0x1(%r15), %r13d
testq %rbx, %rbx
je 0x2d33e2
incl (%rbx)
movq %r14, %rdi
movl $0x56, %esi
movl %r13d, %ecx
callq 0x2a83e1
movl %eax, %ebp
movq %r14, %rdi
movl %eax, %esi
movq %rbx, %rdx
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x27b778
addl $0x2, %ebp
movq %r14, %rdi
movl $0x10, %esi
movl %ebp, %edx
movl %r12d, %ebx
movl %r12d, %ecx
movl %ebp, %r8d
callq 0x2a83e1
movl 0x90(%r14), %eax
movq (%r14), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2d343a
leaq 0x1eba50(%rip), %rcx    # 0x4bee88
jmp 0x2d3458
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 0x10(%rsp), %r12
movl %eax, 0x8(%rcx)
movq 0x8(%rsp), %rax
movl 0xc(%rax), %edx
movl 0x10(%rax), %r8d
decl %r8d
movq %r14, %rdi
movl $0x4d, %esi
movl %r13d, %ecx
callq 0x2a83e1
movq %r14, %rdi
movl $0x45, %esi
movl $0x1, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movq 0x18(%rsp), %r13
movq (%r13), %rcx
xorl %eax, %eax
cmpb $0x0, 0x61(%rcx)
jne 0x2d362b
movl 0xc(%r12), %edx
testl %edx, %edx
jle 0x2d34ca
movq %r14, %rdi
movl $0x30, %esi
movl %ebx, %ecx
movl $0x1, %r8d
callq 0x2a83e1
movq 0x20(%rsp), %r15
movzbl (%r15), %eax
addl $-0xa, %eax
cmpl $0x3, %eax
ja 0x2d35cf
leaq 0xfdc6e(%rip), %rcx     # 0x3d1154
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0x30(%r13)
jne 0x2d35ea
movl 0x4(%r15), %ecx
movq 0x8(%rsp), %rax
movl 0xc(%rax), %edx
movl 0x10(%rax), %r8d
movq 0x10(%r13), %rdi
movl $0x4c, %esi
jmp 0x2d35e5
movb 0x1f(%r13), %al
testb %al, %al
je 0x2d363a
leal -0x1(%rax), %ecx
movb %cl, 0x1f(%r13)
movzbl %cl, %ecx
movl 0xd4(%r13,%rcx,4), %r9d
testb %cl, %cl
je 0x2d3645
addb $-0x2, %al
movb %al, 0x1f(%r13)
movzbl %al, %eax
movl 0xd4(%r13,%rax,4), %ebp
jmp 0x2d364f
movl 0xc(%r15), %ecx
movq 0x8(%rsp), %rax
movl 0x10(%rax), %r8d
testl %ecx, %ecx
jne 0x2d3583
movq %r13, %rdi
movl %r8d, %esi
callq 0x2beb15
movl %eax, %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0xc(%r15)
movl 0x10(%rax), %r8d
movl %r8d, 0x10(%r15)
movl 0xc(%rax), %edx
movq 0x10(%r13), %rdi
movl $0x4c, %esi
callq 0x2a83e1
movl 0x4(%r15), %edx
movq %r14, %rdi
movl $0xe, %esi
xorl %ecx, %ecx
jmp 0x2d35e2
movb 0x1f(%r13), %al
testb %al, %al
movl %ebx, 0x28(%rsp)
movq %r13, 0x18(%rsp)
je 0x2d370e
decb %al
movb %al, 0x1f(%r13)
movzbl %al, %eax
movl 0xd4(%r13,%rax,4), %r15d
jmp 0x2d3719
movq 0x8(%rsp), %rax
movl 0xc(%rax), %edx
movl 0x10(%rax), %ecx
movq %r14, %rdi
movl $0x50, %esi
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x8(%r12), %edx
testl %edx, %edx
je 0x2d3607
movl 0x78(%rsp), %ecx
movq %r14, %rdi
movl $0x3b, %esi
xorl %r8d, %r8d
callq 0x2a83e1
movq %r14, %rdi
movl %ebx, %esi
callq 0x2bfa39
movq %r14, %rdi
movl $0x41, %esi
movl 0x34(%rsp), %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x30(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x38(%r13), %r9d
incl %r9d
movl %r9d, 0x38(%r13)
movl 0x38(%r13), %ebp
incl %ebp
movl %ebp, 0x38(%r13)
movq 0x8(%rsp), %rax
movl %r9d, 0x8(%rsp)
movl 0xc(%rax), %edx
movl 0x10(%rax), %ecx
movq %r14, %rdi
movl $0x5b, %esi
movl %r9d, %r8d
callq 0x2a83e1
movq 0x20(%rsp), %r15
movl 0x4(%r15), %edx
movq %r14, %rdi
movl $0x78, %esi
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x4(%r15), %edx
movl 0x8(%rsp), %r15d
movq %r14, %rdi
movl $0x79, %esi
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x2a83e1
movslq 0x90(%r14), %rax
testq %rax, %rax
jle 0x2d36c4
movq 0x88(%r14), %rcx
leaq (%rax,%rax,2), %rax
movw $0x8, -0x16(%rcx,%rax,8)
testl %ebp, %ebp
je 0x2d36e2
movzbl 0x1f(%r13), %eax
cmpq $0x7, %rax
ja 0x2d36e2
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r13)
movl %ebp, 0xd4(%r13,%rax,4)
testl %r15d, %r15d
je 0x2d35ea
movzbl 0x1f(%r13), %eax
cmpq $0x7, %rax
ja 0x2d35ea
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r13)
movl %r15d, 0xd4(%r13,%rax,4)
jmp 0x2d35ea
movl 0x38(%r13), %r15d
incl %r15d
movl %r15d, 0x38(%r13)
movq 0x8(%rsp), %rbp
movl 0xc(%rbp), %edx
movl 0x10(%rbp), %ebx
movq 0x20(%rsp), %r13
movq 0x18(%r13), %rax
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movl $0x5b, %esi
movl %ebx, %ecx
movl %r15d, %r8d
callq 0x2a83e1
movq %r14, %rdi
movl %eax, %esi
movq 0x10(%rsp), %rdx
movl %ebx, %ecx
callq 0x27b778
movl 0x4(%r13), %edx
movl 0xc(%rbp), %r8d
movl 0x10(%rbp), %ebx
movq %r14, %rdi
movl $0x82, %esi
movl %r15d, %ecx
callq 0x2a83e1
movq (%r14), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2d378f
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
movl 0x28(%rsp), %ebx
movq 0x18(%rsp), %rdx
je 0x2d35ea
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x2d35ea
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %r15d, 0xd4(%rdx,%rax,4)
jmp 0x2d35ea