#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 */
char *strchr(char *, char const);
size_t strlen(char const *);
int /*<<< orphan*/ strncmp(char *, char const *, size_t);
char *strstr(const char *str1, const char *str2) {
  size_t len_str2 = strlen(str2);
  char *cur;
  for (cur = (char *)str1; cur != NULL; cur = strchr(cur, *str2)) {
    if (!strncmp(cur, str2, len_str2)) {
      break;
    }
    cur++;
  }
  return cur;
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a4 <strstr+0x74>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    117f <strstr+0x4f>
jmp    11a4 <strstr+0x74>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
jmp    1155 <strstr+0x25>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %rbx,%rbx
je     117a <strstr+0x4a>
mov    %rax,%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
je     117c <strstr+0x4c>
add    $0x1,%rbx
movsbl (%r14),%esi
mov    %rbx,%rdi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1150 <strstr+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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