#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 my_strlen(char *);
scalar_t__ my_strncmp(char *, char *, size_t);
char *my_strstr(char *str, char *to_find) {
  char c;
  size_t len;
  c = *to_find++;
  if (!c)
    return (char *)str;
  len = my_strlen(to_find);
  do {
    char sc;
    do {
      sc = *str++;
      if (!sc)
        return "null";
    } while (sc != c);
  } while (my_strncmp(str, to_find, len) != 0);
  return (str - 1);
}


x86 assembly (clang, -O0):
<my_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 <my_strstr+0x3b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <my_strstr+0xbc>
mov    -0x18(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %rax,-0x28(%rbp)
jmp    116d <my_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    119b <my_strstr+0x7b>
lea    0xe6e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11dc <my_strstr+0xbc>
jmp    11a0 <my_strstr+0x80>
movsbl -0x29(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    116d <my_strstr+0x4d>
jmp    11b5 <my_strstr+0x95>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <my_strncmp@plt>
cmp    $0x0,%rax
jne    1168 <my_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):
<my_strstr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    (%rsi),%bpl
test   %bpl,%bpl
je     1179 <my_strstr+0x59>
mov    %rsi,%r14
add    $0x1,%r14
mov    %r14,%rdi
call   1030 <my_strlen@plt>
mov    %rax,%r12
lea    0xeb1(%rip),%r13
nop
movzbl (%r15),%eax
test   %al,%al
je     117e <my_strstr+0x5e>
mov    %r15,%rbx
add    $0x1,%r15
cmp    %bpl,%al
jne    1150 <my_strstr+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <my_strncmp@plt>
test   %rax,%rax
jne    1150 <my_strstr+0x30>
jmp    1181 <my_strstr+0x61>
mov    %r15,%rbx
jmp    1181 <my_strstr+0x61>
mov    %r13,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"null\00"
define i8* @my_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 @my_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* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), 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 @my_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):
@.str = [5 x i8] c"null\00"
define i8* @my_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 @my_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 @my_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 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %8 ]
ret i8* %20
}