#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 */
typedef size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
char *strstr(char *, char *);
ssize_t strFindLast(char *string, char *search) {
  char *pos;
  char *lastpos;
  assert(string != NULL);
  assert(search != NULL);
  lastpos = NULL;
  pos = strstr(string, search);
  while (pos) {
    lastpos = pos;
    pos = strstr(pos + 1, search);
  }
  if (lastpos)
    return (size_t)(lastpos - string);
  else
    return -1;
}


x86 assembly (clang, -O0):
<strFindLast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119a <strFindLast+0x7a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
jmp    116d <strFindLast+0x4d>
cmpq   $0x0,-0x28(%rbp)
je     11b9 <strFindLast+0x99>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11c1 <strFindLast+0xa1>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strFindLast>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1030 <assert@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1176 <strFindLast+0x56>
nopw   0x0(%rax,%rax,1)
mov    %rax,%rbx
lea    0x1(%rax),%rdi
mov    %r15,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
jne    1160 <strFindLast+0x40>
jmp    1178 <strFindLast+0x58>
xor    %ebx,%ebx
mov    %rbx,%rcx
sub    %r14,%rcx
cmp    $0x1,%rbx
sbb    %rax,%rax
or     %rcx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @strFindLast(i8* %0, i8* %1) {
%3 = alloca i64
%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 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
store i8* null, i8** %7
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i8* @strstr(i8* %16, i8* %17)
store i8* %18, i8** %6
br label %19
19: ; preds = %22, %2
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %6
store i8* %23, i8** %7
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8*, i8** %5
%27 = call i8* @strstr(i8* %25, i8* %26)
store i8* %27, i8** %6
br label %19
28: ; preds = %19
%29 = load i8*, i8** %7
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = load i8*, i8** %4
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
store i64 %36, i64* %3
br label %38
37: ; preds = %28
store i64 -1, i64* %3
br label %38
38: ; preds = %37, %31
%39 = load i64, i64* %3
ret i64 %39
}

LLVM IR (-O2):
define i64 @strFindLast(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 i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2, %11
%12 = phi i8* [ %14, %11 ], [ %9, %2 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = tail call i8* @strstr(i8* %13, i8* dereferenceable(1) %1)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %11
16: ; preds = %11, %2
%17 = phi i8* [ null, %2 ], [ %12, %11 ]
%18 = icmp eq i8* %17, null
%19 = ptrtoint i8* %17 to i64
%20 = ptrtoint i8* %0 to i64
%21 = sub i64 %19, %20
%22 = select i1 %18, i64 -1, i64 %21
ret i64 %22
}