#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 */
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
char *strchr(char const *, char const);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int /*<<< orphan*/ const);
char *strstr(const char *s1, const char *s2) {
  const char *p = s1;
  const int32_t len = strlen(s2);
  for (; (p = strchr(p, *s2)) != 0; p++) {
    if (strncmp(p, s2, len) == 0)
      return (char *)p;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11af <strstr+0x7f>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1199 <strstr+0x69>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b7 <strstr+0x87>
jmp    119e <strstr+0x6e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1154 <strstr+0x24>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
movsbl (%rbx),%esi
mov    %rbp,%rdi
call   1050 <strchr@plt>
test   %rax,%rax
je     118a <strstr+0x5a>
mov    %rax,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118c <strstr+0x5c>
add    $0x1,%rbp
movsbl (%rbx),%esi
mov    %rbp,%rdi
call   1050 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1160 <strstr+0x30>
xor    %ebp,%ebp
mov    %rbp,%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 i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
store i8* %8, i8** %6
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
br label %11
11: ; preds = %26, %2
%12 = load i8*, i8** %6
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = call i8* @strchr(i8* %12, i8 signext %14)
store i8* %15, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %29
17: ; preds = %11
%18 = load i8*, i8** %6
%19 = load i8*, i8** %5
%20 = load i32, i32* %7
%21 = call i64 @strncmp(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** %6
store i8* %24, i8** %3
br label %30
25: ; preds = %17
br label %26
26: ; preds = %25
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %6
br label %11
29: ; preds = %11
store i8* null, i8** %3
br label %30
30: ; preds = %29, %23
%31 = load i8*, i8** %3
ret i8* %31
}

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