#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 *xstrdup(char const *);
char *os_GetLastname(char const *path) {
  int len, i;
  if (!path)
    return xstrdup("");
  i = len = strlen(path);
  while (i > 0 && path[i - 1] != '/' && path[i - 1] != '\\' &&
         path[i - 1] != ':') {
    --i;
  }
  return xstrdup(path + i);
}


x86 assembly (clang, -O0):
<os_GetLastname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114c <os_GetLastname+0x2c>
lea    0xec2(%rip),%rdi
call   1040 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11f4 <os_GetLastname+0xd4>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jle    11c2 <os_GetLastname+0xa2>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x19(%rbp)
je     11c2 <os_GetLastname+0xa2>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x5c,%ecx
mov    %al,-0x19(%rbp)
je     11c2 <os_GetLastname+0xa2>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11d2 <os_GetLastname+0xb2>
jmp    11e0 <os_GetLastname+0xc0>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    115b <os_GetLastname+0x3b>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
call   1040 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_GetLastname>:
test   %rdi,%rdi
je     1180 <os_GetLastname+0x60>
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %edx,%edx
test   %eax,%eax
cmovs  %eax,%edx
movabs $0x200000000801,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %ecx,%ecx
jle    1171 <os_GetLastname+0x51>
movzbl -0x1(%rbx,%rcx,1),%eax
add    $0xffffffffffffffff,%rcx
add    $0xd1,%al
cmp    $0x2d,%al
ja     1150 <os_GetLastname+0x30>
movzbl %al,%eax
bt     %rax,%rsi
jae    1150 <os_GetLastname+0x30>
add    $0x1,%ecx
mov    %ecx,%edx
movslq %edx,%rax
add    %rax,%rbx
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <xstrdup@plt>
lea    0xe79(%rip),%rdi
jmp    1040 <xstrdup@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @os_GetLastname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i8* @xstrdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %2
br label %54
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %4
store i32 %12, i32* %5
br label %13
13: ; preds = %45, %10
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 47
br i1 %24, label %25, label %43
25: ; preds = %16
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 92
br i1 %33, label %34, label %43
34: ; preds = %25
%35 = load i8*, i8** %3
%36 = load i32, i32* %5
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 58
br label %43
43: ; preds = %34, %25, %16, %13
%44 = phi i1 [ false, %25 ], [ false, %16 ], [ false, %13 ], [ %42, %34 ]
br i1 %44, label %45, label %48
45: ; preds = %43
%46 = load i32, i32* %5
%47 = add nsw i32 %46, -1
store i32 %47, i32* %5
br label %13
48: ; preds = %43
%49 = load i8*, i8** %3
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = call i8* @xstrdup(i8* %52)
store i8* %53, i8** %2
br label %54
54: ; preds = %48, %8
%55 = load i8*, i8** %2
ret i8* %55
}

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 %24
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = zext i32 %6 to i64
%8 = call i32 @llvm.smin.i32(i32 %6, i32 0)
br label %9
9: ; preds = %13, %5
%10 = phi i64 [ %14, %13 ], [ %7, %5 ]
%11 = trunc i64 %10 to i32
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = add nsw i64 %10, -1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
switch i8 %16, label %9 [
i8 47, label %17
i8 92, label %17
i8 58, label %17
]
17: ; preds = %13, %13, %13
%18 = trunc i64 %10 to i32
br label %19
19: ; preds = %9, %17
%20 = phi i32 [ %18, %17 ], [ %8, %9 ]
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = tail call i8* @xstrdup(i8* %22)
br label %24
24: ; preds = %19, %3
%25 = phi i8* [ %23, %19 ], [ %4, %3 ]
ret i8* %25
}