#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 *malloc(scalar_t__);
int /*<<< orphan*/ strchr(char const *, char const);
scalar_t__ strlen(char const *);
char *strip_chars(const char *string, const char *chars) {
  char *newstr = malloc(strlen(string) + 1);
  int counter = 0;
  for (; *string; string++) {
    if (!strchr(chars, *string)) {
      newstr[counter] = *string;
      ++counter;
    }
  }
  newstr[counter] = 0;
  return newstr;
}


x86 assembly (clang, -O0):
<strip_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b6 <strip_chars+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%eax
jne    11a0 <strip_chars+0x70>
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a5 <strip_chars+0x75>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1160 <strip_chars+0x30>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_chars>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    (%rbx),%al
test   %al,%al
je     118b <strip_chars+0x5b>
add    $0x1,%rbx
xor    %r12d,%r12d
jmp    116b <strip_chars+0x3b>
xchg   %ax,%ax
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     118e <strip_chars+0x5e>
movsbl %al,%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %eax,%eax
jne    1160 <strip_chars+0x30>
movzbl -0x1(%rbx),%eax
movslq %r12d,%r12
mov    %al,(%r15,%r12,1)
add    $0x1,%r12d
jmp    1160 <strip_chars+0x30>
xor    %r12d,%r12d
movslq %r12d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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