#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 */
scalar_t__ strlen(char const *);
char *strtok(char *, char const *);
void split(char *src, const char *separator, char **dest, int *num) {
  char *pNext;
  int count = 0;
  if (src == NULL || strlen(src) == 0)
    return;
  if (separator == NULL || strlen(separator) == 0)
    return;
  pNext = strtok(src, separator);
  while (pNext != NULL) {
    *dest++ = pNext;
    ++count;
    pNext = strtok(NULL, separator);
  }
  *num = count;
}


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)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115d <split+0x3d>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    1162 <split+0x42>
jmp    11df <split+0xbf>
cmpq   $0x0,-0x10(%rbp)
je     1180 <split+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    1185 <split+0x65>
jmp    11df <split+0xbf>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d6 <split+0xb6>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1196 <split+0x76>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     116a <split+0x5a>
mov    %rsi,%r12
test   %rsi,%rsi
je     116a <split+0x5a>
cmpb   $0x0,(%rdi)
je     116a <split+0x5a>
cmpb   $0x0,(%r12)
je     116a <split+0x5a>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %r12,%rsi
call   1030 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1167 <split+0x57>
cs nopw 0x0(%rax,%rax,1)
mov    %rax,(%r15,%rbx,8)
xor    %edi,%edi
mov    %r12,%rsi
call   1030 <strtok@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <split+0x40>
mov    %ebx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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