// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, %r14
movl %ecx, -0x5c(%rbp)
movq %rdx, %r12
movq %rsi, -0x78(%rbp)
movq %rdi, %r13
movq 0x10(%rdi), %rbx
movl 0x1c(%rdx), %r15d
movq 0x30(%rbx), %rdi
callq 0x51729
movl %eax, -0x4c(%rbp)
movq (%r12), %r8
movzbl (%r14), %edi
movq %r14, -0x68(%rbp)
movl 0x4(%r14), %eax
movl %eax, -0x48(%rbp)
movl 0x14(%r12), %ecx
testl %ecx, %ecx
je 0x5fb1a
movq %r8, -0x40(%rbp)
movq %rdi, %r14
movl 0x10(%r12), %edx
movq %rbx, %rdi
movl $0xf, %esi
xorl %r8d, %r8d
callq 0x3ea9f
movq %rbx, %rdi
movl $0xe, %esi
xorl %edx, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movq 0x30(%rbx), %rax
movq 0x80(%rax), %rdx
testq %rdx, %rdx
je 0x5fb0b
movslq 0x14(%r12), %rsi
movl 0x3c(%rbx), %ecx
notq %rsi
movl %ecx, (%rdx,%rsi,4)
jmp 0x5fb0e
movl 0x3c(%rbx), %ecx
decl %ecx
movl %ecx, 0x68(%rax)
movq %r14, %rdi
movq -0x40(%rbp), %r8
movl 0xc(%r12), %edx
movl %edi, %eax
orl $0x4, %eax
cmpl $0xd, %eax
movq %r13, -0x70(%rbp)
jne 0x5fb43
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
movl $0x0, -0x44(%rbp)
movl -0x5c(%rbp), %ecx
movl %ecx, %r13d
jmp 0x5fb8e
movb 0x1f(%r13), %al
testb %al, %al
je 0x5fb71
leal -0x1(%rax), %ecx
movb %cl, 0x1f(%r13)
movzbl %cl, %ecx
movl 0x24(%r13,%rcx,4), %esi
movl %esi, -0x44(%rbp)
testb %cl, %cl
je 0x5fb7e
addb $-0x2, %al
movb %al, 0x1f(%r13)
movzbl %al, %eax
movl 0x24(%r13,%rax,4), %eax
jmp 0x5fb88
movl 0x54(%r13), %eax
incl %eax
movl %eax, -0x44(%rbp)
movl %eax, 0x54(%r13)
movl 0x54(%r13), %eax
incl %eax
movl %eax, 0x54(%r13)
movl $0x1, %r13d
movl (%r8), %ecx
subl 0x8(%r12), %ecx
movq %rcx, -0x80(%rbp)
testb $0x1, 0x20(%r12)
movl %r15d, -0x30(%rbp)
movq %r12, -0x58(%rbp)
movl %edx, -0x40(%rbp)
movl %eax, -0x34(%rbp)
movq %rdi, -0x88(%rbp)
jne 0x5fbfc
movq %rbx, %rdi
movl $0x6d, %esi
movl %r15d, %ecx
movl %edx, %r14d
xorl %r8d, %r8d
callq 0x3ea9f
movl %eax, -0x2c(%rbp)
movq -0x78(%rbp), %rax
movl 0x10(%rax), %edx
movl $0x1, %r15d
testl %edx, %edx
jle 0x5fbf7
movq %rbx, %rdi
movl $0x8b, %esi
movl -0x4c(%rbp), %ecx
movl $0x1, %r8d
callq 0x3ea9f
jmp 0x5fcfb
movq -0x70(%rbp), %r15
movl 0x50(%r15), %r14d
movq %r12, %rcx
movl 0x54(%r15), %r12d
incl %r12d
movl %r12d, 0x54(%r15)
leal 0x1(%r14), %eax
movl %eax, 0x50(%r15)
cmpl $0x0, 0x14(%rcx)
je 0x5fc4a
movq %r15, %rdi
callq 0x4f63b
movl 0x5c(%r15), %edx
leal 0x1(%rdx), %ecx
movl %ecx, 0x5c(%r15)
movq %rax, %rdi
movl $0x2d, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl %eax, %r15d
jmp 0x5fc4d
xorl %r15d, %r15d
movq -0x80(%rbp), %rax
leal (%rax,%r13), %r8d
incl %r8d
movq %rbx, %rdi
movl $0x3d, %esi
movl %r14d, %edx
movl %r12d, %ecx
callq 0x3ea9f
testl %r15d, %r15d
movl -0x40(%rbp), %edx
je 0x5fcab
movl 0x3c(%rbx), %eax
leal -0x1(%rax), %ecx
movq 0x30(%rbx), %rsi
movl %ecx, 0x68(%rsi)
movq (%rbx), %rsi
cmpb $0x0, 0x51(%rsi)
je 0x5fc92
leaq 0x33868(%rip), %rcx     # 0x934f8
jmp 0x5fca8
testl %r15d, %r15d
cmovnsl %r15d, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%rbx), %rcx
movl %eax, 0x8(%rcx)
xorl %r15d, %r15d
movq %rbx, %rdi
movl $0x6c, %esi
movl -0x30(%rbp), %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl %eax, -0x2c(%rbp)
movq -0x78(%rbp), %rax
movl 0x10(%rax), %edx
testl %edx, %edx
jle 0x5fce5
movq %rbx, %rdi
movl $0x8b, %esi
movl -0x4c(%rbp), %ecx
movl $0x1, %r8d
callq 0x3ea9f
movq %rbx, %rdi
movl $0x66, %esi
movl -0x40(%rbp), %edx
movl %r12d, %ecx
movl %r14d, %r8d
callq 0x3ea9f
testl %r13d, %r13d
jle 0x5fd29
addl -0x80(%rbp), %r15d
movl -0x34(%rbp), %r12d
movq %rbx, %rdi
movl $0x30, %esi
movl %r14d, %edx
movl %r15d, %ecx
movl %r12d, %r8d
callq 0x3ea9f
incl %r12d
incl %r15d
decl %r13d
jne 0x5fd08
movq -0x88(%rbp), %rcx
addl $-0x9, %ecx
cmpl $0x3, %ecx
ja 0x5fe77
leaq 0x18569(%rip), %rax     # 0x782ac
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
movq -0x70(%rbp), %r12
movl -0x44(%rbp), %r13d
jmpq *%rcx
movq -0x68(%rbp), %r14
movl 0x8(%r14), %edx
movq %rbx, %rdi
movl $0x22, %esi
movl -0x5c(%rbp), %r15d
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl 0x8(%r14), %esi
movq %r12, %rdi
movl %r15d, %edx
callq 0x51780
movl -0x30(%rbp), %r14d
movq -0x58(%rbp), %r15
movl -0x40(%rbp), %edx
jmp 0x5fea3
movq -0x68(%rbp), %r15
incq %r15
movq %rbx, %rdi
movl $0x32, %esi
movl -0x34(%rbp), %r14d
movl %r14d, %edx
movl $0x1, %ecx
movl %r13d, %r8d
callq 0x3ea9f
movq %rbx, %rdi
movl %eax, %esi
movq %r15, %rdx
movl $0x1, %ecx
callq 0x14b4f
movq %r12, %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x51780
movq %rbx, %rdi
movl $0x70, %esi
movl -0x48(%rbp), %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
jmp 0x5fe67
movq %rbx, %rdi
movl $0x54, %esi
movl -0x48(%rbp), %r14d
movl %r14d, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movq %rbx, %rdi
movl $0x5f, %esi
movl %r14d, %edx
movl -0x34(%rbp), %ecx
movl %r13d, %r8d
callq 0x3ea9f
movq (%rbx), %rax
cmpb $0x0, 0x51(%rax)
movq -0x58(%rbp), %r15
je 0x5feab
leaq 0x336c5(%rip), %rax     # 0x934f8
jmp 0x5febf
movq 0x10(%r12), %rdi
movl $0x1e, %esi
movl -0x34(%rbp), %r14d
movl %r14d, %edx
movl -0x48(%rbp), %ecx
movl $0x1, %r8d
callq 0x3ea9f
movq %r12, %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x51780
movl %r14d, %edi
movl -0x30(%rbp), %r14d
movq -0x58(%rbp), %r15
movl -0x40(%rbp), %edx
jmp 0x5fea6
movq -0x68(%rbp), %rax
movl 0x4(%rax), %edx
movq %rbx, %rdi
movl $0x14, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movl -0x30(%rbp), %r14d
movq -0x58(%rbp), %r15
movq -0x70(%rbp), %r12
movl -0x40(%rbp), %edx
movl -0x44(%rbp), %r13d
movl -0x34(%rbp), %edi
movl -0x2c(%rbp), %ecx
jmp 0x5fed0
movslq 0x3c(%rbx), %rax
movq 0x8(%rbx), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
addq $-0x18, %rax
movl -0x30(%rbp), %r14d
movl -0x40(%rbp), %edx
movl -0x2c(%rbp), %ecx
movb $0x8, 0x3(%rax)
movl -0x34(%rbp), %edi
testl %r13d, %r13d
je 0x5ff4c
movb 0x1f(%r12), %al
testl %edi, %edi
je 0x5ff15
cmpb $0x7, %al
ja 0x5ff4c
movzbl %al, %r8d
xorl %esi, %esi
cmpl %edi, 0x94(%r12,%rsi)
je 0x5ff0c
addq $0x14, %rsi
cmpl $0xc8, %esi
jne 0x5fee8
incb %al
movb %al, 0x1f(%r12)
movl %edi, 0x24(%r12,%r8,4)
jmp 0x5ff15
movb $0x1, 0x8e(%r12,%rsi)
cmpb $0x7, %al
ja 0x5ff4c
xorl %esi, %esi
cmpl %r13d, 0x94(%r12,%rsi)
je 0x5ff43
addq $0x14, %rsi
cmpl $0xc8, %esi
jne 0x5ff1b
leal 0x1(%rax), %esi
movb %sil, 0x1f(%r12)
movzbl %al, %eax
movl %r13d, 0x24(%r12,%rax,4)
jmp 0x5ff4c
movb $0x1, 0x8e(%r12,%rsi)
incl %ecx
movq 0x30(%rbx), %rax
movq 0x80(%rax), %rdi
testq %rdi, %rdi
je 0x5ff70
movl -0x4c(%rbp), %esi
notl %esi
movl 0x3c(%rbx), %r8d
movslq %esi, %rsi
movl %r8d, (%rdi,%rsi,4)
jmp 0x5ff74
movl 0x3c(%rbx), %r8d
decl %r8d
movl %r8d, 0x68(%rax)
xorl %eax, %eax
testb $0x1, 0x20(%r15)
sete %al
leal 0x4(,%rax,4), %esi
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0x3ea9f
movl 0x10(%r15), %edx
testl %edx, %edx
je 0x5ffb1
movq %rbx, %rdi
movl $0x10, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3ea9f
movq 0x30(%rbx), %rax
movq 0x80(%rax), %rdx
testq %rdx, %rdx
je 0x5ffcf
notl %r14d
movl 0x3c(%rbx), %ecx
movslq %r14d, %rsi
movl %ecx, (%rdx,%rsi,4)
jmp 0x5ffd2
movl 0x3c(%rbx), %ecx
decl %ecx
movl %ecx, 0x68(%rax)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq