// File: /workspace/github_c_makefile_star2_O3/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, %r15d
movq %rsi, %r13
movq %rdi, %rbx
movq 0x50(%rdi), %rcx
movq %rcx, %rax
subq %r12, %rax
movq %rdi, -0x38(%rbp)
jle 0x17699
movslq %r15d, %rdx
leaq (%rdx,%r12), %rsi
cmpq %rcx, %rsi
jle 0x17733
movq 0x68(%rbx), %rsi
addq %r12, %rsi
movslq %eax, %rbx
movq %r13, %rdi
movq %rbx, %rdx
callq 0x82f0
addq %rbx, %r13
subl %ebx, %r15d
addq %rbx, %r12
movq -0x38(%rbp), %rbx
movl 0x18(%rbx), %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x8320
cmpq %r12, %rax
jne 0x17724
movl $0x0, -0x2c(%rbp)
movl %r15d, -0x30(%rbp)
andl $0x1ffff, %r15d         # imm = 0x1FFFF
movq %r13, -0x40(%rbp)
movl 0x18(%rbx), %edi
movslq %r15d, %r14
movq %r13, %rsi
movq %r14, %rdx
callq *0x7d245(%rip)          # 0x94918
movq %rax, %rbx
subl %ebx, %r14d
je 0x17757
testl %ebx, %ebx
js 0x176f6
je 0x1775c
movl %ebx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, %r12
addl %ebx, -0x2c(%rbp)
addq %rax, %r13
movl %r14d, %r15d
jmp 0x17706
callq 0x8060
movl (%rax), %eax
cmpl $0x4, %eax
jne 0x177ae
movq -0x38(%rbp), %rbx
movl 0x18(%rbx), %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x8320
cmpq %r12, %rax
je 0x176c1
movq -0x40(%rbp), %r13
movl -0x30(%rbp), %r15d
cmpq $-0x1, %rax
je 0x17746
movl $0x0, 0x20(%rbx)
jmp 0x17750
addq 0x68(%rbx), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x82f0
xorl %eax, %eax
jmp 0x1779f
callq 0x8060
movl (%rax), %eax
movl %eax, 0x20(%rbx)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x1776b
movl %r15d, %ebx
jmp 0x1775e
xorl %ebx, %ebx
movl -0x2c(%rbp), %eax
addl %eax, %ebx
movq -0x40(%rbp), %r13
movl -0x30(%rbp), %r15d
xorl %eax, %eax
subl %ebx, %r15d
je 0x1779f
testl %ebx, %ebx
js 0x1779a
movq -0x38(%rbp), %rax
movl $0x0, 0x20(%rax)
movl %ebx, %eax
addq %rax, %r13
movslq %r15d, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x8200
movl $0x20a, %eax            # imm = 0x20A
jmp 0x1779f
movl $0x10a, %eax            # imm = 0x10A
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rcx
movl %eax, 0x20(%rcx)
xorl %eax, %eax
jmp 0x17761