#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 *in, const char *str) {
  char c;
  size_t len;
  c = *str++;
  if (!c)
    return (char *)in;
  len = strlen(str);
  do {
    char sc;
    do {
      sc = *in++;
      if (!sc)
        return (char *)0;
    } while (sc != c);
  } while (strncmp(in, str, len) != 0);
  return (char *)(in - 1);
}


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,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
cmpb   $0x0,-0x19(%rbp)
jne    115b <strstr+0x3b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d9 <strstr+0xb9>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    116d <strstr+0x4d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x29(%rbp)
cmpb   $0x0,-0x29(%rbp)
jne    1198 <strstr+0x78>
movq   $0x0,-0x8(%rbp)
jmp    11d9 <strstr+0xb9>
jmp    119d <strstr+0x7d>
movsbl -0x29(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    116d <strstr+0x4d>
jmp    11b2 <strstr+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1168 <strstr+0x48>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%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   %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 i64
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %5
%11 = load i8, i8* %9
store i8 %11, i8* %6
%12 = load i8, i8* %6
%13 = icmp ne i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = load i8*, i8** %4
store i8* %15, i8** %3
br label %44
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %7
br label %19
19: ; preds = %35, %16
br label %20
20: ; preds = %28, %19
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
%23 = load i8, i8* %21
store i8 %23, i8* %8
%24 = load i8, i8* %8
%25 = icmp ne i8 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %20
store i8* null, i8** %3
br label %44
27: ; preds = %20
br label %28
28: ; preds = %27
%29 = load i8, i8* %8
%30 = sext i8 %29 to i32
%31 = load i8, i8* %6
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %30, %32
br i1 %33, label %20, label %34
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = load i64, i64* %7
%39 = call i64 @strncmp(i8* %36, i8* %37, i64 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %19, label %41
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 -1
store i8* %43, i8** %3
br label %44
44: ; preds = %41, %26, %14
%45 = load i8*, i8** %3
ret i8* %45
}

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
}