// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %rdi, %r12
movq %rsi, -0x30(%rbp)
movl (%rsi), %edi
leal 0x2(%rdi), %esi
movl 0x48(%r12), %eax
subl %esi, %eax
movq %rdx, -0x50(%rbp)
movl %ecx, -0x34(%rbp)
movq %rdi, -0x58(%rbp)
jge 0x5b914
movl 0x58(%r12), %eax
leal 0x1(%rax), %edx
addl %esi, %eax
movl %eax, 0x58(%r12)
jmp 0x5b926
movl 0x4c(%r12), %edx
leal (%rdx,%rsi), %ecx
movl %ecx, 0x4c(%r12)
movl %eax, 0x48(%r12)
movq %rdx, -0x40(%rbp)
movq %rsi, -0x48(%rbp)
movq 0x10(%r12), %r13
movb 0x1f(%r12), %al
testb %al, %al
je 0x5b94d
decb %al
movb %al, 0x1f(%r12)
movzbl %al, %eax
movl 0x28(%r12,%rax,4), %ebx
jmp 0x5b959
movl 0x58(%r12), %ebx
incl %ebx
movl %ebx, 0x58(%r12)
movq %r12, %rdi
callq 0x552af
movq %r12, %rdi
movq -0x30(%rbp), %r15
movq %r15, %rsi
movq -0x40(%rbp), %r14
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x4e5c4
movl 0x4(%r15), %edx
movq -0x58(%rbp), %r15
leal (%r14,%r15), %ecx
movq %r13, %rdi
movl $0x40, %esi
xorl %r8d, %r8d
callq 0x45f15
leal (%r14,%r15), %edx
incl %edx
movq %r12, %rdi
movl -0x34(%rbp), %esi
movl $0x1, %ecx
callq 0x552f9
movq %r13, %rdi
movl $0x2b, %esi
movl %r14d, %edx
movq -0x48(%rbp), %rcx
movl %ebx, %r8d
callq 0x45f15
movq -0x50(%rbp), %rax
movzwl 0xa(%rax), %eax
andl $0x40, %eax
cmpw $0x1, %ax
movl $0x0, %esi
adcl $0x66, %esi
movq -0x30(%rbp), %rax
movl 0x4(%rax), %edx
movq %r13, %rdi
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x45f15
testl %ebx, %ebx
je 0x5ba2a
movzbl 0x1f(%r12), %eax
cmpq $0x7, %rax
ja 0x5ba2a
xorl %ecx, %ecx
cmpl %ebx, 0x84(%r12,%rcx)
je 0x5ba24
addq $0x18, %rcx
cmpl $0xf0, %ecx
jne 0x5b9ff
leal 0x1(%rax), %ecx
movb %cl, 0x1f(%r12)
movl %ebx, 0x28(%r12,%rax,4)
jmp 0x5ba2a
movb $0x1, 0x7c(%r12,%rcx)
movq %r12, %rdi
movq -0x40(%rbp), %r14
movl %r14d, %esi
movq -0x48(%rbp), %rbx
movl %ebx, %edx
callq 0x4e564
cmpl %ebx, 0x48(%r12)
jge 0x5ba50
movl %ebx, 0x48(%r12)
movl %r14d, 0x4c(%r12)
movq -0x50(%rbp), %rcx
movl 0xc(%rcx), %eax
testl %eax, %eax
je 0x5bb15
movl 0x10(%rcx), %ecx
leal 0x1(%rcx), %ebx
testl %ecx, %ecx
cmovel %eax, %ebx
movq %r13, %rdi
movl $0x80, %esi
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl %eax, %r14d
movq %r13, %rdi
movl $0x20, %esi
movl %ebx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x45f15
movq %r13, %rdi
movl $0xe, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl %eax, %ebx
testl %r14d, %r14d
js 0x5bacb
movl 0x34(%r13), %eax
cmpl %r14d, %eax
jbe 0x5bacb
movq 0x8(%r13), %rcx
movl %r14d, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
movq -0x30(%rbp), %r14
movl 0x4(%r14), %edx
movq %r13, %rdi
movl $0x62, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
movl 0x4(%r14), %edx
movq %r13, %rdi
movl $0x46, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x45f15
testl %ebx, %ebx
js 0x5bb15
movl 0x34(%r13), %eax
cmpl %ebx, %eax
jbe 0x5bb15
movq 0x8(%r13), %rcx
movl %ebx, %edx
leaq (%rdx,%rdx,2), %rdx
movl %eax, 0x8(%rcx,%rdx,8)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq