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


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1189 <strstr+0x59>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e4 <strstr+0xb4>
jmp    118e <strstr+0x5e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11dc <strstr+0xac>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11c6 <strstr+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e4 <strstr+0xb4>
jmp    11cb <strstr+0x9b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    118e <strstr+0x5e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     118f <strstr+0x5f>
cmpb   $0x0,(%rbx)
je     118d <strstr+0x5d>
mov    %rax,%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118f <strstr+0x5f>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1170 <strstr+0x40>
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** %4
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %6
%17 = load i64, i64* %6
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = load i8*, i8** %4
store i8* %20, i8** %3
br label %40
21: ; preds = %2
br label %22
22: ; preds = %36, %21
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %39
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = load i64, i64* %6
%31 = call i64 @strncmp(i8* %28, i8* %29, i64 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = load i8*, i8** %4
store i8* %34, i8** %3
br label %40
35: ; preds = %27
br label %36
36: ; preds = %35
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
br label %22
39: ; preds = %22
store i8* null, i8** %3
br label %40
40: ; preds = %39, %33, %19
%41 = load i8*, i8** %3
ret i8* %41
}

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