#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);
char *strstr(const char *s, const char *find) {
  char c, sc;
  size_t len;
  if ((c = *find++) != '\0') {
    len = strlen(find);
    do {
      do {
        if ((sc = *s++) == '\0') {
          return (NULL);
        }
      } while (sc != c);
    } while (strncmp(s, find, len) != 0);
    s--;
  }
  return ((char *)s);
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11d0 <strstr+0xb0>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    1162 <strstr+0x42>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
jne    118f <strstr+0x6f>
movq   $0x0,-0x8(%rbp)
jmp    11d8 <strstr+0xb8>
jmp    1194 <strstr+0x74>
movsbl -0x1a(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    1162 <strstr+0x42>
jmp    11a9 <strstr+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    115d <strstr+0x3d>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    (%rsi),%bpl
test   %bpl,%bpl
je     1179 <strstr+0x59>
mov    %rsi,%r14
add    $0x1,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15),%eax
test   %al,%al
je     117e <strstr+0x5e>
mov    %r15,%rbx
add    $0x1,%r15
cmp    %bpl,%al
jne    1150 <strstr+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1150 <strstr+0x30>
jmp    1180 <strstr+0x60>
mov    %r15,%rbx
jmp    1180 <strstr+0x60>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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