#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 *);
char *strrchr(char const *, char);
char *xmemdup(char const *, int);
char *xstrdup(char *);
char *os_GetLastname(char const *path) {
  char const *sp, *dp;
  int l;
  if (!path)
    return xstrdup("");
  l = strlen(path);
  sp = strrchr(path, '/');
  if (!sp)
    sp = path;
  else
    sp++;
  dp = path + l;
  return xmemdup(sp, dp - sp);
}


x86 assembly (clang, -O0):
<os_GetLastname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116c <os_GetLastname+0x2c>
lea    0xea2(%rip),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11d7 <os_GetLastname+0x97>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <os_GetLastname+0x62>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ae <os_GetLastname+0x6e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1060 <xmemdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_GetLastname>:
test   %rdi,%rdi
je     117b <os_GetLastname+0x3b>
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
cmove  %rbx,%rdi
add    %ebp,%ebx
sub    %edi,%ebx
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <xmemdup@plt>
lea    0xe7e(%rip),%rdi
jmp    1050 <xstrdup@plt>

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

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