#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 */
double atof(char *);
double *malloc(int);
char *strdup(char *);
char *strtok(char *, char *);
double *readData(char *data) {
  double *ret = malloc((sizeof(int) * 5) + 1);
  if (ret == NULL) {
    return NULL;
  }
  char *strCopy = strdup(data);
  strCopy = strtok(strCopy, ",");
  int index = 0;
  while (strCopy != NULL) {
    ret[index] = atof(strCopy);
    index += 1;
    strCopy = strtok(NULL, ",");
  }
  return ret;
}


x86 assembly (clang, -O0):
<readData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x15,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1172 <readData+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <readData+0xa5>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11dd <readData+0x9d>
mov    -0x20(%rbp),%rdi
call   1030 <atof@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe31(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    119a <readData+0x5a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readData>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x15,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     119f <readData+0x5f>
mov    %rbx,%rdi
call   1060 <strdup@plt>
lea    0xe97(%rip),%rsi
mov    %rax,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     119f <readData+0x5f>
lea    0xe83(%rip),%r15
mov    %r14,%rbx
mov    %rax,%rdi
call   1030 <atof@plt>
movsd  %xmm0,(%rbx)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    1180 <readData+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define double* @readData(i8* %0) {
%2 = alloca double*
%3 = alloca i8*
%4 = alloca double*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = call double* @malloc(i32 21)
store double* %7, double** %4
%8 = load double*, double** %4
%9 = icmp eq double* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store double* null, double** %2
br label %31
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %5
store i32 0, i32* %6
br label %16
16: ; preds = %19, %11
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i8*, i8** %5
%21 = call double @atof(i8* %20)
%22 = load double*, double** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
store double %21, double* %25
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %28, i8** %5
br label %16
29: ; preds = %16
%30 = load double*, double** %4
store double* %30, double** %2
br label %31
31: ; preds = %29, %10
%32 = load double*, double** %2
ret double* %32
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define noalias double* @readData(i8* nocapture %0) {
%2 = tail call double* @malloc(i32 21)
%3 = icmp eq double* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
%6 = tail call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %16, label %8
8: ; preds = %4, %8
%9 = phi i64 [ %13, %8 ], [ 0, %4 ]
%10 = phi i8* [ %14, %8 ], [ %6, %4 ]
%11 = tail call double @atof(i8* %10)
%12 = getelementptr inbounds double, double* %2, i64 %9
store double %11, double* %12
%13 = add nuw i64 %9, 1
%14 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %8
16: ; preds = %8, %4, %1
ret double* %2
}