#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 */
scalar_t__ calloc(int, int);
size_t rev_strspn(char const *, char const *);
char *slice_str(size_t, size_t, char const *);
size_t strlen(char const *);
size_t strspn(char const *, char const *);
char *trim_any_str(const char *s, const char *reject) {
  size_t s_len = strlen(s);
  size_t reject_start = strspn(s, reject);
  size_t reject_stop = rev_strspn(s, reject);
  if ((reject_start + reject_stop) > s_len) {
    return (char *)calloc(1, sizeof(char));
  }
  return slice_str(reject_start, (s_len - reject_stop), s);
}


x86 assembly (clang, -O0):
<trim_any_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strspn@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <rev_strspn@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    11b6 <trim_any_str+0x66>
mov    $0x1,%esi
mov    %esi,%edi
call   1070 <calloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11cf <trim_any_str+0x7f>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
sub    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <slice_str@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_any_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strspn@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <rev_strspn@plt>
lea    (%rax,%r15,1),%rcx
cmp    %r14,%rcx
jbe    11a2 <trim_any_str+0x52>
mov    $0x1,%edi
mov    $0x1,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <calloc@plt>
sub    %rax,%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <slice_str@plt>

LLVM IR (-O0):
define i8* @trim_any_str(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %6
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i64 @strspn(i8* %11, i8* %12)
store i64 %13, i64* %7
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = call i64 @rev_strspn(i8* %14, i8* %15)
store i64 %16, i64* %8
%17 = load i64, i64* %7
%18 = load i64, i64* %8
%19 = add i64 %17, %18
%20 = load i64, i64* %6
%21 = icmp ugt i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = call i64 @calloc(i32 1, i32 1)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %3
br label %32
25: ; preds = %2
%26 = load i64, i64* %7
%27 = load i64, i64* %6
%28 = load i64, i64* %8
%29 = sub i64 %27, %28
%30 = load i8*, i8** %4
%31 = call i8* @slice_str(i64 %26, i64 %29, i8* %30)
store i8* %31, i8** %3
br label %32
32: ; preds = %25, %22
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
define i8* @trim_any_str(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strspn(i8* %0, i8* %1)
%5 = tail call i64 @rev_strspn(i8* %0, i8* %1)
%6 = add i64 %5, %4
%7 = icmp ugt i64 %6, %3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i64 @calloc(i32 1, i32 1)
%10 = inttoptr i64 %9 to i8*
br label %14
11: ; preds = %2
%12 = sub i64 %3, %5
%13 = tail call i8* @slice_str(i64 %4, i64 %12, i8* %0)
br label %14
14: ; preds = %11, %8
%15 = phi i8* [ %10, %8 ], [ %13, %11 ]
ret i8* %15
}