#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 const *);
scalar_t__ strncmp(char const *, char const *, size_t);
char *strstr(const char *s, const char *wanted) {
  register const char *scan;
  register size_t len;
  register char firstc;
  firstc = *wanted;
  len = strlen(wanted);
  for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0;)
    if (*scan++ == '\0')
      return (NULL);
  return ((char *)scan);
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
movsbl -0x29(%rbp),%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x2a(%rbp)
jne    1181 <strstr+0x61>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    1191 <strstr+0x71>
jmp    11be <strstr+0x9e>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b9 <strstr+0x99>
movq   $0x0,-0x8(%rbp)
jmp    11c6 <strstr+0xa6>
jmp    114e <strstr+0x2e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%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),%bpl
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
jmp    1148 <strstr+0x28>
nopl   (%rax)
add    $0x1,%rbx
test   %al,%al
je     1168 <strstr+0x48>
movzbl (%rbx),%eax
cmp    %bpl,%al
jne    1140 <strstr+0x20>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     116a <strstr+0x4a>
movzbl (%rbx),%eax
jmp    1140 <strstr+0x20>
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 i8*
%7 = alloca i64
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
store i8 %10, i8* %8
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %7
%13 = load i8*, i8** %4
store i8* %13, i8** %6
br label %14
14: ; preds = %36, %2
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = load i8, i8* %8
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %27, label %21
21: ; preds = %14
%22 = load i8*, i8** %6
%23 = load i8*, i8** %5
%24 = load i64, i64* %7
%25 = call i64 @strncmp(i8* %22, i8* %23, i64 %24)
%26 = icmp ne i64 %25, 0
br label %27
27: ; preds = %21, %14
%28 = phi i1 [ true, %14 ], [ %26, %21 ]
br i1 %28, label %29, label %37
29: ; preds = %27
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
%32 = load i8, i8* %30
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i8* null, i8** %3
br label %39
36: ; preds = %29
br label %14
37: ; preds = %27
%38 = load i8*, i8** %6
store i8* %38, i8** %3
br label %39
39: ; preds = %37, %35
%40 = load i8*, i8** %3
ret i8* %40
}

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