#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 MAP_ANON;
int MAP_PRIVATE;
int O_RDONLY;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
scalar_t__ mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int open(char *, int);
int pread(int, void *, int, int);
double *read_data_mmap(int n, int o, char *p) {
  int fd;
  int real_size = n * sizeof(double);
  int read_size;
  double *mapping;
  fd = open(p, O_RDONLY | 0);
  assert(fd > 0);
  mapping = (double *)mmap(NULL, real_size, PROT_READ | PROT_WRITE,
                           MAP_PRIVATE | MAP_ANON, -1, 0);
  assert(mapping != NULL);
  read_size = pread(fd, (void *)mapping, real_size, o);
  assert(real_size == read_size);
  close(fd);
  return mapping;
}


x86 assembly (clang, -O0):
<read_data_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%esi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
mov    0x2e27(%rip),%rax
or     (%rax),%edx
mov    0x2e0e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e0d(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%ecx
call   1070 <pread@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data_mmap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
shl    $0x3,%ebx
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
mov    %rdx,%rdi
call   1060 <open@plt>
mov    %eax,%r15d
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1050 <assert@plt>
mov    0x2e71(%rip),%rax
mov    0x2e42(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e27(%rip),%rax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbp
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1070 <pread@plt>
xor    %edi,%edi
cmp    %eax,%ebx
sete   %dil
call   1050 <assert@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
define double* @read_data_mmap(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
store i32 %14, i32* %8
%15 = load i8*, i8** %6
%16 = load i32, i32* @O_RDONLY
%17 = or i32 %16, 0
%18 = call i32 @open(i8* %15, i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp sgt i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %8
%24 = load i32, i32* @PROT_READ
%25 = load i32, i32* @PROT_WRITE
%26 = or i32 %24, %25
%27 = load i32, i32* @MAP_PRIVATE
%28 = load i32, i32* @MAP_ANON
%29 = or i32 %27, %28
%30 = call i64 @mmap(i32* null, i32 %23, i32 %26, i32 %29, i32 -1, i32 0)
%31 = inttoptr i64 %30 to double*
store double* %31, double** %10
%32 = load double*, double** %10
%33 = icmp ne double* %32, null
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %7
%37 = load double*, double** %10
%38 = bitcast double* %37 to i8*
%39 = load i32, i32* %8
%40 = load i32, i32* %5
%41 = call i32 @pread(i32 %36, i8* %38, i32 %39, i32 %40)
store i32 %41, i32* %9
%42 = load i32, i32* %8
%43 = load i32, i32* %9
%44 = icmp eq i32 %42, %43
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i32, i32* %7
%48 = call i32 @close(i32 %47)
%49 = load double*, double** %10
ret double* %49
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANON = global i32 0
define double* @read_data_mmap(i32 %0, i32 %1, i8* nocapture %2) {
%4 = shl i32 %0, 3
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %2, i32 %5)
%7 = icmp sgt i32 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = load i32, i32* @PROT_READ
%11 = load i32, i32* @PROT_WRITE
%12 = or i32 %11, %10
%13 = load i32, i32* @MAP_PRIVATE
%14 = load i32, i32* @MAP_ANON
%15 = or i32 %14, %13
%16 = tail call i64 @mmap(i32* null, i32 %4, i32 %12, i32 %15, i32 -1, i32 0)
%17 = inttoptr i64 %16 to double*
%18 = icmp ne i64 %16, 0
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = inttoptr i64 %16 to i8*
%22 = tail call i32 @pread(i32 %6, i8* %21, i32 %4, i32 %1)
%23 = icmp eq i32 %4, %22
%24 = zext i1 %23 to i32
%25 = tail call i32 @assert(i32 %24)
%26 = tail call i32 @close(i32 %6)
ret double* %17
}