#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 */
scalar_t__ towlower(scalar_t__);
size_t wcslen(scalar_t__ const *);
scalar_t__ wcsncasecmp(scalar_t__ const *, scalar_t__ const *, size_t);
const wchar_t *wcscasestr(const wchar_t *s, const wchar_t *find) {
  wchar_t c, sc;
  size_t len;
  if ((c = *find++) != 0) {
    c = (wchar_t)towlower((wchar_t)c);
    len = wcslen(find);
    do {
      do {
        if ((sc = *s++) == 0)
          return (NULL);
      } while ((wchar_t)towlower((wchar_t)sc) != c);
    } while (wcsncasecmp(s, find, len) != 0);
    s--;
  }
  return (s);
}


x86 assembly (clang, -O0):
<wcscasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f0 <wcscasestr+0xc0>
mov    -0x20(%rbp),%rdi
call   1050 <towlower@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <wcslen@plt>
mov    %rax,-0x30(%rbp)
jmp    117f <wcscasestr+0x4f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ac <wcscasestr+0x7c>
movq   $0x0,-0x8(%rbp)
jmp    11f8 <wcscasestr+0xc8>
jmp    11b1 <wcscasestr+0x81>
mov    -0x28(%rbp),%rdi
call   1050 <towlower@plt>
cmp    -0x20(%rbp),%rax
jne    117f <wcscasestr+0x4f>
jmp    11c9 <wcscasestr+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <wcsncasecmp@plt>
cmp    $0x0,%rax
jne    117a <wcscasestr+0x4a>
mov    -0x10(%rbp),%rax
add    $0xfffffffffffffff8,%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):
<wcscasestr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
mov    (%rsi),%rdi
test   %rdi,%rdi
je     118f <wcscasestr+0x5f>
mov    %rsi,%r14
add    $0x8,%r14
call   1050 <towlower@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <wcslen@plt>
mov    %rax,%r13
xchg   %ax,%ax
mov    (%r12),%rdi
test   %rdi,%rdi
je     1194 <wcscasestr+0x64>
mov    %r12,%rbx
add    $0x8,%r12
call   1050 <towlower@plt>
cmp    %r15,%rax
jne    1160 <wcscasestr+0x30>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1040 <wcsncasecmp@plt>
test   %rax,%rax
jne    1160 <wcscasestr+0x30>
jmp    1196 <wcscasestr+0x66>
mov    %r12,%rbx
jmp    1196 <wcscasestr+0x66>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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