#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 *s1, const char *s2) {
  register const char *scan;
  register size_t len;
  register char firstc;
  firstc = *s2;
  if (firstc == 0)
    return (char *)s1;
  len = strlen(s2);
  for (scan = s1; *scan != firstc || strncmp(scan, s2, 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)
movsbl -0x29(%rbp),%eax
cmp    $0x0,%eax
jne    1153 <strstr+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e0 <strstr+0xc0>
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    119b <strstr+0x7b>
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    11ab <strstr+0x8b>
jmp    11d8 <strstr+0xb8>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d3 <strstr+0xb3>
movq   $0x0,-0x8(%rbp)
jmp    11e0 <strstr+0xc0>
jmp    1168 <strstr+0x48>
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    %rdi,%rbx
mov    (%rsi),%bpl
test   %bpl,%bpl
je     117a <strstr+0x5a>
mov    %rsi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
jmp    1158 <strstr+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
test   %al,%al
je     1178 <strstr+0x58>
movzbl (%rbx),%eax
cmp    %bpl,%al
jne    1150 <strstr+0x30>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     117a <strstr+0x5a>
movzbl (%rbx),%eax
jmp    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 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* %8
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i8*, i8** %4
store i8* %15, i8** %3
br label %45
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %7
%19 = load i8*, i8** %4
store i8* %19, i8** %6
br label %20
20: ; preds = %42, %16
%21 = load i8*, i8** %6
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i8, i8* %8
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %23, %25
br i1 %26, label %33, label %27
27: ; preds = %20
%28 = load i8*, i8** %6
%29 = load i8*, i8** %5
%30 = load i64, i64* %7
%31 = call i64 @strncmp(i8* %28, i8* %29, i64 %30)
%32 = icmp ne i64 %31, 0
br label %33
33: ; preds = %27, %20
%34 = phi i1 [ true, %20 ], [ %32, %27 ]
br i1 %34, label %35, label %43
35: ; preds = %33
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %6
%38 = load i8, i8* %36
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %35
store i8* null, i8** %3
br label %45
42: ; preds = %35
br label %20
43: ; preds = %33
%44 = load i8*, i8** %6
store i8* %44, i8** %3
br label %45
45: ; preds = %43, %41, %14
%46 = load i8*, i8** %3
ret i8* %46
}

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