#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 *, int);
int strlen(char const *);
char *strstr(const char *s1, const char *s2) {
  int 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    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1153 <strstr+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <strstr+0x93>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     11ab <strstr+0x8b>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    119a <strstr+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <strstr+0x93>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115f <strstr+0x3f>
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,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1170 <strstr+0x50>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %r15d,%eax
jl     116e <strstr+0x4e>
mov    %eax,%ebp
add    $0x1,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcmp@plt>
test   %eax,%eax
je     1170 <strstr+0x50>
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    %r15d,%ebp
jg     1150 <strstr+0x30>
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
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp ne i32 %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 i32 @strlen(i8* %15)
store i32 %16, i32* %6
br label %17
17: ; preds = %31, %14
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i32, i32* %6
%23 = add nsw i32 %22, -1
store i32 %23, i32* %6
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = load i32, i32* %7
%27 = call i32 @memcmp(i8* %24, i8* %25, i32 %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* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp slt i32 %6, %3
br i1 %7, label %17, label %8
8: ; preds = %5, %13
%9 = phi i32 [ %14, %13 ], [ %6, %5 ]
%10 = phi i8* [ %15, %13 ], [ %0, %5 ]
%11 = tail call i32 @memcmp(i8* %10, i8* %1, i32 %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = add nsw i32 %9, -1
%15 = getelementptr inbounds i8, i8* %10, i64 1
%16 = icmp sgt i32 %9, %3
br i1 %16, label %8, label %17
17: ; preds = %8, %13, %5, %2
%18 = phi i8* [ %0, %2 ], [ null, %5 ], [ %10, %8 ], [ null, %13 ]
ret i8* %18
}