#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 *, int);
char *strstr(const char *s1, const char *s2) {
  const char *p, *q;
  int c0, c;
  c0 = *s2;
  if (c0 == '\0')
    return (char *)s1;
  --s1;
  while ((s1 = strchr(s1 + 1, c0)) != NULL) {
    p = s1;
    q = s2;
    for (;;) {
      if ((c = *++p) == '\0')
        return (char *)s1;
      if (c != *++q)
        break;
    }
  }
  return NULL;
}


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
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1141 <strstr+0x31>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <strstr+0xcc>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x2c(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11d4 <strstr+0xc4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jne    11a7 <strstr+0x97>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <strstr+0xcc>
mov    -0x30(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
movsbl 0x1(%rcx),%ecx
cmp    %ecx,%eax
je     11ca <strstr+0xba>
jmp    11cf <strstr+0xbf>
jmp    117b <strstr+0x6b>
jmp    114d <strstr+0x3d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
movsbl (%rsi),%ebp
test   %ebp,%ebp
je     116c <strstr+0x5c>
mov    %rsi,%rbx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     116c <strstr+0x5c>
mov    $0x1,%ecx
nopl   0x0(%rax,%rax,1)
movzbl (%rax,%rcx,1),%edx
test   %dl,%dl
je     1169 <strstr+0x59>
lea    0x1(%rcx),%rsi
cmp    (%rbx,%rcx,1),%dl
mov    %rsi,%rcx
je     1140 <strstr+0x30>
add    $0x1,%rax
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1133 <strstr+0x23>
jmp    116c <strstr+0x5c>
mov    %rax,%r14
mov    %r14,%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 i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i8*, i8** %4
store i8* %16, i8** %3
br label %48
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i32 -1
store i8* %19, i8** %4
br label %20
20: ; preds = %46, %17
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i32, i32* %8
%24 = call i8* @strchr(i8* %22, i32 %23)
store i8* %24, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %47
26: ; preds = %20
%27 = load i8*, i8** %4
store i8* %27, i8** %6
%28 = load i8*, i8** %5
store i8* %28, i8** %7
br label %29
29: ; preds = %45, %26
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
store i32 %33, i32* %9
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = load i8*, i8** %4
store i8* %36, i8** %3
br label %48
37: ; preds = %29
%38 = load i32, i32* %9
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %7
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %38, %42
br i1 %43, label %44, label %45
44: ; preds = %37
br label %46
45: ; preds = %37
br label %29
46: ; preds = %44
br label %20
47: ; preds = %20
store i8* null, i8** %3
br label %48
48: ; preds = %47, %35, %15
%49 = load i8*, i8** %3
ret i8* %49
}

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