#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 str_length(char const *);
char *str_pfind(char const *, char const *);
char *str_slicep(char const *, char *);
char *str_splitl(const char **last, const char *delim) {
  char *ret = NULL;
  if (*last) {
    char *next = str_pfind(*last, delim);
    ret = str_slicep(*last, next);
    *last = next ? next + str_length(delim) : NULL;
  }
  return ret;
}


x86 assembly (clang, -O0):
<str_splitl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11c5 <str_splitl+0x95>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <str_pfind@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <str_slicep@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11af <str_splitl+0x7f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <str_length@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    11ba <str_splitl+0x8a>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11ba <str_splitl+0x8a>
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_splitl>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1170 <str_splitl+0x40>
mov    %rsi,%r12
call   1050 <str_pfind@plt>
mov    %rax,%rbx
mov    (%r15),%rdi
mov    %rax,%rsi
call   1040 <str_slicep@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1175 <str_splitl+0x45>
mov    %r12,%rdi
call   1030 <str_length@plt>
cltq
add    %rax,%rbx
jmp    1177 <str_splitl+0x47>
xor    %r14d,%r14d
jmp    117a <str_splitl+0x4a>
xor    %ebx,%ebx
mov    %rbx,(%r15)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @str_splitl(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = tail call i8* @str_pfind(i8* %3, i8* %1)
%7 = load i8*, i8** %0
%8 = tail call i8* @str_slicep(i8* %7, i8* %6)
%9 = icmp eq i8* %6, null
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = tail call i32 @str_length(i8* %1)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %6, i64 %12
br label %14
14: ; preds = %5, %10
%15 = phi i8* [ %13, %10 ], [ null, %5 ]
store i8* %15, i8** %0
br label %16
16: ; preds = %14, %2
%17 = phi i8* [ %8, %14 ], [ null, %2 ]
ret i8* %17
}