#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(char const *, char const *, size_t);
size_t strlen(char const *);
char *strstr(const char *s1, const char *s2) {
  size_t l1, l2;
  l2 = strlen(s2);
  if (!l2)
    return (char *)s1;
  l1 = strlen(s1);
  while (l1 >= l2) {
    l1--;
    if (!memcmp(s1, s2, l2))
      return (char *)s1;
    s1++;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1155 <strstr+0x35>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <strstr+0x9c>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     11b4 <strstr+0x94>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    11a3 <strstr+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <strstr+0x9c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1162 <strstr+0x42>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1172 <strstr+0x52>
mov    %rax,%r15
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %r15,%rax
jb     116f <strstr+0x4f>
mov    %rax,%rbx
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <bcmp@plt>
test   %eax,%eax
je     1172 <strstr+0x52>
add    $0xffffffffffffffff,%rbx
add    $0x1,%r12
cmp    %r15,%rbx
jae    1150 <strstr+0x30>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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