#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 **galloc(int);
int str_occurs(char const *, char const *);
char *str_splitl(char const **, char const *);
char **str_split(const char *s, const char *delim) {
  unsigned i = 0, o = str_occurs(s, delim) + 1;
  char **strings = galloc(sizeof(const char *) * (o + 1));
  const char *last = s;
  while ((strings[i] = str_splitl(&last, delim)))
    i++;
  return strings;
}


x86 assembly (clang, -O0):
<str_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <str_occurs@plt>
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <galloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1050 <str_splitl@plt>
mov    -0x20(%rbp),%rcx
mov    -0x14(%rbp),%edx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
je     11a9 <str_split+0x79>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <str_split+0x49>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_split>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <str_occurs@plt>
lea    0x10(,%rax,8),%edi
call   1030 <galloc@plt>
mov    %rax,%rbx
mov    %r15,(%rsp)
xor    %ebp,%ebp
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <str_splitl@plt>
mov    %ebp,%ecx
mov    %rax,(%rbx,%rcx,8)
add    $0x1,%ebp
test   %rax,%rax
jne    1160 <str_split+0x30>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @str_split(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%9 = load i8*, i8** %3
%10 = load i8*, i8** %4
%11 = call i32 @str_occurs(i8* %9, i8* %10)
%12 = add nsw i32 %11, 1
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = add i32 %13, 1
%15 = zext i32 %14 to i64
%16 = mul i64 8, %15
%17 = trunc i64 %16 to i32
%18 = call i8** @galloc(i32 %17)
store i8** %18, i8*** %7
%19 = load i8*, i8** %3
store i8* %19, i8** %8
br label %20
20: ; preds = %28, %2
%21 = load i8*, i8** %4
%22 = call i8* @str_splitl(i8** %8, i8* %21)
%23 = load i8**, i8*** %7
%24 = load i32, i32* %5
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
store i8* %22, i8** %26
%27 = icmp ne i8* %22, null
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i32, i32* %5
%30 = add i32 %29, 1
store i32 %30, i32* %5
br label %20
31: ; preds = %20
%32 = load i8**, i8*** %7
ret i8** %32
}

LLVM IR (-O2):
define i8** @str_split(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = tail call i32 @str_occurs(i8* %0, i8* %1)
%5 = shl i32 %4, 3
%6 = add i32 %5, 16
%7 = tail call i8** @galloc(i32 %6)
%8 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
br label %9
9: ; preds = %9, %2
%10 = phi i32 [ 0, %2 ], [ %15, %9 ]
%11 = call i8* @str_splitl(i8** %3, i8* %1)
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds i8*, i8** %7, i64 %12
store i8* %11, i8** %13
%14 = icmp eq i8* %11, null
%15 = add i32 %10, 1
br i1 %14, label %16, label %9
16: ; preds = %9
ret i8** %7
}