#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ printf(char *, char *);
double *read_csv_doubles(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ stderr;
char *strerror(int);
double *readDoubleVecFile(int *valuesRead, char *filename) {
  FILE *file = fopen(filename, "r");
  if (file == NULL) {
    fprintf(stderr, "Error reading %s: %d (%s)\n", filename, errno,
            strerror(errno));
    exit(0);
  }
  double *res = read_csv_doubles(file, valuesRead);
  if (res == NULL) {
    printf("readDoubleVecFile: Error reading file '%s'\n", filename);
    fclose(file);
    exit(0);
  }
  fclose(file);
  return res;
}


x86 assembly (clang, -O0):
<readDoubleVecFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ed <readDoubleVecFile+0x7d>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    %rax,%r8
lea    0xe21(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <read_csv_doubles@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1229 <readDoubleVecFile+0xb9>
mov    -0x10(%rbp),%rsi
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readDoubleVecFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe7b(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bc <readDoubleVecFile+0x4c>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
call   1070 <read_csv_doubles@plt>
test   %rax,%rax
je     11f2 <readDoubleVecFile+0x82>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e0c(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xe26(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %rax,%r8
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe24(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error reading %s: %d (%s)\0A\00"
@errno = global i32 0
@.str.2 = [44 x i8] c"readDoubleVecFile: Error reading file '%s'\0A\00"
define double* @readDoubleVecFile(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca double*
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %4
%14 = load i32, i32* @errno
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %14, i8* %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = load i32*, i32** %5
%21 = load i32*, i32** %3
%22 = call double* @read_csv_doubles(i32* %20, i32* %21)
store double* %22, double** %6
%23 = load double*, double** %6
%24 = icmp eq double* %23, null
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32*, i32** %5
%29 = call i32 @fclose(i32* %28)
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %19
%32 = load i32*, i32** %5
%33 = call i32 @fclose(i32* %32)
%34 = load double*, double** %6
ret double* %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error reading %s: %d (%s)\0A\00"
@errno = global i32 0
@.str.2 = [44 x i8] c"readDoubleVecFile: Error reading file '%s'\0A\00"
define double* @readDoubleVecFile(i32* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %7, i8* %8)
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = tail call double* @read_csv_doubles(i32* %3, i32* %0)
%13 = icmp eq double* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%16 = tail call i32 @fclose(i32* %3)
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %11
%19 = tail call i32 @fclose(i32* %3)
ret double* %12
}