#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*/ const *wcsnpbrk(int /*<<< orphan*/ const *,
                                   int /*<<< orphan*/ const *, size_t);
wchar_t *(wcsnprbrk)(const wchar_t *string, const wchar_t *stopset,
                     size_t maxlen) {
  wchar_t *r;
  int found = 0;
  while (string)
    if ((r = wcsnpbrk(string + 1, stopset, maxlen - 1)))
      maxlen -= (r - string), string = r, found = 1;
  return found ? string : NULL;
}


x86 assembly (clang, -O0):
<wcsnprbrk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     118b <wcsnprbrk+0x7b>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <wcsnpbrk@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1186 <wcsnprbrk+0x76>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    112b <wcsnprbrk+0x1b>
cmpl   $0x0,-0x24(%rbp)
je     11a2 <wcsnprbrk+0x92>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11ad <wcsnprbrk+0x9d>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11ad <wcsnprbrk+0x9d>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsnprbrk>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     115a <wcsnprbrk+0x4a>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x4(%rbx),%rdi
lea    -0x1(%r15),%rdx
mov    %r14,%rsi
call   1030 <wcsnpbrk@plt>
mov    %rax,%rcx
sub    %rbx,%rcx
sar    $0x2,%rcx
test   %rax,%rax
cmove  %rax,%rcx
cmovne %rax,%rbx
sub    %rcx,%r15
jmp    1130 <wcsnprbrk+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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