#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 */
char *strstr(char *, char const *);
char *findLast(const char *s1, const char *s2) {
  char *last = NULL;
  char *ptr = (char *)s1;
  if (s1 == NULL || s2 == NULL)
    return NULL;
  while ((ptr = strstr(ptr, s2)) != NULL) {
    last = ptr;
    ptr++;
  }
  return last;
}


x86 assembly (clang, -O0):
<findLast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <findLast+0x36>
cmpq   $0x0,-0x18(%rbp)
jne    1153 <findLast+0x43>
movq   $0x0,-0x8(%rbp)
jmp    1194 <findLast+0x84>
jmp    1158 <findLast+0x48>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     118c <findLast+0x7c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1158 <findLast+0x48>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findLast>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     1144 <findLast+0x34>
mov    %rsi,%r14
test   %rsi,%rsi
je     1144 <findLast+0x34>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rbx
mov    %r14,%rsi
call   1030 <strstr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
jne    1130 <findLast+0x20>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @findLast(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
store i8* null, i8** %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store i8* null, i8** %3
br label %27
15: ; preds = %11
br label %16
16: ; preds = %21, %15
%17 = load i8*, i8** %7
%18 = load i8*, i8** %5
%19 = call i8* @strstr(i8* %17, i8* %18)
store i8* %19, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i8*, i8** %7
store i8* %22, i8** %6
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %7
br label %16
25: ; preds = %16
%26 = load i8*, i8** %6
store i8* %26, i8** %3
br label %27
27: ; preds = %25, %14
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
define i8* @findLast(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %12, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %9, %6 ], [ null, %2 ]
%8 = phi i8* [ %11, %6 ], [ %0, %2 ]
%9 = tail call i8* @strstr(i8* dereferenceable(1) %8, i8* dereferenceable(1) %1)
%10 = icmp eq i8* %9, null
%11 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %10, label %12, label %6
12: ; preds = %6, %2
%13 = phi i8* [ null, %2 ], [ %7, %6 ]
ret i8* %13
}