#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 */
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char const *, size_t);
const char *findString(const char *contentStart, const char *contentEnd,
                       const char *string) {
  size_t stringLength;
  const char *currentPosition;
  const char *found;
  found = NULL;
  stringLength = strlen(string);
  currentPosition = contentStart;
  for (currentPosition = contentStart; currentPosition < contentEnd;
       currentPosition++) {
    if (*currentPosition == string[0]) {
      if (currentPosition + stringLength < contentEnd) {
        if (strncmp(currentPosition, string, stringLength) == 0) {
          found = currentPosition;
          break;
        }
      }
    }
  }
  return found;
}


x86 assembly (clang, -O0):
<findString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11d7 <findString+0xb7>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11c1 <findString+0xa1>
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11bc <findString+0x9c>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b7 <findString+0x97>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11d7 <findString+0xb7>
jmp    11bc <findString+0x9c>
jmp    11c1 <findString+0xa1>
jmp    11c6 <findString+0xa6>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1159 <findString+0x39>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findString>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1040 <strlen@plt>
cmp    %r15,%rbx
jae    1180 <findString+0x60>
mov    %rax,%r12
mov    %r15,%r13
sub    %rbx,%r13
jmp    115a <findString+0x3a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0xffffffffffffffff,%r13
je     1180 <findString+0x60>
movzbl (%rbx),%eax
cmp    (%r14),%al
jne    1150 <findString+0x30>
lea    (%rbx,%r12,1),%rax
cmp    %r15,%rax
jae    1150 <findString+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1150 <findString+0x30>
jmp    1182 <findString+0x62>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @findString(i8* %0, i8* readnone %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%5 = icmp ult i8* %0, %1
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = ptrtoint i8* %1 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = getelementptr i8, i8* %0, i64 %9
br label %11
11: ; preds = %6, %22
%12 = phi i8* [ %23, %22 ], [ %0, %6 ]
%13 = load i8, i8* %12
%14 = load i8, i8* %2
%15 = icmp eq i8 %13, %14
%16 = getelementptr inbounds i8, i8* %12, i64 %4
%17 = icmp ult i8* %16, %1
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = tail call i64 @strncmp(i8* %12, i8* %2, i64 %4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %11, %19
%23 = getelementptr inbounds i8, i8* %12, i64 1
%24 = icmp eq i8* %23, %10
br i1 %24, label %25, label %11
25: ; preds = %22, %19, %3
%26 = phi i8* [ null, %3 ], [ %12, %19 ], [ null, %22 ]
ret i8* %26
}