#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 *basename(const char *path) {
  const char *p = path + strlen(path) - 1;
  for (; p >= path; --p) {
    if (*p == '/' || *p == '\\') {
      return p + 1;
    }
  }
  return path;
}


x86 assembly (clang, -O0):
<basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     1196 <basename+0x86>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     116f <basename+0x5f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1180 <basename+0x70>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    119e <basename+0x8e>
jmp    1185 <basename+0x75>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1141 <basename+0x31>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %rbx,%rax
jb     114d <basename+0x3d>
movzbl (%rax),%ecx
add    $0xffffffffffffffff,%rax
cmp    $0x5c,%cl
je     1146 <basename+0x36>
cmp    $0x2f,%cl
jne    1130 <basename+0x20>
add    $0x2,%rax
mov    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @basename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
%10 = getelementptr inbounds i8, i8* %9, i64 -1
store i8* %10, i8** %4
br label %11
11: ; preds = %29, %1
%12 = load i8*, i8** %4
%13 = load i8*, i8** %3
%14 = icmp uge i8* %12, %13
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 92
br i1 %24, label %25, label %28
25: ; preds = %20, %15
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %27, i8** %2
br label %34
28: ; preds = %20
br label %29
29: ; preds = %28
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %4
br label %11
32: ; preds = %11
%33 = load i8*, i8** %3
store i8* %33, i8** %2
br label %34
34: ; preds = %32, %25
%35 = load i8*, i8** %2
ret i8* %35
}

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