#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 */
scalar_t__ calloc(int, int);
int count_tokens_in_string(char *, char *);
int /*<<< orphan*/ free(char *);
char *get_token_from_string(char *, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strdup(char const *);
scalar_t__ strlen(char *);
char **llspeech_make_string_array(const char *original, int *lengthP) {
  char **string_array;
  char *copy, *copy2, *next, *token, delim[3] = ",:";
  int i = 0, len;
  if (!original) {
    if (lengthP) {
      *lengthP = 0;
      return NULL;
    } else {
      string_array = (char **)calloc(1, sizeof(char *));
      string_array[0] = strdup("0");
      return string_array;
    }
  }
  copy = strdup(original);
  len = count_tokens_in_string(copy, delim);
  if (lengthP) {
    string_array = (char **)calloc(len, sizeof(char *));
    *lengthP = len;
  } else {
    string_array = (char **)calloc(len + 1, sizeof(char *));
    string_array[0] = (char *)malloc(64);
    sprintf(string_array[0], "%d", len);
    i++;
  }
  token = copy;
  copy2 = strdup(original);
  next = get_token_from_string(copy2, delim, token);
  while (strlen(token)) {
    string_array[i++] = strdup(token);
    next = get_token_from_string(next, delim, token);
  }
  if (copy)
    free(copy);
  if (copy2)
    free(copy2);
  return string_array;
}


x86 assembly (clang, -O0):
<llspeech_make_string_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0xe69(%rip),%ax
mov    %ax,-0x43(%rbp)
mov    0xe61(%rip),%al
mov    %al,-0x41(%rbp)
movl   $0x0,-0x48(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120e <llspeech_make_string_array+0x8e>
cmpq   $0x0,-0x18(%rbp)
je     11d8 <llspeech_make_string_array+0x58>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1345 <llspeech_make_string_array+0x1c5>
mov    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe11(%rip),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1345 <llspeech_make_string_array+0x1c5>
mov    -0x10(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x43(%rbp),%rsi
call   1060 <count_tokens_in_string@plt>
mov    %eax,-0x4c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1255 <llspeech_make_string_array+0xd5>
mov    -0x4c(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    129c <llspeech_make_string_array+0x11c>
mov    -0x4c(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x40,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x4c(%rbp),%edx
lea    0xd77(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x43(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1080 <get_token_from_string@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     1315 <llspeech_make_string_array+0x195>
mov    -0x40(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x48(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rdi
lea    -0x43(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1080 <get_token_from_string@plt>
mov    %rax,-0x38(%rbp)
jmp    12c6 <llspeech_make_string_array+0x146>
cmpq   $0x0,-0x28(%rbp)
je     1329 <llspeech_make_string_array+0x1a9>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     133d <llspeech_make_string_array+0x1bd>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<llspeech_make_string_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
movb   $0x0,0x6(%rsp)
movw   $0x3a2c,0x4(%rsp)
test   %rdi,%rdi
je     11c6 <llspeech_make_string_array+0x56>
mov    %rdi,%r15
call   1090 <strdup@plt>
mov    %rax,%r13
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
call   1050 <count_tokens_in_string@plt>
mov    %eax,%ebp
mov    %eax,%edi
test   %r12,%r12
je     11df <llspeech_make_string_array+0x6f>
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
mov    %ebp,(%r12)
xor    %r12d,%r12d
jmp    1213 <llspeech_make_string_array+0xa3>
test   %r12,%r12
je     128e <llspeech_make_string_array+0x11e>
movl   $0x0,(%r12)
xor    %r14d,%r14d
jmp    12af <llspeech_make_string_array+0x13f>
add    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
lea    0xe02(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1080 <sprintf@plt>
mov    $0x1,%r12d
mov    %r15,%rdi
call   1090 <strdup@plt>
mov    %rax,%r15
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
call   1070 <get_token_from_string@plt>
cmpb   $0x0,0x0(%r13)
je     1277 <llspeech_make_string_array+0x107>
mov    %rax,%rbp
lea    (%r14,%r12,8),%rbx
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1090 <strdup@plt>
mov    %rax,(%rbx)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <get_token_from_string@plt>
mov    %rax,%rbp
add    $0x8,%rbx
cmpb   $0x0,0x0(%r13)
jne    1250 <llspeech_make_string_array+0xe0>
mov    %r13,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     12af <llspeech_make_string_array+0x13f>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    12af <llspeech_make_string_array+0x13f>
mov    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
lea    0xd5c(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,(%r14)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.llspeech_make_string_array.delim = [3 x i8] c",:\00"
@.str = [2 x i8] c"0\00"
@.str.1 = [3 x i8] c"%d\00"
define i8** @llspeech_make_string_array(i8* %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [3 x i8]
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%14 = bitcast [3 x i8]* %11 to i8*
store i32 0, i32* %12
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %29, label %17
17: ; preds = %2
%18 = load i32*, i32** %5
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load i32*, i32** %5
store i32 0, i32* %21
store i8** null, i8*** %3
br label %97
22: ; preds = %17
%23 = call i64 @calloc(i32 1, i32 8)
%24 = inttoptr i64 %23 to i8**
store i8** %24, i8*** %6
%25 = call i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = load i8**, i8*** %6
%27 = getelementptr inbounds i8*, i8** %26, i64 0
store i8* %25, i8** %27
%28 = load i8**, i8*** %6
store i8** %28, i8*** %3
br label %97
29: ; preds = %2
%30 = load i8*, i8** %4
%31 = call i8* @strdup(i8* %30)
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%34 = call i32 @count_tokens_in_string(i8* %32, i8* %33)
store i32 %34, i32* %13
%35 = load i32*, i32** %5
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %43
37: ; preds = %29
%38 = load i32, i32* %13
%39 = call i64 @calloc(i32 %38, i32 8)
%40 = inttoptr i64 %39 to i8**
store i8** %40, i8*** %6
%41 = load i32, i32* %13
%42 = load i32*, i32** %5
store i32 %41, i32* %42
br label %59
43: ; preds = %29
%44 = load i32, i32* %13
%45 = add nsw i32 %44, 1
%46 = call i64 @calloc(i32 %45, i32 8)
%47 = inttoptr i64 %46 to i8**
store i8** %47, i8*** %6
%48 = call i64 @malloc(i32 64)
%49 = inttoptr i64 %48 to i8*
%50 = load i8**, i8*** %6
%51 = getelementptr inbounds i8*, i8** %50, i64 0
store i8* %49, i8** %51
%52 = load i8**, i8*** %6
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = load i32, i32* %13
%56 = call i32 @sprintf(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %12
%58 = add nsw i32 %57, 1
store i32 %58, i32* %12
br label %59
59: ; preds = %43, %37
%60 = load i8*, i8** %7
store i8* %60, i8** %10
%61 = load i8*, i8** %4
%62 = call i8* @strdup(i8* %61)
store i8* %62, i8** %8
%63 = load i8*, i8** %8
%64 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%65 = load i8*, i8** %10
%66 = call i8* @get_token_from_string(i8* %63, i8* %64, i8* %65)
store i8* %66, i8** %9
br label %67
67: ; preds = %71, %59
%68 = load i8*, i8** %10
%69 = call i64 @strlen(i8* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %83
71: ; preds = %67
%72 = load i8*, i8** %10
%73 = call i8* @strdup(i8* %72)
%74 = load i8**, i8*** %6
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
%77 = sext i32 %75 to i64
%78 = getelementptr inbounds i8*, i8** %74, i64 %77
store i8* %73, i8** %78
%79 = load i8*, i8** %9
%80 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%81 = load i8*, i8** %10
%82 = call i8* @get_token_from_string(i8* %79, i8* %80, i8* %81)
store i8* %82, i8** %9
br label %67
83: ; preds = %67
%84 = load i8*, i8** %7
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i8*, i8** %7
%88 = call i32 @free(i8* %87)
br label %89
89: ; preds = %86, %83
%90 = load i8*, i8** %8
%91 = icmp ne i8* %90, null
br i1 %91, label %92, label %95
92: ; preds = %89
%93 = load i8*, i8** %8
%94 = call i32 @free(i8* %93)
br label %95
95: ; preds = %92, %89
%96 = load i8**, i8*** %6
store i8** %96, i8*** %3
br label %97
97: ; preds = %95, %22, %20
%98 = load i8**, i8*** %3
ret i8** %98
}

LLVM IR (-O2):
@__const.llspeech_make_string_array.delim = [3 x i8] c",:\00"
@.str = [2 x i8] c"0\00"
@.str.1 = [3 x i8] c"%d\00"
define i8** @llspeech_make_string_array(i8* %0, i32* writeonly %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = icmp eq i32* %1, null
br i1 %7, label %9, label %8
8: ; preds = %6
store i32 0, i32* %1
br label %48
9: ; preds = %6
%10 = tail call i64 @calloc(i32 1, i32 8)
%11 = inttoptr i64 %10 to i8**
%12 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %11
br label %48
13: ; preds = %2
%14 = tail call i8* @strdup(i8* %0)
%15 = call i32 @count_tokens_in_string(i8* %14, i8* %4)
%16 = icmp eq i32* %1, null
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i64 @calloc(i32 %15, i32 8)
%19 = inttoptr i64 %18 to i8**
store i32 %15, i32* %1
br label %27
20: ; preds = %13
%21 = add nsw i32 %15, 1
%22 = call i64 @calloc(i32 %21, i32 8)
%23 = inttoptr i64 %22 to i8**
%24 = call i64 @malloc(i32 64)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %23
%26 = call i32 @sprintf(i8* dereferenceable(1) %25, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %27
27: ; preds = %20, %17
%28 = phi i8** [ %19, %17 ], [ %23, %20 ]
%29 = phi i64 [ 0, %17 ], [ 1, %20 ]
%30 = call i8* @strdup(i8* %0)
%31 = call i8* @get_token_from_string(i8* %30, i8* %4, i8* %14)
%32 = load i8, i8* %14
%33 = icmp eq i8 %32, 0
br i1 %33, label %43, label %34
34: ; preds = %27, %34
%35 = phi i64 [ %38, %34 ], [ %29, %27 ]
%36 = phi i8* [ %40, %34 ], [ %31, %27 ]
%37 = call i8* @strdup(i8* %14)
%38 = add nuw i64 %35, 1
%39 = getelementptr inbounds i8*, i8** %28, i64 %35
store i8* %37, i8** %39
%40 = call i8* @get_token_from_string(i8* %36, i8* %4, i8* %14)
%41 = load i8, i8* %14
%42 = icmp eq i8 %41, 0
br i1 %42, label %43, label %34
43: ; preds = %34, %27
%44 = call i32 @free(i8* %14)
%45 = icmp eq i8* %30, null
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = call i32 @free(i8* %30)
br label %48
48: ; preds = %43, %46, %9, %8
%49 = phi i8** [ null, %8 ], [ %11, %9 ], [ %28, %46 ], [ %28, %43 ]
ret i8** %49
}