#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 scalar_t__ wchar_t;

/* Variables and functions */
int wcscspn(scalar_t__ *, scalar_t__ const *);
int /*<<< orphan*/ wcsspn(scalar_t__ *, scalar_t__ const *);
wchar_t *wcstok(wchar_t *restrict s, const wchar_t *restrict sep,
                wchar_t **restrict p) {
  if (!s && !(s = *p))
    return NULL;
  s += wcsspn(s, sep);
  if (!*s)
    return *p = 0;
  *p = s + wcscspn(s, sep);
  if (**p)
    *(*p)++ = 0;
  else
    *p = 0;
  return s;
}


x86 assembly (clang, -O0):
<wcstok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1161 <wcstok+0x41>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1161 <wcstok+0x41>
movq   $0x0,-0x8(%rbp)
jmp    1212 <wcstok+0xf2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <wcsspn@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11a8 <wcstok+0x88>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1212 <wcstok+0xf2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <wcscspn@plt>
mov    -0x28(%rbp),%rcx
cltq
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     11ff <wcstok+0xdf>
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,(%rcx)
movq   $0x0,(%rax)
jmp    120a <wcstok+0xea>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcstok>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
test   %rdi,%rdi
jne    113b <wcstok+0x1b>
mov    (%r14),%rbx
test   %rbx,%rbx
je     1182 <wcstok+0x62>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <wcsspn@plt>
cltq
cmpq   $0x0,(%rbx,%rax,8)
je     117b <wcstok+0x5b>
lea    (%rbx,%rax,8),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <wcscspn@plt>
cltq
cmpq   $0x0,(%rbx,%rax,8)
je     1186 <wcstok+0x66>
lea    (%rbx,%rax,8),%rax
lea    0x8(%rax),%rcx
mov    %rcx,(%r14)
movq   $0x0,(%rax)
jmp    118d <wcstok+0x6d>
movq   $0x0,(%r14)
xor    %ebx,%ebx
jmp    118d <wcstok+0x6d>
movq   $0x0,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i64* @wcstok(i64* noalias %0, i64* noalias %1, i64** noalias nocapture %2) {
%4 = icmp eq i64* %0, null
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = load i64*, i64** %2
%7 = icmp eq i64* %6, null
br i1 %7, label %25, label %8
8: ; preds = %5, %3
%9 = phi i64* [ %0, %3 ], [ %6, %5 ]
%10 = tail call i32 @wcsspn(i64* %9, i64* %1)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i64, i64* %9, i64 %11
%13 = load i64, i64* %12
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %8
store i64* null, i64** %2
br label %25
16: ; preds = %8
%17 = tail call i32 @wcscspn(i64* %12, i64* %1)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i64, i64* %12, i64 %18
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = getelementptr inbounds i64, i64* %19, i64 1
store i64* %23, i64** %2
store i64 0, i64* %19
br label %25
24: ; preds = %16
store i64* null, i64** %2
br label %25
25: ; preds = %22, %24, %5, %15
%26 = phi i64* [ null, %15 ], [ null, %5 ], [ %12, %24 ], [ %12, %22 ]
ret i64* %26
}