#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 /*<<< orphan*/ memcmp(int /*<<< orphan*/, char const *, int);
int strlen(char const *);
char *strstr(char *s1, const char *s2) {
  int len = strlen(s2);
  while (*s1)
    if (!memcmp(s1++, s2, len))
      return s1 - 1;
  return 0;
}


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   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1185 <strstr+0x65>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    1180 <strstr+0x60>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    118d <strstr+0x6d>
jmp    113c <strstr+0x1c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    -0x1(%r15),%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rbx)
je     1161 <strstr+0x41>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcmp@plt>
add    $0x1,%rbx
add    $0x1,%r15d
test   %eax,%eax
jne    1140 <strstr+0x20>
jmp    1163 <strstr+0x43>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
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 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 = %24, %2
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
%16 = ptrtoint i8* %14 to i32
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = call i32 @memcmp(i32 %16, i8* %17, i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 -1
store i8* %23, i8** %3
br label %26
24: ; preds = %13
br label %9
25: ; preds = %9
store i8* null, i8** %3
br label %26
26: ; preds = %25, %21
%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)
br label %4
4: ; preds = %8, %2
%5 = phi i8* [ %0, %2 ], [ %9, %8 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %5, i64 1
%10 = ptrtoint i8* %5 to i64
%11 = trunc i64 %10 to i32
%12 = tail call i32 @memcmp(i32 %11, i8* %1, i32 %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %4, %8
%15 = phi i8* [ %5, %8 ], [ null, %4 ]
ret i8* %15
}