// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x430ae0
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x42d540
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x447fa7
movq -0x38(%rbp), %rdi
movl -0x30(%rbp), %edx
movl $0x14, %esi
callq 0x42ba70
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x60(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x58(%rbp)
movq 0x10(%rbp), %rdi
callq 0x43d960
movq -0x68(%rbp), %rdi
movl -0x60(%rbp), %edx
movl -0x5c(%rbp), %ecx
movl -0x58(%rbp), %r8d
movq %rax, %r9
movl $0x56, %esi
movl $0xfffffff7, (%rsp)     # imm = 0xFFFFFFF7
callq 0x429aa0
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
movl -0x48(%rbp), %edx
addl $0x2, %edx
movl -0x3c(%rbp), %ecx
movl -0x48(%rbp), %r8d
addl $0x2, %r8d
movl $0x10, %esi
callq 0x410130
movq -0x38(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x429a70
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0xc(%rax), %edx
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl 0x10(%rax), %r8d
subl $0x1, %r8d
movl $0x4d, %esi
callq 0x410130
movq -0x38(%rbp), %rdi
movl -0x30(%rbp), %ecx
movl $0x45, %esi
movl $0x1, %edx
callq 0x410100
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpb $0x0, 0x61(%rax)
je 0x447fc0
movl $0x0, -0x4(%rbp)
jmp 0x448202
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %esi
movl -0x3c(%rbp), %edx
callq 0x447e40
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
addl $-0xa, %eax
movl %eax, %ecx
movq %rcx, -0x70(%rbp)
subl $0x3, %eax
ja 0x4481a1
movq -0x70(%rbp), %rax
leaq 0x15e4c9(%rip), %rcx    # 0x5a64c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
callq 0x42f190
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x42f190
movl %eax, -0x50(%rbp)
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
movl -0x4c(%rbp), %r8d
movl $0x5b, %esi
callq 0x410130
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movl -0x50(%rbp), %ecx
movl $0x78, %esi
callq 0x410100
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movl -0x4c(%rbp), %ecx
movl -0x50(%rbp), %r8d
movl $0x79, %esi
callq 0x410130
movq -0x38(%rbp), %rdi
movl $0x8, %esi
callq 0x3cb9f0
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
callq 0x42e560
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x42e560
jmp 0x4481bd
movq -0x10(%rbp), %rdi
callq 0x42f190
movl %eax, -0x54(%rbp)
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
movl -0x54(%rbp), %r8d
movq -0x28(%rbp), %rax
movq 0x18(%rax), %r9
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x5b, %esi
movl %eax, (%rsp)
callq 0x429aa0
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movl -0x54(%rbp), %ecx
movq -0x20(%rbp), %rax
movl 0xc(%rax), %r8d
movq -0x20(%rbp), %rax
movl 0x10(%rax), %r9d
movl $0x82, %esi
callq 0x3cb970
movq -0x10(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x42e560
jmp 0x4481bd
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x448136
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0xc(%rax), %esi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
callq 0x444c60
jmp 0x4481bd
movq -0x28(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x44816c
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x42cb30
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0xc(%rax), %esi
movq -0x28(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
callq 0x444c60
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movl $0xe, %esi
callq 0x42ba70
jmp 0x4481bd
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
movl $0x50, %esi
callq 0x410100
movq -0x18(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x4481df
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
movl 0x18(%rbp), %ecx
movl $0x3b, %esi
callq 0x410100
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x42dc90
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %edx
movl $0x41, %esi
callq 0x42ba70
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop