#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*/ *strchr(char const *, char);
size_t strlen(char *);
void util_rtrim(char *s, const char *trim) {
  size_t l = strlen(s);
  while (l != 0 && strchr(trim, s[l - 1]) != NULL)
    s[--l] = '\0';
}


x86 assembly (clang, -O0):
<util_rtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     1170 <util_rtrim+0x50>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1180 <util_rtrim+0x60>
jmp    119d <util_rtrim+0x7d>
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    113d <util_rtrim+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_rtrim>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %rax,%rax
je     115f <util_rtrim+0x3f>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
movsbl -0x1(%r15,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     115f <util_rtrim+0x3f>
movb   $0x0,-0x1(%r15,%rbx,1)
add    $0xffffffffffffffff,%rbx
jne    1140 <util_rtrim+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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