#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*/ __tokencap_dump(char const *, int /*<<< orphan*/, int);
scalar_t__ __tokencap_is_ro(char const *);
int /*<<< orphan*/ strlen(char const *);
char *strstr(const char *haystack, const char *needle) {
  if (__tokencap_is_ro(haystack))
    __tokencap_dump(haystack, strlen(haystack), 1);
  if (__tokencap_is_ro(needle))
    __tokencap_dump(needle, strlen(needle), 1);
  do {
    const char *n = needle;
    const char *h = haystack;
    while (*n && *h && *n == *h)
      n++, h++;
    if (!*n)
      return (char *)haystack;
  } while (*(haystack++));
  return 0;
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <__tokencap_is_ro@plt>
cmp    $0x0,%rax
je     1174 <strstr+0x44>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1030 <__tokencap_dump@plt>
mov    -0x18(%rbp),%rdi
call   1050 <__tokencap_is_ro@plt>
cmp    $0x0,%rax
je     11a8 <strstr+0x78>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1030 <__tokencap_dump@plt>
jmp    11ad <strstr+0x7d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     11fd <strstr+0xcd>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     11fd <strstr+0xcd>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    -0x28(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    120d <strstr+0xdd>
jmp    122a <strstr+0xfa>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11bd <strstr+0x8d>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1244 <strstr+0x114>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1269 <strstr+0x139>
jmp    1249 <strstr+0x119>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,(%rax)
jne    11ad <strstr+0x7d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1050 <__tokencap_is_ro@plt>
test   %rax,%rax
je     115c <strstr+0x2c>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1030 <__tokencap_dump@plt>
mov    %r15,%rdi
call   1050 <__tokencap_is_ro@plt>
test   %rax,%rax
je     1180 <strstr+0x50>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   1030 <__tokencap_dump@plt>
mov    (%r15),%sil
mov    %r14,%rcx
test   %sil,%sil
je     11c1 <strstr+0x91>
xor    %edx,%edx
mov    %esi,%eax
nop
movzbl (%rcx,%rdx,1),%ebx
test   %bl,%bl
je     11b0 <strstr+0x80>
cmp    %bl,%al
jne    11b0 <strstr+0x80>
movzbl 0x1(%r15,%rdx,1),%eax
add    $0x1,%rdx
test   %al,%al
jne    1190 <strstr+0x60>
jmp    11be <strstr+0x8e>
nopl   0x0(%rax)
cmpb   $0x0,(%rcx)
lea    0x1(%rcx),%rcx
jne    1186 <strstr+0x56>
xor    %r14d,%r14d
jmp    11c1 <strstr+0x91>
mov    %rcx,%r14
mov    %r14,%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 i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i64 @__tokencap_is_ro(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @__tokencap_dump(i8* %12, i32 %14, i32 1)
br label %16
16: ; preds = %11, %2
%17 = load i8*, i8** %5
%18 = call i64 @__tokencap_is_ro(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %5
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @__tokencap_dump(i8* %21, i32 %23, i32 1)
br label %25
25: ; preds = %20, %16
br label %26
26: ; preds = %61, %25
%27 = load i8*, i8** %5
store i8* %27, i8** %6
%28 = load i8*, i8** %4
store i8* %28, i8** %7
br label %29
29: ; preds = %49, %26
%30 = load i8*, i8** %6
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %47
34: ; preds = %29
%35 = load i8*, i8** %7
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %34
%40 = load i8*, i8** %6
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = load i8*, i8** %7
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %42, %45
br label %47
47: ; preds = %39, %34, %29
%48 = phi i1 [ false, %34 ], [ false, %29 ], [ %46, %39 ]
br i1 %48, label %49, label %54
49: ; preds = %47
%50 = load i8*, i8** %6
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %6
%52 = load i8*, i8** %7
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %7
br label %29
54: ; preds = %47
%55 = load i8*, i8** %6
%56 = load i8, i8* %55
%57 = icmp ne i8 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %54
%59 = load i8*, i8** %4
store i8* %59, i8** %3
br label %67
60: ; preds = %54
br label %61
61: ; preds = %60
%62 = load i8*, i8** %4
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %4
%64 = load i8, i8* %62
%65 = icmp ne i8 %64, 0
br i1 %65, label %26, label %66
66: ; preds = %61
store i8* null, i8** %3
br label %67
67: ; preds = %66, %58
%68 = load i8*, i8** %3
ret i8* %68
}

LLVM IR (-O2):
define i8* @strstr(i8* %0, i8* %1) {
%3 = tail call i64 @__tokencap_is_ro(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i32 @__tokencap_dump(i8* %0, i32 %6, i32 1)
br label %8
8: ; preds = %5, %2
%9 = tail call i64 @__tokencap_is_ro(i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @strlen(i8* %1)
%13 = tail call i32 @__tokencap_dump(i8* %1, i32 %12, i32 1)
br label %14
14: ; preds = %11, %8
%15 = load i8, i8* %1
%16 = icmp eq i8 %15, 0
br label %17
17: ; preds = %32, %14
%18 = phi i8* [ %0, %14 ], [ %33, %32 ]
br i1 %16, label %36, label %19
19: ; preds = %17, %27
%20 = phi i8 [ %30, %27 ], [ %15, %17 ]
%21 = phi i8* [ %29, %27 ], [ %18, %17 ]
%22 = phi i8* [ %28, %27 ], [ %1, %17 ]
%23 = load i8, i8* %21
%24 = icmp ne i8 %23, 0
%25 = icmp eq i8 %20, %23
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %27, label %32
27: ; preds = %19
%28 = getelementptr inbounds i8, i8* %22, i64 1
%29 = getelementptr inbounds i8, i8* %21, i64 1
%30 = load i8, i8* %28
%31 = icmp eq i8 %30, 0
br i1 %31, label %36, label %19
32: ; preds = %19
%33 = getelementptr inbounds i8, i8* %18, i64 1
%34 = load i8, i8* %18
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %17
36: ; preds = %32, %17, %27
%37 = phi i8* [ %18, %27 ], [ %0, %17 ], [ null, %32 ]
ret i8* %37
}