#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__ realloc(char **, int);
char *strdup(char const *);
int strlen(char const *);
char *strstr(char *, char const *);
void split_string(const char *in, const char *split, char ***list,
                  int *list_n) {
  char *copy = strdup(in), *pc = copy;
  int split_len = strlen(split);
  for (;;) {
    char *term = strstr(pc, split);
    if (term)
      *term = 0x00;
    *list = (char **)realloc(*list, (*list_n + 1) * sizeof(char *));
    (*list)[*list_n] = strdup(pc);
    (*list_n)++;
    if (!term)
      break;
    pc = term + split_len;
  }
  free(copy);
}


x86 assembly (clang, -O0):
<split_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     11ac <split_string+0x5c>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
cmpq   $0x0,-0x40(%rbp)
jne    120c <split_string+0xbc>
jmp    1220 <split_string+0xd0>
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1189 <split_string+0x39>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%rbp
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rbp,0x10(%rsp)
mov    %rbp,%rdi
call   1040 <strlen@plt>
movslq %eax,%r15
mov    %rbx,0x8(%rsp)
jmp    11c9 <split_string+0x79>
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%rdi
mov    0x0(%r13),%eax
lea    0x8(,%rax,8),%esi
call   1050 <realloc@plt>
mov    %rax,%r12
mov    %rax,(%r14)
mov    %rbx,%rdi
call   1060 <strdup@plt>
movslq 0x0(%r13),%rcx
lea    0x1(%rcx),%edx
lea    (%r15,%rbp,1),%rbx
mov    %rax,(%r12,%rcx,8)
mov    %edx,0x0(%r13)
test   %rbp,%rbp
je     11e4 <split_string+0x94>
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
call   1070 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1190 <split_string+0x40>
movb   $0x0,0x0(%rbp)
jmp    1190 <split_string+0x40>
mov    0x8(%rsp),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @split_string(i8* nocapture %0, i8* %1, i8*** nocapture %2, i32* nocapture %3) {
%5 = tail call i8* @strdup(i8* %0)
%6 = tail call i32 @strlen(i8* %1)
%7 = sext i32 %6 to i64
br label %8
8: ; preds = %13, %4
%9 = phi i8* [ %5, %4 ], [ %25, %13 ]
%10 = tail call i8* @strstr(i8* dereferenceable(1) %9, i8* dereferenceable(1) %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %8
store i8 0, i8* %10
br label %13
13: ; preds = %12, %8
%14 = load i8**, i8*** %2
%15 = load i32, i32* %3
%16 = shl i32 %15, 3
%17 = add i32 %16, 8
%18 = tail call i64 @realloc(i8** %14, i32 %17)
%19 = inttoptr i64 %18 to i8**
store i8** %19, i8*** %2
%20 = tail call i8* @strdup(i8* %9)
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %19, i64 %22
store i8* %20, i8** %23
%24 = add nsw i32 %21, 1
store i32 %24, i32* %3
%25 = getelementptr inbounds i8, i8* %10, i64 %7
br i1 %11, label %26, label %8
26: ; preds = %13
%27 = tail call i32 @free(i8* %5)
ret void
}