#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 */
char *Csv_readDoubles(char *, unsigned int const, unsigned int, unsigned int,
                      double *);
int /*<<< orphan*/ halt(char *, unsigned int, unsigned int);
double *malloc(int);
double *readFeatures(unsigned nObservations, unsigned nDimensions,
                     char **headerP) {
  double *featuresP = malloc(sizeof(double) * nObservations * nDimensions);
  if (!featuresP)
    halt("unable to allocate features: %u x %u\n", nObservations, nDimensions);
  const unsigned expectHeader = 1;
  char *headerBuffer = Csv_readDoubles("features.csv", expectHeader,
                                       nObservations, nDimensions, featuresP);
  *headerP = headerBuffer;
  return featuresP;
}


x86 assembly (clang, -O0):
<readFeatures>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x3,%rax
mov    -0x8(%rbp),%ecx
imul   %rcx,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1178 <readFeatures+0x48>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe8d(%rip),%rdi
call   1050 <halt@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%r8
lea    0xe96(%rip),%rdi
mov    $0x1,%esi
call   1030 <Csv_readDoubles@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFeatures>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
imul   %esi,%edi
shl    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1163 <readFeatures+0x33>
lea    0xea7(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1050 <halt@plt>
lea    0xebc(%rip),%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %rbp,%r8
call   1030 <Csv_readDoubles@plt>
mov    %rax,(%r14)
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"unable to allocate features: %u x %u\0A\00"
@.str.1 = [13 x i8] c"features.csv\00"
define double* @readFeatures(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca double*
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%10 = load i32, i32* %4
%11 = zext i32 %10 to i64
%12 = mul i64 8, %11
%13 = load i32, i32* %5
%14 = zext i32 %13 to i64
%15 = mul i64 %12, %14
%16 = trunc i64 %15 to i32
%17 = call double* @malloc(i32 %16)
store double* %17, double** %7
%18 = load double*, double** %7
%19 = icmp ne double* %18, null
br i1 %19, label %24, label %20
20: ; preds = %3
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @halt(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
br label %24
24: ; preds = %20, %3
store i32 1, i32* %8
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = load double*, double** %7
%28 = call i8* @Csv_readDoubles(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %25, i32 %26, double* %27)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = load i8**, i8*** %6
store i8* %29, i8** %30
%31 = load double*, double** %7
ret double* %31
}

LLVM IR (-O2):
@.str = [38 x i8] c"unable to allocate features: %u x %u\0A\00"
@.str.1 = [13 x i8] c"features.csv\00"
define double* @readFeatures(i32 %0, i32 %1, i8** nocapture writeonly %2) {
%4 = shl i32 %0, 3
%5 = mul i32 %4, %1
%6 = tail call double* @malloc(i32 %5)
%7 = icmp eq double* %6, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @halt(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
br label %10
10: ; preds = %8, %3
%11 = tail call i8* @Csv_readDoubles(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %0, i32 %1, double* %6)
store i8* %11, i8** %2
ret double* %6
}