#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*/ memmove(char *, char *, int);
int strlen(char *);
char *strstr(char *, char *);
char *strrmv(char *text, char *removeword) {
  char *p = text;
  int rlen;
  rlen = strlen(removeword);
  while (NULL != (p = strstr(p, removeword))) {
    memmove(p, p + rlen, strlen(p + rlen) + 1);
  }
  return text;
}


x86 assembly (clang, -O0):
<strrmv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     11b1 <strrmv+0x81>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memmove@plt>
jmp    1154 <strrmv+0x24>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrmv>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     118d <strrmv+0x5d>
mov    %rax,%rbx
movslq %ebp,%r12
xchg   %ax,%ax
lea    (%rbx,%r12,1),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <memmove@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <strrmv+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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