#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;
  c = *find++;
  if (c != 0) {
    len = strlen(find);
    do {
      do {
        sc = *s++;
        if (sc == 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 -0x19(%rbp),%eax
cmp    $0x0,%eax
je     11d2 <strstr+0xb2>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    1163 <strstr+0x43>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
movsbl -0x1a(%rbp),%eax
cmp    $0x0,%eax
jne    1191 <strstr+0x71>
movq   $0x0,-0x8(%rbp)
jmp    11da <strstr+0xba>
jmp    1196 <strstr+0x76>
movsbl -0x1a(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    1163 <strstr+0x43>
jmp    11ab <strstr+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    115e <strstr+0x3e>
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 = load i8, i8* %6
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %44
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %8
br label %18
18: ; preds = %35, %15
br label %19
19: ; preds = %28, %18
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %20
store i8 %22, i8* %7
%23 = load i8, i8* %7
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %19
store i8* null, i8** %3
br label %46
27: ; preds = %19
br label %28
28: ; preds = %27
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
%31 = load i8, i8* %6
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %19, label %34
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = load i64, i64* %8
%39 = call i64 @strncmp(i8* %36, i8* %37, i64 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %18, label %41
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 -1
store i8* %43, i8** %4
br label %44
44: ; preds = %41, %2
%45 = load i8*, i8** %4
store i8* %45, i8** %3
br label %46
46: ; preds = %44, %26
%47 = load i8*, i8** %3
ret i8* %47
}

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
}