#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 *path_basename(const char *path) {
  const char *base;
  size_t len = strlen(path);
  if (len == 0)
    return ".";
  for (base = path + len - 1; base > path && *base == '/'; base--)
    ;
  while (base > path && base[-1] != '/')
    base--;
  return base;
}


x86 assembly (clang, -O0):
<path_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1144 <path_basename+0x34>
lea    0xec5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ef <path_basename+0xdf>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x21(%rbp)
jbe    1177 <path_basename+0x67>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1187 <path_basename+0x77>
jmp    119d <path_basename+0x8d>
jmp    118c <path_basename+0x7c>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1154 <path_basename+0x44>
jmp    11a2 <path_basename+0x92>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x22(%rbp)
jbe    11c6 <path_basename+0xb6>
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11d6 <path_basename+0xc6>
jmp    11e7 <path_basename+0xd7>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11a2 <path_basename+0x92>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_basename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
je     1164 <path_basename+0x54>
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rcx
cmp    %rbx,%rax
jbe    1150 <path_basename+0x40>
lea    -0x1(%rcx),%rax
cmpb   $0x2f,(%rcx)
je     1130 <path_basename+0x20>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rax
cmp    %rbx,%rcx
jbe    1162 <path_basename+0x52>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,-0x1(%rax)
jne    1150 <path_basename+0x40>
pop    %rbx
ret
lea    0xe95(%rip),%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @path_basename(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 %2
br label %6
6: ; preds = %10, %4
%7 = phi i8* [ %5, %4 ], [ %8, %10 ]
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = icmp ugt i8* %8, %0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 47
br i1 %12, label %6, label %13
13: ; preds = %6, %10
br label %14
14: ; preds = %13, %17
%15 = phi i8* [ %18, %17 ], [ %8, %13 ]
%16 = icmp ugt i8* %15, %0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %15, i64 -1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 47
br i1 %20, label %21, label %14
21: ; preds = %17, %14, %1
%22 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ], [ %15, %14 ], [ %15, %17 ]
ret i8* %22
}