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


x86 assembly (clang, -O0):
<rm_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jbe    118d <rm_name+0x7d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x2f,%eax
cmp    %ecx,%eax
jne    1188 <rm_name+0x78>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <rm_name+0xa3>
jmp    1143 <rm_name+0x33>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
mov    (%r14),%rdi
add    %rax,%rbx
add    $0xffffffffffffffff,%rbx
xchg   %ax,%ax
cmp    %rdi,%rbx
jbe    114e <rm_name+0x3e>
lea    -0x1(%rbx),%rax
cmpb   $0x2f,(%rbx)
mov    %rax,%rbx
jne    1130 <rm_name+0x20>
movb   $0x0,0x1(%rax)
add    $0x2,%rax
mov    %rax,%rbx
jmp    1158 <rm_name+0x48>
call   1030 <strlen@plt>
cltq
add    %rax,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @rm_name(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = tail call i32 @strlen(i8* %2)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %2, i64 %4
%6 = load i8*, i8** %0
br label %7
7: ; preds = %11, %1
%8 = phi i8* [ %5, %1 ], [ %9, %11 ]
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = icmp ugt i8* %9, %6
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 47
br i1 %13, label %14, label %7
14: ; preds = %11
store i8 0, i8* %9
br label %20
15: ; preds = %7
%16 = tail call i32 @strlen(i8* %6)
%17 = load i8*, i8** %0
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8* %19, i8** %0
br label %20
20: ; preds = %15, %14
%21 = phi i8* [ %8, %14 ], [ %9, %15 ]
ret i8* %21
}