#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*/ free(char *);
int /*<<< orphan*/ halt(char *, unsigned int, unsigned int);
double *malloc(int);
double *readFeatures(unsigned nObservations, unsigned nDimensions) {
  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 *featuresHeader = Csv_readDoubles("features.csv", expectHeader,
                                         nObservations, nDimensions, featuresP);
  free(featuresHeader);
  return featuresP;
}


x86 assembly (clang, -O0):
<readFeatures>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x3,%rax
mov    -0x8(%rbp),%ecx
imul   %rcx,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <readFeatures+0x44>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe81(%rip),%rdi
call   1060 <halt@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%r8
lea    0xe8a(%rip),%rdi
mov    $0x1,%esi
call   1040 <Csv_readDoubles@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFeatures>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
imul   %esi,%edi
shl    $0x3,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116d <readFeatures+0x2d>
lea    0xe9d(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1060 <halt@plt>
lea    0xeb2(%rip),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
mov    %rbx,%r8
call   1040 <Csv_readDoubles@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
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) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double*
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = zext i32 %8 to i64
%10 = mul i64 8, %9
%11 = load i32, i32* %4
%12 = zext i32 %11 to i64
%13 = mul i64 %10, %12
%14 = trunc i64 %13 to i32
%15 = call double* @malloc(i32 %14)
store double* %15, double** %5
%16 = load double*, double** %5
%17 = icmp ne double* %16, null
br i1 %17, label %22, label %18
18: ; preds = %2
%19 = load i32, i32* %3
%20 = load i32, i32* %4
%21 = call i32 @halt(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20)
br label %22
22: ; preds = %18, %2
store i32 1, i32* %6
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = load double*, double** %5
%26 = call i8* @Csv_readDoubles(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %23, i32 %24, double* %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = call i32 @free(i8* %27)
%29 = load double*, double** %5
ret double* %29
}

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) {
%3 = shl i32 %0, 3
%4 = mul i32 %3, %1
%5 = tail call double* @malloc(i32 %4)
%6 = icmp eq double* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @halt(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
br label %9
9: ; preds = %7, %2
%10 = 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* %5)
%11 = tail call i32 @free(i8* %10)
ret double* %5
}