#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 **realloc(char **, int);
char *safe_alloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strsep(char **, char const *);
int split(char **stringp, const char *delim, char ***list) {
  char *pt;
  int n = 0;
  *list = NULL;
  for (pt = strsep(stringp, delim); pt != NULL; pt = strsep(stringp, delim)) {
    *list = realloc(*list, (n + 1) * sizeof(**list));
    (*list)[n] = safe_alloc(strlen(pt) + 1);
    strcpy((*list)[n], pt);
    n++;
  }
  return n;
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1214 <split+0xc4>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <safe_alloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strsep@plt>
mov    %rax,-0x20(%rbp)
jmp    1187 <split+0x37>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
movq   $0x0,(%rdx)
call   1060 <strsep@plt>
test   %rax,%rax
je     11f1 <split+0xa1>
mov    %rax,%r15
mov    $0x8,%ebp
xor    %r14d,%r14d
mov    %rbx,(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rbx
mov    %r14,%r13
mov    (%r12),%rdi
add    $0x1,%r14
mov    %ebp,%esi
call   1070 <realloc@plt>
mov    %rax,(%r12)
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <safe_alloc@plt>
mov    (%r12),%rcx
mov    %rax,(%rcx,%r13,8)
mov    (%r12),%rax
mov    (%rax,%r13,8),%rdi
mov    %rbx,%r13
mov    (%rsp),%rbx
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strsep@plt>
mov    %rax,%r15
add    $0x8,%ebp
test   %rax,%rax
jne    1190 <split+0x40>
jmp    11f4 <split+0xa4>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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