#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 const *, char const);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char const *, int);
char *strstr(const char *s1, const char *s2) {
  int len2;
  len2 = strlen(s2);
  while (1) {
    s1 = strchr(s1, s2[0]);
    if (s1 == NULL) {
      break;
    }
    if (!strncmp(s1, s2, len2)) {
      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   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1170 <strstr+0x40>
jmp    11a7 <strstr+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1196 <strstr+0x66>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <strstr+0x7f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114c <strstr+0x1c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%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     1189 <strstr+0x59>
mov    %rax,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     118b <strstr+0x5b>
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 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 = %2, %26
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = call i8* @strchr(i8* %10, i8 signext %13)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %9
br label %29
18: ; preds = %9
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = call i32 @strncmp(i8* %19, i8* %20, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = load i8*, i8** %4
store i8* %25, i8** %3
br label %30
26: ; preds = %18
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %4
br label %9
29: ; preds = %17
store i8* null, i8** %3
br label %30
30: ; preds = %29, %24
%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 i32 @strncmp(i8* %8, i8* %1, i32 %3)
%10 = icmp eq i32 %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
}