#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 */
typedef int /*<<< orphan*/ const wchar_t;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(int /*<<< orphan*/ const *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ const *wcsdup(int /*<<< orphan*/ const *);
int /*<<< orphan*/ const *wcstok(int /*<<< orphan*/ const *,
                                 int /*<<< orphan*/ const *,
                                 int /*<<< orphan*/ const **);
void split(const wchar_t *text, const wchar_t *seps, wchar_t ***str,
           int *count) {
  wchar_t *last, *tok, *data;
  int i;
  *count = 0;
  data = wcsdup(text);
  for (tok = wcstok(data, seps, &last); tok != NULL;
       tok = wcstok(NULL, seps, &last))
    (*count)++;
  free(data);
  fflush(stdout);
  data = wcsdup(text);
  *str = (wchar_t **)malloc((size_t)(*count) * sizeof(wchar_t *));
  for (i = 0, tok = wcstok(data, seps, &last); tok != NULL;
       tok = wcstok(NULL, seps, &last), i++)
    (*str)[i] = wcsdup(tok);
  free(data);
}


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)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1060 <wcsdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <wcstok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11c4 <split+0x74>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rdx
call   1070 <wcstok@plt>
mov    %rax,-0x30(%rbp)
jmp    1194 <split+0x44>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x8(%rbp),%rdi
call   1060 <wcsdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
movslq (%rax),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <wcstok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1267 <split+0x117>
mov    -0x30(%rbp),%rdi
call   1060 <wcsdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rdx
call   1070 <wcstok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    121e <split+0xce>
mov    -0x38(%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
push   %rax
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
movl   $0x0,(%rcx)
call   1060 <wcsdup@plt>
mov    %rax,%r13
mov    %rsp,%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1070 <wcstok@plt>
test   %rax,%rax
je     11a7 <split+0x57>
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
addl   $0x1,(%r12)
xor    %edi,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1070 <wcstok@plt>
test   %rax,%rax
jne    1190 <split+0x40>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    %r15,%rdi
call   1060 <wcsdup@plt>
mov    %rax,%r15
movslq (%r12),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,(%r14)
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <wcstok@plt>
test   %rax,%rax
je     1215 <split+0xc5>
xor    %ebp,%ebp
mov    %rsp,%r12
mov    %rax,%rdi
call   1060 <wcsdup@plt>
mov    (%r14),%rcx
mov    %rax,(%rcx,%rbp,1)
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1070 <wcstok@plt>
add    $0x8,%rbp
test   %rax,%rax
jne    11f0 <split+0xa0>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stdout = global i32 0
define void @split(i32* %0, i32* %1, i32*** nocapture %2, i32* nocapture %3) {
%5 = alloca i32*
%6 = bitcast i32** %5 to i8*
store i32 0, i32* %3
%7 = tail call i32* @wcsdup(i32* %0)
%8 = call i32* @wcstok(i32* %7, i32* %1, i32** %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %4, %10
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = call i32* @wcstok(i32* null, i32* %1, i32** %5)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %10
15: ; preds = %10, %4
%16 = call i32 @free(i32* %7)
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
%19 = call i32* @wcsdup(i32* %0)
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = shl nsw i64 %21, 3
%23 = call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to i32**
store i32** %24, i32*** %2
%25 = call i32* @wcstok(i32* %19, i32* %1, i32** %5)
%26 = icmp eq i32* %25, null
br i1 %26, label %36, label %27
27: ; preds = %15, %27
%28 = phi i64 [ %34, %27 ], [ 0, %15 ]
%29 = phi i32* [ %33, %27 ], [ %25, %15 ]
%30 = call i32* @wcsdup(i32* %29)
%31 = load i32**, i32*** %2
%32 = getelementptr inbounds i32*, i32** %31, i64 %28
store i32* %30, i32** %32
%33 = call i32* @wcstok(i32* null, i32* %1, i32** %5)
%34 = add nuw i64 %28, 1
%35 = icmp eq i32* %33, null
br i1 %35, label %36, label %27
36: ; preds = %27, %15
%37 = call i32 @free(i32* %19)
ret void
}