#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 */
typedef size_t ssize_t;

/* 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*/ *, size_t, int, int, int,
                int /*<<< orphan*/);
int open(char *, int);
size_t pread(int, void *, size_t, long);
int /*<<< orphan*/ printf(char *, char *, ...);
double *read_data_mmap(long n, long o, char *p, char *nodeid) {
  int fd;
  size_t real_size = n * sizeof(double);
  ssize_t 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);
  printf("[%s] read: %ld floats. Bytes  %ld at %ld, mapping %p\n", nodeid, n,
         real_size, o, mapping);
  if (real_size != read_size) {
    printf("[%s]: error: mapping %p, n %ld, o %ld, real_size %ld, read_size "
           "%ld.\n",
           nodeid, mapping, n, o, real_size, read_size);
  }
  assert(real_size == read_size);
  close(fd);
  return mapping;
}


x86 assembly (clang, -O0):
<read_data_mmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x30(%rbp),%rsi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    0x2e0f(%rip),%rax
or     (%rax),%edx
mov    0x2df6(%rip),%rax
mov    (%rax),%ecx
mov    0x2df5(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x24(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   1080 <pread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x40(%rbp),%r9
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     126f <read_data_mmap+0x10f>
mov    -0x20(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
lea    0xdd2(%rip),%rdi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_data_mmap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x0(,%rdi,8),%rbx
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    %rdx,%rdi
call   1070 <open@plt>
mov    %eax,%r13d
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
mov    0x2e4f(%rip),%rax
mov    0x2e20(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e05(%rip),%rax
mov    0x2e06(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbp
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1080 <pread@plt>
mov    %rax,%r15
lea    0xdfb(%rip),%rdi
mov    0x8(%rsp),%rsi
mov    %r14,0x10(%rsp)
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
mov    %rbp,%r9
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r15,%rbx
je     124c <read_data_mmap+0xec>
mov    %r15,(%rsp)
lea    0xe04(%rip),%rdi
mov    0x8(%rsp),%rsi
mov    %rbp,%rdx
mov    0x10(%rsp),%rcx
mov    %r12,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmp    %r15,%rbx
sete   %dil
call   1060 <assert@plt>
mov    %r13d,%edi
call   1050 <close@plt>
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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
@.str = [54 x i8] c"[%s] read: %ld floats. Bytes %ld at %ld, mapping %p\0A\00"
@.str.1 = [70 x i8] c"[%s]: error: mapping %p, n %ld, o %ld, real_size %ld, read_size %ld.\0A\00"
define double* @read_data_mmap(i64 %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca double*
store i64 %0, i64* %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%13 = load i64, i64* %5
%14 = mul i64 %13, 8
store i64 %14, i64* %10
%15 = load i8*, i8** %7
%16 = load i32, i32* @O_RDONLY
%17 = or i32 %16, 0
%18 = call i32 @open(i8* %15, i32 %17)
store i32 %18, i32* %9
%19 = load i32, i32* %9
%20 = icmp sgt i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i64, i64* %10
%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, i64 %23, i32 %26, i32 %29, i32 -1, i32 0)
%31 = inttoptr i64 %30 to double*
store double* %31, double** %12
%32 = load double*, double** %12
%33 = icmp ne double* %32, null
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %9
%37 = load double*, double** %12
%38 = bitcast double* %37 to i8*
%39 = load i64, i64* %10
%40 = load i64, i64* %6
%41 = call i64 @pread(i32 %36, i8* %38, i64 %39, i64 %40)
store i64 %41, i64* %11
%42 = load i8*, i8** %8
%43 = load i64, i64* %5
%44 = load i64, i64* %10
%45 = load i64, i64* %6
%46 = load double*, double** %12
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %42, i64 %43, i64 %44, i64 %45, double* %46)
%48 = load i64, i64* %10
%49 = load i64, i64* %11
%50 = icmp ne i64 %48, %49
br i1 %50, label %51, label %59
51: ; preds = %4
%52 = load i8*, i8** %8
%53 = load double*, double** %12
%54 = load i64, i64* %5
%55 = load i64, i64* %6
%56 = load i64, i64* %10
%57 = load i64, i64* %11
%58 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %52, double* %53, i64 %54, i64 %55, i64 %56, i64 %57)
br label %59
59: ; preds = %51, %4
%60 = load i64, i64* %10
%61 = load i64, i64* %11
%62 = icmp eq i64 %60, %61
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = load i32, i32* %9
%66 = call i32 @close(i32 %65)
%67 = load double*, double** %12
ret double* %67
}

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
@.str = [54 x i8] c"[%s] read: %ld floats. Bytes %ld at %ld, mapping %p\0A\00"
@.str.1 = [70 x i8] c"[%s]: error: mapping %p, n %ld, o %ld, real_size %ld, read_size %ld.\0A\00"
define double* @read_data_mmap(i64 %0, i64 %1, i8* nocapture %2, i8* %3) {
%5 = shl i64 %0, 3
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %2, i32 %6)
%8 = icmp sgt i32 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @PROT_WRITE
%13 = or i32 %12, %11
%14 = load i32, i32* @MAP_PRIVATE
%15 = load i32, i32* @MAP_ANON
%16 = or i32 %15, %14
%17 = tail call i64 @mmap(i32* null, i64 %5, i32 %13, i32 %16, i32 -1, i32 0)
%18 = inttoptr i64 %17 to double*
%19 = icmp ne i64 %17, 0
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
%22 = inttoptr i64 %17 to i8*
%23 = tail call i64 @pread(i32 %7, i8* %22, i64 %5, i64 %1)
%24 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %3, i64 %0, i64 %5, i64 %1, double* %18)
%25 = icmp eq i64 %5, %23
br i1 %25, label %28, label %26
26: ; preds = %4
%27 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %3, double* %18, i64 %0, i64 %1, i64 %5, i64 %23)
br label %28
28: ; preds = %26, %4
%29 = zext i1 %25 to i32
%30 = tail call i32 @assert(i32 %29)
%31 = tail call i32 @close(i32 %7)
ret double* %18
}