// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: vdbeSorterListToPMA
static int vdbeSorterListToPMA(SortSubtask *pTask, SorterList *pList){
  sqlite3 *db = pTask->pSorter->db;
  int rc = SQLITE_OK;             /* Return code */
  PmaWriter writer;               /* Object used to write to the file */

#ifdef SQLITE_DEBUG
  /* Set iSz to the expected size of file pTask->file after writing the PMA.
  ** This is used by an assert() statement at the end of this function.  */
  i64 iSz = pList->szPMA + sqlite3VarintLen(pList->szPMA) + pTask->file.iEof;
#endif

  vdbeSorterWorkDebug(pTask, "enter");
  memset(&writer, 0, sizeof(PmaWriter));
  assert( pList->szPMA>0 );

  /* If the first temporary PMA file has not been opened, open it now. */
  if( pTask->file.pFd==0 ){
    rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd);
    assert( rc!=SQLITE_OK || pTask->file.pFd );
    assert( pTask->file.iEof==0 );
    assert( pTask->nPMA==0 );
  }

  /* Try to get the file to memory map */
  if( rc==SQLITE_OK ){
    vdbeSorterExtendFile(db, pTask->file.pFd, pTask->file.iEof+pList->szPMA+9);
  }

  /* Sort the list */
  if( rc==SQLITE_OK ){
    rc = vdbeSorterSort(pTask, pList);
  }

  if( rc==SQLITE_OK ){
    SorterRecord *p;
    SorterRecord *pNext = 0;

    vdbePmaWriterInit(pTask->file.pFd, &writer, pTask->pSorter->pgsz,
                      pTask->file.iEof);
    pTask->nPMA++;
    vdbePmaWriteVarint(&writer, pList->szPMA);
    for(p=pList->pList; p; p=pNext){
      pNext = p->u.pNext;
      vdbePmaWriteVarint(&writer, p->nVal);
      vdbePmaWriteBlob(&writer, SRVAL(p), p->nVal);
      if( pList->aMemory==0 ) sqlite3_free(p);
    }
    pList->pList = p;
    rc = vdbePmaWriterFinish(&writer, &pTask->file.iEof);
  }

  vdbeSorterWorkDebug(pTask, "exit");
  assert( rc!=SQLITE_OK || pList->pList==0 );
  assert( rc!=SQLITE_OK || pTask->file.iEof==iSz );
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x19360
movq -0x8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x408cda
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0x48, %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x408e10
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x408d08
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdx
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rax
addq %rax, %rdx
addq $0x9, %rdx
callq 0x408eb0
cmpl $0x0, -0x1c(%rbp)
jne 0x408d1e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x4083f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x408dfa
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl 0xc(%rax), %edx
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rcx
leaq -0x50(%rbp), %rsi
callq 0x408f50
movq -0x8(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rsi
leaq -0x50(%rbp), %rdi
callq 0x409000
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x408dd7
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movslq (%rax), %rsi
leaq -0x50(%rbp), %rdi
callq 0x409000
movq -0x58(%rbp), %rsi
addq $0x10, %rsi
movq -0x58(%rbp), %rax
movl (%rax), %edx
leaq -0x50(%rbp), %rdi
callq 0x409040
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x408dcb
movq -0x58(%rbp), %rdi
callq 0x3c0800
jmp 0x408dcd
movq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x408d7d
movq -0x58(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rsi
addq $0x48, %rsi
addq $0x8, %rsi
leaq -0x50(%rbp), %rdi
callq 0x409180
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)