#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 const);
char *strstr(const char *cs, const char *ct) {
  const size_t len = strlen(ct);
  if (!len || !cs) {
    return ((char *)cs);
  }
  while ((*cs != *ct) || (strncmp(cs, ct, len))) {
    if (*cs++ == '\0') {
      return ((char *)NULL);
    }
  }
  return ((char *)cs);
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1153 <strstr+0x33>
cmpq   $0x0,-0x10(%rbp)
jne    1160 <strstr+0x40>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e0 <strstr+0xc0>
jmp    1165 <strstr+0x45>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x21(%rbp)
jne    119b <strstr+0x7b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ab <strstr+0x8b>
jmp    11d8 <strstr+0xb8>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d3 <strstr+0xb3>
movq   $0x0,-0x8(%rbp)
jmp    11e0 <strstr+0xc0>
jmp    1165 <strstr+0x45>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %rbx,%rbx
je     117a <strstr+0x5a>
mov    %rax,%r15
test   %rax,%rax
jne    1158 <strstr+0x38>
jmp    117a <strstr+0x5a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
test   %al,%al
je     1178 <strstr+0x58>
movzbl (%rbx),%eax
cmp    (%r14),%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
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strstr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11, %2
%15 = load i8*, i8** %4
store i8* %15, i8** %3
br label %43
16: ; preds = %11
br label %17
17: ; preds = %40, %16
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %20, %23
br i1 %24, label %31, label %25
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = load i64, i64* %6
%29 = call i64 @strncmp(i8* %26, i8* %27, i64 %28)
%30 = icmp ne i64 %29, 0
br label %31
31: ; preds = %25, %17
%32 = phi i1 [ true, %17 ], [ %30, %25 ]
br i1 %32, label %33, label %41
33: ; preds = %31
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
%36 = load i8, i8* %34
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
store i8* null, i8** %3
br label %43
40: ; preds = %33
br label %17
41: ; preds = %31
%42 = load i8*, i8** %4
store i8* %42, i8** %3
br label %43
43: ; preds = %41, %39, %14
%44 = load i8*, i8** %3
ret i8* %44
}

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