#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 *strchr(char *, char);
ssize_t strFindLastChar(char *string, char search) {
  char *pos;
  char *lastpos;
  assert(string != NULL);
  lastpos = NULL;
  pos = strchr(string, search);
  while (pos) {
    lastpos = pos;
    pos = strchr(pos + 1, search);
  }
  if (lastpos)
    return (size_t)(lastpos - string);
  else
    return -1;
}


x86 assembly (clang, -O0):
<strFindLastChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118a <strFindLastChar+0x6a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
jmp    115d <strFindLastChar+0x3d>
cmpq   $0x0,-0x28(%rbp)
je     11a9 <strFindLastChar+0x89>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <strFindLastChar+0x91>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strFindLastChar>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1165 <strFindLastChar+0x45>
movsbl %bpl,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rax,%rbx
lea    0x1(%rax),%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1150 <strFindLastChar+0x30>
jmp    1167 <strFindLastChar+0x47>
xor    %ebx,%ebx
mov    %rbx,%rcx
sub    %r14,%rcx
cmp    $0x1,%rbx
sbb    %rax,%rax
or     %rcx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i64 @strFindLastChar(i8* %0, i8 signext %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)
store i8* null, i8** %7
%12 = load i8*, i8** %4
%13 = load i8, i8* %5
%14 = call i8* @strchr(i8* %12, i8 signext %13)
store i8* %14, i8** %6
br label %15
15: ; preds = %18, %2
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i8*, i8** %6
store i8* %19, i8** %7
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %5
%23 = call i8* @strchr(i8* %21, i8 signext %22)
store i8* %23, i8** %6
br label %15
24: ; preds = %15
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i8*, i8** %7
%29 = load i8*, i8** %4
%30 = ptrtoint i8* %28 to i64
%31 = ptrtoint i8* %29 to i64
%32 = sub i64 %30, %31
store i64 %32, i64* %3
br label %34
33: ; preds = %24
store i64 -1, i64* %3
br label %34
34: ; preds = %33, %27
%35 = load i64, i64* %3
ret i64 %35
}

LLVM IR (-O2):
define i64 @strFindLastChar(i8* %0, i8 signext %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %2, %8
%9 = phi i8* [ %11, %8 ], [ %6, %2 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = tail call i8* @strchr(i8* %10, i8 signext %1)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %8
13: ; preds = %8, %2
%14 = phi i8* [ null, %2 ], [ %9, %8 ]
%15 = icmp eq i8* %14, null
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %0 to i64
%18 = sub i64 %16, %17
%19 = select i1 %15, i64 -1, i64 %18
ret i64 %19
}