#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 O_CREAT;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int close(int);
void *create_data(int, int, long);
int /*<<< orphan*/ io_error(char *, char const *);
int md_calc_size(unsigned int, long const *);
int open(char const *, int, int);
int write_coo(int, unsigned int, long const *);
float *create_coo(const char *name, unsigned int D, const long dims[D]) {
  int ofd;
  if (-1 == (ofd = open(name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)))
    io_error("Creating coo file %s", name);
  if (-1 == write_coo(ofd, D, dims))
    io_error("Creating coo file %s", name);
  long T = md_calc_size(D, dims) * sizeof(float);
  void *addr;
  if (NULL == (addr = create_data(ofd, 4096, T)))
    io_error("Creating coo file %s", name);
  if (-1 == close(ofd))
    io_error("Creating coo file %s", name);
  return (float *)addr;
}


x86 assembly (clang, -O0):
<create_coo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
or     (%rax),%esi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    0x2e3f(%rip),%rax
or     (%rax),%edx
call   1060 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11c2 <create_coo+0x62>
mov    -0x8(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1070 <io_error@plt>
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1080 <write_coo@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11f0 <create_coo+0x90>
mov    -0x8(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1070 <io_error@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <md_calc_size@plt>
cltq
shl    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <create_data@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1239 <create_coo+0xd9>
mov    -0x8(%rbp),%rsi
lea    0xdcc(%rip),%rdi
call   1070 <io_error@plt>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1260 <create_coo+0x100>
mov    -0x8(%rbp),%rsi
lea    0xda5(%rip),%rdi
call   1070 <io_error@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_coo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2e6a(%rip),%rax
mov    0x2e7b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e40(%rip),%rax
mov    0x2e49(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1060 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11ae <create_coo+0x4e>
lea    0xe5a(%rip),%rdi
mov    %r14,%rsi
call   1070 <io_error@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15,%rdx
call   1080 <write_coo@plt>
cmp    $0xffffffff,%eax
jne    11ce <create_coo+0x6e>
lea    0xe3a(%rip),%rdi
mov    %r14,%rsi
call   1070 <io_error@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <md_calc_size@plt>
movslq %eax,%rdx
shl    $0x2,%rdx
mov    %ebp,%edi
mov    $0x1000,%esi
call   1050 <create_data@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1202 <create_coo+0xa2>
lea    0xe06(%rip),%rdi
mov    %r14,%rsi
call   1070 <io_error@plt>
mov    %ebp,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    121d <create_coo+0xbd>
lea    0xdeb(%rip),%rdi
mov    %r14,%rsi
call   1070 <io_error@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [21 x i8] c"Creating coo file %s\00"
define float* @create_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*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64* %2, i64** %6
%10 = load i32, i32* %5
%11 = zext i32 %10 to i64
%12 = load i8*, i8** %4
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_CREAT
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %12, i32 %15, i32 %18)
store i32 %19, i32* %7
%20 = icmp eq i32 -1, %19
br i1 %20, label %21, label %24
21: ; preds = %3
%22 = load i8*, i8** %4
%23 = call i32 @io_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %3
%25 = load i32, i32* %7
%26 = load i32, i32* %5
%27 = load i64*, i64** %6
%28 = call i32 @write_coo(i32 %25, i32 %26, i64* %27)
%29 = icmp eq i32 -1, %28
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i8*, i8** %4
%32 = call i32 @io_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %30, %24
%34 = load i32, i32* %5
%35 = load i64*, i64** %6
%36 = call i32 @md_calc_size(i32 %34, i64* %35)
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 4
store i64 %38, i64* %8
%39 = load i32, i32* %7
%40 = load i64, i64* %8
%41 = call i8* @create_data(i32 %39, i32 4096, i64 %40)
store i8* %41, i8** %9
%42 = icmp eq i8* null, %41
br i1 %42, label %43, label %46
43: ; preds = %33
%44 = load i8*, i8** %4
%45 = call i32 @io_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %33
%47 = load i32, i32* %7
%48 = call i32 @close(i32 %47)
%49 = icmp eq i32 -1, %48
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = load i8*, i8** %4
%52 = call i32 @io_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %46
%54 = load i8*, i8** %9
%55 = bitcast i8* %54 to float*
ret float* %55
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [21 x i8] c"Creating coo file %s\00"
define float* @create_coo(i8* %0, i32 %1, i64* %2) {
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* %0, i32 %6, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = tail call i32 @io_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %12, %3
%15 = tail call i32 @write_coo(i32 %10, i32 %1, i64* %2)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @io_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %17, %14
%20 = tail call i32 @md_calc_size(i32 %1, i64* %2)
%21 = sext i32 %20 to i64
%22 = shl nsw i64 %21, 2
%23 = tail call i8* @create_data(i32 %10, i32 4096, i64 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = tail call i32 @io_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %27
27: ; preds = %25, %19
%28 = tail call i32 @close(i32 %10)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = tail call i32 @io_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %32
32: ; preds = %30, %27
%33 = bitcast i8* %23 to float*
ret float* %33
}