#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 EINVAL;
size_t strlen(char *const);
scalar_t__ strstr(char const *const, char *);
int trim_end(char *const s, const char *const seps) {
  if (NULL == s || NULL == seps) {
    return EINVAL;
  }
  {
    size_t len = strlen(s);
    char buf[2] = {0};
    size_t idx = 0;
    for (idx = len; idx > 0; idx--) {
      buf[0] = s[idx - 1];
      if (strstr(seps, buf)) {
        s[idx - 1] = '\0';
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<trim_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1158 <trim_end+0x28>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1169 <trim_end+0x39>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f7 <trim_end+0xc7>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x22(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <memset@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jbe    11f0 <trim_end+0xc0>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x22(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11da <trim_end+0xaa>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11df <trim_end+0xaf>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1196 <trim_end+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_end>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     118e <trim_end+0x6e>
mov    %rsi,%r14
test   %rsi,%rsi
je     118e <trim_end+0x6e>
mov    %rdi,%r15
call   1030 <strlen@plt>
movw   $0x0,0xe(%rsp)
test   %rax,%rax
je     1199 <trim_end+0x79>
mov    %rax,%rbx
lea    0xe(%rsp),%r12
jmp    1168 <trim_end+0x48>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rbx
test   %r13,%r13
je     1199 <trim_end+0x79>
lea    -0x1(%rbx),%r13
movzbl -0x1(%r15,%rbx,1),%eax
mov    %al,0xe(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1160 <trim_end+0x40>
movb   $0x0,-0x1(%r15,%rbx,1)
jmp    1160 <trim_end+0x40>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
jmp    119b <trim_end+0x7b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EINVAL = global i32 0
define i32 @trim_end(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [2 x i8]
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp eq i8* null, %9
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp eq i8* null, %12
br i1 %13, label %14, label %16
14: ; preds = %11, %2
%15 = load i32, i32* @EINVAL
store i32 %15, i32* %3
br label %45
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %6
%19 = bitcast [2 x i8]* %7 to i8*
store i64 0, i64* %8
%20 = load i64, i64* %6
store i64 %20, i64* %8
br label %21
21: ; preds = %41, %16
%22 = load i64, i64* %8
%23 = icmp ugt i64 %22, 0
br i1 %23, label %24, label %44
24: ; preds = %21
%25 = load i8*, i8** %4
%26 = load i64, i64* %8
%27 = sub i64 %26, 1
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
store i8 %29, i8* %30
%31 = load i8*, i8** %5
%32 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%33 = call i64 @strstr(i8* %31, i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %24
%36 = load i8*, i8** %4
%37 = load i64, i64* %8
%38 = sub i64 %37, 1
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %35, %24
br label %41
41: ; preds = %40
%42 = load i64, i64* %8
%43 = add i64 %42, -1
store i64 %43, i64* %8
br label %21
44: ; preds = %21
store i32 0, i32* %3
br label %45
45: ; preds = %44, %14
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@EINVAL = global i32 0
define i32 @trim_end(i8* %0, i8* %1) {
%3 = alloca i16
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = load i32, i32* @EINVAL
br label %24
9: ; preds = %2
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = bitcast i16* %3 to i8*
store i16 0, i16* %3
%12 = icmp eq i64 %10, 0
br i1 %12, label %23, label %13
13: ; preds = %9, %21
%14 = phi i64 [ %15, %21 ], [ %10, %9 ]
%15 = add i64 %14, -1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %11
%18 = call i64 @strstr(i8* %1, i8* %11)
%19 = icmp eq i64 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %13
store i8 0, i8* %16
br label %21
21: ; preds = %13, %20
%22 = icmp eq i64 %15, 0
br i1 %22, label %23, label %13
23: ; preds = %21, %9
br label %24
24: ; preds = %23, %7
%25 = phi i32 [ %8, %7 ], [ 0, %23 ]
ret i32 %25
}