#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*/ strcpy(char *, char const *);
int strlen(char const *);
char *remove_last_slashes(const char *str) {
  static char path[256 + 1];
  int i = strlen(str) - 1;
  strcpy(path, str);
  while (i > 0 && path[i] == '/') {
    path[i] = '\0';
    i--;
  }
  return path;
}


x86 assembly (clang, -O0):
<remove_last_slashes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0x2efa(%rip),%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jle    1172 <remove_last_slashes+0x52>
movslq -0xc(%rbp),%rcx
lea    0x2edb(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1182 <remove_last_slashes+0x62>
jmp    119f <remove_last_slashes+0x7f>
movslq -0xc(%rbp),%rcx
lea    0x2eb3(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <remove_last_slashes+0x2b>
lea    0x2e9a(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_last_slashes>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0x2f0a(%rip),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
cmp    $0x2,%r14d
jl     1167 <remove_last_slashes+0x47>
mov    %r14d,%eax
add    $0x1,%rax
xchg   %ax,%ax
lea    -0x2(%rax),%ecx
cmpb   $0x2f,(%rcx,%rbx,1)
jne    1167 <remove_last_slashes+0x47>
movb   $0x0,(%rcx,%rbx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x2,%rax
ja     1150 <remove_last_slashes+0x30>
lea    0x2ed2(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@remove_last_slashes.path = internal global [257 x i8] zeroinitializer
define i8* @remove_last_slashes(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strcpy(i8* getelementptr inbounds ([257 x i8], [257 x i8]* @remove_last_slashes.path, i64 0, i64 0), i8* %0)
%4 = icmp sgt i32 %2, 1
br i1 %4, label %5, label %16
5: ; preds = %1
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %14
%8 = phi i64 [ %6, %5 ], [ %9, %14 ]
%9 = add nsw i64 %8, -1
%10 = and i64 %9, 4294967295
%11 = getelementptr inbounds [257 x i8], [257 x i8]* @remove_last_slashes.path, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %14, label %16
14: ; preds = %7
store i8 0, i8* %11
%15 = icmp ugt i64 %8, 2
br i1 %15, label %7, label %16
16: ; preds = %7, %14, %1
ret i8* getelementptr inbounds ([257 x i8], [257 x i8]* @remove_last_slashes.path, i64 0, i64 0)
}