// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: vdbePmaReadBlob
static int vdbePmaReadBlob(
  PmaReader *p,                   /* PmaReader from which to take the blob */
  int nByte,                      /* Bytes of data to read */
  u8 **ppOut                      /* OUT: Pointer to buffer containing data */
){
  int iBuf;                       /* Offset within buffer to read from */
  int nAvail;                     /* Bytes of data available in buffer */

  if( p->aMap ){
    *ppOut = &p->aMap[p->iReadOff];
    p->iReadOff += nByte;
    return SQLITE_OK;
  }

  assert( p->aBuffer );

  /* If there is no more data to be read from the buffer, read the next
  ** p->nBuffer bytes of data from the file into it. Or, if there are less
  ** than p->nBuffer bytes remaining in the PMA, read all remaining data.  */
  iBuf = p->iReadOff % p->nBuffer;
  if( iBuf==0 ){
    int nRead;                    /* Bytes to read from disk */
    int rc;                       /* sqlite3OsRead() return code */

    /* Determine how many bytes of data to read. */
    if( (p->iEof - p->iReadOff) > (i64)p->nBuffer ){
      nRead = p->nBuffer;
    }else{
      nRead = (int)(p->iEof - p->iReadOff);
    }
    assert( nRead>0 );

    /* Readr data from the file. Return early if an error occurs. */
    rc = sqlite3OsRead(p->pFd, p->aBuffer, nRead, p->iReadOff);
    assert( rc!=SQLITE_IOERR_SHORT_READ );
    if( rc!=SQLITE_OK ) return rc;
  }
  nAvail = p->nBuffer - iBuf;

  if( nByte<=nAvail ){
    /* The requested data is available in the in-memory buffer. In this
    ** case there is no need to make a copy of the data, just return a
    ** pointer into the buffer to the caller.  */
    *ppOut = &p->aBuffer[iBuf];
    p->iReadOff += nByte;
  }else{
    /* The requested data is not all available in the in-memory buffer.
    ** In this case, allocate space at p->aAlloc[] to copy the requested
    ** range into. Then return a copy of pointer p->aAlloc to the caller.  */
    int nRem;                     /* Bytes remaining to copy */

    /* Extend the p->aAlloc[] allocation if required. */
    if( p->nAlloc<nByte ){
      u8 *aNew;
      sqlite3_int64 nNew = MAX(128, 2*(sqlite3_int64)p->nAlloc);
      while( nByte>nNew ) nNew = nNew*2;
      aNew = sqlite3Realloc(p->aAlloc, nNew);
      if( !aNew ) return SQLITE_NOMEM_BKPT;
      p->nAlloc = nNew;
      p->aAlloc = aNew;
    }

    /* Copy as much data as is available in the buffer into the start of
    ** p->aAlloc[].  */
    memcpy(p->aAlloc, &p->aBuffer[iBuf], nAvail);
    p->iReadOff += nAvail;
    nRem = nByte - nAvail;

    /* The following loop copies up to p->nBuffer bytes per iteration into
    ** the p->aAlloc[] buffer.  */
    while( nRem>0 ){
      int rc;                     /* vdbePmaReadBlob() return code */
      int nCopy;                  /* Number of bytes to copy */
      u8 *aNext;                  /* Pointer to buffer to copy data from */

      nCopy = nRem;
      if( nRem>p->nBuffer ) nCopy = p->nBuffer;
      rc = vdbePmaReadBlob(p, nCopy, &aNext);
      if( rc!=SQLITE_OK ) return rc;
      assert( aNext!=p->aAlloc );
      memcpy(&p->aAlloc[nByte - nRem], aNext, nCopy);
      nRem -= nCopy;
    }

    *ppOut = p->aAlloc;
  }

  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x409d8e
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movslq -0x14(%rbp), %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x409fb6
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x38(%rcx), %rcx
cqto
idivq %rcx
movl %edx, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x409e1c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
movq -0x10(%rbp), %rcx
movslq 0x38(%rcx), %rcx
cmpq %rcx, %rax
jle 0x409dd5
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x409de7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
callq 0x3dfc00
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x409e1a
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x409fb6
jmp 0x409e1c
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
subl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0x409e5a
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movslq -0x24(%rbp), %rax
addq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movslq -0x14(%rbp), %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x409faf
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0x14(%rbp), %eax
jge 0x409ef9
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rcx
shlq %rcx
movl $0x80, %eax
cmpq %rcx, %rax
jle 0x409e8a
movl $0x80, %eax
movq %rax, -0x60(%rbp)
jmp 0x409e99
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x48(%rbp)
movslq -0x14(%rbp), %rax
cmpq -0x48(%rbp), %rax
jle 0x409eb8
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x48(%rbp)
jmp 0x409ea1
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x48(%rbp), %rsi
callq 0x3c0910
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x409ee0
movl $0x7, -0x4(%rbp)
jmp 0x409fb6
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movslq -0x24(%rbp), %rax
addq %rax, %rsi
movslq -0x28(%rbp), %rdx
callq 0x19610
movslq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl -0x14(%rbp), %eax
subl -0x28(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x409fa0
movl -0x34(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jle 0x409f52
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl -0x50(%rbp), %esi
leaq -0x58(%rbp), %rdx
callq 0x409d40
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x409f73
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x409fb6
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x14(%rbp), %eax
subl -0x34(%rbp), %eax
cltq
addq %rax, %rdi
movq -0x58(%rbp), %rsi
movslq -0x50(%rbp), %rdx
callq 0x19610
movl -0x50(%rbp), %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
jmp 0x409f30
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop