#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 __numOccurrences(char const *, char const *);
scalar_t__ crAlloc(int);
int crStrlen(char const *);
char *crStrndup(char *, int);
char *crStrstr(char *, char const *);
char **crStrSplit(const char *str, const char *splitstr) {
  char *temp = (char *)str;
  int num_args = __numOccurrences(str, splitstr) + 1;
  char **faked_argv = (char **)crAlloc((num_args + 1) * sizeof(*faked_argv));
  int i;
  for (i = 0; i < num_args; i++) {
    char *end;
    end = crStrstr(temp, splitstr);
    if (!end)
      end = temp + crStrlen(temp);
    faked_argv[i] = crStrndup(temp, end - temp);
    temp = end + crStrlen(splitstr);
  }
  faked_argv[num_args] = NULL;
  return faked_argv;
}


x86 assembly (clang, -O0):
<crStrSplit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <__numOccurrences@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <crAlloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1236 <crStrSplit+0xe6>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <crStrstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e2 <crStrSplit+0x92>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <crStrlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1030 <crStrndup@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <crStrlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1199 <crStrSplit+0x49>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crStrSplit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <__numOccurrences@plt>
mov    %eax,%r12d
lea    0x10(,%r12,8),%edi
call   1050 <crAlloc@plt>
mov    %rax,%r14
lea    0x1(%r12),%eax
mov    %eax,0x4(%rsp)
test   %r12d,%r12d
js     11db <crStrSplit+0x8b>
mov    0x4(%rsp),%ebp
xor    %r13d,%r13d
jmp    11b8 <crStrSplit+0x68>
mov    %r12d,%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1030 <crStrndup@plt>
mov    %rax,(%r14,%r13,8)
mov    %r15,%rdi
call   1060 <crStrlen@plt>
movslq %eax,%rbx
add    %r12,%rbx
add    $0x1,%r13
cmp    %r13,%rbp
je     11db <crStrSplit+0x8b>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <crStrstr@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1190 <crStrSplit+0x40>
mov    %rbx,%rdi
call   1060 <crStrlen@plt>
movslq %eax,%r12
add    %rbx,%r12
jmp    1190 <crStrSplit+0x40>
movslq 0x4(%rsp),%rax
movq   $0x0,(%r14,%rax,8)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @crStrSplit(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
store i8* %10, i8** %5
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = call i32 @__numOccurrences(i8* %11, i8* %12)
%14 = add nsw i32 %13, 1
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 8
%19 = trunc i64 %18 to i32
%20 = call i64 @crAlloc(i32 %19)
%21 = inttoptr i64 %20 to i8**
store i8** %21, i8*** %7
store i32 0, i32* %8
br label %22
22: ; preds = %56, %2
%23 = load i32, i32* %8
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %59
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = load i8*, i8** %4
%29 = call i8* @crStrstr(i8* %27, i8* %28)
store i8* %29, i8** %9
%30 = load i8*, i8** %9
%31 = icmp ne i8* %30, null
br i1 %31, label %38, label %32
32: ; preds = %26
%33 = load i8*, i8** %5
%34 = load i8*, i8** %5
%35 = call i32 @crStrlen(i8* %34)
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8* %37, i8** %9
br label %38
38: ; preds = %32, %26
%39 = load i8*, i8** %5
%40 = load i8*, i8** %9
%41 = load i8*, i8** %5
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = trunc i64 %44 to i32
%46 = call i8* @crStrndup(i8* %39, i32 %45)
%47 = load i8**, i8*** %7
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
store i8* %46, i8** %50
%51 = load i8*, i8** %9
%52 = load i8*, i8** %4
%53 = call i32 @crStrlen(i8* %52)
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8* %55, i8** %5
br label %56
56: ; preds = %38
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %22
59: ; preds = %22
%60 = load i8**, i8*** %7
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
store i8* null, i8** %63
%64 = load i8**, i8*** %7
ret i8** %64
}

LLVM IR (-O2):
define i8** @crStrSplit(i8* %0, i8* %1) {
%3 = tail call i32 @__numOccurrences(i8* %0, i8* %1)
%4 = shl i32 %3, 3
%5 = add i32 %4, 16
%6 = tail call i64 @crAlloc(i32 %5)
%7 = inttoptr i64 %6 to i8**
%8 = icmp slt i32 %3, 0
%9 = add i32 %3, 1
br i1 %8, label %34, label %10
10: ; preds = %2
%11 = zext i32 %9 to i64
br label %12
12: ; preds = %10, %21
%13 = phi i64 [ 0, %10 ], [ %32, %21 ]
%14 = phi i8* [ %0, %10 ], [ %31, %21 ]
%15 = tail call i8* @crStrstr(i8* %14, i8* %1)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = tail call i32 @crStrlen(i8* %14)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %14, i64 %19
br label %21
21: ; preds = %17, %12
%22 = phi i8* [ %15, %12 ], [ %20, %17 ]
%23 = ptrtoint i8* %22 to i64
%24 = ptrtoint i8* %14 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = tail call i8* @crStrndup(i8* %14, i32 %26)
%28 = getelementptr inbounds i8*, i8** %7, i64 %13
store i8* %27, i8** %28
%29 = tail call i32 @crStrlen(i8* %1)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %22, i64 %30
%32 = add nuw nsw i64 %13, 1
%33 = icmp eq i64 %32, %11
br i1 %33, label %34, label %12
34: ; preds = %21, %2
%35 = sext i32 %9 to i64
%36 = getelementptr inbounds i8*, i8** %7, i64 %35
store i8* null, i8** %36
ret i8** %7
}