#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 */
void *malloc(int);
char **realloc(char **, long);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strsep(char **, char *);
int /*<<< orphan*/ *strstr(char *, char *);
char **explode(char *sep, char *str, long *arrsize) {
  long i = 0, size = 1;
  char *section, ** final = malloc((strlen(str) + 1) * sizeof(char *));
  if (strstr(str, sep) != NULL) {
    for (i = 0, size = 0; (section = strsep(&str, sep)) != NULL; i++, size++) {
      final[i] = malloc(strlen(section) + 1);
      strcpy(final[i], section);
    }
  } else {
    final[0] = malloc(strlen(str) + 1);
    strcpy(final[0], str);
  }
  *arrsize = size;
  return realloc(final, size * sizeof(char *));
}


x86 assembly (clang, -O0):
<explode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     123c <explode+0xdc>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdi
call   1060 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1237 <explode+0xd7>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c8 <explode+0x68>
jmp    1269 <explode+0x109>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
shl    $0x3,%rsi
call   1070 <realloc@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<explode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,(%rsp)
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x8(,%rax,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11f8 <explode+0x98>
mov    %rsp,%rdi
mov    %r12,%rsi
call   1060 <strsep@plt>
test   %rax,%rax
je     121d <explode+0xbd>
mov    %rax,%rbp
xor    %ebx,%ebx
mov    %rsp,%r13
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
add    $0x1,%rbx
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <strsep@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11c0 <explode+0x60>
jmp    121f <explode+0xbf>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%ebx
jmp    121f <explode+0xbf>
xor    %ebx,%ebx
mov    %rbx,(%r14)
shl    $0x3,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <realloc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8** @explode(i8* %0, i8* %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
store i8* %1, i8** %4
%5 = tail call i32 @strlen(i8* %1)
%6 = shl i32 %5, 3
%7 = add i32 %6, 8
%8 = tail call i8* @malloc(i32 %7)
%9 = bitcast i8* %8 to i8**
%10 = tail call i32* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %26, label %12
12: ; preds = %3
%13 = call i8* @strsep(i8** %4, i8* %0)
%14 = icmp eq i8* %13, null
br i1 %14, label %31, label %15
15: ; preds = %12, %15
%16 = phi i8* [ %24, %15 ], [ %13, %12 ]
%17 = phi i64 [ %23, %15 ], [ 0, %12 ]
%18 = call i32 @strlen(i8* %16)
%19 = add nsw i32 %18, 1
%20 = call i8* @malloc(i32 %19)
%21 = getelementptr inbounds i8*, i8** %9, i64 %17
store i8* %20, i8** %21
%22 = call i32 @strcpy(i8* %20, i8* %16)
%23 = add nuw nsw i64 %17, 1
%24 = call i8* @strsep(i8** %4, i8* %0)
%25 = icmp eq i8* %24, null
br i1 %25, label %31, label %15
26: ; preds = %3
%27 = tail call i32 @strlen(i8* %1)
%28 = add nsw i32 %27, 1
%29 = tail call i8* @malloc(i32 %28)
store i8* %29, i8** %9
%30 = tail call i32 @strcpy(i8* %29, i8* %1)
br label %31
31: ; preds = %15, %12, %26
%32 = phi i64 [ 1, %26 ], [ 0, %12 ], [ %23, %15 ]
store i64 %32, i64* %2
%33 = shl i64 %32, 3
%34 = call i8** @realloc(i8** %9, i64 %33)
ret i8** %34
}