#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, unsigned int);
int /*<<< orphan*/ strcpy(char *, char const *);
unsigned int strlen(char const *);
char *strstr(char *, char *);
void split(char *src, const char *separator, char **dest, int *num) {
  char *pSeparator, *pStart, *pEnd;
  unsigned int sep_len;
  int count = 0;
  if (src == NULL || strlen(src) == 0)
    return;
  pSeparator = (char *)malloc(16);
  if (pSeparator == NULL)
    return;
  if (separator == NULL || strlen(separator) == 0)
    strcpy(pSeparator, " ");
  else
    strcpy(pSeparator, separator);
  sep_len = strlen(pSeparator);
  pStart = src;
  while (1) {
    pEnd = strstr(pStart, pSeparator);
    if (pEnd != NULL) {
      memset(pEnd, '\0', sep_len);
      *dest++ = pStart;
      pEnd = pEnd + sep_len;
      pStart = pEnd;
      ++count;
    } else {
      *dest = pStart;
      ++count;
      break;
    }
  }
  *num = count;
  if (pSeparator != NULL)
    free(pSeparator);
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119c <split+0x3c>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    11a1 <split+0x41>
jmp    12b1 <split+0x151>
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bf <split+0x5f>
jmp    12b1 <split+0x151>
cmpq   $0x0,-0x10(%rbp)
je     11dc <split+0x7c>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    11f1 <split+0x91>
mov    -0x28(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11fe <split+0x9e>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1276 <split+0x116>
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    128f <split+0x12f>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1294 <split+0x134>
jmp    1212 <split+0xb2>
mov    -0x40(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     12b1 <split+0x151>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     11b8 <split+0x58>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbp
call   1050 <strlen@plt>
test   %eax,%eax
je     11b8 <split+0x58>
mov    $0x10,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11b8 <split+0x58>
mov    %rax,%rbx
test   %r12,%r12
mov    %r14,0x10(%rsp)
je     11c7 <split+0x67>
mov    %r12,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     11c7 <split+0x67>
mov    %rbx,%rdi
mov    %r12,%rsi
jmp    11d1 <split+0x71>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,0xc(%rsp)
mov    %rbp,%rdi
mov    %rbx,%r13
mov    %rbx,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     1244 <split+0xe4>
mov    %rax,%rbx
mov    0xc(%rsp),%r12d
mov    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    0xc(%rsp),%edx
call   1060 <memset@plt>
mov    %rbp,(%r15)
add    $0x8,%r15
mov    %rbx,%rbp
add    %r12,%rbp
add    $0x1,%r14d
mov    %rbp,%rdi
mov    %r13,%rsi
call   1080 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1210 <split+0xb0>
jmp    124a <split+0xea>
mov    $0x1,%r14d
mov    %rbp,(%r15)
mov    0x10(%rsp),%rax
mov    %r14d,(%rax)
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
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 i8*
%11 = alloca i8*
%12 = alloca i32
%13 = 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* %13
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %4
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16, %4
br label %79
21: ; preds = %16
%22 = call i64 @malloc(i32 16)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
br label %79
27: ; preds = %21
%28 = load i8*, i8** %6
%29 = icmp eq i8* %28, null
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30, %27
%35 = load i8*, i8** %9
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %41
37: ; preds = %30
%38 = load i8*, i8** %9
%39 = load i8*, i8** %6
%40 = call i32 @strcpy(i8* %38, i8* %39)
br label %41
41: ; preds = %37, %34
%42 = load i8*, i8** %9
%43 = call i32 @strlen(i8* %42)
store i32 %43, i32* %12
%44 = load i8*, i8** %5
store i8* %44, i8** %10
br label %45
45: ; preds = %41, %70
%46 = load i8*, i8** %10
%47 = load i8*, i8** %9
%48 = call i8* @strstr(i8* %46, i8* %47)
store i8* %48, i8** %11
%49 = load i8*, i8** %11
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %65
51: ; preds = %45
%52 = load i8*, i8** %11
%53 = load i32, i32* %12
%54 = call i32 @memset(i8* %52, i8 signext 0, i32 %53)
%55 = load i8*, i8** %10
%56 = load i8**, i8*** %7
%57 = getelementptr inbounds i8*, i8** %56, i32 1
store i8** %57, i8*** %7
store i8* %55, i8** %56
%58 = load i8*, i8** %11
%59 = load i32, i32* %12
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8* %61, i8** %11
%62 = load i8*, i8** %11
store i8* %62, i8** %10
%63 = load i32, i32* %13
%64 = add nsw i32 %63, 1
store i32 %64, i32* %13
br label %70
65: ; preds = %45
%66 = load i8*, i8** %10
%67 = load i8**, i8*** %7
store i8* %66, i8** %67
%68 = load i32, i32* %13
%69 = add nsw i32 %68, 1
store i32 %69, i32* %13
br label %71
70: ; preds = %51
br label %45
71: ; preds = %65
%72 = load i32, i32* %13
%73 = load i32*, i32** %8
store i32 %72, i32* %73
%74 = load i8*, i8** %9
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load i8*, i8** %9
%78 = call i32 @free(i8* %77)
br label %79
79: ; preds = %20, %26, %76, %71
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
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 %44, label %6
6: ; preds = %4
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %44, label %9
9: ; preds = %6
%10 = tail call i64 @malloc(i32 16)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %44, label %13
13: ; preds = %9
%14 = icmp eq i8* %1, null
br i1 %14, label %18, label %15
15: ; preds = %13
%16 = tail call i32 @strlen(i8* %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15, %13
%19 = tail call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
20: ; preds = %15
%21 = tail call i32 @strcpy(i8* %11, i8* %1)
br label %22
22: ; preds = %20, %18
%23 = tail call i32 @strlen(i8* %11)
%24 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* %11)
%25 = icmp eq i8* %24, null
br i1 %25, label %39, label %26
26: ; preds = %22
%27 = zext i32 %23 to i64
br label %28
28: ; preds = %26, %28
%29 = phi i8* [ %24, %26 ], [ %37, %28 ]
%30 = phi i32 [ 1, %26 ], [ %36, %28 ]
%31 = phi i8** [ %2, %26 ], [ %34, %28 ]
%32 = phi i8* [ %0, %26 ], [ %35, %28 ]
%33 = tail call i32 @memset(i8* %29, i8 signext 0, i32 %23)
%34 = getelementptr inbounds i8*, i8** %31, i64 1
store i8* %32, i8** %31
%35 = getelementptr inbounds i8, i8* %29, i64 %27
%36 = add i32 %30, 1
%37 = tail call i8* @strstr(i8* dereferenceable(1) %35, i8* %11)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %28
39: ; preds = %28, %22
%40 = phi i8* [ %0, %22 ], [ %35, %28 ]
%41 = phi i8** [ %2, %22 ], [ %34, %28 ]
%42 = phi i32 [ 1, %22 ], [ %36, %28 ]
store i8* %40, i8** %41
store i32 %42, i32* %3
%43 = tail call i32 @free(i8* %11)
br label %44
44: ; preds = %9, %4, %6, %39
ret void
}