#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 *);
scalar_t__ malloc(int);
scalar_t__ realloc(char **, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
int strlen(char *);
char *strsep(char **, char *);
char **strsplit(char *instr, char *delim) {
  char *token;
  char *str;
  char **rtn;
  int n = 0;
  str = (char *)malloc(sizeof(char *) * strlen(instr));
  str = strdup(instr);
  rtn = (char **)malloc(sizeof(char *));
  if (str != NULL) {
    while ((token = strsep(&str, delim)) != NULL) {
      if (0 == strcmp(token, ""))
        continue;
      rtn = (char **)realloc(rtn, sizeof(char *) * (n + 1));
      rtn[n] = (char *)malloc(sizeof(char) * (strlen(token) + 1));
      strcpy(rtn[n], token);
      strcat(rtn[n], "\0");
      n++;
    }
  }
  free(token);
  free(str);
  return rtn;
}


x86 assembly (clang, -O0):
<strsplit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12ad <strsplit+0x11d>
jmp    11ec <strsplit+0x5c>
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1080 <strsep@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12a8 <strsplit+0x118>
mov    -0x18(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    122a <strsplit+0x9a>
jmp    11ec <strsplit+0x5c>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd6c(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ec <strsplit+0x5c>
jmp    12ad <strsplit+0x11d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strsplit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1050 <strlen@plt>
lea    0x0(,%rax,8),%edi
call   1070 <malloc@plt>
mov    %rbp,%rdi
call   10b0 <strdup@plt>
mov    %rax,%rbp
mov    %rax,0x8(%rsp)
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
test   %rbp,%rbp
je     126b <strsplit+0xdb>
xor    %r13d,%r13d
lea    0x8(%rsp),%r15
lea    0xe16(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strsep@plt>
test   %rax,%rax
je     1264 <strsplit+0xd4>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f0 <strsplit+0x60>
lea    0x1(%r13),%rax
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,8),%esi
mov    %r14,%rdi
call   1090 <realloc@plt>
mov    %rax,%r14
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,(%r14,%r13,8)
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    (%r14,%r13,8),%rdi
lea    0xda9(%rip),%rsi
call   10a0 <strcat@plt>
mov    0x10(%rsp),%r13
jmp    11f0 <strsplit+0x60>
mov    0x8(%rsp),%rbx
jmp    126d <strsplit+0xdd>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] zeroinitializer
define i8** @strsplit(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32 @strlen(i8* %0)
%6 = shl i32 %5, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = tail call i8* @strdup(i8* %0)
store i8* %8, i8** %3
%9 = tail call i64 @malloc(i32 8)
%10 = inttoptr i64 %9 to i8**
%11 = icmp eq i8* %8, null
br i1 %11, label %37, label %12
12: ; preds = %2, %21
%13 = phi i64 [ %22, %21 ], [ 0, %2 ]
%14 = phi i8** [ %26, %21 ], [ %10, %2 ]
br label %15
15: ; preds = %12, %18
%16 = call i8* @strsep(i8** %3, i8* %1)
%17 = icmp eq i8* %16, null
br i1 %17, label %35, label %18
18: ; preds = %15
%19 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %15, label %21
21: ; preds = %18
%22 = add nuw i64 %13, 1
%23 = trunc i64 %22 to i32
%24 = shl i32 %23, 3
%25 = call i64 @realloc(i8** %14, i32 %24)
%26 = inttoptr i64 %25 to i8**
%27 = call i32 @strlen(i8* %16)
%28 = add nsw i32 %27, 1
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to i8*
%31 = getelementptr inbounds i8*, i8** %26, i64 %13
store i8* %30, i8** %31
%32 = call i32 @strcpy(i8* %30, i8* %16)
%33 = load i8*, i8** %31
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %12
35: ; preds = %15
%36 = load i8*, i8** %3
br label %37
37: ; preds = %35, %2
%38 = phi i8* [ null, %2 ], [ %36, %35 ]
%39 = phi i8** [ %10, %2 ], [ %14, %35 ]
%40 = call i32 @free(i8* null)
%41 = call i32 @free(i8* %38)
ret i8** %39
}