#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 *s) {
  char *rv;
  if (!s || !*s)
    return ".";
  rv = s + strlen(s) - 1;
  do {
    if (((*rv) == '/'))
      return rv + 1;
    --rv;
  } while (rv >= s);
  return s;
}


x86 assembly (clang, -O0):
<basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1134 <basename+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1144 <basename+0x34>
lea    0xec5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ac <basename+0x9c>
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
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    118a <basename+0x7a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11ac <basename+0x9c>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1169 <basename+0x59>
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
lea    0xee8(%rip),%rax
test   %rdi,%rdi
je     1151 <basename+0x41>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1151 <basename+0x41>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x2f,(%rax)
je     1153 <basename+0x43>
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jae    1140 <basename+0x30>
mov    %rbx,%rax
pop    %rbx
ret
add    $0x1,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
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 = icmp ne i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %7, %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
br label %36
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -1
store i8* %18, i8** %4
br label %19
19: ; preds = %30, %12
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 47
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %2
br label %36
27: ; preds = %19
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %4
br label %30
30: ; preds = %27
%31 = load i8*, i8** %4
%32 = load i8*, i8** %3
%33 = icmp uge i8* %31, %32
br i1 %33, label %19, label %34
34: ; preds = %30
%35 = load i8*, i8** %3
store i8* %35, i8** %2
br label %36
36: ; preds = %34, %24, %11
%37 = load i8*, i8** %2
ret i8* %37
}

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