#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 */
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char const *, char);
char *getname(const char *s) {
  static char tname[64];
  char *p;
  p = strrchr(s, '/');
  if (p == NULL)
    p = strrchr(s, '\\');
  if (p != NULL)
    p++;
  if (p == NULL)
    p = s;
  strncpy(tname, p, 63);
  p = strchr(tname, '.');
  if (p != NULL)
    *p = 0;
  return tname;
}


x86 assembly (clang, -O0):
<getname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <getname+0x3b>
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1182 <getname+0x52>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1195 <getname+0x65>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0x2eb0(%rip),%rdi
mov    $0x3f,%edx
call   1030 <strncpy@plt>
lea    0x2e9f(%rip),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d1 <getname+0xa1>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e78(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getname>:
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
jne    1150 <getname+0x20>
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rsi
test   %rax,%rax
cmove  %rbx,%rsi
lea    0x2eee(%rip),%rbx
mov    %rbx,%rdi
mov    $0x3f,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1184 <getname+0x54>
movb   $0x0,(%rax)
lea    0x2ec5(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@getname.tname = internal global [64 x i8] zeroinitializer
define i8* @getname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @strrchr(i8* %4, i8 signext 47)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i8* @strrchr(i8* %9, i8 signext 92)
store i8* %10, i8** %3
br label %11
11: ; preds = %8, %1
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
br label %17
17: ; preds = %14, %11
%18 = load i8*, i8** %3
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load i8*, i8** %2
store i8* %21, i8** %3
br label %22
22: ; preds = %20, %17
%23 = load i8*, i8** %3
%24 = call i32 @strncpy(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getname.tname, i64 0, i64 0), i8* %23, i32 63)
%25 = call i8* @strchr(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getname.tname, i64 0, i64 0), i8 signext 46)
store i8* %25, i8** %3
%26 = load i8*, i8** %3
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = load i8*, i8** %3
store i8 0, i8* %29
br label %30
30: ; preds = %28, %22
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getname.tname, i64 0, i64 0)
}

LLVM IR (-O2):
@getname.tname = internal global [64 x i8] zeroinitializer
define i8* @getname(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
br label %6
6: ; preds = %4, %1
%7 = phi i8* [ %5, %4 ], [ %2, %1 ]
%8 = icmp eq i8* %7, null
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = select i1 %8, i8* %0, i8* %9
%11 = tail call i32 @strncpy(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getname.tname, i64 0, i64 0), i8* %10, i32 63)
%12 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @getname.tname, i64 0, i64 0), i8 signext 46)
%13 = icmp eq i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %6
store i8 0, i8* %12
br label %15
15: ; preds = %14, %6
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getname.tname, i64 0, i64 0)
}