#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 *misc_basename(char *path) {
  char *ptr = path + strlen(path);
  while (path < ptr && *--ptr != '/')
    ;
  if (*ptr == '/')
    ptr++;
  return ptr;
}


x86 assembly (clang, -O0):
<misc_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
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x19(%rbp)
jae    116c <misc_basename+0x5c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117c <misc_basename+0x6c>
jmp    1181 <misc_basename+0x71>
jmp    113d <misc_basename+0x2d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    119d <misc_basename+0x8d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<misc_basename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rcx
add    %rbx,%rcx
nop
cmp    %rbx,%rcx
jbe    113c <misc_basename+0x2c>
lea    -0x1(%rcx),%rdx
cmpb   $0x2f,-0x1(%rcx)
mov    %rdx,%rcx
jne    1120 <misc_basename+0x10>
mov    $0x1,%eax
mov    %rdx,%rcx
jmp    1144 <misc_basename+0x34>
xor    %eax,%eax
cmpb   $0x2f,(%rcx)
sete   %al
add    %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @misc_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
store i8* %8, i8** %3
br label %9
9: ; preds = %21, %1
%10 = load i8*, i8** %2
%11 = load i8*, i8** %3
%12 = icmp ult i8* %10, %11
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 -1
store i8* %15, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 47
br label %19
19: ; preds = %13, %9
%20 = phi i1 [ false, %9 ], [ %18, %13 ]
br i1 %20, label %21, label %22
21: ; preds = %19
br label %9
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 47
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
br label %30
30: ; preds = %27, %22
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
define i8* @misc_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 = %12, %1
%6 = phi i8* [ %4, %1 ], [ %13, %12 ]
%7 = icmp ugt i8* %6, %0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 47
%11 = zext i1 %10 to i64
br label %16
12: ; preds = %5
%13 = getelementptr inbounds i8, i8* %6, i64 -1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %16, label %5
16: ; preds = %12, %8
%17 = phi i64 [ %11, %8 ], [ 1, %12 ]
%18 = phi i8* [ %6, %8 ], [ %13, %12 ]
%19 = getelementptr i8, i8* %18, i64 %17
ret i8* %19
}