#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 */
char *strchr(char *, char);
char *strdup(char *);
int /*<<< orphan*/ strlen(char *);
char *strfilter2(char *string, char *letters) {
  char buffer[strlen(string) + 1];
  char *dest = buffer;
  char c;
  while (c = *string++) {
    char *ptr = strchr(letters, c);
    if (ptr) {
      *dest++ = c;
    }
  }
  *dest = '\0';
  return strdup(buffer);
}


x86 assembly (clang, -O0):
<strfilter2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x40(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x29(%rbp)
cmp    $0x0,%al
je     11c6 <strfilter2+0x96>
mov    -0x10(%rbp),%rdi
movsbl -0x29(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11c1 <strfilter2+0x91>
mov    -0x29(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    1175 <strfilter2+0x45>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
call   1050 <strdup@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfilter2>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x0(%r13),%bl
mov    %r15,%r12
test   %bl,%bl
je     11a7 <strfilter2+0x77>
add    $0x1,%r13
mov    %r15,%r12
jmp    118d <strfilter2+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13),%ebx
add    $0x1,%r13
test   %bl,%bl
je     11a7 <strfilter2+0x77>
movsbl %bl,%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1180 <strfilter2+0x50>
mov    %bl,(%r12)
add    $0x1,%r12
jmp    1180 <strfilter2+0x50>
movb   $0x0,(%r12)
mov    %r15,%rdi
call   1050 <strdup@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @strfilter2(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %5
%15 = alloca i8, i64 %13
store i64 %13, i64* %6
store i8* %15, i8** %7
br label %16
16: ; preds = %31, %2
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
%19 = load i8, i8* %17
store i8 %19, i8* %8
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i8, i8* %8
%24 = call i8* @strchr(i8* %22, i8 signext %23)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i8, i8* %8
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %7
store i8 %28, i8* %29
br label %31
31: ; preds = %27, %21
br label %16
32: ; preds = %16
%33 = load i8*, i8** %7
store i8 0, i8* %33
%34 = call i8* @strdup(i8* %15)
%35 = load i8*, i8** %5
ret i8* %34
}

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