#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__ HF_strncasecmp(char const *, char const *, size_t, int (*)(int), int,
                          uintptr_t);
size_t __builtin_strlen(char const *);
int /*<<< orphan*/ instrumentAddConstStr(char const *);
char *HF_strcasestr(const char *haystack, const char *needle,
                    int (*cmp_func)(int), uintptr_t addr) {
  size_t needle_len = __builtin_strlen(needle);
  if (needle_len == 0) {
    return (char *)haystack;
  }
  instrumentAddConstStr(needle);
  for (size_t i = 0; haystack[i]; i++) {
    if (HF_strncasecmp(&haystack[i], needle, needle_len, cmp_func, false,
                       addr) == 0) {
      return (char *)(&haystack[i]);
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<HF_strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    116d <HF_strcasestr+0x3d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e9 <HF_strcasestr+0xb9>
mov    -0x18(%rbp),%rdi
call   1050 <instrumentAddConstStr@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11e1 <HF_strcasestr+0xb1>
mov    -0x10(%rbp),%rdi
add    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r9
xor    %r8d,%r8d
call   1040 <HF_strncasecmp@plt>
cmp    $0x0,%rax
jne    11cb <HF_strcasestr+0x9b>
mov    -0x10(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e9 <HF_strcasestr+0xb9>
jmp    11d0 <HF_strcasestr+0xa0>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    117e <HF_strcasestr+0x4e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HF_strcasestr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1198 <HF_strcasestr+0x68>
mov    %rax,%r13
mov    %r12,%rdi
call   1050 <instrumentAddConstStr@plt>
cmpb   $0x0,(%rbx)
je     1196 <HF_strcasestr+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
xor    %r8d,%r8d
mov    %r14,%r9
call   1040 <HF_strncasecmp@plt>
test   %rax,%rax
je     1198 <HF_strcasestr+0x68>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1170 <HF_strcasestr+0x40>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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