// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/sqlite-3.33.0/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 regData 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 = 0;                               /* 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 */
  int iSkip = 0;                     /* End of the sorter insert loop */

  assert( bSeq==0 || bSeq==1 );

  /* Three cases:
  **   (1) The data to be sorted has already been packed into a Record
  **       by a prior OP_MakeRecord.  In this case nData==1 and regData
  **       will be completely unrelated to regOrigData.
  **   (2) All output columns are included in the sort record.  In that
  **       case regData==regOrigData.
  **   (3) Some output columns are omitted from the sort record due to
  **       the SQLITE_ENABLE_SORTER_REFERENCE optimization, or due to the
  **       SQLITE_ECEL_OMITREF optimization, or due to the
  **       SortCtx.pDeferredRowLoad optimiation.  In any of these cases
  **       regOrigData is 0 to prevent this routine from trying to copy
  **       values that might not yet exist.
  */
  assert( nData==1 || regData==regOrigData || regOrigData==0 );

  if( nPrefixReg ){
    assert( nPrefixReg==nExpr+bSeq );
    regBase = regData - nPrefixReg;
  }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(pParse);
  sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
                          SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
  if( bSeq ){
    sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
  }
  if( nPrefixReg==0 && nData>0 ){
    sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
  }
  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 */

    regRecord = makeSorterRecord(pParse, pSort, pSelect, regBase, nBase);
    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->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */
    sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
    testcase( pKI->nAllField > pKI->nKeyField+2 );
    pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,
                                           pKI->nAllField-pKI->nKeyField-1);
    pOp = 0; /* Ensure pOp not used after sqltie3VdbeAddOp3() */
    addrJmp = sqlite3VdbeCurrentAddr(v);
    sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
    pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse);
    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( iLimit ){
    /* At this point the values for the new sorter entry are stored
    ** in an array of registers. They need to be composed into a record
    ** and inserted into the sorter if either (a) there are currently
    ** less than LIMIT+OFFSET items or (b) the new record is smaller than
    ** the largest record currently in the sorter. If (b) is true and there
    ** are already LIMIT+OFFSET items in the sorter, delete the largest
    ** entry before inserting the new one. This way there are never more
    ** than LIMIT+OFFSET items in the sorter.
    **
    ** If the new record does not need to be inserted into the sorter,
    ** jump to the next iteration of the loop. If the pSort->labelOBLopt
    ** value is not zero, then it is a label of where to jump.  Otherwise,
    ** just bypass the row insert logic.  See the header comment on the
    ** sqlite3WhereOrderByLimitOptLabel() function for additional info.
    */
    int iCsr = pSort->iECursor;
    sqlite3VdbeAddOp2(v, OP_IfNotZero, iLimit, sqlite3VdbeCurrentAddr(v)+4);
    VdbeCoverage(v);
    sqlite3VdbeAddOp2(v, OP_Last, iCsr, 0);
    iSkip = sqlite3VdbeAddOp4Int(v, OP_IdxLE,
                                 iCsr, 0, regBase+nOBSat, nExpr-nOBSat);
    VdbeCoverage(v);
    sqlite3VdbeAddOp1(v, OP_Delete, iCsr);
  }
  if( regRecord==0 ){
    regRecord = makeSorterRecord(pParse, pSort, pSelect, regBase, nBase);
  }
  if( pSort->sortFlags & SORTFLAG_UseSorter ){
    op = OP_SorterInsert;
  }else{
    op = OP_IdxInsert;
  }
  sqlite3VdbeAddOp4Int(v, op, pSort->iECursor, regRecord,
                       regBase+nOBSat, nBase-nOBSat);
  if( iSkip ){
    sqlite3VdbeChangeP2(v, iSkip,
         pSort->labelOBLopt ? pSort->labelOBLopt : sqlite3VdbeCurrentAddr(v));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r8d, %eax
movl %ecx, %ebp
movq %rsi, %rbx
movl 0x80(%rsp), %r14d
movzbl 0x24(%rsi), %r13d
andl $0x1, %r13d
movl %r13d, %r15d
xorl $0x1, %r15d
movq (%rsi), %rsi
movl (%rsi), %r8d
movq %r9, 0x10(%rsp)
leal (%r15,%r9), %r10d
movq %r8, 0x28(%rsp)
addl %r8d, %r10d
movl 0x8(%rbx), %ecx
movq %rcx, 0x30(%rsp)
testl %r14d, %r14d
je 0x2dfeb2
movl %ebp, %ecx
subl %r14d, %ecx
movq %rcx, 0x18(%rsp)
jmp 0x2dfec4
movl 0x38(%rdi), %ecx
leal 0x1(%rcx), %r8d
movq %r8, 0x18(%rsp)
addl %r10d, %ecx
movl %ecx, 0x38(%rdi)
movl 0xc(%rdx), %ecx
testl %ecx, %ecx
movl %r10d, 0xc(%rsp)
movq %rdx, 0x38(%rsp)
movl %ebp, 0x8(%rsp)
je 0x2dfedd
incl %ecx
jmp 0x2dfee0
movl 0x8(%rdx), %ecx
movl %ecx, 0x20(%rsp)
movq 0x10(%rdi), %rbp
movl 0x44(%rdi), %ecx
decl %ecx
movl %ecx, 0x44(%rdi)
movl %ecx, 0x1c(%rbx)
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leal 0x1(,%rcx,4), %r8d
movq %rdi, %r12
movq 0x18(%rsp), %rdx
movl %eax, %ecx
callq 0x2beb59
testb %r13b, %r13b
jne 0x2dff35
movl 0xc(%rbx), %edx
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
addl %eax, %ecx
movq %rbp, %rdi
movl $0x77, %esi
xorl %r8d, %r8d
callq 0x2a83e1
testl %r14d, %r14d
setne %al
movq 0x10(%rsp), %r8
testl %r8d, %r8d
setle %cl
orb %al, %cl
jne 0x2dff6a
addl 0x28(%rsp), %r15d
addl 0x18(%rsp), %r15d
movq 0x10(%r12), %rdi
movl $0x4c, %esi
movl 0x8(%rsp), %edx
movl %r15d, %ecx
callq 0x2a83e1
movl $0x0, 0x10(%rsp)
movl $0x0, %ecx
movq 0x30(%rsp), %r15
testl %r15d, %r15d
movq %rbp, %r14
jle 0x2e01a7
movq %r12, %rdi
movq %rbx, %rsi
movq 0x38(%rsp), %rdx
movq 0x18(%rsp), %r15
movl %r15d, %ecx
movl 0xc(%rsp), %r8d
callq 0x2e030b
movl %eax, 0x8(%rsp)
movl 0x38(%r12), %ebp
movl 0x8(%rbx), %eax
movq %rax, 0x40(%rsp)
addl %ebp, %eax
incl %ebp
movl %eax, 0x38(%r12)
testb %r13b, %r13b
je 0x2dffd1
movl 0xc(%rbx), %edx
movq %r14, %rdi
movl $0x71, %esi
jmp 0x2dffe2
movq 0x28(%rsp), %rax
leal (%r15,%rax), %edx
movq %r14, %rdi
movl $0x14, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl %eax, 0x24(%rsp)
movl 0x8(%rbx), %r8d
movq %r14, %rdi
movl $0x56, %esi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x2a83e1
movl 0x18(%rbx), %eax
testl %eax, %eax
jns 0x2e0016
movl 0x90(%r14), %eax
decl %eax
movq (%r14), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2e0028
leaq 0x1dee62(%rip), %r13    # 0x4bee88
jmp 0x2e0039
cltq
leaq (%rax,%rax,2), %r13
shlq $0x3, %r13
addq 0x88(%r14), %r13
movq (%r12), %rax
cmpb $0x0, 0x61(%rax)
jne 0x2e02fc
movl 0xc(%rsp), %eax
subl 0x40(%rsp), %eax
movl %eax, 0x8(%r13)
movq 0x10(%r13), %r15
movq 0x18(%r15), %rdi
movzwl 0x6(%r15), %edx
xorl %esi, %esi
callq 0x173a0
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r15, %rdx
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x27b778
movq (%rbx), %rsi
movzwl 0x8(%r15), %eax
movzwl 0x6(%r15), %ecx
notl %ecx
addl %eax, %ecx
movq %r12, %rdi
movq 0x30(%rsp), %rdx
callq 0x2cde19
movq %rax, 0x10(%r13)
movl 0x90(%r14), %r15d
leal 0x1(%r15), %edx
movq %r14, %rdi
movl $0x10, %esi
xorl %ecx, %ecx
movl %edx, %r8d
callq 0x2a83e1
movl 0x44(%r12), %ecx
decl %ecx
movl %ecx, 0x44(%r12)
movl %ecx, 0x14(%rbx)
movl 0x38(%r12), %edx
incl %edx
movl %edx, 0x38(%r12)
movl %edx, 0x10(%rbx)
movq %r14, %rdi
movl $0xc, %esi
xorl %r8d, %r8d
callq 0x2a83e1
movl 0xc(%rbx), %edx
movq %r14, %rdi
movl $0x8a, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x20(%rsp), %edx
testl %edx, %edx
je 0x2e0119
movl 0x1c(%rbx), %ecx
movq %r14, %rdi
movl $0x14, %esi
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x90(%r14), %eax
movq (%r14), %rcx
leaq 0x1ded5e(%rip), %r13    # 0x4bee88
cmpb $0x0, 0x61(%rcx)
movq %r13, %rcx
jne 0x2e0151
leal -0x1(%rax), %ecx
movl 0x24(%rsp), %edx
testl %edx, %edx
cmovnsl %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r14), %rcx
movl %eax, 0x8(%rcx)
movl 0x8(%rbx), %r8d
movq 0x10(%r12), %rdi
movl $0x4c, %esi
movq 0x18(%rsp), %rdx
movl %ebp, %ecx
callq 0x2a83e1
movl 0x90(%r14), %eax
movq (%r14), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2e019a
leal -0x1(%rax), %ecx
testl %r15d, %r15d
cmovnsl %r15d, %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %r13
shlq $0x3, %r13
addq 0x88(%r14), %r13
movl %eax, 0x8(%r13)
movq 0x30(%rsp), %r15
movl 0x8(%rsp), %ecx
movl 0x20(%rsp), %edx
testl %edx, %edx
movq 0x18(%rsp), %r13
je 0x2e0248
movl %ecx, 0x8(%rsp)
movl 0xc(%rbx), %ebp
movl 0x90(%r14), %ecx
addl $0x4, %ecx
movq %r14, %rdi
movl $0x31, %esi
xorl %r8d, %r8d
callq 0x2a83e1
movq %r14, %rdi
movl $0x21, %esi
movl %ebp, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
leal (%r15,%r13), %r8d
movq %r14, %rdi
movl $0x26, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0x2a83e1
movl %eax, 0x10(%rsp)
movq (%r14), %rax
cmpb $0x0, 0x61(%rax)
jne 0x2e0230
movq 0x28(%rsp), %rdx
subl %r15d, %edx
movq 0x88(%r14), %rax
movslq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movb $-0x3, 0x1(%rax,%rcx,8)
movl %edx, 0x10(%rax,%rcx,8)
movq %r14, %rdi
movl $0x7a, %esi
movl %ebp, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2a83e1
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
jne 0x2e0266
movq %r12, %rdi
movq %rbx, %rsi
movq 0x38(%rsp), %rdx
movl %r13d, %ecx
movl 0xc(%rsp), %r8d
callq 0x2e030b
movl %eax, %ecx
movzbl 0x24(%rbx), %esi
andl $0x1, %esi
orl $0x82, %esi
movl 0xc(%rbx), %edx
addl %r15d, %r13d
movq %r14, %rdi
movl %r13d, %r8d
callq 0x2a83e1
movq (%r14), %rcx
cmpb $0x0, 0x61(%rcx)
jne 0x2e02aa
movl 0xc(%rsp), %edx
subl %r15d, %edx
movq 0x88(%r14), %rcx
cltq
leaq (%rax,%rax,2), %rax
movb $-0x3, 0x1(%rcx,%rax,8)
movl %edx, 0x10(%rcx,%rax,8)
cmpl $0x0, 0x10(%rsp)
je 0x2e02fc
movl 0x20(%rbx), %eax
testl %eax, %eax
jne 0x2e02bf
movl 0x90(%r14), %eax
cmpl $0x0, 0x10(%rsp)
jns 0x2e02d3
movl 0x90(%r14), %ecx
decl %ecx
movl %ecx, 0x10(%rsp)
movq (%r14), %rcx
cmpb $0x0, 0x61(%rcx)
je 0x2e02e5
leaq 0x1deba5(%rip), %rcx    # 0x4bee88
jmp 0x2e02f9
movslq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x88(%r14), %rcx
movl %eax, 0x8(%rcx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq