#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__ string_strncasecmp(char const *, char const *, int);
char *utf8_next_char(char const *);
int utf8_strlen(char const *);
const char *string_strcasestr(const char *string, const char *search) {
  int length_search;
  length_search = utf8_strlen(search);
  if (!string || !search || (length_search == 0))
    return NULL;
  while (string[0]) {
    if (string_strncasecmp(string, search, length_search) == 0)
      return (char *)string;
    string = utf8_next_char(string);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<string_strcasestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <utf8_strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116c <string_strcasestr+0x3c>
cmpq   $0x0,-0x18(%rbp)
je     116c <string_strcasestr+0x3c>
cmpl   $0x0,-0x1c(%rbp)
jne    1179 <string_strcasestr+0x49>
movq   $0x0,-0x8(%rbp)
jmp    11cc <string_strcasestr+0x9c>
jmp    117e <string_strcasestr+0x4e>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c4 <string_strcasestr+0x94>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <string_strncasecmp@plt>
cmp    $0x0,%rax
jne    11b2 <string_strcasestr+0x82>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <string_strcasestr+0x9c>
mov    -0x10(%rbp),%rdi
call   1050 <utf8_next_char@plt>
mov    %rax,-0x10(%rbp)
jmp    117e <string_strcasestr+0x4e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_strcasestr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <utf8_strlen@plt>
xor    %r14d,%r14d
test   %rbx,%rbx
je     118c <string_strcasestr+0x5c>
test   %r15,%r15
je     118c <string_strcasestr+0x5c>
mov    %eax,%ebp
test   %eax,%eax
je     118c <string_strcasestr+0x5c>
cmpb   $0x0,(%rbx)
je     1184 <string_strcasestr+0x54>
xor    %r14d,%r14d
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <string_strncasecmp@plt>
test   %rax,%rax
je     1189 <string_strcasestr+0x59>
mov    %rbx,%rdi
call   1050 <utf8_next_char@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    1160 <string_strcasestr+0x30>
jmp    118c <string_strcasestr+0x5c>
xor    %r14d,%r14d
jmp    118c <string_strcasestr+0x5c>
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @string_strcasestr(i8* %0, i8* %1) {
%3 = tail call i32 @utf8_strlen(i8* %1)
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i32 %3, 0
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %20, label %9
9: ; preds = %2
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %9, %16
%13 = phi i8* [ %17, %16 ], [ %0, %9 ]
%14 = tail call i64 @string_strncasecmp(i8* %13, i8* %1, i32 %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = tail call i8* @utf8_next_char(i8* %13)
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %12
20: ; preds = %12, %16, %9, %2
%21 = phi i8* [ null, %2 ], [ null, %9 ], [ %13, %12 ], [ null, %16 ]
ret i8* %21
}