#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 CSS2Array(char *str, int **array) {
  int data[8192];
  int counter = 0;
  char *n = malloc(sizeof(char) * 8192);
  strcpy(n, str);
  char *sizes_ptr = n;
  for (char *token = strsep(&sizes_ptr, ","); token != NULL;
       token = strsep(&sizes_ptr, ",")) {
    if (token[0] != '\0') {
      data[counter] = strtol(token, NULL, 10);
      counter++;
    }
  }
  *array = (int *)malloc(sizeof(int) * counter);
  for (int i = 0; i < counter; i++) {
    (*array)[i] = data[i];
  }
  free(n);
  return counter;
}


x86 assembly (clang, -O0):
<CSS2Array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x8014(%rbp)
mov    $0x2000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8020(%rbp)
mov    -0x8020(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8020(%rbp),%rax
mov    %rax,-0x8028(%rbp)
lea    -0x8028(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1070 <strsep@plt>
mov    %rax,-0x8030(%rbp)
cmpq   $0x0,-0x8030(%rbp)
je     122f <CSS2Array+0xdf>
mov    -0x8030(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     120b <CSS2Array+0xbb>
mov    -0x8030(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ecx
movslq -0x8014(%rbp),%rax
mov    %ecx,-0x8010(%rbp,%rax,4)
mov    -0x8014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8014(%rbp)
jmp    1210 <CSS2Array+0xc0>
lea    -0x8028(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   1070 <strsep@plt>
mov    %rax,-0x8030(%rbp)
jmp    11b6 <CSS2Array+0x66>
movslq -0x8014(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x8034(%rbp)
mov    -0x8034(%rbp),%eax
cmp    -0x8014(%rbp),%eax
jge    129a <CSS2Array+0x14a>
movslq -0x8034(%rbp),%rax
mov    -0x8010(%rbp,%rax,4),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x8034(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8034(%rbp)
jmp    1255 <CSS2Array+0x105>
mov    -0x8020(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8014(%rbp),%eax
add    $0x8040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CSS2Array>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8010,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2000,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r15,0x8(%rsp)
lea    0xe66(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1080 <strsep@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11f0 <CSS2Array+0x90>
lea    0xe4e(%rip),%r12
lea    0x8(%rsp),%r13
jmp    11d0 <CSS2Array+0x70>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <strsep@plt>
test   %rax,%rax
je     11f0 <CSS2Array+0x90>
cmpb   $0x0,(%rax)
je     11c0 <CSS2Array+0x60>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
movslq %ebx,%rbx
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%ebx
jmp    11c0 <CSS2Array+0x60>
lea    0x0(,%rbx,4),%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %ebx,%ebx
jle    1216 <CSS2Array+0xb6>
mov    %ebx,%edx
shl    $0x2,%rdx
lea    0x10(%rsp),%rsi
mov    %rax,%rdi
call   1060 <memcpy@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8010,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define i32 @CSS2Array(i8* %0, i32** %1) {
%3 = alloca i8*
%4 = alloca i32**
%5 = alloca [8192 x i32]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i32** %1, i32*** %4
store i32 0, i32* %6
%11 = call i8* @malloc(i32 8192)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = load i8*, i8** %3
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %7
store i8* %15, i8** %8
%16 = call i8* @strsep(i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %9
br label %17
17: ; preds = %35, %2
%18 = load i8*, i8** %9
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %37
20: ; preds = %17
%21 = load i8*, i8** %9
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %20
%27 = load i8*, i8** %9
%28 = call i32 @strtol(i8* %27, i32* null, i32 10)
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [8192 x i32], [8192 x i32]* %5, i64 0, i64 %30
store i32 %28, i32* %31
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %34
34: ; preds = %26, %20
br label %35
35: ; preds = %34
%36 = call i8* @strsep(i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %36, i8** %9
br label %17
37: ; preds = %17
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = mul i64 4, %39
%41 = trunc i64 %40 to i32
%42 = call i8* @malloc(i32 %41)
%43 = bitcast i8* %42 to i32*
%44 = load i32**, i32*** %4
store i32* %43, i32** %44
store i32 0, i32* %10
br label %45
45: ; preds = %59, %37
%46 = load i32, i32* %10
%47 = load i32, i32* %6
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %62
49: ; preds = %45
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [8192 x i32], [8192 x i32]* %5, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = load i32**, i32*** %4
%55 = load i32*, i32** %54
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
store i32 %53, i32* %58
br label %59
59: ; preds = %49
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %45
62: ; preds = %45
%63 = load i8*, i8** %7
%64 = call i32 @free(i8* %63)
%65 = load i32, i32* %6
ret i32 %65
}

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