// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %r8d, -0x30(%rbp)
movl %ecx, %r13d
movq %rsi, %r14
movq %rdi, %rbx
movq 0x10(%rdi), %rax
movq %rax, -0x40(%rbp)
movzbl 0x20(%rsi), %r15d
andl $0x1, %r15d
movl %r15d, %r12d
xorl $0x1, %r12d
movq (%rsi), %rax
movl (%rax), %esi
movq %rsi, -0x58(%rbp)
addl %esi, %r12d
movl 0x54(%rdi), %esi
leal 0x1(%rsi), %r8d
movl %r8d, 0x54(%rdi)
movq %r9, -0x70(%rbp)
leal (%r12,%r9), %edi
movl 0x8(%r14), %eax
movq %rax, -0x60(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x6a5b9
movl %r13d, %esi
subl %r12d, %esi
jmp 0x6a5c3
addl $0x2, %esi
leal (%rdi,%r8), %eax
movl %eax, 0x54(%rbx)
movq %rbx, -0x50(%rbp)
movq %rsi, -0x38(%rbp)
movl 0x10(%rdx), %eax
testl %eax, %eax
movq %r8, -0x68(%rbp)
movq %rdi, -0x48(%rbp)
je 0x6a5de
incl %eax
jmp 0x6a5e1
movl 0xc(%rdx), %eax
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x528c8
movl %eax, 0x1c(%r14)
movq (%r14), %rsi
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rdx
movl -0x30(%rbp), %ecx
movl $0x5, %r8d
callq 0x52b74
testb %r15b, %r15b
jne 0x6a630
movl 0xc(%r14), %edx
movq -0x38(%rbp), %rax
movq -0x58(%rbp), %rcx
addl %eax, %ecx
movq %rbx, %rdi
movl $0x4b, %esi
xorl %r8d, %r8d
callq 0x3fa9e
cmpl $0x0, 0x10(%rbp)
jne 0x6a66b
addl -0x38(%rbp), %r12d
movq -0x50(%rbp), %rbx
movq 0x10(%rbx), %rdi
movl $0x1e, %esi
movl %r13d, %edx
movl %r12d, %ecx
movq -0x70(%rbp), %r12
movl %r12d, %r8d
callq 0x3fa9e
movq %rbx, %rdi
movq -0x40(%rbp), %rbx
movl %r13d, %esi
movl %r12d, %edx
callq 0x5291f
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %r12
leal (%rax,%r12), %edx
movq -0x48(%rbp), %rax
movl %eax, %ecx
subl %r12d, %ecx
movq %rbx, %rdi
movl $0x32, %esi
movq -0x68(%rbp), %r8
callq 0x3fa9e
testl %r12d, %r12d
jle 0x6a8bb
movq -0x50(%rbp), %r13
movl 0x54(%r13), %ecx
movl 0x8(%r14), %r12d
leal (%r12,%rcx), %eax
incl %ecx
movq %rcx, -0x40(%rbp)
movl %eax, 0x54(%r13)
testb %r15b, %r15b
je 0x6a6d8
movl 0xc(%r14), %edx
movq %rbx, %rdi
movl $0x3c, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl %eax, -0x30(%rbp)
movq -0x38(%rbp), %r15
jmp 0x6a6f8
movq -0x38(%rbp), %r15
movq -0x58(%rbp), %rdx
addl %r15d, %edx
movq %rbx, %rdi
movl $0x2f, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl %eax, -0x30(%rbp)
movl 0x8(%r14), %r8d
movq %rbx, %rdi
movl $0x2b, %esi
movq -0x40(%rbp), %rdx
movl %r15d, %ecx
callq 0x3fa9e
movl 0x18(%r14), %eax
testl %eax, %eax
jns 0x6a71d
movl 0x3c(%rbx), %eax
decl %eax
movq (%rbx), %rcx
cmpb $0x0, 0x51(%rcx)
movq -0x48(%rbp), %rcx
je 0x6a733
leaq 0x2adb7(%rip), %r15     # 0x954e8
jmp 0x6a741
cltq
leaq (%rax,%rax,2), %r15
shlq $0x3, %r15
addq 0x8(%rbx), %r15
movq (%r13), %rax
cmpb $0x0, 0x51(%rax)
movl -0x2c(%rbp), %eax
jne 0x6a960
subl %r12d, %ecx
movl %ecx, 0x8(%r15)
movq 0x10(%r15), %r12
movq 0x18(%r12), %rdi
movzwl 0x6(%r12), %edx
xorl %esi, %esi
movl %eax, -0x2c(%rbp)
callq 0xa210
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r12, %rdx
movl $0xfffffffa, %ecx       # imm = 0xFFFFFFFA
callq 0x14ab9
movq (%r14), %rsi
movzwl 0x8(%r12), %ecx
decl %ecx
movq %r13, %rdi
movq -0x60(%rbp), %rdx
callq 0x5e371
movq %rax, 0x10(%r15)
movl 0x3c(%rbx), %eax
movq %rax, -0x48(%rbp)
leal 0x1(%rax), %edx
movq %rbx, %rdi
movl $0x2c, %esi
xorl %ecx, %ecx
movl %edx, %r8d
callq 0x3fa9e
movq %rbx, %rdi
callq 0x528c8
movl %eax, 0x14(%r14)
movl 0x54(%r13), %edx
incl %edx
movl %edx, 0x54(%r13)
movl %edx, 0x10(%r14)
movq %rbx, %rdi
movl $0xf, %esi
movl %eax, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl 0xc(%r14), %edx
movq %rbx, %rdi
movl $0x79, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl -0x2c(%rbp), %edx
testl %edx, %edx
je 0x6a81b
movl 0x1c(%r14), %ecx
movq %rbx, %rdi
movl $0x2f, %esi
xorl %r8d, %r8d
callq 0x3fa9e
movl 0x3c(%rbx), %eax
leal -0x1(%rax), %ecx
movq 0x30(%rbx), %rdx
movl %ecx, 0x68(%rdx)
movq (%rbx), %rdx
leaq 0x2acb6(%rip), %rsi     # 0x954e8
cmpb $0x0, 0x51(%rdx)
movq %rsi, %rdx
jne 0x6a852
movl -0x30(%rbp), %edx
testl %edx, %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%rbx), %rdx
movl %eax, 0x8(%rdx)
movl 0x8(%r14), %r12d
movq 0x10(%r13), %rdi
movl $0x1e, %esi
movq -0x38(%rbp), %r15
movl %r15d, %edx
movq -0x40(%rbp), %rcx
movl %r12d, %r8d
callq 0x3fa9e
movq %r13, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x5291f
movl 0x3c(%rbx), %eax
leal -0x1(%rax), %ecx
movq 0x30(%rbx), %rdx
movl %ecx, 0x68(%rdx)
movq (%rbx), %rdx
cmpb $0x0, 0x51(%rdx)
leaq 0x2ac4a(%rip), %rdx     # 0x954e8
jne 0x6a8b8
movq -0x48(%rbp), %rdx
testl %edx, %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%rbx), %rdx
movl %eax, 0x8(%rdx)
movzbl 0x20(%r14), %eax
andl $0x1, %eax
movl $0x70, %esi
subl %eax, %esi
movl 0xc(%r14), %edx
movq %rbx, %rdi
movq -0x68(%rbp), %rcx
xorl %r8d, %r8d
callq 0x3fa9e
movl -0x2c(%rbp), %edx
testl %edx, %edx
je 0x6a960
movq %rbx, %rdi
movl $0x8d, %esi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x3fa9e
movl %eax, %r15d
movl 0xc(%r14), %edx
movq %rbx, %rdi
movl $0x6b, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl 0xc(%r14), %edx
movq %rbx, %rdi
movl $0x63, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3fa9e
movl 0x3c(%rbx), %eax
leal -0x1(%rax), %ecx
movq 0x30(%rbx), %rdx
movl %ecx, 0x68(%rdx)
movq (%rbx), %rdx
cmpb $0x0, 0x51(%rdx)
je 0x6a947
leaq 0x2aba3(%rip), %rcx     # 0x954e8
jmp 0x6a95d
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)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq