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


x86 assembly (clang, -O0):
<ivalues>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x4,%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    11bb <ivalues+0x8b>
mov    -0x20(%rbp),%rdi
lea    0xe80(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x28(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe5c(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <ivalues+0x3b>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ivalues>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,%r13
lea    0xeaa(%rip),%rsi
mov    %r14,%rdi
call   1050 <strtok@plt>
test   %ebp,%ebp
jle    11aa <ivalues+0x7a>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe95(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xe87(%rip),%r12
nopl   0x0(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
mov    0x4(%rsp),%eax
mov    %eax,0x0(%r13,%rbx,4)
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <ivalues+0x50>
mov    %r13,%rax
add    $0x8,%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 = [3 x i8] c"%d\00"
define i32* @ivalues(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = call i32* @calloc(i32 %9, i32 4)
store i32* %10, i32** %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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%20 = load i32, i32* %8
%21 = load i32*, i32** %5
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
store i32 %20, i32* %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 i32*, i32** %5
ret i32* %30
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [3 x i8] c"%d\00"
define noalias i32* @ivalues(i8* %0, i32 %1) {
%3 = alloca i32
%4 = tail call i32* @calloc(i32 %1, i32 4)
%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 i32* %3 to i8*
%9 = zext i32 %1 to i64
br label %11
10: ; preds = %11, %2
ret i32* %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 ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%15 = load i32, i32* %3
%16 = getelementptr inbounds i32, i32* %4, i64 %12
store i32 %15, i32* %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
}