// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: unixRead
static int unixRead(
  sqlite3_file *id, 
  void *pBuf, 
  int amt,
  sqlite3_int64 offset
){
  unixFile *pFile = (unixFile *)id;
  int got;
  assert( id );
  assert( offset>=0 );
  assert( amt>0 );

  /* If this is a database file (not a journal, master-journal or temp
  ** file), the bytes in the locking range should never be read or written. */
#if 0
  assert( pFile->pUnused==0
       || offset>=PENDING_BYTE+512
       || offset+amt<=PENDING_BYTE 
  );
#endif

#if SQLITE_MAX_MMAP_SIZE>0
  /* Deal with as much of this read request as possible by transfering
  ** data from the memory mapping using memcpy().  */
  if( offset<pFile->mmapSize ){
    if( offset+amt <= pFile->mmapSize ){
      memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt);
      return SQLITE_OK;
    }else{
      int nCopy = pFile->mmapSize - offset;
      memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], nCopy);
      pBuf = &((u8 *)pBuf)[nCopy];
      amt -= nCopy;
      offset += nCopy;
    }
  }
#endif

  got = seekAndRead(pFile, offset, pBuf, amt);
  if( got==amt ){
    return SQLITE_OK;
  }else if( got<0 ){
    /* lastErrno set by seekAndRead */
    return SQLITE_IOERR_READ;
  }else{
    pFile->lastErrno = 0; /* not a system error */
    /* Unread parts of the buffer must be zero-filled */
    memset(&((char*)pBuf)[got], 0, amt-got);
    return SQLITE_IOERR_SHORT_READ;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r12
movl %edx, %r8d
movq %rsi, %r14
movq %rdi, %r15
movq 0x50(%rdi), %rcx
movq %rcx, %rax
subq %r12, %rax
jle 0x15968
movslq %r8d, %rdx
leaq (%rdx,%r12), %rsi
cmpq %rcx, %rsi
jle 0x159f4
movq 0x68(%r15), %rsi
addq %r12, %rsi
movslq %eax, %rbx
movq %r14, %rdi
movq %rbx, %rdx
movl %r8d, %r13d
callq 0x82c0
movl %r13d, %r8d
addq %rbx, %r14
subl %ebx, %r8d
addq %rbx, %r12
movl %r8d, -0x30(%rbp)
andl $0x1ffff, %r8d          # imm = 0x1FFFF
movl $0x0, -0x2c(%rbp)
movq %r14, -0x40(%rbp)
movq %r14, %rbx
movl %r8d, -0x34(%rbp)
movslq %r8d, %r14
movl 0x18(%r15), %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x82f0
cmpq %r12, %rax
jne 0x159e4
movl 0x18(%r15), %edi
movq %rbx, %rsi
movq %r14, %rdx
callq *0x71f6d(%rip)          # 0x87918
movq %rax, %r13
movl %r14d, %r8d
subl %r13d, %r8d
je 0x15a07
testl %r13d, %r13d
jns 0x159c9
callq 0x8050
movl (%rax), %eax
cmpl $0x4, %eax
je 0x15988
jmp 0x15a12
je 0x15a72
movl %r13d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %rcx, %r12
addl %r13d, -0x2c(%rbp)
addq %rcx, %rbx
jmp 0x15981
cmpq $-0x1, %rax
movl -0x30(%rbp), %ecx
je 0x15a20
andl $0x0, 0x20(%r15)
jmp 0x15a2e
addq 0x68(%r15), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x82c0
xorl %eax, %eax
jmp 0x15a63
movl -0x34(%rbp), %eax
movl %eax, %r13d
movl -0x2c(%rbp), %eax
jmp 0x15a18
movl %eax, 0x20(%r15)
xorl %eax, %eax
addl %eax, %r13d
movl -0x30(%rbp), %ecx
jmp 0x15a32
callq 0x8050
movl -0x30(%rbp), %ecx
movl (%rax), %eax
movl %eax, 0x20(%r15)
pushq $-0x1
popq %r13
xorl %eax, %eax
subl %r13d, %ecx
je 0x15a63
testl %r13d, %r13d
js 0x15a5e
andl $0x0, 0x20(%r15)
movl %r13d, %eax
movq -0x40(%rbp), %rdi
addq %rax, %rdi
movslq %ecx, %rdx
xorl %esi, %esi
callq 0x81e0
movl $0x20a, %eax            # imm = 0x20A
jmp 0x15a63
movl $0x10a, %eax            # imm = 0x10A
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
jmp 0x15a0d