#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*/ wchar_t;
struct TokenStream {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ token_stream_add(struct TokenStream *, int /*<<< orphan*/ *);
struct TokenStream *token_stream_new();
int /*<<< orphan*/ *wcstok(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ **);
struct TokenStream *token_split(wchar_t *data) {
  if (data == NULL)
    return NULL;
  struct TokenStream *ts = token_stream_new();
  wchar_t *split = NULL, *state;
  split = wcstok(data, L" ", &state);
  while (split != NULL) {
    token_stream_add(ts, split);
    split = wcstok(NULL, L" ", &state);
  }
  return ts;
}


x86 assembly (clang, -O0):
<token_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <token_split+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11bc <token_split+0x8c>
mov    $0x0,%al
call   1050 <token_stream_new@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <wcstok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b4 <token_split+0x84>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <token_stream_add@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe5e(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <wcstok@plt>
mov    %rax,-0x20(%rbp)
jmp    117f <token_split+0x4f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<token_split>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     118f <token_split+0x5f>
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <token_stream_new@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1040 <wcstok@plt>
test   %rax,%rax
je     1191 <token_split+0x61>
lea    0xe95(%rip),%r14
lea    0x8(%rsp),%r15
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <token_stream_add@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <wcstok@plt>
test   %rax,%rax
jne    1170 <token_split+0x40>
jmp    1191 <token_split+0x61>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TokenStream = type { i32 }
@.str = [2 x i32] [i32 32, i32 0]
define %struct.TokenStream* @token_split(i32* %0) {
%2 = alloca %struct.TokenStream*
%3 = alloca i32*
%4 = alloca %struct.TokenStream*
%5 = alloca i32*
%6 = alloca i32*
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store %struct.TokenStream* null, %struct.TokenStream** %2
br label %24
10: ; preds = %1
%11 = call %struct.TokenStream* (...) @token_stream_new()
store %struct.TokenStream* %11, %struct.TokenStream** %4
store i32* null, i32** %5
%12 = load i32*, i32** %3
%13 = call i32* @wcstok(i32* %12, i8* bitcast ([2 x i32]* @.str to i8*), i32** %6)
store i32* %13, i32** %5
br label %14
14: ; preds = %17, %10
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load %struct.TokenStream*, %struct.TokenStream** %4
%19 = load i32*, i32** %5
%20 = call i32 @token_stream_add(%struct.TokenStream* %18, i32* %19)
%21 = call i32* @wcstok(i32* null, i8* bitcast ([2 x i32]* @.str to i8*), i32** %6)
store i32* %21, i32** %5
br label %14
22: ; preds = %14
%23 = load %struct.TokenStream*, %struct.TokenStream** %4
store %struct.TokenStream* %23, %struct.TokenStream** %2
br label %24
24: ; preds = %22, %9
%25 = load %struct.TokenStream*, %struct.TokenStream** %2
ret %struct.TokenStream* %25
}

LLVM IR (-O2):
%struct.TokenStream = type { i32 }
@.str = [2 x i32] [i32 32, i32 0]
define %struct.TokenStream* @token_split(i32* %0) {
%2 = alloca i32*
%3 = icmp eq i32* %0, null
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = tail call %struct.TokenStream* (...) @token_stream_new()
%6 = bitcast i32** %2 to i8*
%7 = call i32* @wcstok(i32* %0, i8* bitcast ([2 x i32]* @.str to i8*), i32** %2)
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %4, %9
%10 = phi i32* [ %12, %9 ], [ %7, %4 ]
%11 = call i32 @token_stream_add(%struct.TokenStream* %5, i32* %10)
%12 = call i32* @wcstok(i32* null, i8* bitcast ([2 x i32]* @.str to i8*), i32** %2)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %9
14: ; preds = %9, %4
br label %15
15: ; preds = %1, %14
%16 = phi %struct.TokenStream* [ %5, %14 ], [ null, %1 ]
ret %struct.TokenStream* %16
}