#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int pread(int, double *, int, int);
void read_data(double *buf, int n, int o, char *p) {
  int fd;
  fd = open(p, O_RDONLY);
  assert(fd > 0);
  assert(pread(fd, buf, n * sizeof(double), o) == n * sizeof(double));
  close(fd);
  return;
}


x86 assembly (clang, -O0):
<read_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
mov    -0x10(%rbp),%ecx
call   1060 <pread@plt>
cltq
movslq -0xc(%rbp),%rcx
shl    $0x3,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    %rcx,%rdi
call   1050 <open@plt>
mov    %eax,%ebx
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1040 <assert@plt>
movslq %ebp,%rbp
shl    $0x3,%rbp
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1060 <pread@plt>
cltq
xor    %edi,%edi
cmp    %rax,%rbp
sete   %dil
call   1040 <assert@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <close@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
define void @read_data(double* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store double* %0, double** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%10 = load i8*, i8** %8
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp sgt i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %9
%18 = load double*, double** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 8
%22 = trunc i64 %21 to i32
%23 = load i32, i32* %7
%24 = call i32 @pread(i32 %17, double* %18, i32 %22, i32 %23)
%25 = sext i32 %24 to i64
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 8
%29 = icmp eq i64 %25, %28
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i32, i32* %9
%33 = call i32 @close(i32 %32)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define void @read_data(double* nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %3, i32 %5)
%7 = icmp sgt i32 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = sext i32 %1 to i64
%11 = shl nsw i64 %10, 3
%12 = trunc i64 %11 to i32
%13 = tail call i32 @pread(i32 %6, double* %0, i32 %12, i32 %2)
%14 = sext i32 %13 to i64
%15 = icmp eq i64 %11, %14
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i32 @close(i32 %6)
ret void
}