#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 remove_trailing_chars(char *path, char c) {
  size_t len;
  len = strlen(path);
  while (len > 0 && path[len - 1] == c)
    path[--len] = '\0';
}


x86 assembly (clang, -O0):
<remove_trailing_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jbe    115b <remove_trailing_chars+0x4b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116b <remove_trailing_chars+0x5b>
jmp    1188 <remove_trailing_chars+0x78>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0x0,-0x1(%rax,%rcx,1)
jmp    112f <remove_trailing_chars+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_trailing_chars>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %rax,%rax
je     1142 <remove_trailing_chars+0x32>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %bpl,-0x1(%rbx,%rax,1)
jne    1142 <remove_trailing_chars+0x32>
movb   $0x0,-0x1(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
jne    1130 <remove_trailing_chars+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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