#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 */
int /*<<< orphan*/ _DIAGASSERT(int /*<<< orphan*/);
char *__UNCONST(char const *);
size_t strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, size_t);
char tolower(unsigned char);
char *strcasestr(const char *s, const char *find) {
  char c, sc;
  size_t len;
  _DIAGASSERT(s != NULL);
  _DIAGASSERT(find != NULL);
  if ((c = *find++) != 0) {
    c = 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 __UNCONST(s);
}


x86 assembly (clang, -O0):
<strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <_DIAGASSERT@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <_DIAGASSERT@plt>
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     1238 <strcasestr+0xe8>
movzbl -0x19(%rbp),%edi
call   1050 <tolower@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    11c2 <strcasestr+0x72>
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    11ef <strcasestr+0x9f>
movq   $0x0,-0x8(%rbp)
jmp    1245 <strcasestr+0xf5>
jmp    11f4 <strcasestr+0xa4>
movzbl -0x1a(%rbp),%edi
call   1050 <tolower@plt>
movsbl %al,%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    11c2 <strcasestr+0x72>
jmp    1211 <strcasestr+0xc1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11bd <strcasestr+0x6d>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <__UNCONST@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasestr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbp
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1040 <_DIAGASSERT@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <_DIAGASSERT@plt>
mov    (%r14),%al
test   %al,%al
je     11d1 <strcasestr+0x81>
add    $0x1,%r14
movzbl %al,%edi
call   1050 <tolower@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%eax
test   %al,%al
je     11e4 <strcasestr+0x94>
mov    %rbp,%rbx
add    $0x1,%rbp
movzbl %al,%edi
call   1050 <tolower@plt>
cmp    %r12b,%al
jne    11a0 <strcasestr+0x50>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <strncasecmp@plt>
test   %rax,%rax
jne    11a0 <strcasestr+0x50>
jmp    11d4 <strcasestr+0x84>
mov    %rbp,%rbx
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <__UNCONST@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
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** %4
%10 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @_DIAGASSERT(i32 %11)
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @_DIAGASSERT(i32 %15)
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %5
%19 = load i8, i8* %17
store i8 %19, i8* %6
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %53
22: ; preds = %2
%23 = load i8, i8* %6
%24 = call signext i8 @tolower(i8 zeroext %23)
store i8 %24, i8* %6
%25 = load i8*, i8** %5
%26 = call i64 @strlen(i8* %25)
store i64 %26, i64* %8
br label %27
27: ; preds = %44, %22
br label %28
28: ; preds = %36, %27
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
%31 = load i8, i8* %29
store i8 %31, i8* %7
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %28
store i8* null, i8** %3
br label %56
35: ; preds = %28
br label %36
36: ; preds = %35
%37 = load i8, i8* %7
%38 = call signext i8 @tolower(i8 zeroext %37)
%39 = sext i8 %38 to i32
%40 = load i8, i8* %6
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %39, %41
br i1 %42, label %28, label %43
43: ; preds = %36
br label %44
44: ; preds = %43
%45 = load i8*, i8** %4
%46 = load i8*, i8** %5
%47 = load i64, i64* %8
%48 = call i64 @strncasecmp(i8* %45, i8* %46, i64 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %27, label %50
50: ; preds = %44
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i32 -1
store i8* %52, i8** %4
br label %53
53: ; preds = %50, %2
%54 = load i8*, i8** %4
%55 = call i8* @__UNCONST(i8* %54)
store i8* %55, i8** %3
br label %56
56: ; preds = %53, %34
%57 = load i8*, i8** %3
ret i8* %57
}

LLVM IR (-O2):
define i8* @strcasestr(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @_DIAGASSERT(i32 %4)
%6 = icmp ne i8* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @_DIAGASSERT(i32 %7)
%9 = getelementptr inbounds i8, i8* %1, i64 1
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %27, label %12
12: ; preds = %2
%13 = tail call signext i8 @tolower(i8 zeroext %10)
%14 = tail call i64 @strlen(i8* %9)
br label %15
15: ; preds = %23, %12
%16 = phi i8* [ %0, %12 ], [ %17, %23 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %16
%19 = icmp eq i8 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %15
%21 = tail call signext i8 @tolower(i8 zeroext %18)
%22 = icmp eq i8 %21, %13
br i1 %22, label %24, label %23
23: ; preds = %20, %24
br label %15
24: ; preds = %20
%25 = tail call i64 @strncasecmp(i8* %17, i8* %9, i64 %14)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %23
27: ; preds = %24, %2
%28 = phi i8* [ %0, %2 ], [ %16, %24 ]
%29 = tail call i8* @__UNCONST(i8* %28)
br label %30
30: ; preds = %15, %27
%31 = phi i8* [ %29, %27 ], [ null, %15 ]
ret i8* %31
}