// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: generateSortTail
static void generateSortTail(
  Parse *pParse,    /* Parsing context */
  Select *p,        /* The SELECT statement */
  Vdbe *v,          /* Generate code into this VDBE */
  int nColumn,      /* Number of columns of data */
  SelectDest *pDest /* Write the sorted results here */
){
  int addrBreak = sqlite3VdbeMakeLabel(v);     /* Jump here to exit loop */
  int addrContinue = sqlite3VdbeMakeLabel(v);  /* Jump here for next cycle */
  int addr;
  int iTab;
  int pseudoTab = 0;
  ExprList *pOrderBy = p->pOrderBy;

  int eDest = pDest->eDest;
  int iParm = pDest->iSDParm;

  int regRow;
  int regRowid;

  iTab = pOrderBy->iECursor;
  regRow = sqlite3GetTempReg(pParse);
  if( eDest==SRT_Output || eDest==SRT_Coroutine ){
    pseudoTab = pParse->nTab++;
    sqlite3VdbeAddOp3(v, OP_OpenPseudo, pseudoTab, regRow, nColumn);
    regRowid = 0;
  }else{
    regRowid = sqlite3GetTempReg(pParse);
  }
  if( p->selFlags & SF_UseSorter ){
    int regSortOut = ++pParse->nMem;
    int ptab2 = pParse->nTab++;
    sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
    addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
    codeOffset(v, p, addrContinue);
    sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
    sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
    sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
  }else{
    addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak);
    codeOffset(v, p, addrContinue);
    sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
  }
  switch( eDest ){
    case SRT_Table:
    case SRT_EphemTab: {
      testcase( eDest==SRT_Table );
      testcase( eDest==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: {
      int i;
      assert( eDest==SRT_Output || eDest==SRT_Coroutine ); 
      testcase( eDest==SRT_Output );
      testcase( eDest==SRT_Coroutine );
      for(i=0; i<nColumn; i++){
        assert( regRow!=pDest->iSdst+i );
        sqlite3VdbeAddOp3(v, OP_Column, pseudoTab, i, pDest->iSdst+i);
        if( i==0 ){
          sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
        }
      }
      if( eDest==SRT_Output ){
        sqlite3VdbeAddOp2(v, OP_ResultRow, pDest->iSdst, nColumn);
        sqlite3ExprCacheAffinityChange(pParse, pDest->iSdst, nColumn);
      }else{
        sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
      }
      break;
    }
  }
  sqlite3ReleaseTempReg(pParse, regRow);
  sqlite3ReleaseTempReg(pParse, regRowid);

  /* The bottom of the loop
  */
  sqlite3VdbeResolveLabel(v, addrContinue);
  if( p->selFlags & SF_UseSorter ){
    sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr);
  }else{
    sqlite3VdbeAddOp2(v, OP_Next, iTab, addr);
  }
  sqlite3VdbeResolveLabel(v, addrBreak);
  if( eDest==SRT_Output || eDest==SRT_Coroutine ){
    sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x67890
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x67890
movl %eax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x66a70
movl %eax, -0x54(%rbp)
cmpl $0x5, -0x4c(%rbp)
je 0x6fdec
cmpl $0xa, -0x4c(%rbp)
jne 0x6fe1f
movq -0x8(%rbp), %rcx
movl 0x54(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x54(%rcx)
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x54(%rbp), %ecx
movl -0x1c(%rbp), %r8d
movl $0x35, %esi
callq 0x5e0f0
movl $0x0, -0x58(%rbp)
jmp 0x6fe2b
movq -0x8(%rbp), %rdi
callq 0x66a70
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x6feec
movq -0x8(%rbp), %rcx
movl 0x58(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x58(%rcx)
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rcx
movl 0x54(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x54(%rcx)
movl %eax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movl -0x60(%rbp), %edx
movl -0x5c(%rbp), %ecx
movq -0x48(%rbp), %rax
movl (%rax), %r8d
addl $0x2, %r8d
movl $0x35, %esi
callq 0x5e0f0
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl $0x63, %esi
callq 0x5e0c0
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x30(%rbp), %edx
callq 0x71b50
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %edx
movl -0x5c(%rbp), %ecx
movl $0x51, %esi
callq 0x5e0c0
movq -0x18(%rbp), %rdi
movl -0x60(%rbp), %edx
movq -0x48(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl -0x54(%rbp), %r8d
movl $0x29, %esi
callq 0x5e0f0
movq -0x18(%rbp), %rdi
movl $0x20, %esi
callq 0x5e540
jmp 0x6ff34
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl $0x64, %esi
callq 0x5e0c0
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x30(%rbp), %edx
callq 0x71b50
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %edx
movq -0x48(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl -0x54(%rbp), %r8d
movl $0x29, %esi
callq 0x5e0f0
movl -0x4c(%rbp), %eax
movl %eax, -0x68(%rbp)
subl $0x6, %eax
je 0x6fff2
jmp 0x6ff45
movl -0x68(%rbp), %eax
subl $0x7, %eax
je 0x6ff9f
jmp 0x6ff4f
movl -0x68(%rbp), %eax
addl $-0x8, %eax
subl $0x1, %eax
ja 0x7000b
jmp 0x6ff60
movq -0x18(%rbp), %rdi
movl -0x50(%rbp), %edx
movl -0x58(%rbp), %ecx
movl $0x41, %esi
callq 0x5e0c0
movq -0x18(%rbp), %rdi
movl -0x50(%rbp), %edx
movl -0x54(%rbp), %ecx
movl -0x58(%rbp), %r8d
movl $0x42, %esi
callq 0x5e0f0
movq -0x18(%rbp), %rdi
movl $0x8, %esi
callq 0x5e540
jmp 0x700a5
movq -0x18(%rbp), %rdi
movl -0x54(%rbp), %edx
movl -0x58(%rbp), %r8d
movq -0x28(%rbp), %r9
addq $0x1, %r9
movl $0x2b, %esi
movl $0x1, %ecx
movl $0x1, (%rsp)
callq 0x5e1b0
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %esi
movl $0x1, %edx
callq 0x69c40
movq -0x18(%rbp), %rdi
movl -0x50(%rbp), %edx
movl -0x58(%rbp), %ecx
movl $0x67, %esi
callq 0x5e0c0
jmp 0x700a5
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %esi
movl -0x50(%rbp), %edx
movl $0x1, %ecx
callq 0x6f4f0
jmp 0x700a5
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x7005b
movq -0x18(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl -0x64(%rbp), %ecx
movq -0x28(%rbp), %rax
movl 0x8(%rax), %r8d
addl -0x64(%rbp), %r8d
movl $0x29, %esi
callq 0x5e0f0
cmpl $0x0, -0x64(%rbp)
jne 0x7004e
movq -0x18(%rbp), %rdi
movl $0x20, %esi
callq 0x5e540
jmp 0x70050
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x70012
cmpl $0x5, -0x4c(%rbp)
jne 0x7008e
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
movl -0x1c(%rbp), %ecx
movl $0x1e, %esi
callq 0x5e0c0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x1c(%rbp), %edx
callq 0x69c40
jmp 0x700a3
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x11, %esi
callq 0x5ecf0
jmp 0x700a5
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x66ac0
movq -0x8(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x66ac0
movq -0x18(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x677f0
movq -0x10(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x700ef
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x5, %esi
callq 0x5e0c0
jmp 0x70103
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %edx
movl -0x34(%rbp), %ecx
movl $0x7, %esi
callq 0x5e0c0
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x677f0
cmpl $0x5, -0x4c(%rbp)
je 0x7011b
cmpl $0xa, -0x4c(%rbp)
jne 0x7012e
movq -0x18(%rbp), %rdi
movl -0x3c(%rbp), %edx
movl $0x36, %esi
xorl %ecx, %ecx
callq 0x5e0c0
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)