#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 /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
char *strsep(char **, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int splitStr(char *input, int *output) {
  char *str = malloc(sizeof(char) * 8192);
  strcpy(str, input);
  char *str_start = str;
  int i = 0;
  for (char *token = strsep(&str, ","); token != NULL;
       token = strsep(&str, ",")) {
    if (token[0] != '\0') {
      output[i] = strtol(token, NULL, 10);
      i++;
    }
  }
  free(str_start);
  return 0;
}


x86 assembly (clang, -O0):
<splitStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ff <splitStr+0xaf>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e1 <splitStr+0x91>
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e6 <splitStr+0x96>
lea    -0x18(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1070 <strsep@plt>
mov    %rax,-0x30(%rbp)
jmp    119e <splitStr+0x4e>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<splitStr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x2000,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe79(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1070 <strsep@plt>
test   %rax,%rax
je     11e0 <splitStr+0x90>
xor    %ebx,%ebx
lea    0xe61(%rip),%r12
lea    0x8(%rsp),%r13
jmp    11c0 <splitStr+0x70>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <strsep@plt>
test   %rax,%rax
je     11e0 <splitStr+0x90>
cmpb   $0x0,(%rax)
je     11b0 <splitStr+0x60>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
movslq %ebx,%rbx
mov    %eax,(%r15,%rbx,4)
add    $0x1,%ebx
jmp    11b0 <splitStr+0x60>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define i32 @splitStr(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call dereferenceable_or_null(8192) i8* @malloc(i32 8192)
store i8* %5, i8** %3
%6 = tail call i32 @strcpy(i8* %5, i8* %0)
%7 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %21, %2
%10 = call i32 @free(i8* %5)
ret i32 0
11: ; preds = %2, %21
%12 = phi i8* [ %23, %21 ], [ %7, %2 ]
%13 = phi i32 [ %22, %21 ], [ 0, %2 ]
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = call i32 @strtol(i8* nocapture %12, i32* null, i32 10)
%18 = sext i32 %13 to i64
%19 = getelementptr inbounds i32, i32* %1, i64 %18
store i32 %17, i32* %19
%20 = add nsw i32 %13, 1
br label %21
21: ; preds = %11, %16
%22 = phi i32 [ %20, %16 ], [ %13, %11 ]
%23 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %9, label %11
}