#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 /*<<< orphan*/ *strchr(char *, char const);
int strlen(char const *);
const char *gnu_basename(const char *filename) {
  const char *p;
  for (p = filename + strlen(filename) - 1; p >= filename; p--) {
    if (strchr("/", *p) != NULL)
      break;
  }
  return p + 1;
}


x86 assembly (clang, -O0):
<gnu_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     1197 <gnu_basename+0x77>
mov    -0x10(%rbp),%rax
lea    0xe96(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1181 <gnu_basename+0x61>
jmp    1197 <gnu_basename+0x77>
jmp    1186 <gnu_basename+0x66>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1151 <gnu_basename+0x31>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gnu_basename>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rcx
add    $0xffffffffffffffff,%rcx
lea    0xec2(%rip),%r15
xchg   %ax,%ax
mov    %rcx,%rbx
cmp    %r14,%rcx
jb     115c <gnu_basename+0x3c>
movsbl (%rbx),%esi
mov    %r15,%rdi
call   1040 <strchr@plt>
lea    -0x1(%rbx),%rcx
test   %rax,%rax
je     1140 <gnu_basename+0x20>
add    $0x1,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @gnu_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 = %9, %1
%6 = phi i8* [ %4, %1 ], [ %7, %9 ]
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = icmp ult i8* %7, %0
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = load i8, i8* %7
%11 = tail call i32* @strchr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %5, label %13
13: ; preds = %9, %5
ret i8* %6
}