// File: /workspace/github_c_makefile_star2_O2/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: pushOntoSorter
static void pushOntoSorter(
  Parse *pParse,         /* Parser context */
  SortCtx *pSort,        /* Information about the ORDER BY clause */
  Select *pSelect,       /* The whole SELECT statement */
  int regData,           /* First register holding data to be sorted */
  int regOrigData,       /* First register holding data before packing */
  int nData,             /* Number of elements in the data array */
  int nPrefixReg         /* No. of reg prior to regData available for use */
){
  Vdbe *v = pParse->pVdbe;                         /* Stmt under construction */
  int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);
  int nExpr = pSort->pOrderBy->nExpr;              /* No. of ORDER BY terms */
  int nBase = nExpr + bSeq + nData;                /* Fields in sorter record */
  int regBase;                                     /* Regs for sorter record */
  int regRecord = ++pParse->nMem;                  /* Assembled sorter record */
  int nOBSat = pSort->nOBSat;                      /* ORDER BY terms to skip */
  int op;                            /* Opcode to add sorter record to sorter */
  int iLimit;                        /* LIMIT counter */

  assert( bSeq==0 || bSeq==1 );
  assert( nData==1 || regData==regOrigData );
  if( nPrefixReg ){
    assert( nPrefixReg==nExpr+bSeq );
    regBase = regData - nExpr - bSeq;
  }else{
    regBase = pParse->nMem + 1;
    pParse->nMem += nBase;
  }
  assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
  iLimit = pSelect->iOffset ? pSelect->iOffset+1 : pSelect->iLimit;
  pSort->labelDone = sqlite3VdbeMakeLabel(v);
  sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
                          SQLITE_ECEL_DUP|SQLITE_ECEL_REF);
  if( bSeq ){
    sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
  }
  if( nPrefixReg==0 ){
    sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
  }
  sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regRecord);
  if( nOBSat>0 ){
    int regPrevKey;   /* The first nOBSat columns of the previous row */
    int addrFirst;    /* Address of the OP_IfNot opcode */
    int addrJmp;      /* Address of the OP_Jump opcode */
    VdbeOp *pOp;      /* Opcode that opens the sorter */
    int nKey;         /* Number of sorting key columns, including OP_Sequence */
    KeyInfo *pKI;     /* Original KeyInfo on the sorter table */

    regPrevKey = pParse->nMem+1;
    pParse->nMem += pSort->nOBSat;
    nKey = nExpr - pSort->nOBSat + bSeq;
    if( bSeq ){
      addrFirst = sqlite3VdbeAddOp1(v, OP_IfNot, regBase+nExpr); 
    }else{
      addrFirst = sqlite3VdbeAddOp1(v, OP_SequenceTest, pSort->iECursor);
    }
    VdbeCoverage(v);
    sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat);
    pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);
    if( pParse->db->mallocFailed ) return;
    pOp->p2 = nKey + nData;
    pKI = pOp->p4.pKeyInfo;
    memset(pKI->aSortOrder, 0, pKI->nField); /* Makes OP_Jump below testable */
    sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
    testcase( pKI->nXField>2 );
    pOp->p4.pKeyInfo = keyInfoFromExprList(pParse, pSort->pOrderBy, nOBSat,
                                           pKI->nXField-1);
    addrJmp = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
    pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
    pSort->regReturn = ++pParse->nMem;
    sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
    sqlite3VdbeAddOp1(v, OP_ResetSorter, pSort->iECursor);
    if( iLimit ){
      sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, pSort->labelDone);
      VdbeCoverage(v);
    }
    sqlite3VdbeJumpHere(v, addrFirst);
    sqlite3ExprCodeMove(pParse, regBase, regPrevKey, pSort->nOBSat);
    sqlite3VdbeJumpHere(v, addrJmp);
  }
  if( pSort->sortFlags & SORTFLAG_UseSorter ){
    op = OP_SorterInsert;
  }else{
    op = OP_IdxInsert;
  }
  sqlite3VdbeAddOp2(v, op, pSort->iECursor, regRecord);
  if( iLimit ){
    int addr;
    addr = sqlite3VdbeAddOp3(v, OP_IfNotZero, iLimit, 0, 1); VdbeCoverage(v);
    sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
    sqlite3VdbeAddOp1(v, OP_Delete, pSort->iECursor);
    sqlite3VdbeJumpHere(v, addr);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, -0x48(%rbp)
movq %rsi, %r14
movq %rdi, %r12
movl 0x10(%rbp), %r8d
movq 0x10(%rdi), %rax
movq %rax, -0x38(%rbp)
movzbl 0x20(%rsi), %ebx
andl $0x1, %ebx
movl %ebx, %r13d
xorl $0x1, %r13d
movq (%rsi), %rax
movl (%rax), %esi
movq %rsi, -0x40(%rbp)
addl %esi, %r13d
movl 0x54(%rdi), %r15d
leal 0x1(%r15), %edi
movl %edi, 0x54(%r12)
movq %r9, -0x78(%rbp)
leal (%r13,%r9), %esi
movl 0x8(%r14), %eax
movq %rax, -0x68(%rbp)
movl %r8d, -0x50(%rbp)
testl %r8d, %r8d
je 0x5d383
movl %ecx, %r15d
subl %r13d, %r15d
jmp 0x5d38f
addl $0x2, %r15d
leal (%rsi,%rdi), %eax
movl %eax, 0x54(%r12)
movl 0x10(%rdx), %eax
testl %eax, %eax
movq %rdi, -0x70(%rbp)
movq %rsi, -0x60(%rbp)
movl %ecx, -0x54(%rbp)
je 0x5d3a5
incl %eax
jmp 0x5d3a8
movl 0xc(%rdx), %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4b9c2
movl %eax, 0x1c(%r14)
movq (%r14), %rsi
pushq $0x5
popq %r8
movq %r12, %rdi
movl %r15d, %edx
movl -0x48(%rbp), %ecx
callq 0x4bc86
testb %bl, %bl
jne 0x5d3e9
movl 0xc(%r14), %edx
movq -0x40(%rbp), %rax
leal (%r15,%rax), %ecx
pushq $0x4b
popq %rsi
movq -0x38(%rbp), %rdi
callq 0x4a1ab
cmpl $0x0, -0x50(%rbp)
jne 0x5d404
addl %r15d, %r13d
movq %r12, %rdi
movl -0x54(%rbp), %esi
movl %r13d, %edx
movq -0x78(%rbp), %rcx
callq 0x57296
movq %r15, %rax
movq %r12, %r15
movq -0x68(%rbp), %r12
movq %rax, -0x50(%rbp)
leal (%rax,%r12), %edx
movq -0x60(%rbp), %rax
movl %eax, %ecx
subl %r12d, %ecx
pushq $0x32
popq %rsi
movq -0x38(%rbp), %r13
movq %r13, %rdi
movq -0x70(%rbp), %r8
callq 0x385b6
testl %r12d, %r12d
jle 0x5d5aa
movq %r15, %r12
movl 0x54(%r15), %ecx
movl 0x8(%r14), %r13d
leal (%rcx,%r13), %eax
incl %ecx
movq %rcx, -0x48(%rbp)
movl %eax, 0x54(%r15)
testb %bl, %bl
je 0x5d474
movl 0xc(%r14), %edx
pushq $0x3c
popq %rsi
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x4b9b3
movl %eax, -0x40(%rbp)
movq -0x50(%rbp), %r15
jmp 0x5d491
movq -0x50(%rbp), %r15
movq -0x40(%rbp), %rdx
addl %r15d, %edx
pushq $0x2f
popq %rsi
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x4b9b3
movl %eax, -0x40(%rbp)
movl 0x8(%r14), %r8d
pushq $0x2b
popq %rsi
movq %rbx, %rdi
movq -0x48(%rbp), %rdx
movl %r15d, %ecx
callq 0x385b6
movq (%r12), %rax
cmpb $0x0, 0x51(%rax)
movl -0x2c(%rbp), %eax
jne 0x5d61b
movl 0x18(%r14), %esi
movq %rbx, %rdi
movl %eax, -0x2c(%rbp)
callq 0x386ca
movq %rax, -0x38(%rbp)
movq -0x60(%rbp), %rcx
subl %r13d, %ecx
movl %ecx, 0x8(%rax)
movq 0x10(%rax), %r13
movq 0x18(%r13), %rdi
movzwl 0x6(%r13), %edx
xorl %esi, %esi
callq 0xa270
pushq $-0x1
popq %rsi
pushq $-0x6
popq %rcx
movq %rbx, %rdi
movq %r13, %rdx
callq 0x1385d
movq (%r14), %rsi
movzwl 0x8(%r13), %ecx
decl %ecx
movq %r12, %rdi
movq -0x68(%rbp), %rdx
callq 0x5387e
movq -0x38(%rbp), %rcx
movq %rax, 0x10(%rcx)
movl 0x3c(%rbx), %r13d
leal 0x1(%r13), %edx
pushq $0x2c
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
movl %edx, %r8d
callq 0x385b6
movq %rbx, %rdi
callq 0x4b9c2
movl %eax, 0x14(%r14)
movl 0x54(%r12), %edx
incl %edx
movl %edx, 0x54(%r12)
movl %edx, 0x10(%r14)
pushq $0xf
popq %rsi
movq %rbx, %rdi
movl %eax, %ecx
callq 0x4a1ab
movl 0xc(%r14), %edx
pushq $0x79
popq %rsi
movq %rbx, %rdi
callq 0x4b9b3
movl -0x2c(%rbp), %edx
testl %edx, %edx
je 0x5d57e
movl 0x1c(%r14), %ecx
pushq $0x2f
popq %rsi
movq %rbx, %rdi
callq 0x4a1ab
movq %rbx, %rdi
movl -0x40(%rbp), %esi
callq 0x4a022
movl 0x8(%r14), %ecx
movq %r12, %rdi
movl %r15d, %esi
movq -0x48(%rbp), %rdx
callq 0x57296
movq %rbx, %rdi
movl %r13d, %esi
callq 0x4a022
movq %rbx, %r13
movzbl 0x20(%r14), %eax
andl $0x1, %eax
pushq $0x70
popq %rsi
subl %eax, %esi
movl 0xc(%r14), %edx
movq %r13, %rdi
movq -0x70(%rbp), %rcx
callq 0x4a1ab
movl -0x2c(%rbp), %edx
testl %edx, %edx
je 0x5d61b
pushq $0x1
popq %r8
movq %r13, %rdi
movl $0x8d, %esi
xorl %ecx, %ecx
callq 0x385b6
movl %eax, %r15d
movl 0xc(%r14), %edx
pushq $0x6b
popq %rsi
movq %r13, %rdi
callq 0x4b9b3
movl 0xc(%r14), %edx
pushq $0x63
popq %rsi
movq %r13, %rdi
callq 0x4b9b3
movq %r13, %rdi
movl %r15d, %esi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4a022
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq