// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/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 p4type,             /* The p4 type for pKeyInfo */
  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 j1, j2;
    j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev);
    j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
                              (char*)pKeyInfo, p4type);
    sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2);
    sqlite3VdbeJumpHere(v, j1);
    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, iContinue);

  switch( pDest->eDest ){
    /* Store the result as data using a unique key.
    */
    case SRT_Table:
    case SRT_EphemTab: {
      int r1 = sqlite3GetTempReg(pParse);
      int r2 = sqlite3GetTempReg(pParse);
      testcase( pDest->eDest==SRT_Table );
      testcase( pDest->eDest==SRT_EphemTab );
      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 );
      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 0  /* Never occurs on an ORDER BY query */
    /* If any row exist in the result set, record that fact and abort.
    */
    case SRT_Exists: {
      sqlite3VdbeAddOp2(v, OP_Integer, 1, pDest->iSDParm);
      /* The LIMIT clause will terminate the loop for us */
      break;
    }
#endif

    /* 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 );
      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, pDest->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 ){
    sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
  }

  /* 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, %ebx
movl %r8d, %r14d
movq %rcx, %r15
movq %rdx, -0x30(%rbp)
movq %rsi, -0x58(%rbp)
movq %rdi, -0x40(%rbp)
movq 0x10(%rdi), %r12
movl 0x34(%r12), %r13d
movq %r12, %rdi
callq 0x4c5eb
movl %eax, -0x34(%rbp)
movq %rbx, %rax
testl %ebx, %ebx
movq -0x30(%rbp), %rbx
movl %r13d, -0x5c(%rbp)
je 0x565fc
movq %r15, -0x50(%rbp)
movl %r14d, -0x44(%rbp)
movq %r12, %rdi
movl $0x28, %esi
movq %rax, %r15
movl %r15d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl %eax, %r13d
leal 0x1(%r15), %r14d
movl 0x8(%rbx), %edx
movl 0xc(%rbx), %r8d
movq %r12, %rdi
movl $0x24, %esi
movl %r14d, %ecx
callq 0x45f15
movl %eax, %ebx
movq %r12, %rdi
movl %eax, %esi
movq 0x10(%rbp), %rdx
movl 0x18(%rbp), %ecx
callq 0x11a9f
addl $0x2, %ebx
movq %r12, %rdi
movl $0x25, %esi
movl %ebx, %edx
movl -0x34(%rbp), %ecx
movl %ebx, %r8d
callq 0x45f15
testl %r13d, %r13d
js 0x565be
movl 0x34(%r12), %eax
cmpl %r13d, %eax
jbe 0x565be
movq 0x8(%r12), %rcx
movl %r13d, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %edx
movl 0xc(%rax), %r8d
decl %r8d
movq %r12, %rdi
movl $0x1c, %esi
movl %r14d, %ecx
callq 0x45f15
movq %r12, %rdi
movl $0x15, %esi
movl $0x1, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl -0x44(%rbp), %r14d
movq -0x50(%rbp), %r15
movq -0x40(%rbp), %rax
movq (%rax), %rcx
xorl %eax, %eax
cmpb $0x0, 0x50(%rcx)
jne 0x5698f
movq %r12, %rdi
movq -0x58(%rbp), %rsi
movl -0x34(%rbp), %edx
callq 0x569a6
movzbl (%r15), %eax
addl $-0x6, %eax
cmpl $0x4, %eax
ja 0x56705
movq %r15, %rbx
leaq 0x1f8d0(%rip), %rcx     # 0x75f08
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movl %r14d, %r13d
jmpq *%rax
movq -0x40(%rbp), %rdx
movb 0x1f(%rdx), %al
testb %al, %al
movq %r12, %r14
movl %r13d, -0x44(%rbp)
movq %rbx, -0x50(%rbp)
je 0x56739
leal -0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movzbl %cl, %ecx
movl 0x28(%rdx,%rcx,4), %r15d
testb %cl, %cl
je 0x56744
addb $-0x2, %al
movb %al, 0x1f(%rdx)
movzbl %al, %eax
movl 0x28(%rdx,%rax,4), %ebx
jmp 0x5674c
movl 0x8(%rbx), %edx
testl %edx, %edx
movq %r12, %r14
je 0x567f7
movl 0xc(%rbx), %ecx
movq -0x40(%rbp), %rdi
jmp 0x56916
movq -0x30(%rbp), %rax
movl 0x8(%rax), %esi
movl 0x4(%rbx), %edx
movq -0x40(%rbp), %rdi
movl $0x1, %ecx
callq 0x552f9
jmp 0x56731
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
leaq 0x1(%rbx), %rax
movq %rax, -0x68(%rbp)
movsbl 0x1(%rbx), %esi
callq 0x4ef70
movq %rbx, -0x50(%rbp)
movb %al, 0x1(%rbx)
movq -0x40(%rbp), %r15
movb 0x1f(%r15), %al
testb %al, %al
movq %r12, %r14
je 0x5681d
decb %al
movb %al, 0x1f(%r15)
movzbl %al, %eax
movl 0x28(%r15,%rax,4), %ebx
jmp 0x56827
movq -0x30(%rbp), %rbx
movl 0x8(%rbx), %edx
movl 0xc(%rbx), %ecx
movq %r12, %rdi
movl $0x1e, %esi
xorl %r8d, %r8d
callq 0x45f15
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
movq -0x40(%rbp), %rdi
callq 0x4e564
movl %r14d, %r13d
movq %r12, %r14
jmp 0x56937
movl 0x58(%rdx), %r15d
incl %r15d
movl %r15d, 0x58(%rdx)
movl 0x58(%rdx), %ebx
incl %ebx
movl %ebx, 0x58(%rdx)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %edx
movl 0xc(%rax), %ecx
movq %r14, %rdi
movl $0x2b, %esi
movl %r15d, %r8d
callq 0x45f15
movq -0x50(%rbp), %r12
movl 0x4(%r12), %edx
movq %r14, %rdi
movl $0x41, %esi
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl 0x4(%r12), %edx
movq %r14, %rdi
movl $0x42, %esi
movl %r15d, %ecx
movl %ebx, %r8d
callq 0x45f15
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x567af
movslq 0x34(%r14), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $0x8, -0x15(%rax,%rcx,8)
testl %ebx, %ebx
movq -0x40(%rbp), %rdx
movl -0x44(%rbp), %r13d
je 0x568c9
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x568c9
xorl %ecx, %ecx
cmpl %ebx, 0x84(%rdx,%rcx)
je 0x568c4
addq $0x18, %rcx
cmpl $0xf0, %ecx
jne 0x567cf
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %ebx, 0x28(%rdx,%rax,4)
jmp 0x568c9
movq -0x30(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x40(%rbp), %rdi
movl 0x48(%rdi), %eax
subl %ecx, %eax
jge 0x56904
movl 0x58(%rdi), %eax
leal 0x1(%rax), %edx
addl %ecx, %eax
movl %eax, 0x58(%rdi)
jmp 0x56910
movl 0x58(%r15), %ebx
incl %ebx
movl %ebx, 0x58(%r15)
movq -0x30(%rbp), %r12
movl 0x8(%r12), %edx
movq %r14, %rdi
movl $0x2b, %esi
movl $0x1, %ecx
movl %ebx, %r8d
callq 0x45f15
movq %r14, %rdi
movl %eax, %esi
movq -0x68(%rbp), %rdx
movl $0x1, %ecx
callq 0x11a9f
movl 0x8(%r12), %esi
movq %r15, %rdi
movl $0x1, %edx
callq 0x4e564
movq -0x50(%rbp), %rax
movl 0x4(%rax), %edx
movq %r14, %rdi
movl $0x67, %esi
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x45f15
testl %ebx, %ebx
je 0x56937
movzbl 0x1f(%r15), %eax
cmpq $0x7, %rax
ja 0x56937
xorl %ecx, %ecx
cmpl %ebx, 0x84(%r15,%rcx)
je 0x5699e
addq $0x18, %rcx
cmpl $0xf0, %ecx
jne 0x5689c
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r15)
movl %ebx, 0x28(%r15,%rax,4)
jmp 0x56937
movb $0x1, 0x7c(%rdx,%rcx)
testl %r15d, %r15d
je 0x56937
movzbl 0x1f(%rdx), %eax
cmpq $0x7, %rax
ja 0x56937
xorl %ecx, %ecx
cmpl %r15d, 0x84(%rdx,%rcx)
je 0x568fd
addq $0x18, %rcx
cmpl $0xf0, %ecx
jne 0x568da
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%rdx)
movl %r15d, 0x28(%rdx,%rax,4)
jmp 0x56937
movb $0x1, 0x7c(%rdx,%rcx)
jmp 0x56937
movl 0x4c(%rdi), %edx
leal (%rdx,%rcx), %esi
movl %esi, 0x4c(%rdi)
movl %eax, 0x48(%rdi)
movl %edx, 0x8(%rbx)
movl %ecx, 0xc(%rbx)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x552f9
movl 0x4(%rbx), %edx
movq %r14, %rdi
movl $0x11, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movq -0x58(%rbp), %rax
movl 0xc(%rax), %edx
testl %edx, %edx
je 0x56958
movl 0x20(%rbp), %ecx
movq %r14, %rdi
movl $0x80, %esi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x45f15
cmpl $0x0, -0x34(%rbp)
movl -0x5c(%rbp), %ebx
jns 0x56978
movq 0x40(%r14), %rax
testq %rax, %rax
je 0x56978
movl -0x34(%rbp), %edx
notl %edx
movl 0x34(%r14), %ecx
movl %edx, %edx
movl %ecx, (%rax,%rdx,4)
movq %r14, %rdi
movl $0x10, %esi
movl %r13d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl %ebx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, 0x7c(%r15,%rcx)
jmp 0x56937