#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 /*<<< orphan*/ isspace(char);
double *malloc(int);
double *realloc(double *, int);
double strtod(char *, char **);
double *read_reference(char *str, int *nobj) {
  double *reference;
  char *endp;
  char *cursor;
  int k = 0, size = 10;
  reference = malloc(size * sizeof(double));
  endp = str;
  do {
    cursor = endp;
    if (k == size) {
      size += 10;
      reference = realloc(reference, size * sizeof(double));
    }
    reference[k] = strtod(cursor, &endp);
    k++;
  } while (cursor != endp);
  while (*cursor != '\0') {
    if (!isspace(*cursor))
      return NULL;
    cursor++;
  }
  if (k == 1)
    return NULL;
  *nobj = k - 1;
  return reference;
}


x86 assembly (clang, -O0):
<read_reference>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0xa,-0x38(%rbp)
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jne    11ad <read_reference+0x6d>
mov    -0x38(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x38(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <strtod@plt>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1179 <read_reference+0x39>
jmp    11e3 <read_reference+0xa3>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1226 <read_reference+0xe6>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    1215 <read_reference+0xd5>
movq   $0x0,-0x8(%rbp)
jmp    1251 <read_reference+0x111>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11e3 <read_reference+0xa3>
cmpl   $0x1,-0x34(%rbp)
jne    123d <read_reference+0xfd>
movq   $0x0,-0x8(%rbp)
jmp    1251 <read_reference+0x111>
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_reference>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbx
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rbx,0x8(%rsp)
mov    $0xa,%r14d
xor    %ebp,%ebp
lea    0x8(%rsp),%r12
jmp    119f <read_reference+0x5f>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <strtod@plt>
movsd  %xmm0,(%r15,%rbp,8)
add    $0x1,%rbp
mov    0x8(%rsp),%rbx
cmp    %rbx,%r13
je     11c8 <read_reference+0x88>
mov    %rbx,%r13
mov    %r14d,%eax
cmp    %rax,%rbp
jne    1180 <read_reference+0x40>
mov    %r14d,%ebx
add    $0xa,%ebx
lea    0x50(,%r14,8),%esi
mov    %r15,%rdi
call   1060 <realloc@plt>
mov    %rax,%r15
mov    %ebx,%r14d
jmp    1180 <read_reference+0x40>
mov    0x0(%r13),%al
test   %al,%al
je     11f9 <read_reference+0xb9>
add    $0x1,%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
call   1040 <isspace@plt>
test   %eax,%eax
je     11fe <read_reference+0xbe>
movzbl 0x0(%r13),%eax
add    $0x1,%r13
test   %al,%al
jne    11e0 <read_reference+0xa0>
cmp    $0x1,%ebp
jne    1203 <read_reference+0xc3>
xor    %r15d,%r15d
jmp    120e <read_reference+0xce>
add    $0xffffffffffffffff,%rbp
mov    0x10(%rsp),%rax
mov    %ebp,(%rax)
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @read_reference(i8* %0, i32* %1) {
%3 = alloca double*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca double*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %9
store i32 10, i32* %10
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 8
%14 = trunc i64 %13 to i32
%15 = call double* @malloc(i32 %14)
store double* %15, double** %6
%16 = load i8*, i8** %4
store i8* %16, i8** %7
br label %17
17: ; preds = %40, %2
%18 = load i8*, i8** %7
store i8* %18, i8** %8
%19 = load i32, i32* %9
%20 = load i32, i32* %10
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 10
store i32 %24, i32* %10
%25 = load double*, double** %6
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 8
%29 = trunc i64 %28 to i32
%30 = call double* @realloc(double* %25, i32 %29)
store double* %30, double** %6
br label %31
31: ; preds = %22, %17
%32 = load i8*, i8** %8
%33 = call double @strtod(i8* %32, i8** %7)
%34 = load double*, double** %6
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double %33, double* %37
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %40
40: ; preds = %31
%41 = load i8*, i8** %8
%42 = load i8*, i8** %7
%43 = icmp ne i8* %41, %42
br i1 %43, label %17, label %44
44: ; preds = %40
br label %45
45: ; preds = %56, %44
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %59
50: ; preds = %45
%51 = load i8*, i8** %8
%52 = load i8, i8* %51
%53 = call i32 @isspace(i8 signext %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %50
store double* null, double** %3
br label %68
56: ; preds = %50
%57 = load i8*, i8** %8
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %8
br label %45
59: ; preds = %45
%60 = load i32, i32* %9
%61 = icmp eq i32 %60, 1
br i1 %61, label %62, label %63
62: ; preds = %59
store double* null, double** %3
br label %68
63: ; preds = %59
%64 = load i32, i32* %9
%65 = sub nsw i32 %64, 1
%66 = load i32*, i32** %5
store i32 %65, i32* %66
%67 = load double*, double** %6
store double* %67, double** %3
br label %68
68: ; preds = %63, %62, %55
%69 = load double*, double** %3
ret double* %69
}

LLVM IR (-O2):
define double* @read_reference(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call double* @malloc(i32 80)
store i8* %0, i8** %3
br label %6
6: ; preds = %17, %2
%7 = phi i8* [ %23, %17 ], [ %0, %2 ]
%8 = phi i64 [ %22, %17 ], [ 0, %2 ]
%9 = phi double* [ %18, %17 ], [ %5, %2 ]
%10 = phi i32 [ %19, %17 ], [ 10, %2 ]
%11 = zext i32 %10 to i64
%12 = icmp eq i64 %8, %11
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = add nsw i32 %10, 10
%15 = shl i32 %14, 3
%16 = tail call double* @realloc(double* %9, i32 %15)
br label %17
17: ; preds = %13, %6
%18 = phi double* [ %16, %13 ], [ %9, %6 ]
%19 = phi i32 [ %14, %13 ], [ %10, %6 ]
%20 = call double @strtod(i8* %7, i8** %3)
%21 = getelementptr inbounds double, double* %18, i64 %8
store double %20, double* %21
%22 = add nuw i64 %8, 1
%23 = load i8*, i8** %3
%24 = icmp eq i8* %7, %23
br i1 %24, label %25, label %6
25: ; preds = %17
%26 = trunc i64 %8 to i32
%27 = load i8, i8* %7
%28 = icmp eq i8 %27, 0
br i1 %28, label %38, label %32
29: ; preds = %32
%30 = load i8, i8* %37
%31 = icmp eq i8 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %25, %29
%33 = phi i8 [ %30, %29 ], [ %27, %25 ]
%34 = phi i8* [ %37, %29 ], [ %7, %25 ]
%35 = tail call i32 @isspace(i8 signext %33)
%36 = icmp eq i32 %35, 0
%37 = getelementptr inbounds i8, i8* %34, i64 1
br i1 %36, label %41, label %29
38: ; preds = %29, %25
%39 = icmp eq i32 %26, 0
br i1 %39, label %41, label %40
40: ; preds = %38
store i32 %26, i32* %1
br label %41
41: ; preds = %32, %38, %40
%42 = phi double* [ %18, %40 ], [ null, %38 ], [ null, %32 ]
ret double* %42
}