#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 */
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, size_t);
char *strstr(const char *ehay, const char *ened) {
  char *hay = (char *)ehay;
  char *ned = (char *)ened;
  char c, s;
  size_t len;
  if ((c = *ned++)) {
    len = strlen(ned);
    do {
      do {
        if (!(s = *hay++))
          return NULL;
      } while (s != c);
    } while (strncmp(hay, ned, len));
    hay--;
  }
  return hay;
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%al
mov    %al,-0x29(%rbp)
cmp    $0x0,%al
je     11d8 <strstr+0xb8>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
jmp    116e <strstr+0x4e>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%al
mov    %al,-0x2a(%rbp)
cmp    $0x0,%al
jne    1197 <strstr+0x77>
movq   $0x0,-0x8(%rbp)
jmp    11e0 <strstr+0xc0>
jmp    119c <strstr+0x7c>
movsbl -0x2a(%rbp),%eax
movsbl -0x29(%rbp),%ecx
cmp    %ecx,%eax
jne    116e <strstr+0x4e>
jmp    11b1 <strstr+0x91>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1169 <strstr+0x49>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    (%rsi),%bpl
test   %bpl,%bpl
je     1179 <strstr+0x59>
mov    %rsi,%r14
add    $0x1,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15),%eax
test   %al,%al
je     117e <strstr+0x5e>
mov    %r15,%rbx
add    $0x1,%r15
cmp    %bpl,%al
jne    1150 <strstr+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1150 <strstr+0x30>
jmp    1180 <strstr+0x60>
mov    %r15,%rbx
jmp    1180 <strstr+0x60>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
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 i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
store i8* %11, i8** %6
%12 = load i8*, i8** %5
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %7
%15 = load i8, i8* %13
store i8 %15, i8* %8
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %44
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %10
br label %20
20: ; preds = %35, %17
br label %21
21: ; preds = %28, %20
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
%24 = load i8, i8* %22
store i8 %24, i8* %9
%25 = icmp ne i8 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %21
store i8* null, i8** %3
br label %46
27: ; preds = %21
br label %28
28: ; preds = %27
%29 = load i8, i8* %9
%30 = sext i8 %29 to i32
%31 = load i8, i8* %8
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %21, label %34
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = load i8*, i8** %6
%37 = load i8*, i8** %7
%38 = load i64, i64* %10
%39 = call i64 @strncmp(i8* %36, i8* %37, i64 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %20, label %41
41: ; preds = %35
%42 = load i8*, i8** %6
%43 = getelementptr inbounds i8, i8* %42, i32 -1
store i8* %43, i8** %6
br label %44
44: ; preds = %41, %2
%45 = load i8*, i8** %6
store i8* %45, i8** %3
br label %46
46: ; preds = %44, %26
%47 = load i8*, i8** %3
ret i8* %47
}

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