#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);
int strlen(char *);
char *strfilter3(char *string, char *letters) {
  int length = strlen(string);
  char buffer[length];
  int j = 0;
  for (int i = 0; i < length; i++) {
    char *ptr = strchr(letters, string[i]);
    if (ptr) {
      buffer[j++] = string[i];
    }
  }
  return buffer;
}


x86 assembly (clang, -O0):
<strfilter3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d3 <strfilter3+0xb3>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11c0 <strfilter3+0xa0>
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x30(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11c5 <strfilter3+0xa5>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1170 <strfilter3+0x50>
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfilter3>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,-0x38(%rbp)
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r13d
mov    %rsp,%rdx
lea    0xf(%r13),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rdx,%rsp
test   %eax,%eax
jle    1191 <strfilter3+0x71>
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    1169 <strfilter3+0x49>
add    $0x1,%rbx
cmp    %rbx,%r13
je     1191 <strfilter3+0x71>
movzbl (%r12,%rbx,1),%r14d
movsbl %r14b,%esi
mov    -0x38(%rbp),%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1160 <strfilter3+0x40>
movslq %r15d,%rax
add    $0x1,%r15d
mov    -0x30(%rbp),%rcx
mov    %r14b,(%rcx,%rax,1)
jmp    1160 <strfilter3+0x40>
mov    -0x30(%rbp),%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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