#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 */
scalar_t__ _strncasecmp(char const *, char const *, size_t, void *);
size_t strlen(char const *);
char *_strcasestr(const char *haystack, const char *needle, void *addr) {
  size_t needle_len = strlen(needle);
  for (size_t i = 0; haystack[i]; i++) {
    if (_strncasecmp(&haystack[i], needle, needle_len, addr) == 0) {
      return (char *)(&haystack[i]);
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<_strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11a5 <_strcasestr+0x85>
mov    -0x10(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <_strncasecmp@plt>
cmp    $0x0,%rax
jne    118f <_strcasestr+0x6f>
mov    -0x10(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ad <_strcasestr+0x8d>
jmp    1194 <_strcasestr+0x74>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1149 <_strcasestr+0x29>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strcasestr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmpb   $0x0,(%rbx)
je     1170 <_strcasestr+0x50>
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
call   1040 <_strncasecmp@plt>
test   %rax,%rax
je     1172 <_strcasestr+0x52>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1150 <_strcasestr+0x30>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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