#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 */
struct stat {
  long st_size;
};

/* Variables and functions */
void *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int PROT_READ;
int PROT_WRITE;
int close(int);
int fstat(int, struct stat *);
int /*<<< orphan*/ io_error(char *, char const *);
int md_calc_size(unsigned int, long *);
void *mmap(int /*<<< orphan*/ *, long, int, int /*<<< orphan*/, int, int);
int open(char const *, int /*<<< orphan*/);
int read_coo(int, unsigned int, long *);
float *load_coo(const char *name, unsigned int D, long dims[D]) {
  int fd;
  if (-1 == (fd = open(name, O_RDONLY)))
    io_error("Loading coo file %s", name);
  if (-1 == read_coo(fd, D, dims))
    io_error("Loading coo file %s", name);
  long T = md_calc_size(D, dims) * sizeof(float);
  void *addr;
  struct stat st;
  if (-1 == fstat(fd, &st))
    io_error("Loading coo file %s", name);
  if (T + 4096 != st.st_size)
    io_error("Loading coo file %s", name);
  if (MAP_FAILED ==
      (addr = mmap(NULL, T, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 4096)))
    io_error("Loading coo file %s", name);
  if (-1 == close(fd))
    io_error("Loading coo file %s", name);
  return (float *)addr;
}


