#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 pos = strlen(string);
  for (size_t i = 0; i < strlen(string); 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)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jae    119f <truncate_trailing_slashes+0x8f>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1184 <truncate_trailing_slashes+0x74>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1189 <truncate_trailing_slashes+0x79>
jmp    119f <truncate_trailing_slashes+0x8f>
jmp    118e <truncate_trailing_slashes+0x7e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1131 <truncate_trailing_slashes+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<truncate_trailing_slashes>:
push   %r15
push   %r14
push   %rbx
cmpb   $0x0,(%rdi)
je     114d <truncate_trailing_slashes+0x3d>
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    (%rax,%r14,1),%rbx
add    $0xffffffffffffffff,%rbx
xor    %r15d,%r15d
nopl   (%rax)
cmpb   $0x2f,(%rbx)
jne    114d <truncate_trailing_slashes+0x3d>
movb   $0x0,(%rbx)
add    $0x1,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0xffffffffffffffff,%rbx
cmp    %rax,%r15
jb     1130 <truncate_trailing_slashes+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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