#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 */
char *path_final_slash(char *);
char *strcpy(char *, char *);
char *basename(char *path) {
  char *sl;
  if (!path || *path == '\0') {
    return ".";
  }
  sl = path_final_slash(path);
  if (!sl) {
    if (!*path)
      return strcpy(path, "/");
    return path;
  }
  return sl + 1;
}


x86 assembly (clang, -O0):
<basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1147 <basename+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1157 <basename+0x37>
lea    0xeb2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <basename+0x8e>
mov    -0x10(%rbp),%rdi
call   1040 <path_final_slash@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <basename+0x82>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1195 <basename+0x75>
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    11ae <basename+0x8e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <basename+0x8e>
mov    -0x18(%rbp),%rax
add    $0x1,%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     1136 <basename+0x26>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1136 <basename+0x26>
mov    %rbx,%rdi
call   1030 <path_final_slash@plt>
test   %rax,%rax
je     1138 <basename+0x28>
add    $0x1,%rax
pop    %rbx
ret
cmpb   $0x0,(%rbx)
jne    1142 <basename+0x32>
movw   $0x2f,(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @basename(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i8* @path_final_slash(i8* %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = bitcast i8* %0 to i16*
store i16 47, i16* %13
br label %16
14: ; preds = %6
%15 = getelementptr inbounds i8, i8* %7, i64 1
br label %16
16: ; preds = %9, %1, %3, %14, %12
%17 = phi i8* [ %15, %14 ], [ %0, %12 ], [ 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, %9 ]
ret i8* %17
}