#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 mstrlen(char *);
scalar_t__ strncmp(char *, char *, size_t);
char *mstrstr(char *string, char *find) {
  size_t stringlen, findlen;
  char *cp;
  findlen = mstrlen(find);
  stringlen = mstrlen(string);
  if (findlen > stringlen)
    return (NULL);
  for (cp = string + stringlen - findlen; cp >= string; cp--)
    if (strncmp(cp, find, findlen) == 0)
      return (cp);
  return (NULL);
}


x86 assembly (clang, -O0):
<mstrstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <mstrlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <mstrlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    1165 <mstrstr+0x45>
movq   $0x0,-0x8(%rbp)
jmp    11ce <mstrstr+0xae>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
xor    %ecx,%ecx
sub    -0x28(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     11c6 <mstrstr+0xa6>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b0 <mstrstr+0x90>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ce <mstrstr+0xae>
jmp    11b5 <mstrstr+0x95>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    117a <mstrstr+0x5a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mstrstr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <mstrlen@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   1040 <mstrlen@plt>
xor    %r15d,%r15d
cmp    %rax,%r13
ja     1181 <mstrstr+0x61>
mov    %rax,%rbx
add    %r12,%rbx
sub    %r13,%rbx
cmp    %r12,%rbx
jb     1181 <mstrstr+0x61>
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
je     117e <mstrstr+0x5e>
add    $0xffffffffffffffff,%rbx
cmp    %r12,%rbx
jae    1160 <mstrstr+0x40>
jmp    1181 <mstrstr+0x61>
mov    %rbx,%r15
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @mstrstr(i8* %0, i8* %1) {
%3 = tail call i64 @mstrlen(i8* %1)
%4 = tail call i64 @mstrlen(i8* %0)
%5 = icmp ugt i64 %3, %4
%6 = getelementptr inbounds i8, i8* %0, i64 %4
%7 = sub i64 0, %3
%8 = getelementptr inbounds i8, i8* %6, i64 %7
%9 = icmp ult i8* %8, %0
%10 = select i1 %5, i1 true, i1 %9
br i1 %10, label %18, label %11
11: ; preds = %2, %15
%12 = phi i8* [ %16, %15 ], [ %8, %2 ]
%13 = tail call i64 @strncmp(i8* %12, i8* %1, i64 %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = getelementptr inbounds i8, i8* %12, i64 -1
%17 = icmp ult i8* %16, %0
br i1 %17, label %18, label %11
18: ; preds = %11, %15, %2
%19 = phi i8* [ null, %2 ], [ %12, %11 ], [ null, %15 ]
ret i8* %19
}