#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 */
size_t strlen(char const *);
const char *os_basename(const char *filename) {
  size_t len = strlen(filename);
  while ((len > 0) && (filename[len - 1] != '\\') &&
         (filename[len - 1] != '/') && (filename[len - 1] != ':')) {
    len--;
  }
  return &filename[len];
}


x86 assembly (clang, -O0):
<os_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jbe    118e <os_basename+0x7e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x5c,%ecx
mov    %al,-0x11(%rbp)
je     118e <os_basename+0x7e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x11(%rbp)
je     118e <os_basename+0x7e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    119e <os_basename+0x8e>
jmp    11af <os_basename+0x9f>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1129 <os_basename+0x19>
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_basename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
movabs $0x200000000801,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdx
sub    $0x1,%rax
jb     114f <os_basename+0x3f>
movzbl -0x1(%rbx,%rdx,1),%ecx
add    $0xd1,%cl
cmp    $0x2d,%cl
ja     1130 <os_basename+0x20>
movzbl %cl,%ecx
bt     %rcx,%rsi
jae    1130 <os_basename+0x20>
add    %rdx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @os_basename(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strlen(i8* %4)
store i64 %5, i64* %3
br label %6
6: ; preds = %35, %1
%7 = load i64, i64* %3
%8 = icmp ugt i64 %7, 0
br i1 %8, label %9, label %33
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i64, i64* %3
%12 = sub i64 %11, 1
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 92
br i1 %16, label %17, label %33
17: ; preds = %9
%18 = load i8*, i8** %2
%19 = load i64, i64* %3
%20 = sub i64 %19, 1
%21 = getelementptr inbounds i8, i8* %18, 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 %33
25: ; preds = %17
%26 = load i8*, i8** %2
%27 = load i64, i64* %3
%28 = sub i64 %27, 1
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 58
br label %33
33: ; preds = %25, %17, %9, %6
%34 = phi i1 [ false, %17 ], [ false, %9 ], [ false, %6 ], [ %32, %25 ]
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i64, i64* %3
%37 = add i64 %36, -1
store i64 %37, i64* %3
br label %6
38: ; preds = %33
%39 = load i8*, i8** %2
%40 = load i64, i64* %3
%41 = getelementptr inbounds i8, i8* %39, i64 %40
ret i8* %41
}

LLVM IR (-O2):
define i8* @os_basename(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %3
3: ; preds = %6, %1
%4 = phi i64 [ %2, %1 ], [ %7, %6 ]
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = add i64 %4, -1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %3 [
i8 92, label %10
i8 47, label %10
i8 58, label %10
]
10: ; preds = %6, %6, %6, %3
%11 = getelementptr inbounds i8, i8* %0, i64 %4
ret i8* %11
}