#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 */
long double *calloc(int, int);
int /*<<< orphan*/ sscanf(char *, char *, long double *);
char *strtok(char *, char *);
long double *ldvalues(char *token, int total) {
  long double *values = calloc(total, sizeof(long double));
  char *tmp = strtok(token, ",");
  for (int i = 0; i < total; i++) {
    long double val;
    sscanf(tmp, "%Lf", &val);
    values[i] = val;
    tmp = strtok(NULL, ",");
  }
  return values;
}


x86 assembly (clang, -O0):
<ldvalues>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x10,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bf <ldvalues+0x8f>
mov    -0x20(%rbp),%rdi
lea    0xe80(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1040 <sscanf@plt>
fldt   -0x40(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
shl    $0x4,%rcx
fstpt  (%rax,%rcx,1)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe58(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <ldvalues+0x3b>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ldvalues>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
mov    $0x10,%esi
call   1030 <calloc@plt>
mov    %rax,%r13
lea    0xea7(%rip),%rsi
mov    %r14,%rdi
call   1050 <strtok@plt>
test   %ebp,%ebp
jle    11a9 <ldvalues+0x79>
mov    %ebp,%ebp
shl    $0x4,%rbp
xor    %ebx,%ebx
lea    0xe8e(%rip),%r14
mov    %rsp,%r15
lea    0xe82(%rip),%r12
xchg   %ax,%ax
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
fldt   (%rsp)
fstpt  0x0(%r13,%rbx,1)
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
add    $0x10,%rbx
cmp    %rbx,%rbp
jne    1180 <ldvalues+0x50>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [4 x i8] c"%Lf\00"
define noalias x86_fp80* @ldvalues(i8* %0, i32 %1) {
%3 = alloca x86_fp80
%4 = tail call x86_fp80* @calloc(i32 %1, i32 16)
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = bitcast x86_fp80* %3 to i8*
%9 = zext i32 %1 to i64
br label %11
10: ; preds = %11, %2
ret x86_fp80* %4
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %18, %11 ]
%13 = phi i8* [ %5, %7 ], [ %17, %11 ]
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), x86_fp80* %3)
%15 = load x86_fp80, x86_fp80* %3
%16 = getelementptr inbounds x86_fp80, x86_fp80* %4, i64 %12
store x86_fp80 %15, x86_fp80* %16
%17 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %9
br i1 %19, label %10, label %11
}