#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 */
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
char *mystrrchr(char *pBegin, char *loc, char chr) {
  char tmpStr[128] = {0};
  strcpy(tmpStr, pBegin);
  *(tmpStr + (loc - pBegin)) = 0;
  char *pChr = strrchr(tmpStr, chr);
  if (!pChr)
    return NULL;
  return pBegin + (pChr - tmpStr);
}


x86 assembly (clang, -O0):
<mystrrchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1040 <strrchr@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    11b0 <mystrrchr+0x80>
movq   $0x0,-0x8(%rbp)
jmp    11cc <mystrrchr+0x9c>
mov    -0x10(%rbp),%rax
mov    -0xa8(%rbp),%rcx
lea    -0xa0(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mystrrchr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
sub    %rbp,%rbx
movb   $0x0,(%rsp,%rbx,1)
mov    %r15,%rdi
mov    %r14d,%esi
call   1040 <strrchr@plt>
mov    %rax,%rcx
sub    %r15,%rcx
add    %rbp,%rcx
test   %rax,%rax
cmovne %rcx,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @mystrrchr(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca [128 x i8]
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
%10 = bitcast [128 x i8]* %8 to i8*
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = load i8*, i8** %5
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = getelementptr inbounds i8, i8* %14, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%22 = load i8, i8* %7
%23 = call i8* @strrchr(i8* %21, i8 signext %22)
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = icmp ne i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %3
store i8* null, i8** %4
br label %35
27: ; preds = %3
%28 = load i8*, i8** %5
%29 = load i8*, i8** %9
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = getelementptr inbounds i8, i8* %28, i64 %33
store i8* %34, i8** %4
br label %35
35: ; preds = %27, %26
%36 = load i8*, i8** %4
ret i8* %36
}

LLVM IR (-O2):
define i8* @mystrrchr(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = ptrtoint i8* %1 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i8* @strrchr(i8* %5, i8 signext %2)
%12 = icmp eq i8* %11, null
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint [128 x i8]* %4 to i64
%15 = sub i64 %13, %14
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = select i1 %12, i8* null, i8* %16
ret i8* %17
}