#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
char *filter_any_ptr(char *string, char *remove) {
  char *p_copy;
  p_copy = malloc(sizeof(*string) + 1);
  char *p = p_copy;
  while (*string != ('\0')) {
    int copy = 0;
    int end = 1;
    char *copy_remove = remove;
    while (*copy_remove != ('\0') && end == 1) {
      if (*string == *copy_remove) {
        copy = 1;
        end = 0;
      }
      copy_remove++;
    }
    if (copy == 0) {
      *p = *string;
      p++;
    }
    string++;
  }
  *p = ('\0');
  p = malloc(sizeof(*p_copy));
  strcpy(p, p_copy);
  free(p_copy);
  return p;
}


x86 assembly (clang, -O0):
<filter_any_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1213 <filter_any_ptr+0xe3>
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     119b <filter_any_ptr+0x6b>
cmpl   $0x1,-0x28(%rbp)
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11ab <filter_any_ptr+0x7b>
jmp    11e0 <filter_any_ptr+0xb0>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    -0x30(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11cf <filter_any_ptr+0x9f>
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    117c <filter_any_ptr+0x4c>
cmpl   $0x0,-0x24(%rbp)
jne    1202 <filter_any_ptr+0xd2>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1156 <filter_any_ptr+0x26>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_any_ptr>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    (%rbx),%cl
mov    %rax,%r9
test   %cl,%cl
je     1198 <filter_any_ptr+0x68>
lea    0x1(%r15),%r8
mov    $0x1,%edx
mov    %r14,%r9
jmp    1172 <filter_any_ptr+0x42>
nop
mov    %cl,(%r9)
add    $0x1,%r9
mov    0x1(%rbx),%cl
add    $0x1,%rbx
test   %cl,%cl
je     1198 <filter_any_ptr+0x68>
mov    (%r15),%al
test   %al,%al
je     1160 <filter_any_ptr+0x30>
xor    %edi,%edi
mov    %r8,%rsi
xchg   %ax,%ax
cmp    %al,%cl
cmove  %edx,%edi
je     1192 <filter_any_ptr+0x62>
movzbl (%rsi),%eax
add    $0x1,%rsi
test   %al,%al
jne    1180 <filter_any_ptr+0x50>
test   %edi,%edi
jne    1167 <filter_any_ptr+0x37>
jmp    1160 <filter_any_ptr+0x30>
movb   $0x0,(%r9)
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @filter_any_ptr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = call i8* @malloc(i32 2)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
store i8* %11, i8** %6
br label %12
12: ; preds = %50, %2
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %53
17: ; preds = %12
store i32 0, i32* %7
store i32 1, i32* %8
%18 = load i8*, i8** %4
store i8* %18, i8** %9
br label %19
19: ; preds = %38, %17
%20 = load i8*, i8** %9
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, 1
br label %27
27: ; preds = %24, %19
%28 = phi i1 [ false, %19 ], [ %26, %24 ]
br i1 %28, label %29, label %41
29: ; preds = %27
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = load i8*, i8** %9
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %32, %35
br i1 %36, label %37, label %38
37: ; preds = %29
store i32 1, i32* %7
store i32 0, i32* %8
br label %38
38: ; preds = %37, %29
%39 = load i8*, i8** %9
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %9
br label %19
41: ; preds = %27
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i8*, i8** %3
%46 = load i8, i8* %45
%47 = load i8*, i8** %6
store i8 %46, i8* %47
%48 = load i8*, i8** %6
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %6
br label %50
50: ; preds = %44, %41
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %3
br label %12
53: ; preds = %12
%54 = load i8*, i8** %6
store i8 0, i8* %54
%55 = call i8* @malloc(i32 1)
store i8* %55, i8** %6
%56 = load i8*, i8** %6
%57 = load i8*, i8** %5
%58 = call i32 @strcpy(i8* %56, i8* %57)
%59 = load i8*, i8** %5
%60 = call i32 @free(i8* %59)
%61 = load i8*, i8** %6
ret i8* %61
}

LLVM IR (-O2):
define i8* @filter_any_ptr(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call dereferenceable_or_null(2) i8* @malloc(i32 2)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %31, label %6
6: ; preds = %2, %26
%7 = phi i8 [ %29, %26 ], [ %4, %2 ]
%8 = phi i8* [ %27, %26 ], [ %3, %2 ]
%9 = phi i8* [ %28, %26 ], [ %0, %2 ]
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %6, %12
%13 = phi i8 [ %19, %12 ], [ %10, %6 ]
%14 = phi i8* [ %18, %12 ], [ %1, %6 ]
%15 = phi i32 [ %17, %12 ], [ 0, %6 ]
%16 = icmp eq i8 %7, %13
%17 = select i1 %16, i32 1, i32 %15
%18 = getelementptr inbounds i8, i8* %14, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
%21 = or i1 %16, %20
br i1 %21, label %22, label %12
22: ; preds = %12
%23 = icmp eq i32 %17, 0
br i1 %23, label %24, label %26
24: ; preds = %6, %22
store i8 %7, i8* %8
%25 = getelementptr inbounds i8, i8* %8, i64 1
br label %26
26: ; preds = %24, %22
%27 = phi i8* [ %25, %24 ], [ %8, %22 ]
%28 = getelementptr inbounds i8, i8* %9, i64 1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %6
31: ; preds = %26, %2
%32 = phi i8* [ %3, %2 ], [ %27, %26 ]
store i8 0, i8* %32
%33 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%34 = tail call i32 @strcpy(i8* %33, i8* %3)
%35 = tail call i32 @free(i8* %3)
ret i8* %33
}