#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 void *caddr_t;

/* Variables and functions */
int MAP_LOCKED;
int MAP_SHARED;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int lseek(int, int, int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/, int, int, int, int, int /*<<< orphan*/);
int open(char const *, int, ...);
int write(int, char *, int);
float *mmapOpen(const char *filename, char create, long count) {
  void *addr;
  int file;
  int size = sizeof(float) * count;
  if ((create && (file = open(filename, O_RDWR | O_CREAT | O_TRUNC,
                              S_IRUSR | S_IWUSR)) < 0) ||
      (!create && (file = open(filename, O_RDWR)) < 0)) {
    return NULL;
  }
  if (lseek(file, size - 1, SEEK_SET) == -1) {
    return NULL;
  }
  if (write(file, "", 1) != 1) {
    return NULL;
  }
  if ((addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED,
                   file, 0)) == (caddr_t)-1) {
    return NULL;
  }
  close(file);
  return (float *)addr;
}


x86 assembly (clang, -O0):
<mmapOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x30(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
je     11c2 <mmapOpen+0x72>
mov    -0x10(%rbp),%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
mov    0x2e66(%rip),%rax
or     (%rax),%esi
mov    0x2e55(%rip),%rax
or     (%rax),%esi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    0x2e13(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jl     11ec <mmapOpen+0x9c>
cmpb   $0x0,-0x11(%rbp)
jne    11f9 <mmapOpen+0xa9>
mov    -0x10(%rbp),%rdi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    11f9 <mmapOpen+0xa9>
movq   $0x0,-0x8(%rbp)
jmp    12b7 <mmapOpen+0x167>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
sub    $0x1,%esi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1226 <mmapOpen+0xd6>
movq   $0x0,-0x8(%rbp)
jmp    12b7 <mmapOpen+0x167>
mov    -0x2c(%rbp),%edi
lea    0xdd0(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1250 <mmapOpen+0x100>
movq   $0x0,-0x8(%rbp)
jmp    12b7 <mmapOpen+0x167>
mov    -0x30(%rbp),%esi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
mov    0x2d3d(%rip),%rax
or     (%rax),%edx
mov    0x2d6c(%rip),%rax
mov    (%rax),%ecx
mov    0x2d3b(%rip),%rax
or     (%rax),%ecx
mov    -0x2c(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    12a7 <mmapOpen+0x157>
movq   $0x0,-0x8(%rbp)
jmp    12b7 <mmapOpen+0x167>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmapOpen>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%eax
mov    0x2e68(%rip),%rcx
mov    (%rcx),%esi
test   %al,%al
je     1195 <mmapOpen+0x45>
mov    0x2e8b(%rip),%rax
or     (%rax),%esi
mov    0x2e7a(%rip),%rax
or     (%rax),%esi
mov    0x2e19(%rip),%rax
mov    0x2e3a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <open@plt>
jmp    119e <mmapOpen+0x4e>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     122a <mmapOpen+0xda>
shl    $0x2,%r14d
lea    -0x1(%r14),%esi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     1228 <mmapOpen+0xd8>
lea    0xe34(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1228 <mmapOpen+0xd8>
mov    0x2e04(%rip),%rax
mov    0x2db5(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2de2(%rip),%rax
mov    0x2db3(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     122a <mmapOpen+0xda>
mov    %rax,%r14
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14,%rbx
jmp    122a <mmapOpen+0xda>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEEK_SET = global i32 0
@.str = [1 x i8] zeroinitializer
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_LOCKED = global i32 0
define float* @mmapOpen(i8* %0, i8 signext %1, i64 %2) {
%4 = alloca float*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8 %1, i8* %6
store i64 %2, i64* %7
%11 = load i64, i64* %7
%12 = mul i64 4, %11
%13 = trunc i64 %12 to i32
store i32 %13, i32* %10
%14 = load i8, i8* %6
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i32, i32* @O_RDWR
%20 = load i32, i32* @O_CREAT
%21 = or i32 %19, %20
%22 = load i32, i32* @O_TRUNC
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IRUSR
%25 = load i32, i32* @S_IWUSR
%26 = or i32 %24, %25
%27 = call i32 (i8*, i32, ...) @open(i8* %18, i32 %23, i32 %26)
store i32 %27, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %37, label %29
29: ; preds = %17, %3
%30 = load i8, i8* %6
%31 = icmp ne i8 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = load i8*, i8** %5
%34 = load i32, i32* @O_RDWR
%35 = call i32 (i8*, i32, ...) @open(i8* %33, i32 %34)
store i32 %35, i32* %9
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32, %17
store float* null, float** %4
br label %68
38: ; preds = %32, %29
%39 = load i32, i32* %9
%40 = load i32, i32* %10
%41 = sub nsw i32 %40, 1
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @lseek(i32 %39, i32 %41, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %46
45: ; preds = %38
store float* null, float** %4
br label %68
46: ; preds = %38
%47 = load i32, i32* %9
%48 = call i32 @write(i32 %47, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1)
%49 = icmp ne i32 %48, 1
br i1 %49, label %50, label %51
50: ; preds = %46
store float* null, float** %4
br label %68
51: ; preds = %46
%52 = load i32, i32* %10
%53 = load i32, i32* @PROT_READ
%54 = load i32, i32* @PROT_WRITE
%55 = or i32 %53, %54
%56 = load i32, i32* @MAP_SHARED
%57 = load i32, i32* @MAP_LOCKED
%58 = or i32 %56, %57
%59 = load i32, i32* %9
%60 = call i8* @mmap(i32 0, i32 %52, i32 %55, i32 %58, i32 %59, i32 0)
store i8* %60, i8** %8
%61 = icmp eq i8* %60, inttoptr (i64 -1 to i8*)
br i1 %61, label %62, label %63
62: ; preds = %51
store float* null, float** %4
br label %68
63: ; preds = %51
%64 = load i32, i32* %9
%65 = call i32 @close(i32 %64)
%66 = load i8*, i8** %8
%67 = bitcast i8* %66 to float*
store float* %67, float** %4
br label %68
68: ; preds = %63, %62, %50, %45, %37
%69 = load float*, float** %4
ret float* %69
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@SEEK_SET = global i32 0
@.str = [1 x i8] zeroinitializer
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_LOCKED = global i32 0
define float* @mmapOpen(i8* nocapture %0, i8 signext %1, i64 %2) {
%4 = trunc i64 %2 to i32
%5 = shl i32 %4, 2
%6 = icmp eq i8 %1, 0
%7 = load i32, i32* @O_RDWR
br i1 %6, label %18, label %8
8: ; preds = %3
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %7
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %14, %13
%16 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %12, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %42, label %21
18: ; preds = %3
%19 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %7)
%20 = icmp slt i32 %19, 0
br i1 %20, label %42, label %21
21: ; preds = %8, %18
%22 = phi i32 [ %19, %18 ], [ %16, %8 ]
%23 = add nsw i32 %5, -1
%24 = load i32, i32* @SEEK_SET
%25 = tail call i32 @lseek(i32 %22, i32 %23, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %42, label %27
27: ; preds = %21
%28 = tail call i32 @write(i32 %22, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 1)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load i32, i32* @PROT_READ
%32 = load i32, i32* @PROT_WRITE
%33 = or i32 %32, %31
%34 = load i32, i32* @MAP_SHARED
%35 = load i32, i32* @MAP_LOCKED
%36 = or i32 %35, %34
%37 = tail call i8* @mmap(i32 0, i32 %5, i32 %33, i32 %36, i32 %22, i32 0)
%38 = icmp eq i8* %37, inttoptr (i64 -1 to i8*)
br i1 %38, label %42, label %39
39: ; preds = %30
%40 = tail call i32 @close(i32 %22)
%41 = bitcast i8* %37 to float*
br label %42
42: ; preds = %30, %27, %21, %8, %18, %39
%43 = phi float* [ %41, %39 ], [ null, %18 ], [ null, %8 ], [ null, %21 ], [ null, %27 ], [ null, %30 ]
ret float* %43
}