// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: pushOntoSorter
static void pushOntoSorter(
  Parse *pParse,         /* Parser context */
  ExprList *pOrderBy,    /* The ORDER BY clause */
  Select *pSelect,       /* The whole SELECT statement */
  int regData            /* Register holding data to be sorted */
){
  Vdbe *v = pParse->pVdbe;
  int nExpr = pOrderBy->nExpr;
  int regBase = sqlite3GetTempRange(pParse, nExpr+2);
  int regRecord = sqlite3GetTempReg(pParse);
  int op;
  sqlite3ExprCacheClear(pParse);
  sqlite3ExprCodeExprList(pParse, pOrderBy, regBase, 0);
  sqlite3VdbeAddOp2(v, OP_Sequence, pOrderBy->iECursor, regBase+nExpr);
  sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+1, 1);
  sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nExpr + 2, regRecord);
  if( pSelect->selFlags & SF_UseSorter ){
    op = OP_SorterInsert;
  }else{
    op = OP_IdxInsert;
  }
  sqlite3VdbeAddOp2(v, op, pOrderBy->iECursor, regRecord);
  sqlite3ReleaseTempReg(pParse, regRecord);
  sqlite3ReleaseTempRange(pParse, regBase, nExpr+2);
  if( pSelect->iLimit ){
    int addr1, addr2;
    int iLimit;
    if( pSelect->iOffset ){
      iLimit = pSelect->iOffset+1;
    }else{
      iLimit = pSelect->iLimit;
    }
    addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit);
    sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
    addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
    sqlite3VdbeJumpHere(v, addr1);
    sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor);
    sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor);
    sqlite3VdbeJumpHere(v, addr2);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, -0x30(%rbp)
movq %rdx, -0x40(%rbp)
movq %rsi, %r14
movq %rdi, %r12
movq 0x10(%rdi), %r13
movl (%rsi), %ebx
leal 0x2(%rbx), %esi
movl %esi, -0x34(%rbp)
callq 0x47c2c
movl %eax, %r15d
movq %r12, %rdi
callq 0x46ff9
movl %eax, -0x38(%rbp)
movq %r12, %rdi
callq 0x4da57
movq %r12, %rdi
movq %r14, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x49599
movl 0x4(%r14), %edx
leal (%r15,%rbx), %ecx
pushq $0x40
popq %rsi
movq %r13, %rdi
callq 0x41f42
leal (%r15,%rbx), %edx
incl %edx
pushq $0x1
popq %rcx
movq %r12, %rdi
movl -0x30(%rbp), %esi
callq 0x4da9a
pushq $0x2b
popq %rsi
movq %r13, %rdi
movl %r15d, %edx
movl -0x34(%rbp), %ecx
movl -0x38(%rbp), %ebx
movl %ebx, %r8d
callq 0x41f4c
movq -0x40(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x40, %eax
cmpw $0x1, %ax
movl $0x0, %esi
adcl $0x66, %esi
movq %r14, -0x48(%rbp)
movl 0x4(%r14), %edx
movq %r13, -0x30(%rbp)
movq %r13, %rdi
movl %ebx, %ecx
callq 0x41f42
movq %r12, %rdi
movl %ebx, %esi
callq 0x4701c
movq %r12, %rdi
movl %r15d, %esi
movl -0x34(%rbp), %edx
callq 0x47d6c
movq -0x40(%rbp), %rcx
movl 0xc(%rcx), %eax
testl %eax, %eax
je 0x529e9
movl 0x10(%rcx), %ecx
leal 0x1(%rcx), %r14d
testl %ecx, %ecx
cmovel %eax, %r14d
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movl $0x80, %esi
movl %r14d, %edx
callq 0x42436
movl %eax, %r15d
pushq $0x20
popq %rsi
pushq $-0x1
popq %rcx
movq %rbx, %rdi
movl %r14d, %edx
callq 0x41f42
pushq $0xe
popq %rsi
movq %rbx, %rdi
callq 0x41f34
movl %eax, %r14d
testl %r15d, %r15d
js 0x5299f
movq -0x30(%rbp), %rax
movl 0x34(%rax), %eax
cmpl %r15d, %eax
jbe 0x5299f
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl %r15d, %edx
imulq $0x18, %rdx, %rdx
movl %eax, 0x8(%rcx,%rdx)
movq -0x48(%rbp), %r15
movl 0x4(%r15), %edx
pushq $0x62
popq %rsi
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x42436
movl 0x4(%r15), %edx
pushq $0x46
popq %rsi
movq %rbx, %rdi
callq 0x42436
testl %r14d, %r14d
js 0x529e9
movq -0x30(%rbp), %rax
movl 0x34(%rax), %eax
cmpl %r14d, %eax
jbe 0x529e9
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl %r14d, %edx
imulq $0x18, %rdx, %rdx
movl %eax, 0x8(%rcx,%rdx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq