// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl -0x34(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x54(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x4593eb
movl -0x1c(%rbp), %eax
subl 0x10(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x459405
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x45941e
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x459428
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
callq 0x42d540
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movl -0x40(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x20(%rbp), %r9d
xorl %eax, %eax
movl $0x4, %r8d
cmpl $0x0, %r9d
cmovnel %r8d, %eax
orl $0x1, %eax
movzbl %al, %r8d
callq 0x42cbc0
cmpl $0x0, -0x34(%rbp)
je 0x459492
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edx
movl -0x40(%rbp), %ecx
addl -0x38(%rbp), %ecx
movl $0x77, %esi
callq 0x410100
cmpl $0x0, 0x10(%rbp)
jne 0x4594b6
cmpl $0x0, -0x24(%rbp)
jle 0x4594b6
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x40(%rbp), %edx
addl -0x38(%rbp), %edx
addl -0x34(%rbp), %edx
movl -0x24(%rbp), %ecx
callq 0x444c60
cmpl $0x0, -0x48(%rbp)
jle 0x4596d3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x40(%rbp), %ecx
movl -0x3c(%rbp), %r8d
callq 0x459840
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x8(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x459528
movq -0x30(%rbp), %rdi
movl -0x40(%rbp), %edx
addl -0x38(%rbp), %edx
movl $0x14, %esi
callq 0x42ba70
movl %eax, -0x5c(%rbp)
jmp 0x459540
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edx
movl $0x71, %esi
callq 0x42ba70
movl %eax, -0x5c(%rbp)
movq -0x30(%rbp), %rdi
movl -0x58(%rbp), %edx
movl -0x40(%rbp), %ecx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %r8d
movl $0x56, %esi
callq 0x410130
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x429e10
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpb $0x0, 0x61(%rax)
je 0x459582
jmp 0x45982b
movl -0x6c(%rbp), %ecx
addl -0x24(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x78(%rbp), %rax
movzwl 0x6(%rax), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x19360
movq -0x30(%rbp), %rdi
movq -0x78(%rbp), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xfffffff7, %ecx       # imm = 0xFFFFFFF7
callq 0x3cbc30
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movl -0x48(%rbp), %edx
movq -0x78(%rbp), %rax
movzwl 0x8(%rax), %ecx
movq -0x78(%rbp), %rax
movzwl 0x6(%rax), %eax
subl %eax, %ecx
subl $0x1, %ecx
callq 0x440f30
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
movq $0x0, -0x68(%rbp)
movq -0x30(%rbp), %rdi
callq 0x430ae0
movl %eax, -0x60(%rbp)
movq -0x30(%rbp), %rdi
movl -0x60(%rbp), %edx
addl $0x1, %edx
movl -0x60(%rbp), %r8d
addl $0x1, %r8d
movl $0x10, %esi
xorl %ecx, %ecx
callq 0x410130
movq -0x8(%rbp), %rdi
callq 0x42d540
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movl $0xc, %esi
callq 0x410100
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edx
movl $0x8a, %esi
callq 0x42ba70
cmpl $0x0, -0x50(%rbp)
je 0x4596a5
movq -0x30(%rbp), %rdi
movl -0x50(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
movl $0x14, %esi
callq 0x410100
movq -0x30(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x429a70
movq -0x8(%rbp), %rdi
movl -0x40(%rbp), %esi
movl -0x58(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
callq 0x444c60
movq -0x30(%rbp), %rdi
movl -0x60(%rbp), %esi
callq 0x429a70
cmpl $0x0, -0x50(%rbp)
je 0x45976a
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x7c(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x30(%rbp), %rdi
callq 0x430ae0
movq -0x90(%rbp), %rdi
movl -0x84(%rbp), %edx
movl %eax, %ecx
addl $0x4, %ecx
movl $0x31, %esi
callq 0x410100
movq -0x30(%rbp), %rdi
movl -0x7c(%rbp), %edx
movl $0x21, %esi
xorl %ecx, %ecx
callq 0x410100
movq -0x30(%rbp), %rdi
movl -0x7c(%rbp), %edx
movl -0x40(%rbp), %r8d
addl -0x48(%rbp), %r8d
movl -0x38(%rbp), %r9d
subl -0x48(%rbp), %r9d
movl $0x26, %esi
xorl %ecx, %ecx
callq 0x3cb970
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rdi
movl -0x7c(%rbp), %edx
movl $0x7a, %esi
callq 0x42ba70
cmpl $0x0, -0x44(%rbp)
jne 0x45978b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x40(%rbp), %ecx
movl -0x3c(%rbp), %r8d
callq 0x459840
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4597a4
movl $0x83, -0x4c(%rbp)
jmp 0x4597ab
movl $0x82, -0x4c(%rbp)
movq -0x30(%rbp), %rdi
movl -0x4c(%rbp), %esi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edx
movl -0x44(%rbp), %ecx
movl -0x40(%rbp), %r8d
addl -0x48(%rbp), %r8d
movl -0x3c(%rbp), %r9d
subl -0x48(%rbp), %r9d
callq 0x3cb970
cmpl $0x0, -0x54(%rbp)
je 0x45982b
movq -0x30(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x94(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
je 0x459804
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0xa4(%rbp)
jmp 0x459813
movq -0x30(%rbp), %rdi
callq 0x430ae0
movl %eax, -0xa4(%rbp)
movl -0x94(%rbp), %esi
movq -0xa0(%rbp), %rdi
movl -0xa4(%rbp), %edx
callq 0x429de0
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)