#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*/ interceptor_increaseBy(int);
scalar_t__ strcasecmp(char const *, char const *);
__attribute__((optimize("0"))) char *strcasestr(const char *haystack,
                                                const char *needle) {
  for (size_t i = 0; haystack[i]; i++) {
    if (strcasecmp(&haystack[i], needle) == 0) {
      return (char *)(&haystack[i]);
    }
    interceptor_increaseBy(1);
  }
  interceptor_increaseBy(5);
  return NULL;
}


x86 assembly (clang, -O0):
<strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1191 <strcasestr+0x71>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1176 <strcasestr+0x56>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <strcasestr+0x83>
mov    $0x1,%edi
call   1040 <interceptor_increaseBy@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1138 <strcasestr+0x18>
mov    $0x5,%edi
call   1040 <interceptor_increaseBy@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasestr>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     1154 <strcasestr+0x34>
mov    %rsi,%r14
mov    %rdi,%rbx
nop
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1160 <strcasestr+0x40>
mov    $0x1,%edi
call   1040 <interceptor_increaseBy@plt>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1130 <strcasestr+0x10>
mov    $0x5,%edi
call   1040 <interceptor_increaseBy@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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