#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(char *);
int /*<<< orphan*/ *strchr(char const *, char);
char *strrchr(char *, int /*<<< orphan*/);
char *str_trim_end_inplace(char *str, const char *set) {
  if (str == NULL)
    return NULL;
  char *end = strrchr(str, 0);
  assert(end);
  if (set == NULL)
    set = " \t\n\r";
  while (--end >= str) {
    if (strchr(set, *end) == NULL)
      break;
    *end = 0;
  }
  return str;
}


x86 assembly (clang, -O0):
<str_trim_end_inplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1158 <str_trim_end_inplace+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <str_trim_end_inplace+0xa4>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1186 <str_trim_end_inplace+0x56>
lea    0xe7e(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    118b <str_trim_end_inplace+0x5b>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
cmp    -0x10(%rbp),%rax
jb     11cc <str_trim_end_inplace+0x9c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    11c0 <str_trim_end_inplace+0x90>
jmp    11cc <str_trim_end_inplace+0x9c>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    118b <str_trim_end_inplace+0x5b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_trim_end_inplace>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     117e <str_trim_end_inplace+0x5e>
mov    %rsi,%r12
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <assert@plt>
test   %r12,%r12
lea    0xeae(%rip),%r15
cmovne %r12,%r15
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jb     117e <str_trim_end_inplace+0x5e>
movsbl (%rbx),%esi
mov    %r15,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     117e <str_trim_end_inplace+0x5e>
movb   $0x0,(%rbx)
jmp    1160 <str_trim_end_inplace+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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