#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 *name) {
  long i;
  for (i = strlen(name) - 1; (name[i] != '/') && (i > 0); i--)
    ;
  if (i == 0)
    return "";
  else {
    name[i] = 0;
    return name;
  }
}


x86 assembly (clang, -O0):
<basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x19(%rbp)
je     1153 <basename+0x43>
cmpq   $0x0,-0x18(%rbp)
setg   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1163 <basename+0x53>
jmp    1179 <basename+0x69>
jmp    1168 <basename+0x58>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    112e <basename+0x1e>
cmpq   $0x0,-0x18(%rbp)
jne    1194 <basename+0x84>
lea    0xe75(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <basename+0x98>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
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>
add    $0xffffffff,%eax
movslq %eax,%rcx
nop
lea    -0x1(%rcx),%rax
cmpb   $0x2f,(%rbx,%rcx,1)
je     1132 <basename+0x22>
test   %rcx,%rcx
mov    %rax,%rcx
jg     1120 <basename+0x10>
cmp    $0xffffffffffffffff,%rax
je     113f <basename+0x2f>
movb   $0x0,0x1(%rbx,%rax,1)
jmp    1146 <basename+0x36>
lea    0xeba(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @basename(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -1
%4 = sext i32 %3 to i64
br label %5
5: ; preds = %5, %1
%6 = phi i64 [ %4, %1 ], [ %12, %5 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 47
%10 = icmp sgt i64 %6, 0
%11 = select i1 %9, i1 %10, i1 false
%12 = add nsw i64 %6, -1
br i1 %11, label %5, label %13
13: ; preds = %5
%14 = icmp eq i64 %6, 0
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 0, i8* %16
br label %17
17: ; preds = %13, %15
%18 = phi i8* [ %0, %15 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %13 ]
ret i8* %18
}