x86 assembly (clang, -O0):
<load_coo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11b7 <load_coo+0x47>
mov    -0x8(%rbp),%rsi
lea    0xe4e(%rip),%rdi
call   1080 <io_error@plt>
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <read_coo@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11e5 <load_coo+0x75>
mov    -0x8(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1080 <io_error@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <md_calc_size@plt>
cltq
shl    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1090 <fstat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1226 <load_coo+0xb6>
mov    -0x8(%rbp),%rsi
lea    0xddf(%rip),%rdi
call   1080 <io_error@plt>
mov    -0x28(%rbp),%rax
add    $0x1000,%rax
cmp    -0x38(%rbp),%rax
je     124a <load_coo+0xda>
mov    -0x8(%rbp),%rsi
lea    0xdbb(%rip),%rdi
call   1080 <io_error@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rsi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
mov    0x2d64(%rip),%rax
or     (%rax),%edx
mov    0x2d53(%rip),%rax
mov    (%rax),%ecx
mov    -0x1c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%r9d
call   1030 <mmap@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,-0x30(%rbp)
cmp    %rcx,%rax
jne    12ae <load_coo+0x13e>
mov    -0x8(%rbp),%rsi
lea    0xd57(%rip),%rdi
call   1080 <io_error@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12d5 <load_coo+0x165>
mov    -0x8(%rbp),%rsi
lea    0xd30(%rip),%rdi
call   1080 <io_error@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_coo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11a3 <load_coo+0x33>
lea    0xe65(%rip),%rdi
mov    %r14,%rsi
call   1080 <io_error@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15,%rdx
call   1050 <read_coo@plt>
cmp    $0xffffffff,%eax
jne    11c3 <load_coo+0x53>
lea    0xe45(%rip),%rdi
mov    %r14,%rsi
call   1080 <io_error@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1060 <md_calc_size@plt>
movslq %eax,%rbx
shl    $0x2,%rbx
mov    %rsp,%rsi
mov    %ebp,%edi
call   1090 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11f2 <load_coo+0x82>
lea    0xe16(%rip),%rdi
mov    %r14,%rsi
call   1080 <io_error@plt>
lea    0x1000(%rbx),%rax
cmp    (%rsp),%rax
je     120e <load_coo+0x9e>
lea    0xdfa(%rip),%rdi
mov    %r14,%rsi
call   1080 <io_error@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%r15
mov    0x2dd9(%rip),%rax
mov    0x2daa(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d97(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %ebp,%r8d
mov    $0x1000,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
cmp    %rax,%r15
jne    125d <load_coo+0xed>
lea    0xdab(%rip),%rdi
mov    %r14,%rsi
call   1080 <io_error@plt>
mov    %ebp,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1278 <load_coo+0x108>
lea    0xd90(%rip),%rdi
mov    %r14,%rsi
call   1080 <io_error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@.str = [20 x i8] c"Loading coo file %s\00"
@MAP_FAILED = global i8* null
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
define float* @load_coo(i8* %0, i32 %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca %struct.stat
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64* %2, i64** %6
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = load i8*, i8** %4
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %7
%16 = icmp eq i32 -1, %15
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %3
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = load i64*, i64** %6
%24 = call i32 @read_coo(i32 %21, i32 %22, i64* %23)
%25 = icmp eq i32 -1, %24
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %20
%30 = load i32, i32* %5
%31 = load i64*, i64** %6
%32 = call i32 @md_calc_size(i32 %30, i64* %31)
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 4
store i64 %34, i64* %8
%35 = load i32, i32* %7
%36 = call i32 @fstat(i32 %35, %struct.stat* %10)
%37 = icmp eq i32 -1, %36
br i1 %37, label %38, label %41
38: ; preds = %29
%39 = load i8*, i8** %4
%40 = call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %29
%42 = load i64, i64* %8
%43 = add nsw i64 %42, 4096
%44 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%45 = load i64, i64* %44
%46 = icmp ne i64 %43, %45
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = load i8*, i8** %4
%49 = call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47, %41
%51 = load i8*, i8** @MAP_FAILED
%52 = load i64, i64* %8
%53 = load i32, i32* @PROT_READ
%54 = load i32, i32* @PROT_WRITE
%55 = or i32 %53, %54
%56 = load i32, i32* @MAP_PRIVATE
%57 = load i32, i32* %7
%58 = call i8* @mmap(i32* null, i64 %52, i32 %55, i32 %56, i32 %57, i32 4096)
store i8* %58, i8** %9
%59 = icmp eq i8* %51, %58
br i1 %59, label %60, label %63
60: ; preds = %50
%61 = load i8*, i8** %4
%62 = call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %60, %50
%64 = load i32, i32* %7
%65 = call i32 @close(i32 %64)
%66 = icmp eq i32 -1, %65
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i8*, i8** %4
%69 = call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %67, %63
%71 = load i8*, i8** %9
%72 = bitcast i8* %71 to float*
ret float* %72
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@.str = [20 x i8] c"Loading coo file %s\00"
@MAP_FAILED = global i8* null
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
define float* @load_coo(i8* %0, i32 %1, i64* %2) {
%4 = alloca %struct.stat
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %8, %3
%11 = tail call i32 @read_coo(i32 %6, i32 %1, i64* %2)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @md_calc_size(i32 %1, i64* %2)
%17 = sext i32 %16 to i64
%18 = shl nsw i64 %17, 2
%19 = bitcast %struct.stat* %4 to i8*
%20 = call i32 @fstat(i32 %6, %struct.stat* %4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = tail call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %22, %15
%25 = add nsw i64 %18, 4096
%26 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%27 = load i64, i64* %26
%28 = icmp eq i64 %25, %27
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = tail call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %31
31: ; preds = %29, %24
%32 = load i8*, i8** @MAP_FAILED
%33 = load i32, i32* @PROT_READ
%34 = load i32, i32* @PROT_WRITE
%35 = or i32 %34, %33
%36 = load i32, i32* @MAP_PRIVATE
%37 = tail call i8* @mmap(i32* null, i64 %18, i32 %35, i32 %36, i32 %6, i32 4096)
%38 = icmp eq i8* %32, %37
br i1 %38, label %39, label %41
39: ; preds = %31
%40 = tail call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %41
41: ; preds = %39, %31
%42 = tail call i32 @close(i32 %6)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i32 @io_error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %46
46: ; preds = %44, %41
%47 = bitcast i8* %37 to float*
ret float* %47
}