#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 */
char ***malloc(int);
int /*<<< orphan*/ string_free_split(char **);
char **string_split(char const *, char *, int /*<<< orphan*/,
                    int /*<<< orphan*/, int *);
char **string_split_shared(char *, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/, int /*<<< orphan*/ *);
char ***string_split_tags(const char *tags, int *num_tags) {
  char ***tags_array, **tags_array_temp;
  int i, tags_count;
  tags_array = NULL;
  tags_count = 0;
  if (tags) {
    tags_array_temp = string_split(tags, ",", 0, 0, &tags_count);
    if (tags_array_temp && (tags_count > 0)) {
      tags_array = malloc((tags_count + 1) * sizeof(*tags_array));
      if (tags_array) {
        for (i = 0; i < tags_count; i++) {
          tags_array[i] =
              string_split_shared(tags_array_temp[i], "+", 0, 0, NULL);
        }
        tags_array[tags_count] = NULL;
      }
    }
    if (tags_array_temp)
      string_free_split(tags_array_temp);
  }
  if (num_tags)
    *num_tags = tags_count;
  return tags_array;
}


x86 assembly (clang, -O0):
<string_split_tags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     123c <string_split_tags+0xfc>
mov    -0x8(%rbp),%rdi
lea    0xe8b(%rip),%rsi
xor    %ecx,%ecx
lea    -0x28(%rbp),%r8
mov    %ecx,%edx
call   1040 <string_split@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1223 <string_split_tags+0xe3>
cmpl   $0x0,-0x28(%rbp)
jle    1223 <string_split_tags+0xe3>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     121e <string_split_tags+0xde>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    120e <string_split_tags+0xce>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe1f(%rip),%rsi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %ecx,%edx
call   1050 <string_split_shared@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c4 <string_split_tags+0x84>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    1223 <string_split_tags+0xe3>
cmpq   $0x0,-0x20(%rbp)
je     1237 <string_split_tags+0xf7>
mov    -0x20(%rbp),%rdi
call   1030 <string_free_split@plt>
jmp    123c <string_split_tags+0xfc>
cmpq   $0x0,-0x10(%rbp)
je     1250 <string_split_tags+0x110>
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_split_tags>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
movl   $0x0,0xc(%rsp)
test   %rdi,%rdi
je     11ed <string_split_tags+0xad>
lea    0xe98(%rip),%rsi
xor    %r15d,%r15d
lea    0xc(%rsp),%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <string_split@plt>
mov    %rax,%r13
test   %rax,%rax
je     11de <string_split_tags+0x9e>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11de <string_split_tags+0x9e>
lea    0x8(,%rax,8),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     120d <string_split_tags+0xcd>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe5c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rdi
mov    %r12,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <string_split_shared@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11b0 <string_split_tags+0x70>
movq   $0x0,(%r15,%rax,8)
test   %r13,%r13
je     11f0 <string_split_tags+0xb0>
mov    %r13,%rdi
call   1030 <string_free_split@plt>
jmp    11f0 <string_split_tags+0xb0>
xor    %r15d,%r15d
test   %r14,%r14
je     11fc <string_split_tags+0xbc>
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %r15d,%r15d
test   %r13,%r13
jne    11e3 <string_split_tags+0xa3>
jmp    11f0 <string_split_tags+0xb0>

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

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [2 x i8] c"+\00"
define noalias i8*** @string_split_tags(i8* %0, i32* writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp eq i8* %0, null
br i1 %5, label %34, label %6
6: ; preds = %2
%7 = call i8** @string_split(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0, i32 0, i32* %3)
%8 = icmp ne i8** %7, null
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %30
12: ; preds = %6
%13 = shl i32 %9, 3
%14 = add i32 %13, 8
%15 = call i8*** @malloc(i32 %14)
%16 = icmp eq i8*** %15, null
br i1 %16, label %30, label %17
17: ; preds = %12, %17
%18 = phi i64 [ %23, %17 ], [ 0, %12 ]
%19 = getelementptr inbounds i8*, i8** %7, i64 %18
%20 = load i8*, i8** %19
%21 = call i8** @string_split_shared(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0, i32* null)
%22 = getelementptr inbounds i8**, i8*** %15, i64 %18
store i8** %21, i8*** %22
%23 = add nuw nsw i64 %18, 1
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %17, label %27
27: ; preds = %17
%28 = sext i32 %24 to i64
%29 = getelementptr inbounds i8**, i8*** %15, i64 %28
store i8** null, i8*** %29
br label %30
30: ; preds = %12, %27, %6
%31 = phi i8*** [ %15, %27 ], [ null, %12 ], [ null, %6 ]
br i1 %8, label %32, label %34
32: ; preds = %30
%33 = call i32 @string_free_split(i8** %7)
br label %34
34: ; preds = %30, %32, %2
%35 = phi i8*** [ %31, %32 ], [ %31, %30 ], [ null, %2 ]
%36 = icmp eq i32* %1, null
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = load i32, i32* %3
store i32 %38, i32* %1
br label %39
39: ; preds = %37, %34
ret i8*** %35
}