#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__ malloc(int);
int sscanf(char *, char *, double *, int *);
int strlen(char const *);
double *alloc_parse_doubles(int nmax, const char *ss, int *n) {
  int ns = strlen(ss);
  char t[2 + ns], *s = t;
  s[0] = ' ';
  for (int i = 0; i <= ns; i++)
    s[i + 1] = ss[i];
  double *r = (double *)malloc(nmax * sizeof *r);
  int i = 0, w;
  while (i < nmax && 1 == sscanf(s, "%*[][ \n\t,:;]%lf%n", r + i, &w)) {
    i += 1;
    s += w;
  }
  *n = i;
  return r;
}


x86 assembly (clang, -O0):
<alloc_parse_doubles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,%rsp
mov    %rcx,-0x30(%rbp)
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x20,(%rax)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11bd <alloc_parse_doubles+0x8d>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1188 <alloc_parse_doubles+0x58>
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x4(%rbp),%ecx
mov    %al,-0x51(%rbp)
jge    121a <alloc_parse_doubles+0xea>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rdx
movslq -0x4c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
lea    0xdfe(%rip),%rsi
lea    -0x50(%rbp),%rcx
call   1050 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
sete   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    122a <alloc_parse_doubles+0xfa>
jmp    1249 <alloc_parse_doubles+0x119>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x50(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    11d7 <alloc_parse_doubles+0xa7>
mov    -0x4c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x48(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_parse_doubles>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r13
mov    %rsi,%r15
mov    %edi,%r12d
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0x2(%rax),%ecx
mov    %rsp,%rdx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rdx,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
neg    %rcx
movb   $0x20,(%rdx,%rcx,1)
test   %eax,%eax
js     1196 <alloc_parse_doubles+0x56>
lea    0x1(%rbx),%rdi
mov    %eax,%edx
add    $0x1,%rdx
mov    %r15,%rsi
call   1040 <memcpy@plt>
lea    0x0(,%r12,8),%edi
call   1050 <malloc@plt>
test   %r12d,%r12d
jle    11fb <alloc_parse_doubles+0xbb>
mov    %r13,-0x40(%rbp)
mov    %r12d,%r12d
xor    %r14d,%r14d
lea    -0x2c(%rbp),%r13
mov    %rax,-0x38(%rbp)
mov    %rax,%r15
nopl   (%rax)
mov    %rbx,%rdi
lea    0xe36(%rip),%rsi
mov    %r15,%rdx
mov    %r13,%rcx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11f1 <alloc_parse_doubles+0xb1>
add    $0x1,%r14
movslq -0x2c(%rbp),%rax
add    %rax,%rbx
add    $0x8,%r15
cmp    %r14,%r12
jne    11c0 <alloc_parse_doubles+0x80>
mov    %r12d,%r14d
mov    -0x40(%rbp),%r13
mov    -0x38(%rbp),%rax
jmp    11fe <alloc_parse_doubles+0xbe>
xor    %r14d,%r14d
mov    %r14d,0x0(%r13)
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%*[][ \0A\09,:;]%lf%n\00"
define double* @alloc_parse_doubles(i32 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = add nsw i32 2, %17
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %8
%21 = alloca i8, i64 %19
store i64 %19, i64* %9
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = getelementptr inbounds i8, i8* %22, i64 0
store i8 32, i8* %23
store i32 0, i32* %11
br label %24
24: ; preds = %39, %3
%25 = load i32, i32* %11
%26 = load i32, i32* %7
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %42
28: ; preds = %24
%29 = load i8*, i8** %5
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = load i8*, i8** %10
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 %33, i8* %38
br label %39
39: ; preds = %28
%40 = load i32, i32* %11
%41 = add nsw i32 %40, 1
store i32 %41, i32* %11
br label %24
42: ; preds = %24
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = mul i64 %44, 8
%46 = trunc i64 %45 to i32
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to double*
store double* %48, double** %12
store i32 0, i32* %13
br label %49
49: ; preds = %63, %42
%50 = load i32, i32* %13
%51 = load i32, i32* %4
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %61
53: ; preds = %49
%54 = load i8*, i8** %10
%55 = load double*, double** %12
%56 = load i32, i32* %13
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = call i32 @sscanf(i8* %54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double* %58, i32* %14)
%60 = icmp eq i32 1, %59
br label %61
61: ; preds = %53, %49
%62 = phi i1 [ false, %49 ], [ %60, %53 ]
br i1 %62, label %63, label %70
63: ; preds = %61
%64 = load i32, i32* %13
%65 = add nsw i32 %64, 1
store i32 %65, i32* %13
%66 = load i32, i32* %14
%67 = load i8*, i8** %10
%68 = sext i32 %66 to i64
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8* %69, i8** %10
br label %49
70: ; preds = %61
%71 = load i32, i32* %13
%72 = load i32*, i32** %6
store i32 %71, i32* %72
%73 = load double*, double** %12
%74 = load i8*, i8** %8
ret double* %73
}

LLVM IR (-O2):
@.str = [18 x i8] c"%*[][ \0A\09,:;]%lf%n\00"
define double* @alloc_parse_doubles(i32 %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, 2
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
store i8 32, i8* %8
%9 = icmp slt i32 %5, 0
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = getelementptr inbounds i8, i8* %8, i64 1
%12 = zext i32 %5 to i64
%13 = add nuw nsw i64 %12, 1
br label %14
14: ; preds = %10, %3
%15 = shl i32 %0, 3
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to double*
%18 = bitcast i32* %4 to i8*
%19 = icmp sgt i32 %0, 0
br i1 %19, label %20, label %36
20: ; preds = %14
%21 = zext i32 %0 to i64
br label %22
22: ; preds = %20, %28
%23 = phi i64 [ 0, %20 ], [ %29, %28 ]
%24 = phi i8* [ %8, %20 ], [ %32, %28 ]
%25 = getelementptr inbounds double, double* %17, i64 %23
%26 = call i32 @sscanf(i8* %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double* %25, i32* %4)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = add nuw nsw i64 %23, 1
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %24, i64 %31
%33 = icmp eq i64 %29, %21
br i1 %33, label %36, label %22
34: ; preds = %22
%35 = trunc i64 %23 to i32
br label %36
36: ; preds = %28, %34, %14
%37 = phi i32 [ 0, %14 ], [ %35, %34 ], [ %0, %28 ]
store i32 %37, i32* %2
ret double* %17
}