// File: /workspace/github_c_makefile_star2_O1/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 %rbx, %rdi
callq 0x528c8
movl %eax, -0x4c(%rbp)
movq (%r12), %rdi
movzbl (%r14), %esi
movq %r14, -0x68(%rbp)
movl 0x4(%r14), %eax
movl %eax, -0x48(%rbp)
movl 0x14(%r12), %ecx
testl %ecx, %ecx
movq %rsi, -0x88(%rbp)
je 0x61112
movq %rdi, -0x40(%rbp)
movl 0x10(%r12), %edx
movq %rbx, %rdi
movl $0xf, %esi
xorl %r8d, %r8d
callq 0x3fa9e
movq %rbx, %rdi
movl $0xe, %esi
xorl %edx, %edx
movl %r15d, %r14d
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movq 0x30(%rbx), %rax
movq 0x80(%rax), %rcx
testq %rcx, %rcx
je 0x610fc
movslq 0x14(%r12), %rdx
movl 0x3c(%rbx), %esi
notq %rdx
movl %esi, (%rcx,%rdx,4)
movl 0x3c(%rbx), %ecx
decl %ecx
movl %ecx, 0x68(%rax)
movq -0x88(%rbp), %rsi
movq -0x40(%rbp), %rdi
movl %r14d, %r15d
movl 0xc(%r12), %edx
movl %esi, %eax
orl $0x4, %eax
cmpl $0xd, %eax
movq %r13, -0x70(%rbp)
jne 0x6113b
movq -0x68(%rbp), %rax
movl 0x8(%rax), %eax
movl $0x0, -0x44(%rbp)
movl -0x5c(%rbp), %ecx
movl %ecx, %r13d
jmp 0x6118b
movb 0x1f(%r13), %al
testb %al, %al
je 0x61156
decb %al
movb %al, 0x1f(%r13)
movzbl %al, %eax
movl 0x24(%r13,%rax,4), %eax
movl %eax, -0x44(%rbp)
jmp 0x61163
movl 0x54(%r13), %eax
incl %eax
movl %eax, -0x44(%rbp)
movl %eax, 0x54(%r13)
movb 0x1f(%r13), %al
testb %al, %al
je 0x6117b
decb %al
movb %al, 0x1f(%r13)
movzbl %al, %eax
movl 0x24(%r13,%rax,4), %eax
jmp 0x61185
movl 0x54(%r13), %eax
incl %eax
movl %eax, 0x54(%r13)
movl $0x1, %r13d
movl %eax, -0x30(%rbp)
movl (%rdi), %eax
subl 0x8(%r12), %eax
movq %rax, -0x80(%rbp)
testb $0x1, 0x20(%r12)
movl %r15d, -0x34(%rbp)
movq %r12, -0x58(%rbp)
movl %edx, -0x40(%rbp)
jne 0x611f4
movq %rbx, %rdi
movl $0x6d, %esi
movl %r15d, %ecx
movl %edx, %r14d
xorl %r8d, %r8d
callq 0x3fa9e
movl %eax, -0x2c(%rbp)
movq -0x78(%rbp), %rax
movl 0x10(%rax), %edx
movl $0x1, %r15d
testl %edx, %edx
jle 0x611ec
movq %rbx, %rdi
movl $0x8b, %esi
movl -0x4c(%rbp), %ecx
movl $0x1, %r8d
callq 0x3fa9e
movl %r14d, %r12d
jmp 0x612f4
movq %r12, %rcx
movq -0x70(%rbp), %r15
movl 0x50(%r15), %r12d
movl 0x54(%r15), %r14d
incl %r14d
movl %r14d, 0x54(%r15)
leal 0x1(%r12), %eax
movl %eax, 0x50(%r15)
cmpl $0x0, 0x14(%rcx)
je 0x61243
movq %r15, %rdi
callq 0x507bf
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 0x3fa9e
movl %eax, %r15d
jmp 0x61246
xorl %r15d, %r15d
movq -0x80(%rbp), %rax
leal (%rax,%r13), %r8d
incl %r8d
movq %rbx, %rdi
movl $0x3d, %esi
movl %r12d, %edx
movl %r14d, %ecx
callq 0x3fa9e
testl %r15d, %r15d
movl -0x40(%rbp), %edx
je 0x612a4
movl 0x3c(%rbx), %eax
leal -0x1(%rax), %ecx
movq 0x30(%rbx), %rsi
movl %ecx, 0x68(%rsi)
movq (%rbx), %rsi
cmpb $0x0, 0x51(%rsi)
je 0x6128b
leaq 0x3425f(%rip), %rcx     # 0x954e8
jmp 0x612a1
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 -0x34(%rbp), %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl %eax, -0x2c(%rbp)
movq -0x78(%rbp), %rax
movl 0x10(%rax), %edx
testl %edx, %edx
jle 0x612de
movq %rbx, %rdi
movl $0x8b, %esi
movl -0x4c(%rbp), %ecx
movl $0x1, %r8d
callq 0x3fa9e
movq %rbx, %rdi
movl $0x66, %esi
movl -0x40(%rbp), %edx
movl %r14d, %ecx
movl %r12d, %r8d
callq 0x3fa9e
testl %r13d, %r13d
jle 0x61322
addl -0x80(%rbp), %r15d
movl -0x30(%rbp), %r14d
movq %rbx, %rdi
movl $0x30, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0x3fa9e
incl %r14d
incl %r15d
decl %r13d
jne 0x61301
movq -0x88(%rbp), %rcx
addl $-0x9, %ecx
cmpl $0x3, %ecx
ja 0x6145d
leaq 0x18f3c(%rip), %rax     # 0x7a278
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
movl -0x34(%rbp), %r15d
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 0x3fa9e
movl 0x8(%r14), %esi
movq %r12, %rdi
movl %r15d, %edx
movl -0x34(%rbp), %r15d
jmp 0x61450
movq -0x68(%rbp), %r15
incq %r15
movq %rbx, %rdi
movl $0x32, %esi
movl -0x30(%rbp), %r14d
movl %r14d, %edx
movl $0x1, %ecx
movl %r13d, %r8d
callq 0x3fa9e
movq %rbx, %rdi
movl %eax, %esi
movq %r15, %rdx
movl -0x34(%rbp), %r15d
movl $0x1, %ecx
callq 0x14ab9
movq %r12, %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x5291f
movq %rbx, %rdi
movl $0x70, %esi
movl -0x48(%rbp), %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
jmp 0x61455
movq %rbx, %rdi
movl $0x54, %esi
movl -0x48(%rbp), %r14d
movl %r14d, %edx
movl %r13d, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movq %rbx, %rdi
movl $0x5f, %esi
movl %r14d, %edx
movl -0x30(%rbp), %ecx
movl %r13d, %r8d
callq 0x3fa9e
movq (%rbx), %rax
cmpb $0x0, 0x51(%rax)
je 0x6148e
leaq 0x340c4(%rip), %rax     # 0x954e8
jmp 0x614a2
movq 0x10(%r12), %rdi
movl $0x1e, %esi
movl -0x30(%rbp), %r14d
movl %r14d, %edx
movl -0x48(%rbp), %ecx
movl $0x1, %r8d
callq 0x3fa9e
movq %r12, %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x5291f
movl -0x40(%rbp), %edx
movl -0x2c(%rbp), %ecx
jmp 0x614ac
movq -0x68(%rbp), %rax
movl 0x4(%rax), %edx
movq %rbx, %rdi
movl $0x14, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl -0x34(%rbp), %r15d
movq -0x58(%rbp), %r14
movq -0x70(%rbp), %r12
movl -0x40(%rbp), %edx
movl -0x44(%rbp), %r13d
movl -0x2c(%rbp), %ecx
jmp 0x614b0
movslq 0x3c(%rbx), %rax
movq 0x8(%rbx), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
addq $-0x18, %rax
movl -0x40(%rbp), %edx
movl -0x2c(%rbp), %ecx
movb $0x8, 0x3(%rax)
movq -0x58(%rbp), %r14
testl %r13d, %r13d
je 0x61534
movl -0x30(%rbp), %esi
testl %esi, %esi
je 0x614f8
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x614f8
xorl %edi, %edi
cmpl %esi, 0x94(%r12,%rdi)
je 0x614ef
addq $0x14, %rdi
cmpl $0xc8, %edi
jne 0x614ca
leal 0x1(%rax), %edi
movb %dil, 0x1f(%r12)
movl %esi, 0x24(%r12,%rax,4)
jmp 0x614f8
movb $0x1, 0x8e(%r12,%rdi)
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x61534
xorl %esi, %esi
cmpl %r13d, 0x94(%r12,%rsi)
je 0x6152b
addq $0x14, %rsi
cmpl $0xc8, %esi
jne 0x61506
leal 0x1(%rax), %esi
movb %sil, 0x1f(%r12)
movl %r13d, 0x24(%r12,%rax,4)
jmp 0x61534
movb $0x1, 0x8e(%r12,%rsi)
incl %ecx
movq 0x30(%rbx), %rax
movq 0x80(%rax), %r8
testq %r8, %r8
je 0x61555
movl -0x4c(%rbp), %esi
notl %esi
movl 0x3c(%rbx), %edi
movslq %esi, %rsi
movl %edi, (%r8,%rsi,4)
movl 0x3c(%rbx), %esi
decl %esi
movl %esi, 0x68(%rax)
xorl %eax, %eax
testb $0x1, 0x20(%r14)
sete %al
leal 0x4(,%rax,4), %esi
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0x3fa9e
movl 0x10(%r14), %edx
testl %edx, %edx
je 0x61593
movq %rbx, %rdi
movl $0x10, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movq 0x30(%rbx), %rax
movq 0x80(%rax), %rcx
testq %rcx, %rcx
je 0x615af
notl %r15d
movl 0x3c(%rbx), %edx
movslq %r15d, %rsi
movl %edx, (%rcx,%rsi,4)
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