#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 */
scalar_t__ isdigit(char);
double *malloc(int);
double strtod(char *, char **);
double *charsToDoubles(char *str) {
  double *pd = malloc(sizeof(double) * 10);
  int i = 0;
  while (*str) {
    if (isdigit(*str) || (*str == '-' && isdigit(*(str + 1)))) {
      double val = strtod(str, &str);
      pd[i] = val;
      i++;
    } else {
      str++;
    }
  }
  return pd;
}


x86 assembly (clang, -O0):
<charsToDoubles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11de <charsToDoubles+0xae>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    119b <charsToDoubles+0x6b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11cd <charsToDoubles+0x9d>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11cd <charsToDoubles+0x9d>
mov    -0x8(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d9 <charsToDoubles+0xa9>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1151 <charsToDoubles+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charsToDoubles>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rdi,(%rsp)
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%al
test   %al,%al
je     11af <charsToDoubles+0x7f>
xor    %r12d,%r12d
mov    %rsp,%r15
jmp    1193 <charsToDoubles+0x63>
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11a5 <charsToDoubles+0x75>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strtod@plt>
movslq %r12d,%r12
movsd  %xmm0,(%r14,%r12,8)
add    $0x1,%r12d
mov    (%rsp),%rbx
movzbl (%rbx),%eax
test   %al,%al
je     11af <charsToDoubles+0x7f>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <charsToDoubles+0x40>
cmpb   $0x2d,(%rbx)
je     115a <charsToDoubles+0x2a>
add    $0x1,%rbx
mov    %rbx,(%rsp)
jmp    118c <charsToDoubles+0x5c>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @charsToDoubles(i8* %0) {
%2 = alloca i8*
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
store i8* %0, i8** %2
%6 = call double* @malloc(i32 80)
store double* %6, double** %3
store i32 0, i32* %4
br label %7
7: ; preds = %40, %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %41
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 45
br i1 %20, label %21, label %37
21: ; preds = %16
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8, i8* %23
%25 = call i64 @isdigit(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %21, %11
%28 = load i8*, i8** %2
%29 = call double @strtod(i8* %28, i8** %2)
store double %29, double* %5
%30 = load double, double* %5
%31 = load double*, double** %3
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double %30, double* %34
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %40
37: ; preds = %21, %16
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %2
br label %40
40: ; preds = %37, %27
br label %7
41: ; preds = %7
%42 = load double*, double** %3
ret double* %42
}

LLVM IR (-O2):
define noalias double* @charsToDoubles(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = tail call double* @malloc(i32 80)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %33, label %6
6: ; preds = %1, %28
%7 = phi i8 [ %31, %28 ], [ %4, %1 ]
%8 = phi i8* [ %29, %28 ], [ %0, %1 ]
%9 = phi i32 [ %30, %28 ], [ 0, %1 ]
%10 = tail call i64 @isdigit(i8 signext %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %6
%13 = load i8, i8* %8
%14 = icmp eq i8 %13, 45
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %8, i64 1
%17 = load i8, i8* %16
%18 = tail call i64 @isdigit(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %15, %6
%21 = call double @strtod(i8* %8, i8** %2)
%22 = sext i32 %9 to i64
%23 = getelementptr inbounds double, double* %3, i64 %22
store double %21, double* %23
%24 = add nsw i32 %9, 1
%25 = load i8*, i8** %2
br label %28
26: ; preds = %15, %12
%27 = getelementptr inbounds i8, i8* %8, i64 1
store i8* %27, i8** %2
br label %28
28: ; preds = %26, %20
%29 = phi i8* [ %25, %20 ], [ %27, %26 ]
%30 = phi i32 [ %24, %20 ], [ %9, %26 ]
%31 = load i8, i8* %29
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %6
33: ; preds = %28, %1
ret double* %3
}