#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 strlen(char const *);
const char *get_short_name(const char *path) {
  const char *p;
  p = path + strlen(path) - 1;
  if (*p == '/') {
    p = "";
  } else {
    p--;
    while (*p != '/' && p > path) {
      p--;
    }
    if (*p != '/') {
      p = path;
    }
  }
  return p;
}


x86 assembly (clang, -O0):
<get_short_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1161 <get_short_name+0x51>
lea    0xea8(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11ce <get_short_name+0xbe>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x19(%rbp)
je     1190 <get_short_name+0x80>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a0 <get_short_name+0x90>
jmp    11b1 <get_short_name+0xa1>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    116d <get_short_name+0x5d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11c9 <get_short_name+0xb9>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11ce <get_short_name+0xbe>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_short_name>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rbx,%rax,1)
jne    112b <get_short_name+0x1b>
lea    0xed7(%rip),%rax
pop    %rbx
ret
lea    (%rax,%rbx,1),%rdx
add    $0xfffffffffffffffe,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rdx),%ecx
lea    -0x1(%rdx),%rax
cmp    $0x2f,%cl
je     1154 <get_short_name+0x44>
cmp    %rbx,%rdx
mov    %rax,%rdx
ja     1140 <get_short_name+0x30>
add    $0x1,%rax
cmp    $0x2f,%cl
cmovne %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @get_short_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 47
br i1 %13, label %14, label %15
14: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %40
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %3
br label %18
18: ; preds = %29, %15
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 47
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i8*, i8** %3
%25 = load i8*, i8** %2
%26 = icmp ugt i8* %24, %25
br label %27
27: ; preds = %23, %18
%28 = phi i1 [ false, %18 ], [ %26, %23 ]
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %3
br label %18
32: ; preds = %27
%33 = load i8*, i8** %3
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 47
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = load i8*, i8** %2
store i8* %38, i8** %3
br label %39
39: ; preds = %37, %32
br label %40
40: ; preds = %39, %14
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @get_short_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 47
br i1 %7, label %17, label %8
8: ; preds = %1, %8
%9 = phi i8* [ %10, %8 ], [ %5, %1 ]
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 47
%13 = icmp ugt i8* %10, %0
%14 = and i1 %12, %13
br i1 %14, label %8, label %15
15: ; preds = %8
%16 = select i1 %12, i8* %0, i8* %10
br label %17
17: ; preds = %15, %1
%18 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ], [ %16, %15 ]
ret i8* %18
}