#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 *, size_t);
int strlen(char const *);
char *strstr(char *, char const *);
void remove_string(char *string, const char *remove) {
  char *found;
  size_t length_remove = strlen(remove);
  while ((found = strstr(string, remove)) != NULL) {
    size_t remaining = strlen(found + length_remove) + 1;
    (void)memmove(found, found + length_remove, remaining);
  }
}


x86 assembly (clang, -O0):
<remove_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     119a <remove_string+0x6a>
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memmove@plt>
jmp    114f <remove_string+0x1f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_string>:
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     1190 <remove_string+0x60>
mov    %rax,%rbx
movslq %ebp,%r12
xchg   %ax,%ax
lea    (%rbx,%r12,1),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <memmove@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <remove_string+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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