// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: vdbeSorterIterInit
static int vdbeSorterIterInit(
  sqlite3 *db,                    /* Database handle */
  const VdbeSorter *pSorter,      /* Sorter object */
  i64 iStart,                     /* Start offset in pFile */
  VdbeSorterIter *pIter,          /* Iterator to populate */
  i64 *pnByte                     /* IN/OUT: Increment this value by PMA size */
){
  int rc = SQLITE_OK;
  int nBuf;

  nBuf = sqlite3BtreeGetPageSize(db->aDb[0].pBt);

  assert( pSorter->iWriteOff>iStart );
  assert( pIter->aAlloc==0 );
  assert( pIter->aBuffer==0 );
  pIter->pFile = pSorter->pTemp1;
  pIter->iReadOff = iStart;
  pIter->nAlloc = 128;
  pIter->aAlloc = (u8 *)sqlite3DbMallocRaw(db, pIter->nAlloc);
  pIter->nBuffer = nBuf;
  pIter->aBuffer = (u8 *)sqlite3DbMallocRaw(db, nBuf);

  if( !pIter->aBuffer ){
    rc = SQLITE_NOMEM;
  }else{
    int iBuf;

    iBuf = iStart % nBuf;
    if( iBuf ){
      int nRead = nBuf - iBuf;
      if( (iStart + nRead) > pSorter->iWriteOff ){
        nRead = (int)(pSorter->iWriteOff - iStart);
      }
      rc = sqlite3OsRead(
          pSorter->pTemp1, &pIter->aBuffer[iBuf], nRead, iStart
      );
      assert( rc!=SQLITE_IOERR_SHORT_READ );
    }

    if( rc==SQLITE_OK ){
      u64 nByte;                       /* Size of PMA in bytes */
      pIter->iEof = pSorter->iWriteOff;
      rc = vdbeSorterIterVarint(db, pIter, &nByte);
      pIter->iEof = pIter->iReadOff + nByte;
      *pnByte += nByte;
    }
  }

  if( rc==SQLITE_OK ){
    rc = vdbeSorterIterNext(db, pIter);
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rdi
callq 0xe590
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movl $0x80, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x134e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x30(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x134e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x45a40
movl $0x7, -0x2c(%rbp)
jmp 0x45af5
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rcx
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x45aa9
movl -0x30(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jle 0x45a83
movq -0x10(%rbp), %rax
movq (%rax), %rax
subq -0x18(%rbp), %rax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rsi
movslq -0x34(%rbp), %rax
addq %rax, %rsi
movl -0x38(%rbp), %edx
movq -0x18(%rbp), %rcx
callq 0x23e30
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x45af3
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x45c70
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x45af5
cmpl $0x0, -0x2c(%rbp)
jne 0x45b0b
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x45d60
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)