#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 */
int /*<<< orphan*/ memset(char *, char, size_t);
size_t strlen(char *);
char *strstr(char *, char *);
char *strtok(char *, char *);
void text_filter(char *source, char *banList) {
  char *token = strtok(banList, ", ");
  while (token) {
    size_t token_length = strlen(token);
    char *substr = strstr(source, token);
    while (substr) {
      int index = substr - source;
      memset(&source[index], '*', token_length);
      substr = strstr(&(*(substr + 1)), token);
    }
    token = strtok(NULL, ", ");
  }
}


x86 assembly (clang, -O0):
<text_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f2 <text_filter+0xb2>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d9 <text_filter+0x99>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
mov    $0x2a,%esi
call   1040 <memset@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
jmp    118d <text_filter+0x4d>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe1c(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1164 <text_filter+0x24>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_filter>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rax
mov    %rdi,%r13
lea    0xeaa(%rip),%rsi
mov    %rax,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11d1 <text_filter+0x91>
mov    %rax,%r15
lea    0xe93(%rip),%r14
jmp    1182 <text_filter+0x42>
nop
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
mov    %rax,%r15
test   %rax,%rax
je     11d1 <text_filter+0x91>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1170 <text_filter+0x30>
mov    %rax,%rbx
mov    %ebx,%eax
sub    %r13d,%eax
movslq %eax,%rdi
add    %r13,%rdi
mov    $0x2a,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a0 <text_filter+0x60>
jmp    1170 <text_filter+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c", \00"
define void @text_filter(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %5
br label %11
11: ; preds = %40, %2
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %42
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %6
%17 = load i8*, i8** %3
%18 = load i8*, i8** %5
%19 = call i8* @strstr(i8* %17, i8* %18)
store i8* %19, i8** %7
br label %20
20: ; preds = %23, %14
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = load i8*, i8** %7
%25 = load i8*, i8** %3
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
store i32 %29, i32* %8
%30 = load i8*, i8** %3
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i64, i64* %6
%35 = call i32 @memset(i8* %33, i8 signext 42, i64 %34)
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8*, i8** %5
%39 = call i8* @strstr(i8* %37, i8* %38)
store i8* %39, i8** %7
br label %20
40: ; preds = %20
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %41, i8** %5
br label %11
42: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c", \00"
define void @text_filter(i8* %0, i8* %1) {
%3 = tail call i8* @strtok(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = ptrtoint i8* %0 to i64
br label %7
7: ; preds = %5, %23
%8 = phi i8* [ %3, %5 ], [ %24, %23 ]
%9 = tail call i64 @strlen(i8* %8)
%10 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* %8)
%11 = icmp eq i8* %10, null
br i1 %11, label %23, label %12
12: ; preds = %7, %12
%13 = phi i8* [ %21, %12 ], [ %10, %7 ]
%14 = ptrtoint i8* %13 to i64
%15 = sub i64 %14, %6
%16 = shl i64 %15, 32
%17 = ashr exact i64 %16, 32
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = tail call i32 @memset(i8* %18, i8 signext 42, i64 %9)
%20 = getelementptr inbounds i8, i8* %13, i64 1
%21 = tail call i8* @strstr(i8* %20, i8* %8)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %12
23: ; preds = %12, %7
%24 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %7
26: ; preds = %23, %2
ret void
}