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

/* Variables and functions */
size_t wcslen(int const *);
scalar_t__ wcsncmp(int const *, int const *, size_t);
wchar_t *wcsstr(const wchar_t *__restrict s, const wchar_t *__restrict find) {
  wchar_t c, sc;
  size_t len;
  if ((c = *find++) != L'\0') {
    len = wcslen(find);
    do {
      do {
        if ((sc = *s++) == L'\0')
          return (NULL);
      } while (sc != c);
    } while (wcsncmp(s, find, len) != 0);
    s--;
  }
  return ((wchar_t *)s);
}


x86 assembly (clang, -O0):
<wcsstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11c6 <wcsstr+0xa6>
mov    -0x18(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %rax,-0x28(%rbp)
jmp    115f <wcsstr+0x3f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jne    1189 <wcsstr+0x69>
movq   $0x0,-0x8(%rbp)
jmp    11ce <wcsstr+0xae>
jmp    118e <wcsstr+0x6e>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    115f <wcsstr+0x3f>
jmp    119f <wcsstr+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <wcsncmp@plt>
cmp    $0x0,%rax
jne    115a <wcsstr+0x3a>
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    (%rsi),%ebp
test   %ebp,%ebp
je     1177 <wcsstr+0x57>
mov    %rsi,%r14
add    $0x4,%r14
mov    %r14,%rdi
call   1030 <wcslen@plt>
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%eax
test   %eax,%eax
je     117c <wcsstr+0x5c>
mov    %r15,%rbx
add    $0x4,%r15
cmp    %ebp,%eax
jne    1150 <wcsstr+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <wcsncmp@plt>
test   %rax,%rax
jne    1150 <wcsstr+0x30>
jmp    117e <wcsstr+0x5e>
mov    %r15,%rbx
jmp    117e <wcsstr+0x5e>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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