// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: generateSortTail
static void generateSortTail(
  Parse *pParse,    /* Parsing context */
  Select *p,        /* The SELECT statement */
  SortCtx *pSort,   /* Information on the ORDER BY clause */
  int nColumn,      /* Number of columns of data */
  SelectDest *pDest /* Write the sorted results here */
){
  Vdbe *v = pParse->pVdbe;                     /* The prepared statement */
  int addrBreak = pSort->labelDone;            /* Jump here to exit loop */
  int addrContinue = sqlite3VdbeMakeLabel(v);  /* Jump here for next cycle */
  int addr;
  int addrOnce = 0;
  int iTab;
  ExprList *pOrderBy = pSort->pOrderBy;
  int eDest = pDest->eDest;
  int iParm = pDest->iSDParm;
  int regRow;
  int regRowid;
  int nKey;
  int iSortTab;                   /* Sorter cursor to read from */
  int nSortData;                  /* Trailing values to read from sorter */
  int i;
  int bSeq;                       /* True if sorter record includes seq. no. */
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
  struct ExprList_item *aOutEx = p->pEList->a;
#endif

  assert( addrBreak<0 );
  if( pSort->labelBkOut ){
    sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
    sqlite3VdbeGoto(v, addrBreak);
    sqlite3VdbeResolveLabel(v, pSort->labelBkOut);
  }
  iTab = pSort->iECursor;
  if( eDest==SRT_Output || eDest==SRT_Coroutine ){
    regRowid = 0;
    regRow = pDest->iSdst;
    nSortData = nColumn;
  }else{
    regRowid = sqlite3GetTempReg(pParse);
    regRow = sqlite3GetTempReg(pParse);
    nSortData = 1;
  }
  nKey = pOrderBy->nExpr - pSort->nOBSat;
  if( pSort->sortFlags & SORTFLAG_UseSorter ){
    int regSortOut = ++pParse->nMem;
    iSortTab = pParse->nTab++;
    if( pSort->labelBkOut ){
      addrOnce = sqlite3CodeOnce(pParse); VdbeCoverage(v);
    }
    sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nSortData);
    if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
    addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
    VdbeCoverage(v);
    codeOffset(v, p->iOffset, addrContinue);
    sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
    bSeq = 0;
  }else{
    addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
    codeOffset(v, p->iOffset, addrContinue);
    iSortTab = iTab;
    bSeq = 1;
  }
  for(i=0; i<nSortData; i++){
    sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
    VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
  }
  switch( eDest ){
    case SRT_EphemTab: {
      sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
      sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);
      sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
      break;
    }
#ifndef SQLITE_OMIT_SUBQUERY
    case SRT_Set: {
      assert( nColumn==1 );
      sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, 1, regRowid,
                        &pDest->affSdst, 1);
      sqlite3ExprCacheAffinityChange(pParse, regRow, 1);
      sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, regRowid);
      break;
    }
    case SRT_Mem: {
      assert( nColumn==1 );
      sqlite3ExprCodeMove(pParse, regRow, iParm, 1);
      /* The LIMIT clause will terminate the loop for us */
      break;
    }
#endif
    default: {
      assert( eDest==SRT_Output || eDest==SRT_Coroutine ); 
      testcase( eDest==SRT_Output );
      testcase( eDest==SRT_Coroutine );
      if( eDest==SRT_Output ){
        sqlite3VdbeAddOp2(v, OP_ResultRow, pDest->iSdst, nColumn);
        sqlite3ExprCacheAffinityChange(pParse, pDest->iSdst, nColumn);
      }else{
        sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
      }
      break;
    }
  }
  if( regRowid ){
    sqlite3ReleaseTempReg(pParse, regRow);
    sqlite3ReleaseTempReg(pParse, regRowid);
  }
  /* The bottom of the loop
  */
  sqlite3VdbeResolveLabel(v, addrContinue);
  if( pSort->sortFlags & SORTFLAG_UseSorter ){
    sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
  }else{
    sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
  }
  if( pSort->regReturn ) sqlite3VdbeAddOp1(v, OP_Return, pSort->regReturn);
  sqlite3VdbeResolveLabel(v, addrBreak);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6e5a0
