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

/* Variables and functions */
int /*<<< orphan*/ *wcsnpbrk(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                             size_t);
wchar_t *wcsnsep(wchar_t **restrict string, const wchar_t *restrict delimiters,
                 size_t *restrict maxlen) {
  wchar_t *r = *string;
  wchar_t *next;
  if (r == NULL)
    return NULL;
  next = wcsnpbrk(r, delimiters, *maxlen);
  if (next != NULL)
    *next++ = 0, *maxlen -= (size_t)(next - r);
  *string = next;
  return r;
}


x86 assembly (clang, -O0):
<wcsnsep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1147 <wcsnsep+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11ae <wcsnsep+0x9e>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
call   1030 <wcsnpbrk@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     119b <wcsnsep+0x8b>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x30(%rbp)
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rax
sub    %rax,%rdx
sar    $0x2,%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsnsep>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%rbx
test   %rbx,%rbx
je     115d <wcsnsep+0x4d>
mov    %rdx,%r15
mov    %rdi,%r14
mov    (%rdx),%r12
mov    %rbx,%rdi
mov    %r12,%rdx
call   1030 <wcsnpbrk@plt>
test   %rax,%rax
je     1158 <wcsnsep+0x48>
mov    %rax,%rcx
add    $0x4,%rcx
movl   $0x0,(%rax)
mov    %rcx,%rax
sub    %rbx,%rax
sar    $0x2,%rax
sub    %rax,%r12
mov    %r12,(%r15)
jmp    115a <wcsnsep+0x4a>
xor    %ecx,%ecx
mov    %rcx,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @wcsnsep(i32** noalias %0, i32* noalias %1, i64* noalias %2) {
%4 = alloca i32*
%5 = alloca i32**
%6 = alloca i32*
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca i32*
store i32** %0, i32*** %5
store i32* %1, i32** %6
store i64* %2, i64** %7
%10 = load i32**, i32*** %5
%11 = load i32*, i32** %10
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32* null, i32** %4
br label %39
15: ; preds = %3
%16 = load i32*, i32** %8
%17 = load i32*, i32** %6
%18 = load i64*, i64** %7
%19 = load i64, i64* %18
%20 = call i32* @wcsnpbrk(i32* %16, i32* %17, i64 %19)
store i32* %20, i32** %9
%21 = load i32*, i32** %9
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %35
23: ; preds = %15
%24 = load i32*, i32** %9
%25 = getelementptr inbounds i32, i32* %24, i32 1
store i32* %25, i32** %9
store i32 0, i32* %24
%26 = load i32*, i32** %9
%27 = load i32*, i32** %8
%28 = ptrtoint i32* %26 to i64
%29 = ptrtoint i32* %27 to i64
%30 = sub i64 %28, %29
%31 = sdiv exact i64 %30, 4
%32 = load i64*, i64** %7
%33 = load i64, i64* %32
%34 = sub i64 %33, %31
store i64 %34, i64* %32
br label %35
35: ; preds = %23, %15
%36 = load i32*, i32** %9
%37 = load i32**, i32*** %5
store i32* %36, i32** %37
%38 = load i32*, i32** %8
store i32* %38, i32** %4
br label %39
39: ; preds = %35, %14
%40 = load i32*, i32** %4
ret i32* %40
}

LLVM IR (-O2):
define i32* @wcsnsep(i32** noalias nocapture %0, i32* noalias %1, i64* noalias nocapture %2) {
%4 = load i32*, i32** %0
%5 = icmp eq i32* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = load i64, i64* %2
%8 = tail call i32* @wcsnpbrk(i32* %4, i32* %1, i64 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %17, label %10
10: ; preds = %6
%11 = getelementptr inbounds i32, i32* %8, i64 1
store i32 0, i32* %8
%12 = ptrtoint i32* %11 to i64
%13 = ptrtoint i32* %4 to i64
%14 = sub i64 %12, %13
%15 = ashr exact i64 %14, 2
%16 = sub i64 %7, %15
store i64 %16, i64* %2
br label %17
17: ; preds = %10, %6
%18 = phi i32* [ %11, %10 ], [ null, %6 ]
store i32* %18, i32** %0
br label %19
19: ; preds = %3, %17
ret i32* %4
}