void _test_split(char *split, char *txt) {
  char **results;
  printf("split '%s' by '%s': (", txt, split);
  long count = string_split(split, txt, &results);
  if (count > 0) {
    printf("'%s'", results[0]);
    free(results[0]);
    int i;
    for (i = 1; i < count; i++) {
      printf(", '%s'", results[i]);
      free(results[i]);
    }
    free(results);
  }
  printf(")\n");
}


x86 assembly (clang, -O0):
<_test_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <string_split@plt>
cltq
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jle    11f2 <_test_split+0xc2>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x1,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    11e9 <_test_split+0xb9>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a2 <_test_split+0x72>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_test_split>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeaa(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <string_split@plt>
test   %eax,%eax
jle    11e4 <_test_split+0xa4>
mov    %eax,%ebx
mov    0x8(%rsp),%rax
mov    (%rax),%rsi
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
cmp    $0x1,%ebx
je     11da <_test_split+0x9a>
mov    %ebx,%r15d
mov    $0x1,%ebx
lea    0xe67(%rip),%r14
nop
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11b0 <_test_split+0x70>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0xe32(%rip),%rdi
call   1040 <puts@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"split '%s' by '%s': (\00"
@.str.1 = [5 x i8] c"'%s'\00"
@.str.2 = [7 x i8] c", '%s'\00"
@.str.3 = [3 x i8] c")\0A\00"
define void @_test_split(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %9)
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = call i32 (i8*, i8*, i8***, ...) bitcast (i32 (...)* @string_split to i32 (i8*, i8*, i8***, ...)*)(i8* %11, i8* %12, i8*** %5)
%14 = sext i32 %13 to i64
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %48
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
store i32 1, i32* %7
br label %25
25: ; preds = %42, %17
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = load i64, i64* %6
%29 = icmp slt i64 %27, %28
br i1 %29, label %30, label %45
30: ; preds = %25
%31 = load i8**, i8*** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i8**, i8*** %5
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
br label %42
42: ; preds = %30
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %25
45: ; preds = %25
%46 = load i8**, i8*** %5
%47 = bitcast i8** %46 to i8*
br label %48
48: ; preds = %45, %2
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"split '%s' by '%s': (\00"
@.str.1 = [5 x i8] c"'%s'\00"
@.str.2 = [7 x i8] c", '%s'\00"
@str = [2 x i8] c")\00"
define void @_test_split(i8* %0, i8* %1) {
%3 = alloca i8**
%4 = bitcast i8*** %3 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
%6 = call i32 (i8*, i8*, i8***, ...) bitcast (i32 (...)* @string_split to i32 (i8*, i8*, i8***, ...)*)(i8* %0, i8* %1, i8*** %3)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %31
8: ; preds = %2
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i8**, i8*** %3
%13 = load i8*, i8** %12
%14 = icmp eq i32 %6, 1
br i1 %14, label %28, label %15
15: ; preds = %8
%16 = zext i32 %6 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 1, %15 ], [ %26, %17 ]
%19 = load i8**, i8*** %3
%20 = getelementptr inbounds i8*, i8** %19, i64 %18
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i8**, i8*** %3
%24 = getelementptr inbounds i8*, i8** %23, i64 %18
%25 = load i8*, i8** %24
%26 = add nuw nsw i64 %18, 1
%27 = icmp eq i64 %26, %16
br i1 %27, label %28, label %17
28: ; preds = %17, %8
%29 = bitcast i8*** %3 to i8**
%30 = load i8*, i8** %29
br label %31
31: ; preds = %28, %2
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}