#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 *atoi(char *);
int /*<<< orphan*/ memset(int **, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strtok(char *, char *);
int str2nums(int *nums[], const char *ns) {
  char *tk, *ps;
  char cns[3 * 15];
  int pos = 0, qtd = 1;
  memset(nums, 0, 15);
  strcpy(cns, ns);
  if (!(tk = strtok(cns, ",")))
    return 0;
  nums[0] = atoi(tk);
  while ((tk = strtok(NULL, ","))) {
    nums[++pos] = atoi(tk);
    qtd++;
  }
  return qtd;
}


x86 assembly (clang, -O0):
<str2nums>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x1,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xf,%edx
call   1040 <memset@plt>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x60(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a5 <str2nums+0x65>
movl   $0x0,-0x4(%rbp)
jmp    120a <str2nums+0xca>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe3d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1204 <str2nums+0xc4>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x64(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x64(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11b8 <str2nums+0x78>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2nums>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xf,%edx
call   1040 <memset@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xe8c(%rip),%rsi
mov    %r12,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11d6 <str2nums+0x96>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %rax,(%r14)
lea    0xe6d(%rip),%rsi
xor    %edi,%edi
call   1050 <strtok@plt>
test   %rax,%rax
je     11d1 <str2nums+0x91>
mov    $0x1,%ebx
lea    0xe55(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %rax,(%r14,%rbx,8)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    11b0 <str2nums+0x70>
jmp    11d6 <str2nums+0x96>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define i32 @str2nums(i32** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [45 x i8]
%9 = alloca i32
%10 = alloca i32
store i32** %0, i32*** %4
store i8* %1, i8** %5
store i32 0, i32* %9
store i32 1, i32* %10
%11 = load i32**, i32*** %4
%12 = call i32 @memset(i32** %11, i32 0, i32 15)
%13 = getelementptr inbounds [45 x i8], [45 x i8]* %8, i64 0, i64 0
%14 = load i8*, i8** %5
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = getelementptr inbounds [45 x i8], [45 x i8]* %8, i64 0, i64 0
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %2
store i32 0, i32* %3
br label %40
20: ; preds = %2
%21 = load i8*, i8** %6
%22 = call i32* @atoi(i8* %21)
%23 = load i32**, i32*** %4
%24 = getelementptr inbounds i32*, i32** %23, i64 0
store i32* %22, i32** %24
br label %25
25: ; preds = %28, %20
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %26, i8** %6
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = call i32* @atoi(i8* %29)
%31 = load i32**, i32*** %4
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32*, i32** %31, i64 %34
store i32* %30, i32** %35
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %25
38: ; preds = %25
%39 = load i32, i32* %10
store i32 %39, i32* %3
br label %40
40: ; preds = %38, %19
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define i32 @str2nums(i32** %0, i8* %1) {
%3 = alloca [45 x i8]
%4 = getelementptr inbounds [45 x i8], [45 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @memset(i32** %0, i32 0, i32 15)
%6 = call i32 @strcpy(i8* %4, i8* %1)
%7 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %23, label %9
9: ; preds = %2
%10 = call i32* @atoi(i8* %7)
store i32* %10, i32** %0
%11 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %13
13: ; preds = %9, %13
%14 = phi i64 [ %18, %13 ], [ 0, %9 ]
%15 = phi i8* [ %21, %13 ], [ %11, %9 ]
%16 = phi i32 [ %20, %13 ], [ 1, %9 ]
%17 = call i32* @atoi(i8* %15)
%18 = add nuw nsw i64 %14, 1
%19 = getelementptr inbounds i32*, i32** %0, i64 %18
store i32* %17, i32** %19
%20 = add nuw nsw i32 %16, 1
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %13
23: ; preds = %13, %9, %2
%24 = phi i32 [ 0, %2 ], [ 1, %9 ], [ %20, %13 ]
ret i32 %24
}