// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3VdbeSorterWrite
SQLITE_PRIVATE int sqlite3VdbeSorterWrite(
  sqlite3 *db,                    /* Database handle */
  const VdbeCursor *pCsr,               /* Sorter cursor */
  Mem *pVal                       /* Memory cell containing record */
){
  VdbeSorter *pSorter = pCsr->pSorter;
  int rc = SQLITE_OK;             /* Return Code */
  SorterRecord *pNew;             /* New list element */

  assert( pSorter );
  pSorter->nInMemory += sqlite3VarintLen(pVal->n) + pVal->n;

  pNew = (SorterRecord *)sqlite3DbMallocRaw(db, pVal->n + sizeof(SorterRecord));
  if( pNew==0 ){
    rc = SQLITE_NOMEM;
  }else{
    pNew->pVal = (void *)&pNew[1];
    memcpy(pNew->pVal, pVal->z, pVal->n);
    pNew->nVal = pVal->n;
    pNew->pNext = pSorter->pRecord;
    pSorter->pRecord = pNew;
  }

  /* See if the contents of the sorter should now be written out. They
  ** are written out when either of the following are true:
  **
  **   * The total memory allocated for the in-memory list is greater 
  **     than (page-size * cache-size), or
  **
  **   * The total memory allocated for the in-memory list is greater 
  **     than (page-size * 10) and sqlite3HeapNearlyFull() returns true.
  */
  if( rc==SQLITE_OK && pSorter->mxPmaSize>0 && (
        (pSorter->nInMemory>pSorter->mxPmaSize)
     || (pSorter->nInMemory>pSorter->mnPmaSize && sqlite3HeapNearlyFull())
  )){
#ifdef SQLITE_DEBUG
    i64 nExpect = pSorter->iWriteOff
                + sqlite3VarintLen(pSorter->nInMemory)
                + pSorter->nInMemory;
#endif
    rc = vdbeSorterListToPMA(db, pCsr);
    pSorter->nInMemory = 0;
    assert( rc!=SQLITE_OK || (nExpect==pSorter->iWriteOff) );
  }

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x18(%rbp), %rax
movslq 0x20(%rax), %rdi
callq 0x3bdd0
movl %eax, %ecx
movq -0x18(%rbp), %rax
addl 0x20(%rax), %ecx
movq -0x20(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq 0x20(%rax), %rax
addq $0x18, %rax
movl %eax, %esi
callq 0x134e0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x3e0a2
movl $0x7, -0x24(%rbp)
jmp 0x3e0f7
movq -0x30(%rbp), %rcx
addq $0x18, %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movslq 0x20(%rax), %rdx
callq 0x82f0
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x40(%rax)
cmpl $0x0, -0x24(%rbp)
jne 0x3e14c
movq -0x20(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jle 0x3e14c
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jg 0x3e131
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jle 0x3e14c
callq 0x46070
cmpl $0x0, %eax
je 0x3e14c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x45290
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl $0x0, 0x10(%rax)
movl -0x24(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)