#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 *filename) {
  char *place = filename + strlen(filename) - 1;
  while (*place == '/') {
    *place = '\0';
    place--;
  }
  while (place >= filename) {
    if (*place == '/')
      return place + 1;
    place--;
  }
  return filename;
}


x86 assembly (clang, -O0):
<basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
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    1169 <basename+0x59>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1141 <basename+0x31>
jmp    116e <basename+0x5e>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     11ae <basename+0x9e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    119d <basename+0x8d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11b6 <basename+0xa6>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    116e <basename+0x5e>
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>
movslq %eax,%rcx
lea    (%rbx,%rcx,1),%rax
add    $0xffffffffffffffff,%rax
mov    -0x1(%rbx,%rcx,1),%cl
cmp    $0x2f,%cl
jne    1140 <basename+0x30>
nopl   (%rax)
movb   $0x0,(%rax)
movzbl -0x1(%rax),%ecx
add    $0xffffffffffffffff,%rax
cmp    $0x2f,%cl
je     1130 <basename+0x20>
cmp    %rbx,%rax
jb     116f <basename+0x5f>
cmp    $0x2f,%cl
je     1168 <basename+0x58>
add    $0xffffffffffffffff,%rax
xchg   %ax,%ax
cmp    %rbx,%rax
jb     116f <basename+0x5f>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,(%rax)
mov    %rcx,%rax
jne    1150 <basename+0x40>
add    $0x1,%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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
%5 = getelementptr inbounds i8, i8* %4, i64 -1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 47
br i1 %7, label %14, label %8
8: ; preds = %14, %1
%9 = phi i8 [ %6, %1 ], [ %17, %14 ]
%10 = phi i8* [ %5, %1 ], [ %16, %14 ]
%11 = icmp ult i8* %10, %0
br i1 %11, label %29, label %12
12: ; preds = %8
%13 = icmp eq i8 %9, 47
br i1 %13, label %19, label %22
14: ; preds = %1, %14
%15 = phi i8* [ %16, %14 ], [ %5, %1 ]
store i8 0, i8* %15
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 47
br i1 %18, label %14, label %8
19: ; preds = %26, %12
%20 = phi i8* [ %10, %12 ], [ %24, %26 ]
%21 = getelementptr inbounds i8, i8* %20, i64 1
br label %29
22: ; preds = %12, %26
%23 = phi i8* [ %24, %26 ], [ %10, %12 ]
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = icmp ult i8* %24, %0
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i8, i8* %24
%28 = icmp eq i8 %27, 47
br i1 %28, label %19, label %22
29: ; preds = %22, %8, %19
%30 = phi i8* [ %21, %19 ], [ %0, %8 ], [ %0, %22 ]
ret i8* %30
}