#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 strlen(char *);
void trim_trailch(char *buf, char ch1, char ch2, char ch3) {
  char *end = buf + strlen(buf) - 1;
  while (end >= buf && (*end == ch1 || *end == ch2 || *end == ch3)) {
    *end = 0;
    end--;
  }
}


x86 assembly (clang, -O0):
<trim_trailch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %rdi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %cl,-0xa(%rbp)
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x21(%rbp)
jb     11ad <trim_trailch+0x9d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
movsbl -0x9(%rbp),%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x22(%rbp)
je     11a7 <trim_trailch+0x97>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
movsbl -0xa(%rbp),%edx
mov    $0x1,%al
cmp    %edx,%ecx
mov    %al,-0x22(%rbp)
je     11a7 <trim_trailch+0x97>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0xb(%rbp),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11bd <trim_trailch+0xad>
jmp    11d5 <trim_trailch+0xc5>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <trim_trailch+0x41>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_trailch>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
call   1030 <strlen@plt>
cltq
add    %rbp,%rax
add    $0xffffffffffffffff,%rax
jmp    1147 <trim_trailch+0x37>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbp,%rax
jb     115d <trim_trailch+0x4d>
movzbl (%rax),%ecx
cmp    %bl,%cl
je     1140 <trim_trailch+0x30>
cmp    %r15b,%cl
je     1140 <trim_trailch+0x30>
cmp    %r14b,%cl
je     1140 <trim_trailch+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @trim_trailch(i8* %0, i8 signext %1, i8 signext %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8*
store i8* %0, i8** %5
store i8 %1, i8* %6
store i8 %2, i8* %7
store i8 %3, i8* %8
%10 = load i8*, i8** %5
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -1
store i8* %15, i8** %9
br label %16
16: ; preds = %45, %4
%17 = load i8*, i8** %9
%18 = load i8*, i8** %5
%19 = icmp uge i8* %17, %18
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = load i8*, i8** %9
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %23, %25
br i1 %26, label %41, label %27
27: ; preds = %20
%28 = load i8*, i8** %9
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = load i8, i8* %7
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %30, %32
br i1 %33, label %41, label %34
34: ; preds = %27
%35 = load i8*, i8** %9
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = load i8, i8* %8
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %37, %39
br label %41
41: ; preds = %34, %27, %20
%42 = phi i1 [ true, %27 ], [ true, %20 ], [ %40, %34 ]
br label %43
43: ; preds = %41, %16
%44 = phi i1 [ false, %16 ], [ %42, %41 ]
br i1 %44, label %45, label %49
45: ; preds = %43
%46 = load i8*, i8** %9
store i8 0, i8* %46
%47 = load i8*, i8** %9
%48 = getelementptr inbounds i8, i8* %47, i32 -1
store i8* %48, i8** %9
br label %16
49: ; preds = %43
ret void
}

LLVM IR (-O2):
define void @trim_trailch(i8* %0, i8 signext %1, i8 signext %2, i8 signext %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = icmp ult i8* %8, %0
br i1 %9, label %21, label %10
10: ; preds = %4, %18
%11 = phi i8* [ %19, %18 ], [ %8, %4 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, %1
%14 = icmp eq i8 %12, %2
%15 = or i1 %13, %14
%16 = icmp eq i8 %12, %3
%17 = or i1 %16, %15
br i1 %17, label %18, label %21
18: ; preds = %10
store i8 0, i8* %11
%19 = getelementptr inbounds i8, i8* %11, i64 -1
%20 = icmp ult i8* %19, %0
br i1 %20, label %21, label %10
21: ; preds = %18, %10, %4
ret void
}