#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 *);
char *basename(char *path) {
  char *ptr = path + strlen(path);
  while (path != ptr && *--ptr != '/')
    ;
  return (*ptr == '/' ? ++ptr : ptr);
}


x86 assembly (clang, -O0):
<basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x19(%rbp)
je     116c <basename+0x5c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117c <basename+0x6c>
jmp    1181 <basename+0x71>
jmp    113d <basename+0x2d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11a6 <basename+0x96>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x28(%rbp)
jmp    11ae <basename+0x9e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
nopl   0x0(%rax,%rax,1)
test   %rax,%rax
je     113d <basename+0x2d>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,-0x1(%rbx,%rax,1)
mov    %rcx,%rax
jne    1120 <basename+0x10>
add    %rcx,%rbx
mov    $0x1,%eax
jmp    1145 <basename+0x35>
xor    %eax,%eax
cmpb   $0x2f,(%rbx)
sete   %al
add    %rbx,%rax
pop    %rbx
ret

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

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 = %12, %1
%6 = phi i8* [ %4, %1 ], [ %13, %12 ]
%7 = icmp eq i8* %6, %0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 47
%11 = zext i1 %10 to i64
br label %16
12: ; preds = %5
%13 = getelementptr inbounds i8, i8* %6, i64 -1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %16, label %5
16: ; preds = %12, %8
%17 = phi i64 [ %11, %8 ], [ 1, %12 ]
%18 = phi i8* [ %0, %8 ], [ %13, %12 ]
%19 = getelementptr i8, i8* %18, i64 %17
ret i8* %19
}