movl %eax, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0x80918
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
movl $0xf, %esi
callq 0x6c310
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x6c1b0
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %esi
callq 0x6e780
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x9, -0x54(%rbp)
je 0x8092e
cmpl $0xd, -0x54(%rbp)
jne 0x80947
movl $0x0, -0x60(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x5c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x80966
movq -0x8(%rbp), %rdi
callq 0x6f960
movl %eax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6f960
movl %eax, -0x5c(%rbp)
movl $0x1, -0x6c(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x8(%rcx), %eax
movl %eax, -0x64(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x80a42
movq -0x8(%rbp), %rcx
movl 0x54(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x54(%rcx)
movl %eax, -0x78(%rbp)
movq -0x8(%rbp), %rcx
movl 0x50(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x50(%rcx)
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0x809c2
movq -0x8(%rbp), %rdi
callq 0x724e0
movl %eax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
movl -0x68(%rbp), %edx
movl -0x78(%rbp), %ecx
movl -0x64(%rbp), %r8d
addl $0x1, %r8d
addl -0x6c(%rbp), %r8d
movl $0x3d, %esi
callq 0x56c10
cmpl $0x0, -0x40(%rbp)
je 0x809f4
movq -0x30(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x6be30
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x6c, %esi
callq 0x6c310
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %esi
movl -0x38(%rbp), %edx
callq 0x827c0
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x78(%rbp), %ecx
movl -0x68(%rbp), %r8d
movl $0x66, %esi
callq 0x56c10
movl $0x0, -0x74(%rbp)
jmp 0x80a7c
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x6d, %esi
callq 0x6c310
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %esi
movl -0x38(%rbp), %edx
callq 0x827c0
movl -0x44(%rbp), %eax
movl %eax, -0x68(%rbp)
movl $0x1, -0x74(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x80ab8
movq -0x30(%rbp), %rdi
movl -0x68(%rbp), %edx
movl -0x64(%rbp), %ecx
addl -0x74(%rbp), %ecx
addl -0x70(%rbp), %ecx
movl -0x5c(%rbp), %r8d
addl -0x70(%rbp), %r8d
movl $0x30, %esi
callq 0x56c10
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x80a83
movl -0x54(%rbp), %eax
movl %eax, -0x7c(%rbp)
subl $0xa, %eax
je 0x80b70
jmp 0x80ac9
movl -0x7c(%rbp), %eax
subl $0xb, %eax
je 0x80b20
jmp 0x80ad3
movl -0x7c(%rbp), %eax
subl $0xc, %eax
jne 0x80b86
jmp 0x80ae1
movq -0x30(%rbp), %rdi
movl -0x58(%rbp), %edx
movl -0x60(%rbp), %ecx
movl $0x54, %esi
callq 0x6c310
movq -0x30(%rbp), %rdi
movl -0x58(%rbp), %edx
movl -0x5c(%rbp), %ecx
movl -0x60(%rbp), %r8d
movl $0x5f, %esi
callq 0x56c10
movq -0x30(%rbp), %rdi
movl $0x8, %esi
callq 0x17b70
jmp 0x80bd0
movq -0x30(%rbp), %rdi
movl -0x5c(%rbp), %edx
movl -0x60(%rbp), %r8d
movq -0x28(%rbp), %r9
addq $0x1, %r9
movl $0x32, %esi
movl $0x1, %ecx
movl $0x1, (%rsp)
callq 0x6be70
movq -0x8(%rbp), %rdi
movl -0x5c(%rbp), %esi
movl $0x1, %edx
callq 0x6e330
movq -0x30(%rbp), %rdi
movl -0x58(%rbp), %edx
movl -0x60(%rbp), %ecx
movl $0x70, %esi
callq 0x6c310
jmp 0x80bd0
movq -0x8(%rbp), %rdi
movl -0x5c(%rbp), %esi
movl -0x58(%rbp), %edx
movl $0x1, %ecx
callq 0x80040
jmp 0x80bd0
cmpl $0x9, -0x54(%rbp)
jne 0x80bb9
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
movl -0x1c(%rbp), %ecx
movl $0x22, %esi
callq 0x6c310
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x1c(%rbp), %edx
callq 0x6e330
jmp 0x80bce
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x14, %esi
callq 0x6e570
jmp 0x80bd0
cmpl $0x0, -0x60(%rbp)
je 0x80bee
movq -0x8(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x6f9b0
movq -0x8(%rbp), %rdi
movl -0x60(%rbp), %esi
callq 0x6f9b0
movq -0x30(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x6e780
movq -0x18(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x80c20
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x3c(%rbp), %ecx
movl $0x4, %esi
callq 0x6c310
jmp 0x80c34
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %edx
movl -0x3c(%rbp), %ecx
movl $0x8, %esi
callq 0x6c310
movq -0x18(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x80c53
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
movl $0x10, %esi
callq 0x6e570
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x6e780
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)