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


x86 assembly (clang, -O0):
<util_remove_trailing_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1132 <util_remove_trailing_chars+0x22>
jmp    1198 <util_remove_trailing_chars+0x88>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jbe    116b <util_remove_trailing_chars+0x5b>
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    117b <util_remove_trailing_chars+0x6b>
jmp    1198 <util_remove_trailing_chars+0x88>
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    113f <util_remove_trailing_chars+0x2f>
add    $0x20,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
define void @util_remove_trailing_chars(i8* %0, i8 signext %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %4, %13
%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, %1
br i1 %12, label %13, label %15
13: ; preds = %7
store i8 0, i8* %10
%14 = icmp eq i64 %9, 0
br i1 %14, label %15, label %7
15: ; preds = %13, %7, %4, %2
ret void
}