#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 */
scalar_t__ strcmp(char *const, char *);
int strlen(char *const);
int /*<<< orphan*/ strncpy(char *const, char const *const, size_t const);
char *strrchr(char const *const, char);
void extractAfterLastSlash(const char *const fullPath, char *const retval,
                           size_t const retvalSize) {
  char *slashPos;
  slashPos = strrchr(fullPath, '/');
  if (slashPos == NULL) {
    strncpy(retval, fullPath, retvalSize);
    retval[retvalSize - 1] = '\0';
  } else {
    strncpy(retval, slashPos + 1, retvalSize);
    retval[retvalSize - 1] = '\0';
  }
  if (strlen(retval) >= 4 && strcmp(retval + strlen(retval) - 4, ".exe") == 0)
    retval[strlen(retval) - 4] = 0;
}


x86 assembly (clang, -O0):
<extractAfterLastSlash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1197 <extractAfterLastSlash+0x57>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11bc <extractAfterLastSlash+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jl     1223 <extractAfterLastSlash+0xe3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe0d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1223 <extractAfterLastSlash+0xe3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractAfterLastSlash>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1169 <extractAfterLastSlash+0x29>
add    $0x1,%rax
mov    %r15,%rdi
mov    %rax,%rsi
jmp    116f <extractAfterLastSlash+0x2f>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%r14,%r15,1)
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jl     11bd <extractAfterLastSlash+0x7d>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
lea    (%r15,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe5d(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11bd <extractAfterLastSlash+0x7d>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x4(%rax,%r15,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c".exe\00"
define void @extractAfterLastSlash(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i8*, i8** %4
%9 = call i8* @strrchr(i8* %8, i8 signext 47)
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = load i64, i64* %6
%16 = call i32 @strncpy(i8* %13, i8* %14, i64 %15)
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = sub i64 %18, 1
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8 0, i8* %20
br label %31
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i64, i64* %6
%26 = call i32 @strncpy(i8* %22, i8* %24, i64 %25)
%27 = load i8*, i8** %5
%28 = load i64, i64* %6
%29 = sub i64 %28, 1
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %21, %12
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
%34 = icmp sge i32 %33, 4
br i1 %34, label %35, label %51
35: ; preds = %31
%36 = load i8*, i8** %5
%37 = load i8*, i8** %5
%38 = call i32 @strlen(i8* %37)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = getelementptr inbounds i8, i8* %40, i64 -4
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %35
%45 = load i8*, i8** %5
%46 = load i8*, i8** %5
%47 = call i32 @strlen(i8* %46)
%48 = sub nsw i32 %47, 4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %45, i64 %49
store i8 0, i8* %50
br label %51
51: ; preds = %44, %35, %31
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".exe\00"
define void @extractAfterLastSlash(i8* %0, i8* %1, i64 %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @strncpy(i8* %1, i8* %0, i64 %2)
br label %11
8: ; preds = %3
%9 = getelementptr inbounds i8, i8* %4, i64 1
%10 = tail call i32 @strncpy(i8* %1, i8* %9, i64 %2)
br label %11
11: ; preds = %8, %6
%12 = add i64 %2, -1
%13 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 0, i8* %13
%14 = tail call i32 @strlen(i8* %1)
%15 = icmp sgt i32 %14, 3
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = tail call i32 @strlen(i8* %1)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -4
%21 = tail call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = tail call i32 @strlen(i8* %1)
%25 = add nsw i32 %24, -4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %1, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %23, %16, %11
ret void
}