#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 */

/* Variables and functions */
size_t strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, size_t);
scalar_t__ tolower(unsigned char);
char *strcasestr(const char *s, const char *find) {
  char c, sc;
  size_t len;
  if ((c = *find++) != 0) {
    c = (char)tolower((unsigned char)c);
    len = strlen(find);
    do {
      do {
        if ((sc = *s++) == 0)
          return (NULL);
      } while ((char)tolower((unsigned char)sc) != c);
    } while (strncasecmp(s, find, len) != 0);
    s--;
  }
  return ((char *)s);
}


x86 assembly (clang, -O0):
<strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11f4 <strcasestr+0xc4>
movzbl -0x19(%rbp),%edi
call   1040 <tolower@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    117e <strcasestr+0x4e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
jne    11ab <strcasestr+0x7b>
movq   $0x0,-0x8(%rbp)
jmp    11fc <strcasestr+0xcc>
jmp    11b0 <strcasestr+0x80>
movzbl -0x1a(%rbp),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    117e <strcasestr+0x4e>
jmp    11cd <strcasestr+0x9d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1179 <strcasestr+0x49>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%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):
<strcasestr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
mov    (%rsi),%al
test   %al,%al
je     1196 <strcasestr+0x66>
mov    %rsi,%r14
add    $0x1,%r14
movzbl %al,%edi
call   1040 <tolower@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
nop
movzbl (%r12),%eax
test   %al,%al
je     1192 <strcasestr+0x62>
mov    %r12,%rbx
add    $0x1,%r12
movzbl %al,%edi
call   1040 <tolower@plt>
xor    %r15b,%al
jne    1160 <strcasestr+0x30>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1050 <strncasecmp@plt>
test   %rax,%rax
jne    1160 <strcasestr+0x30>
jmp    1199 <strcasestr+0x69>
xor    %ebx,%ebx
jmp    1199 <strcasestr+0x69>
mov    %r12,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strcasestr(i8* %0, i8* nocapture %1) {
%3 = getelementptr inbounds i8, i8* %1, i64 1
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = tail call i64 @tolower(i8 zeroext %4)
%8 = tail call i64 @strlen(i8* %3)
br label %9
9: ; preds = %19, %6
%10 = phi i8* [ %0, %6 ], [ %11, %19 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %9
%15 = tail call i64 @tolower(i8 zeroext %12)
%16 = xor i64 %15, %7
%17 = and i64 %16, 255
%18 = icmp eq i64 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %14, %20
br label %9
20: ; preds = %14
%21 = tail call i64 @strncasecmp(i8* %11, i8* %3, i64 %8)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %19
23: ; preds = %20, %9, %2
%24 = phi i8* [ %0, %2 ], [ %10, %20 ], [ null, %9 ]
ret i8* %24
}