#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 const *);
void *strrchr(char const *, char);
void getname(char *name, int name_size, const char *filename) {
  const char *p;
  char *q;
  p = strrchr(filename, '/');
  if (!p)
    p = filename;
  else
    p++;
  strcpy(name, p);
  q = strrchr(name, '.');
  if (q)
    *q = '\0';
}


x86 assembly (clang, -O0):
<getname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115d <getname+0x3d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1169 <getname+0x49>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     119a <getname+0x7a>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getname>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %rdx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rsi
test   %rax,%rax
cmove  %rbx,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     115f <getname+0x3f>
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @getname(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i8* @strrchr(i8* %9, i8 signext 47)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = load i8*, i8** %6
store i8* %14, i8** %7
br label %18
15: ; preds = %3
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %7
br label %18
18: ; preds = %15, %13
%19 = load i8*, i8** %4
%20 = load i8*, i8** %7
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %4
%23 = call i8* @strrchr(i8* %22, i8 signext 46)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = load i8*, i8** %8
store i8 0, i8* %27
br label %28
28: ; preds = %26, %18
ret void
}

LLVM IR (-O2):
define void @getname(i8* %0, i32 %1, i8* %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%5 = icmp eq i8* %4, null
%6 = getelementptr inbounds i8, i8* %4, i64 1
%7 = select i1 %5, i8* %2, i8* %6
%8 = tail call i32 @strcpy(i8* %0, i8* %7)
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %3
store i8 0, i8* %9
br label %12
12: ; preds = %11, %3
ret void
}