#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*/ assert(int /*<<< orphan*/);
char *strchr(char *, char);
scalar_t__ strspn(char *, char const *);
char *rtrimstr(char *str, const char *list) {
  char *end;
  assert(str != NULL);
  if (list == NULL)
    list = " \n\r\t\v\f";
  end = strchr(str, '\0') - 1;
  while (end != str && strspn(end, list) != 0)
    end--;
  end[1] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<rtrimstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1168 <rtrimstr+0x38>
lea    0xe9c(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
je     11a5 <rtrimstr+0x75>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strspn@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11b5 <rtrimstr+0x85>
jmp    11c6 <rtrimstr+0x96>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    117b <rtrimstr+0x4b>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtrimstr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
test   %rbx,%rbx
lea    0xea9(%rip),%r15
cmovne %rbx,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
lea    0x1(%r14),%r13
lea    (%rax,%r14,1),%r12
add    $0x1,%r12
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
test   %rbx,%rbx
je     11a1 <rtrimstr+0x71>
lea    -0x2(%r12),%rdi
mov    %r15,%rsi
call   1040 <strspn@plt>
add    $0xffffffffffffffff,%r12
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1180 <rtrimstr+0x50>
jmp    11a4 <rtrimstr+0x74>
mov    %r13,%r12
movb   $0x0,(%r12)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c" \0A\0D\09\0B\0C\00"
define i8* @rtrimstr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4
br label %13
13: ; preds = %12, %2
%14 = load i8*, i8** %3
%15 = call i8* @strchr(i8* %14, i8 signext 0)
%16 = getelementptr inbounds i8, i8* %15, i64 -1
store i8* %16, i8** %5
br label %17
17: ; preds = %28, %13
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = icmp ne i8* %18, %19
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = load i8*, i8** %4
%24 = call i64 @strspn(i8* %22, i8* %23)
%25 = icmp ne i64 %24, 0
br label %26
26: ; preds = %21, %17
%27 = phi i1 [ false, %17 ], [ %25, %21 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %5
br label %17
31: ; preds = %26
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8 0, i8* %33
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
@.str = [7 x i8] c" \0A\0D\09\0B\0C\00"
define i8* @rtrimstr(i8* returned %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp eq i8* %1, null
%7 = select i1 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = getelementptr i8, i8* %0, i64 %8
%10 = getelementptr i8, i8* %0, i64 1
br label %11
11: ; preds = %15, %2
%12 = phi i8* [ %9, %2 ], [ %13, %15 ]
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = icmp eq i8* %13, %0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = tail call i64 @strspn(i8* %13, i8* %7)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %11
18: ; preds = %11, %15
%19 = phi i8* [ %10, %11 ], [ %12, %15 ]
store i8 0, i8* %19
ret i8* %0
}