#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*/);
long pread(int, double *, long, long);
void read_data(double *buf, long n, long 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    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
shl    $0x3,%rdx
mov    -0x18(%rbp),%rcx
call   1060 <pread@plt>
mov    -0x10(%rbp),%rcx
shl    $0x3,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x24(%rbp),%edi
call   1030 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    %rcx,%rdi
call   1050 <open@plt>
mov    %eax,%ebp
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1040 <assert@plt>
shl    $0x3,%rbx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <pread@plt>
xor    %edi,%edi
cmp    %rbx,%rax
sete   %dil
call   1040 <assert@plt>
mov    %ebp,%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, i64 %1, i64 %2, i8* %3) {
%5 = alloca double*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store double* %0, double** %5
store i64 %1, i64* %6
store i64 %2, i64* %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 i64, i64* %6
%20 = mul i64 %19, 8
%21 = load i64, i64* %7
%22 = call i64 @pread(i32 %17, double* %18, i64 %20, i64 %21)
%23 = load i64, i64* %6
%24 = mul i64 %23, 8
%25 = icmp eq i64 %22, %24
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i32, i32* %9
%29 = call i32 @close(i32 %28)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define void @read_data(double* nocapture %0, i64 %1, i64 %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 = shl i64 %1, 3
%11 = tail call i64 @pread(i32 %6, double* %0, i64 %10, i64 %2)
%12 = icmp eq i64 %11, %10
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @close(i32 %6)
ret void
}