#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__ malloc(int);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char *StripName(char *name) {
  char *begin = strrchr(name, '/');
  char *end, *result;
  int length;
  begin = (begin ? begin + 1 : name);
  end = strchr(begin, '.');
  length = (end ? (end - begin) : strlen(begin));
  result = (char *)malloc(length + 1);
  strncpy(result, begin, length);
  result[length] = '\0';
  return (result);
}


x86 assembly (clang, -O0):
<StripName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118a <StripName+0x3a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1192 <StripName+0x42>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cb <StripName+0x7b>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
jmp    11da <StripName+0x8a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StripName>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1060 <strrchr@plt>
lea    0x1(%rax),%r14
test   %rax,%rax
cmove  %rbx,%r14
mov    %r14,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1187 <StripName+0x37>
mov    %rax,%rbx
sub    %r14,%rbx
jmp    1191 <StripName+0x41>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @StripName(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 1
br label %16
14: ; preds = %1
%15 = load i8*, i8** %2
br label %16
16: ; preds = %14, %11
%17 = phi i8* [ %13, %11 ], [ %15, %14 ]
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = call i8* @strchr(i8* %18, i8 signext 46)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = load i8*, i8** %3
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
br label %32
28: ; preds = %16
%29 = load i8*, i8** %3
%30 = call i32 @strlen(i8* %29)
%31 = sext i32 %30 to i64
br label %32
32: ; preds = %28, %22
%33 = phi i64 [ %27, %22 ], [ %31, %28 ]
%34 = trunc i64 %33 to i32
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %5
%39 = load i8*, i8** %5
%40 = load i8*, i8** %3
%41 = load i32, i32* %6
%42 = call i32 @strncpy(i8* %39, i8* %40, i32 %41)
%43 = load i8*, i8** %5
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 0, i8* %46
%47 = load i8*, i8** %5
ret i8* %47
}

LLVM IR (-O2):
define i8* @StripName(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
%4 = getelementptr inbounds i8, i8* %2, i64 1
%5 = select i1 %3, i8* %0, i8* %4
%6 = tail call i8* @strchr(i8* dereferenceable(1) %5, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = ptrtoint i8* %6 to i64
%10 = ptrtoint i8* %5 to i64
%11 = sub i64 %9, %10
br label %15
12: ; preds = %1
%13 = tail call i32 @strlen(i8* %5)
%14 = zext i32 %13 to i64
br label %15
15: ; preds = %12, %8
%16 = phi i64 [ %11, %8 ], [ %14, %12 ]
%17 = trunc i64 %16 to i32
%18 = add nsw i32 %17, 1
%19 = tail call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = tail call i32 @strncpy(i8* %20, i8* %5, i32 %17)
%22 = shl i64 %16, 32
%23 = ashr exact i64 %22, 32
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
ret i8* %20
}