// File: /workspace/github_c_makefile_star2_O1/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 0x50(%rdi), %rcx
movq %rcx, %rax
subq %r12, %rax
movq %rdi, -0x40(%rbp)
jle 0x1769f
movslq %r15d, %rdx
leaq (%rdx,%r12), %rsi
cmpq %rcx, %rsi
jle 0x17724
movq 0x68(%rdi), %rsi
addq %r12, %rsi
movslq %eax, %rbx
movq %r13, %rdi
movq %rbx, %rdx
callq 0x82f0
addq %rbx, %r13
subl %ebx, %r15d
addq %rbx, %r12
movl %r15d, -0x2c(%rbp)
andl $0x1ffff, %r15d         # imm = 0x1FFFF
movl $0x0, -0x30(%rbp)
movq %r13, -0x38(%rbp)
movq -0x40(%rbp), %rbx
movl 0x18(%rbx), %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x8320
cmpq %r12, %rax
jne 0x17737
movl 0x18(%rbx), %edi
movslq %r15d, %r14
movq %r13, %rsi
movq %r14, %rdx
callq *0x7d23b(%rip)          # 0x94918
movq %rax, %rbx
subl %ebx, %r14d
je 0x1771d
testl %ebx, %ebx
js 0x17702
je 0x17715
movl %ebx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, %r12
addl %ebx, -0x30(%rbp)
addq %rax, %r13
movb $0x1, %al
movl %r14d, %r15d
jmp 0x17717
callq 0x8060
movl (%rax), %ecx
movb $0x1, %al
cmpl $0x4, %ecx
je 0x17717
jmp 0x1779b
xorl %eax, %eax
testb %al, %al
jne 0x176b5
xorl %ebx, %ebx
movl -0x30(%rbp), %eax
addl %eax, %ebx
jmp 0x17755
addq 0x68(%rdi), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x82f0
xorl %eax, %eax
jmp 0x1778c
cmpq $-0x1, %rax
je 0x17746
movl $0x0, 0x20(%rbx)
jmp 0x17750
callq 0x8060
movl (%rax), %eax
movl %eax, 0x20(%rbx)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
subl %ebx, %ecx
je 0x1778c
testl %ebx, %ebx
js 0x17787
movq -0x40(%rbp), %rax
movl $0x0, 0x20(%rax)
movl %ebx, %eax
addq %rax, %rdi
movslq %ecx, %rdx
xorl %esi, %esi
callq 0x8200
movl $0x20a, %eax            # imm = 0x20A
jmp 0x1778c
movl $0x10a, %eax            # imm = 0x10A
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x40(%rbp), %rax
movl %ecx, 0x20(%rax)
xorl %eax, %eax
jmp 0x17720