#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strfilter4(char *string, char *letters) {
  char buffer[100];
  char c;
  while (c = *string++) {
    char *ptr = strchr(letters, c);
    if (ptr) {
      strcat(buffer, c);
    }
  }
  int length = sizeof(buffer);
  char *res = (char *)malloc(length * sizeof(char));
  strcpy(buffer, res);
  return res;
}


x86 assembly (clang, -O0):
<strfilter4>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x81(%rbp)
cmp    $0x0,%al
je     11ac <strfilter4+0x6c>
mov    -0x10(%rbp),%rdi
movsbl -0x81(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
je     11a7 <strfilter4+0x67>
lea    -0x80(%rbp),%rdi
movsbl -0x81(%rbp),%esi
call   1060 <strcat@plt>
jmp    1153 <strfilter4+0x13>
movl   $0x64,-0x94(%rbp)
movslq -0x94(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0xa0(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xa0(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfilter4>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    (%rdi),%al
test   %al,%al
je     1189 <strfilter4+0x49>
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x1,%rbx
mov    %rsp,%r15
jmp    116b <strfilter4+0x2b>
nop
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1189 <strfilter4+0x49>
movsbl %al,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1160 <strfilter4+0x20>
mov    %r15,%rdi
mov    %ebp,%esi
call   1060 <strcat@plt>
jmp    1160 <strfilter4+0x20>
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @strfilter4(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [100 x i8]
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %10
10: ; preds = %25, %2
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
%13 = load i8, i8* %11
store i8 %13, i8* %6
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i8, i8* %6
%18 = call i8* @strchr(i8* %16, i8 signext %17)
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%23 = load i8, i8* %6
%24 = call i32 @strcat(i8* %22, i8 signext %23)
br label %25
25: ; preds = %21, %15
br label %10
26: ; preds = %10
store i32 100, i32* %8
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 1
%30 = trunc i64 %29 to i32
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %9
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%34 = load i8*, i8** %9
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i8*, i8** %9
ret i8* %36
}

LLVM IR (-O2):
define i8* @strfilter4(i8* nocapture %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %18, label %7
7: ; preds = %2, %15
%8 = phi i8 [ %16, %15 ], [ %5, %2 ]
%9 = phi i8* [ %10, %15 ], [ %0, %2 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = call i8* @strchr(i8* dereferenceable(1) %1, i8 signext %8)
%12 = icmp eq i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = call i32 @strcat(i8* %4, i8 signext %8)
br label %15
15: ; preds = %13, %7
%16 = load i8, i8* %10
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %7
18: ; preds = %15, %2
%19 = call i64 @malloc(i32 100)
%20 = inttoptr i64 %19 to i8*
%21 = call i32 @strcpy(i8* %4, i8* %20)
ret i8* %20
}