#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*/ assert(char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ realloc(char **, int);
char *strdup(char const *);
char *strsep(char **, char *);
char **smf_core_strsplit(const char *s, char *sep, int *nelems) {
  char **sl = NULL;
  char *cp = NULL;
  char *tf = NULL;
  char *tmp = NULL;
  int count = 0;
  assert(s);
  assert(sep);
  tf = cp = strdup(s);
  while ((tmp = strsep(&cp, sep)) != NULL) {
    sl = (char **)realloc(sl, (sizeof(*sl) * (count + 2)));
    sl[count] = strdup(tmp);
    count++;
  }
  free(tf);
  sl[count] = '\0';
  if (nelems != NULL)
    *nelems = count;
  return (sl);
}


x86 assembly (clang, -O0):
<smf_core_strsplit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdi
call   1050 <strsep@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     120a <smf_core_strsplit+0xba>
mov    -0x20(%rbp),%rdi
mov    -0x3c(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ae <smf_core_strsplit+0x5e>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
cmpq   $0x0,-0x18(%rbp)
je     1237 <smf_core_strsplit+0xe7>
mov    -0x3c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smf_core_strsplit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x8(%rsp)
mov    %rsi,%r13
mov    %rdi,%rbx
call   1040 <assert@plt>
mov    %r13,%rdi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,(%rsp)
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <strsep@plt>
mov    %rax,%r14
mov    $0x10,%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %rax,(%rbx,%r15,8)
add    $0x1,%r15
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <strsep@plt>
mov    %rax,%r14
add    $0x8,%ebp
test   %rax,%rax
jne    11b0 <smf_core_strsplit+0x60>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r15d,%eax
movq   $0x0,(%rbx,%rax,8)
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1204 <smf_core_strsplit+0xb4>
mov    %r15d,(%rax)
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8** @smf_core_strsplit(i8* %0, i8* %1, i32* writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i32 @assert(i8* %0)
%7 = tail call i32 @assert(i8* %1)
%8 = tail call i8* @strdup(i8* %0)
store i8* %8, i8** %4
%9 = call i8* @strsep(i8** %4, i8* %1)
%10 = icmp ne i8* %9, null
br label %11
11: ; preds = %3, %11
%12 = phi i64 [ 0, %3 ], [ %22, %11 ]
%13 = phi i8* [ %9, %3 ], [ %23, %11 ]
%14 = phi i8** [ null, %3 ], [ %19, %11 ]
%15 = trunc i64 %12 to i32
%16 = shl i32 %15, 3
%17 = add i32 %16, 16
%18 = call i64 @realloc(i8** %14, i32 %17)
%19 = inttoptr i64 %18 to i8**
%20 = call i8* @strdup(i8* %13)
%21 = getelementptr inbounds i8*, i8** %19, i64 %12
store i8* %20, i8** %21
%22 = add nuw i64 %12, 1
%23 = call i8* @strsep(i8** %4, i8* %1)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %11
25: ; preds = %11
%26 = inttoptr i64 %18 to i8**
%27 = call i32 @free(i8* %8)
%28 = and i64 %22, 4294967295
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
store i8* null, i8** %29
%30 = icmp eq i32* %2, null
br i1 %30, label %33, label %31
31: ; preds = %25
%32 = trunc i64 %22 to i32
store i32 %32, i32* %2
br label %33
33: ; preds = %31, %25
ret i8** %26
}