#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 */
size_t strlen(char *);
void truncate_trailing_slashes(char *string) {
  size_t len = strlen(string);
  size_t pos = len;
  for (size_t i = 0; i <= len; i++) {
    pos--;
    if (string[pos] == '/') {
      string[pos] = '\0';
    } else {
      break;
    }
  }
}


x86 assembly (clang, -O0):
<truncate_trailing_slashes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     1194 <truncate_trailing_slashes+0x84>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1179 <truncate_trailing_slashes+0x69>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    117e <truncate_trailing_slashes+0x6e>
jmp    1194 <truncate_trailing_slashes+0x84>
jmp    1183 <truncate_trailing_slashes+0x73>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1139 <truncate_trailing_slashes+0x29>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<truncate_trailing_slashes>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    (%rax,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x2f,(%rcx)
jne    1145 <truncate_trailing_slashes+0x35>
movb   $0x0,(%rcx)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rcx
cmp    %rax,%rdx
jbe    1130 <truncate_trailing_slashes+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define void @truncate_trailing_slashes(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %3
%8 = load i64, i64* %3
store i64 %8, i64* %4
store i64 0, i64* %5
br label %9
9: ; preds = %28, %1
%10 = load i64, i64* %5
%11 = load i64, i64* %3
%12 = icmp ule i64 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load i64, i64* %4
%15 = add i64 %14, -1
store i64 %15, i64* %4
%16 = load i8*, i8** %2
%17 = load i64, i64* %4
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 47
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = load i8*, i8** %2
%24 = load i64, i64* %4
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 0, i8* %25
br label %27
26: ; preds = %13
br label %31
27: ; preds = %22
br label %28
28: ; preds = %27
%29 = load i64, i64* %5
%30 = add i64 %29, 1
store i64 %30, i64* %5
br label %9
31: ; preds = %26, %9
ret void
}

LLVM IR (-O2):
define void @truncate_trailing_slashes(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %3
3: ; preds = %1, %10
%4 = phi i64 [ 0, %1 ], [ %11, %10 ]
%5 = phi i64 [ %2, %1 ], [ %6, %10 ]
%6 = add i64 %5, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
br i1 %9, label %10, label %13
10: ; preds = %3
store i8 0, i8* %7
%11 = add i64 %4, 1
%12 = icmp ugt i64 %11, %2
br i1 %12, label %13, label %3
13: ; preds = %3, %10
ret void
}