#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 strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, int);
const char *strstri(const char *str, const char *subStr) {
  int len = strlen(subStr);
  if (len == 0) {
    return NULL;
  }
  while (*str) {
    if (strncasecmp(str, subStr, len) == 0) {
      return str;
    }
    ++str;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strstri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1153 <strstri+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11a5 <strstri+0x85>
jmp    1158 <strstri+0x38>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     119d <strstri+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    118c <strstri+0x6c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a5 <strstri+0x85>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1158 <strstri+0x38>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstri>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     115c <strstri+0x3c>
cmpb   $0x0,(%rbx)
je     115c <strstri+0x3c>
mov    %eax,%ebp
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     115e <strstri+0x3e>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1140 <strstri+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @strstri(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 @strlen(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i8* null, i8** %3
br label %29
12: ; preds = %2
br label %13
13: ; preds = %25, %12
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = call i64 @strncasecmp(i8* %18, i8* %19, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = load i8*, i8** %4
store i8* %24, i8** %3
br label %29
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
br label %13
28: ; preds = %13
store i8* null, i8** %3
br label %29
29: ; preds = %28, %23, %11
%30 = load i8*, i8** %3
ret i8* %30
}

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