#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 */
scalar_t__ 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 = (char *)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 i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
store i32 0, i32* %6
br label %12
12: ; preds = %32, %2
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %35
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = call i32 @strchr(i8* %17, i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %31, label %22
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %31
31: ; preds = %22, %16
br label %32
32: ; preds = %31
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
br label %12
35: ; preds = %12
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %5
ret i8* %40
}

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