#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__ strcasecmp(char const *, char const *);
const char *strcasestr(const char *haystack, const char *needle) {
  while (strcasecmp(haystack, needle) != 0 && *haystack)
    haystack++;
  return *haystack ? haystack : 0;
}


x86 assembly (clang, -O0):
<strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     114f <strcasestr+0x3f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    115f <strcasestr+0x4f>
jmp    1170 <strcasestr+0x60>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1120 <strcasestr+0x10>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118d <strcasestr+0x7d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1198 <strcasestr+0x88>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    1198 <strcasestr+0x88>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcasestr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     113b <strcasestr+0x2b>
cmpb   $0x0,(%rbx)
je     113b <strcasestr+0x2b>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
jmp    1120 <strcasestr+0x10>
xor    %eax,%eax
cmpb   $0x0,(%rbx)
cmovne %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*
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %5
5: ; preds = %17, %2
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i64 @strcasecmp(i8* %6, i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %10, %5
%16 = phi i1 [ false, %5 ], [ %14, %10 ]
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
br label %5
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i8*, i8** %3
br label %28
27: ; preds = %20
br label %28
28: ; preds = %27, %25
%29 = phi i8* [ %26, %25 ], [ null, %27 ]
ret i8* %29
}

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