#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__ strncmp(char const *, char const *, int);
char *strstr(const char *s, const char *find) {
  int len;
  len = strlen(find);
  while (1) {
    if (strncmp(s, find, len) == 0)
      return s;
    if (*s == '\0')
      return (char *)0;
    s++;
  }
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1163 <strstr+0x43>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1191 <strstr+0x71>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1180 <strstr+0x60>
movq   $0x0,-0x8(%rbp)
jmp    1191 <strstr+0x71>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <strstr+0x1c>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
nopl   0x0(%rax)
call   1030 <strncmp@plt>
test   %rax,%rax
je     115f <strstr+0x3f>
cmpb   $0x0,(%rbx)
je     115d <strstr+0x3d>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
jmp    1140 <strstr+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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