#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*/ memcpy(char *, char *, int);
int strlen(char *);
char *strstr(char *, char *);
void str_remove(char *str, char *remove) {
  int len, rlen;
  char *pch;
  len = strlen(str);
  rlen = strlen(remove);
  pch = strstr(str, remove);
  while (pch) {
    memcpy(pch, pch + rlen, rlen + 1);
    pch = strstr(pch, remove);
  }
  return;
}


x86 assembly (clang, -O0):
<str_remove>:
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    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a4 <str_remove+0x74>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
jmp    1169 <str_remove+0x39>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_remove>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1191 <str_remove+0x61>
mov    %rax,%rbx
movslq %ebp,%r15
lea    0x1(%r15),%ebp
cs nopw 0x0(%rax,%rax,1)
lea    (%rbx,%r15,1),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1170 <str_remove+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @str_remove(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %6
%12 = load i8*, i8** %3
%13 = load i8*, i8** %4
%14 = call i8* @strstr(i8* %12, i8* %13)
store i8* %14, i8** %7
br label %15
15: ; preds = %18, %2
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = load i8*, i8** %7
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
%26 = call i32 @memcpy(i8* %19, i8* %23, i32 %25)
%27 = load i8*, i8** %7
%28 = load i8*, i8** %4
%29 = call i8* @strstr(i8* %27, i8* %28)
store i8* %29, i8** %7
br label %15
30: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @str_remove(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = sext i32 %4 to i64
%9 = add nsw i32 %4, 1
br label %10
10: ; preds = %7, %10
%11 = phi i8* [ %5, %7 ], [ %14, %10 ]
%12 = getelementptr inbounds i8, i8* %11, i64 %8
%13 = tail call i32 @memcpy(i8* %11, i8* %12, i32 %9)
%14 = tail call i8* @strstr(i8* %11, i8* dereferenceable(1) %1)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %10
16: ; preds = %10, %2
ret void
}