#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 */
size_t wcslen(int /*<<< orphan*/ const *);
scalar_t__ wstrcmpi_n(int /*<<< orphan*/ const *, int /*<<< orphan*/ const *,
                      size_t);
wchar_t *wstrstri(const wchar_t *str, const wchar_t *find) {
  size_t len;
  if (!str || !find)
    return NULL;
  len = wcslen(find);
  do {
    if (wstrcmpi_n(str, find, len) == 0)
      return (wchar_t *)str;
  } while (*str++);
  return NULL;
}


x86 assembly (clang, -O0):
<wstrstri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <wstrstri+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1153 <wstrstri+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11ad <wstrstri+0x8d>
mov    -0x18(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <wstrcmpi_n@plt>
cmp    $0x0,%rax
jne    1188 <wstrstri+0x68>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ad <wstrstri+0x8d>
jmp    118d <wstrstri+0x6d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
cmpl   $0x0,(%rax)
jne    1160 <wstrstri+0x40>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wstrstri>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     1171 <wstrstri+0x51>
mov    %rsi,%r15
test   %rsi,%rsi
je     1171 <wstrstri+0x51>
mov    %rdi,%rbx
mov    %r15,%rdi
call   1030 <wcslen@plt>
mov    %rax,%r12
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <wstrcmpi_n@plt>
test   %rax,%rax
je     116e <wstrstri+0x4e>
cmpl   $0x0,(%rbx)
lea    0x4(%rbx),%rbx
jne    1150 <wstrstri+0x30>
jmp    1171 <wstrstri+0x51>
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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